forked from CMU-313/nodebb-spring-26-clean-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-redis-url.sh
More file actions
43 lines (34 loc) · 880 Bytes
/
Copy pathparse-redis-url.sh
File metadata and controls
43 lines (34 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env sh
set -eu
uri="${REDIS_URL:-}"
# Drop scheme
rest="${uri#redis://}"
# Defaults
REDIS_USERNAME=""
REDIS_PASSWORD=""
# Split creds vs host:port
if [ "${rest#*@}" != "$rest" ]; then
creds="${rest%@*}" # user:password (or just user)
hostport="${rest#*@}" # host:port[/...]
if [ "${creds#*:}" != "$creds" ]; then
REDIS_USERNAME="${creds%%:*}"
REDIS_PASSWORD="${creds#*:}"
else
REDIS_USERNAME="$creds"
REDIS_PASSWORD=""
fi
else
hostport="$rest"
fi
# Strip any /db suffix
hostport="${hostport%%/*}"
REDIS_HOST="${hostport%%:*}"
REDIS_PORT="${hostport##*:}"
# Export generic vars
# export REDIS_HOST REDIS_PORT REDIS_USERNAME REDIS_PASSWORD
# Export NodeBB vars
export NODEBB_DB_HOST="$REDIS_HOST"
export NODEBB_DB_PORT="$REDIS_PORT"
export NODEBB_DB_USER="$REDIS_USERNAME"
export NODEBB_DB_PASSWORD="$REDIS_PASSWORD"
exec "$@"