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,32 +40,59 @@ 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
58
+
59
+ # if DB_HOST contains a port and DB_HOST is not a IPv6 without brackets [..]
60
+ # support ipv4:port, [ipv6]:port, and domain:port
61
+ if [[ ${DB_HOST} =~ :[0-9]+$ ]] && ! [[ ${DB_HOST} =~ ^(:{0,2}[a-fA-F0-9]{1,4})+$ ]]; then
62
+ DB_HOST_PORT="${DB_HOST}"
63
+ fi
64
+
65
+ # if DB_HOST_PORT is set
66
+ if [[ -n "${DB_HOST_PORT}" ]]; then
67
+ # if DB_PORT is set
68
+ if [[ -n "${DB_PORT}" ]]; then
69
+ echo "DB_PORT is not supported when using DB_HOST with port"
70
+ sleep infinity
71
+ fi
72
+ DB_HOST="${DB_HOST_PORT%:*}"
73
+ DB_PORT="${DB_HOST_PORT##*:}"
74
+ fi
75
+
76
+ # if DB_PORT is not set
77
+ if [[ -z "${DB_PORT}" ]]; then
78
+ DB_PORT="3306"
79
+ fi
80
+
81
+ # check to see if DB_HOST is set, if it is then run seds and if not then leave them
82
+ if [[ -n "${DB_HOST}" ]]; then
83
+ echo "Running config - DB_HOST set"
84
+
85
+ if ! grep -xqE "^[#]?DB_PORT=.*" /config/www/.env; then
86
+ # add DB_PORT line to /config/www/.env because current /app/www/.env.example doesn't have it
87
+ sed -i -E "/^[#]?DB_HOST=.*/a DB_PORT=${DB_PORT}" /config/www/.env
88
+ echo "**** Insert DB_PORT=${DB_PORT} into /config/www/.env ****"
89
+ fi
90
+
91
+ sed -i -E "s/^[#]?DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/www/.env
92
+ sed -i -E "s/^[#]?DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/www/.env
93
+ sed -i -E "s/^[#]?DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env
94
+ sed -i -E "s/^[#]?DB_USERNAME=.*/DB_USERNAME=${DB_USER}/g" /config/www/.env
95
+ sed -i -E "s/^[#]?DB_PASSWORD=.*/DB_PASSWORD=${DB_PASS}/g" /config/www/.env
70
96
fi
71
97
72
98
# set appurl
89
115
90
116
## Bump php upload max filesize and post max size to 100MB by default
91
117
if ! grep -qx '^upload_max_filesize.*$' /config/php/php-local.ini; then
92
- echo 'upload_max_filesize = 100M' >> /config/php/php-local.ini
118
+ echo 'upload_max_filesize = 100M' >>/config/php/php-local.ini
93
119
fi
94
120
if ! grep -qx '^post_max_size.*$' /config/php/php-local.ini; then
95
- echo 'post_max_size = 100M' >> /config/php/php-local.ini
121
+ echo 'post_max_size = 100M' >>/config/php/php-local.ini
96
122
fi
97
123
98
124
# check for the mysql endpoint for 30 seconds
99
- END=$((SECONDS+ 30))
100
- while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST+x }" ]; do
101
- if /usr/bin/nc -z ${DB_HOST} 3306 ; then
102
- if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} 3306 )" ]; then
103
- if [ ! -z "${RUN}" ]; then
125
+ END=$((SECONDS + 30))
126
+ while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST}" ]; do
127
+ if /usr/bin/nc -z " ${DB_HOST}" "${DB_PORT}" ; then
128
+ if [ -n "$(/usr/bin/nc -w1 " ${DB_HOST}" "${DB_PORT}" )" ]; then
129
+ if [ -n "${RUN}" ]; then
104
130
break
105
131
fi
106
132
RUN="RAN"
0 commit comments