8
8
9
9
# create directory structure
10
10
mkdir -p \
11
- /config/www/{uploads,files,images,themes}
11
+ /config/www/{uploads,files,images,themes}
12
12
13
13
# check for .env and copy default if needed
14
14
if [[ ! -f "/config/www/.env" ]] || [[ ! -s "/config/www/.env" ]]; then
15
15
cp /app/www/.env.example /config/www/.env
16
16
fi
17
17
18
18
# create symlinks
19
- symlinks=( \
20
- /app/www/themes \
21
- /app/www/storage/uploads/files \
22
- /app/www/storage/uploads/images \
23
- /app/www/public/uploads \
24
- /app/www/.env \
25
- /app/www/storage/logs/laravel.log
19
+ symlinks=(
20
+ /app/www/themes
21
+ /app/www/storage/uploads/files
22
+ /app/www/storage/uploads/images
23
+ /app/www/public/uploads
24
+ /app/www/.env
25
+ /app/www/storage/logs/laravel.log
26
26
)
27
27
28
- for i in "${symlinks[@]}"
29
- do
30
- if [[ -e "$i" && ! -L "$i" ]]; then
31
- rm -rf "$i"
28
+ for i in "${symlinks[@]}"; do
29
+ if [[ -e "${i}" && ! -L "${i}" ]]; then
30
+ rm -rf "${i}"
32
31
fi
33
- if [[ ! -L "$i " ]]; then
34
- ln -s /config/www/"$(basename "$i ")" "$i "
32
+ if [[ ! -L "${i} " ]]; then
33
+ ln -s /config/www/"$(basename "${i} ")" "${i} "
35
34
fi
36
35
done
37
36
@@ -41,42 +40,58 @@ if [ -n "${TEST_RUN}" ]; then
41
40
fi
42
41
43
42
# Create API key if needed
44
- if [ ! -f "/config/BOOKSTACK_APP_KEY.txt" ];
45
- then
43
+ if [ ! -f "/config/BOOKSTACK_APP_KEY.txt" ]; then
46
44
echo "Generating BookStack app key for first run"
47
45
key=$(php /app/www/artisan key:generate --show)
48
- echo $key > /config/BOOKSTACK_APP_KEY.txt
49
- echo "App Key set to $key you can modify the file to update /config/BOOKSTACK_APP_KEY.txt"
50
- elif [ -f "/config/BOOKSTACK_APP_KEY.txt" ];
51
- then
46
+ echo "${key}" >/config/BOOKSTACK_APP_KEY.txt
47
+ echo "App Key set to ${key} you can modify the file to update /config/BOOKSTACK_APP_KEY.txt"
48
+ elif [ -f "/config/BOOKSTACK_APP_KEY.txt" ]; then
52
49
echo "App Key found - setting variable for seds"
53
50
key=$(cat /config/BOOKSTACK_APP_KEY.txt)
54
51
fi
55
52
56
53
# .env file setup
57
54
# check for the default app key or if it has been updated
58
- if grep -Fxq "APP_KEY=SomeRandomString" /config/www/.env || \
59
- ! grep -Fxq "APP_KEY=${key}" /config/www/.env; then
55
+ if ! grep -Fxq "APP_KEY=${key}" /config/www/.env; then
60
56
sed -i "s#^APP_KEY=.*#APP_KEY=${key}#" /config/www/.env
61
57
fi
62
- # check to see if db_user is set, if it is then run seds and if not then leave them
63
- if [ "${DB_USER}" ];
64
- then
65
- echo "Running config - db_user set"
66
- sed -i "s/^DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/www/.env
67
- sed -i "s/^DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env
68
- sed -i "s/^DB_USERNAME=.*/DB_USERNAME=${DB_USER}/g" /config/www/.env
69
- sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=${DB_PASS}/g" /config/www/.env
70
-
71
- if [ -n "${DB_PORT}" ]; then
72
- if ! grep -xq "^DB_PORT=.*" /config/www/.env; then
73
- # add line DB_PORT=3306 to /config/www/.env because current /app/www/.env.example dont have it
74
- sed -i "/^DB_HOST=.*/a DB_PORT=${DB_PORT}" /config/www/.env
75
- echo "**** Insert DB_PORT=${DB_PORT} into /config/www/.env ****"
76
- else
77
- sed -i "s/^DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env
78
- fi
79
- fi
58
+
59
+ # if DB_HOST contains a port
60
+ if echo "${DB_HOST}" | grep -qP '^(?:[0-9.]+|(?:\[[0-9a-fA-F:]+\]))(:[0-9]+)$'; then
61
+ DB_HOST_PORT="${DB_HOST}"
62
+ fi
63
+
64
+ # if DB_HOST_PORT is set
65
+ if [[ -n "${DB_HOST_PORT}" ]]; then
66
+ # if DB_PORT is set
67
+ if [[ -n "${DB_PORT}" ]]; then
68
+ echo "DB_PORT is not supported when using DB_HOST with port"
69
+ sleep infinity
70
+ fi
71
+ DB_HOST="${DB_HOST_PORT%:*}"
72
+ DB_PORT="${DB_HOST_PORT##*:}"
73
+ fi
74
+
75
+ # if DB_PORT is not set
76
+ if [[ -z "${DB_PORT}" ]]; then
77
+ DB_PORT="3306"
78
+ fi
79
+
80
+ # check to see if DB_HOST is set, if it is then run seds and if not then leave them
81
+ if [[ -n "${DB_HOST}" ]]; then
82
+ echo "Running config - DB_HOST set"
83
+
84
+ if ! grep -xq "^DB_PORT=.*" /config/www/.env; then
85
+ # add DB_PORT line to /config/www/.env because current /app/www/.env.example doesn't have it
86
+ sed -i "/^DB_HOST=.*/a DB_PORT=${DB_PORT}" /config/www/.env
87
+ echo "**** Insert DB_PORT=${DB_PORT} into /config/www/.env ****"
88
+ fi
89
+
90
+ sed -i "s/^DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/www/.env
91
+ sed -i "s/^DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env
92
+ sed -i "s/^DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env
93
+ sed -i "s/^DB_USERNAME=.*/DB_USERNAME=${DB_USER}/g" /config/www/.env
94
+ sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=${DB_PASS}/g" /config/www/.env
80
95
fi
81
96
82
97
# set appurl
99
114
100
115
## Bump php upload max filesize and post max size to 100MB by default
101
116
if ! grep -qx '^upload_max_filesize.*$' /config/php/php-local.ini; then
102
- echo 'upload_max_filesize = 100M' >> /config/php/php-local.ini
117
+ echo 'upload_max_filesize = 100M' >>/config/php/php-local.ini
103
118
fi
104
119
if ! grep -qx '^post_max_size.*$' /config/php/php-local.ini; then
105
- echo 'post_max_size = 100M' >> /config/php/php-local.ini
120
+ echo 'post_max_size = 100M' >>/config/php/php-local.ini
106
121
fi
107
122
108
- # extract actual host and port from DB_HOST endpoint format, not support IPv6
109
- # DB_HOST enpoint 'domainIp:port' or 'domainIp'
110
- # DB_HOST_ONLY drop ':port' portion
111
- # DB_PORT_ONLY drop host_only portion, remains '' or ':port'
112
- # DB_PORT_ONLY drop ':' if any, remain '' or 'port'
113
- # ${DB_PORT_ONLY:-${DB_PORT:-3306}} use DB_PORT if no port provided in DB_HOST, use default 3306 if not provide DB_PORT
114
- DB_HOST_ONLY=${DB_HOST%:*}
115
- DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY}
116
- DB_PORT_ONLY=${DB_PORT_ONLY#:}
117
-
118
123
# check for the mysql endpoint for 30 seconds
119
- END=$((SECONDS+ 30))
120
- while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST_ONLY+x }" ]; do
121
- if /usr/bin/nc -z ${DB_HOST_ONLY} ${DB_PORT_ONLY:-${ DB_PORT:-3306}} ; then
122
- if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST_ONLY} ${DB_PORT_ONLY:-${ DB_PORT:-3306}} )" ]; then
123
- if [ ! -z "${RUN}" ]; then
124
+ END=$((SECONDS + 30))
125
+ while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST }" ]; do
126
+ if /usr/bin/nc -z "${DB_HOST}" "${ DB_PORT}" ; then
127
+ if [ -n "$(/usr/bin/nc -w1 "${DB_HOST}" "${ DB_PORT}" )" ]; then
128
+ if [ -n "${RUN}" ]; then
124
129
break
125
130
fi
126
131
RUN="RAN"
0 commit comments