-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy path.profile
More file actions
40 lines (33 loc) · 1.17 KB
/
Copy path.profile
File metadata and controls
40 lines (33 loc) · 1.17 KB
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
replace_in_config() {
key="$1"
value="$2"
sed -i -r "s|(${key}\s+)=.+\$|\1= '${value}';|" /app/build/config.php
}
# Parse MySQL_URL
protocol="$(echo "$MYSQL_URL" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
url="$(echo ${MYSQL_URL/$protocol/})"
# extract the credentials
userpass="$(echo $url | grep @ | cut -d@ -f1)"
password="$(echo $userpass | grep : | cut -d: -f2)"
if [ -n "$password" ]; then
# We received a password, so split to retrieve the username
username="$(echo $userpass | grep : | cut -d: -f1)"
else
# Username has been supplied, no password
username=$userpass
fi
# extract the host
host="$(echo ${url/$user@/} | cut -d/ -f1 | rev | cut -d':' -f2- | rev)"
# Remove credentials from the host if present
basename="$(echo ${host#"$userpass"})"
# extract the path
path="$(echo $url | grep / | cut -d/ -f2-)"
if [ ! -f "/app/build/config.php" ]; then
cp /app/build/config-sample.php /app/build/config.php
echo "Created /app/build/config.php"
fi
replace_in_config "BASE_URL" "$BASE_URL"
replace_in_config "DB_HOST" "$basename"
replace_in_config "DB_NAME" "$path"
replace_in_config "DB_USERNAME" "$username"
replace_in_config "DB_PASSWORD" "$password"