-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy path50-config
89 lines (77 loc) · 2.6 KB
/
50-config
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/with-contenv bash
# create directory structure
mkdir -p \
/config/www/{uploads,files,images}
# check for .env and copy default if needed
[[ ! -f "/config/www/.env" ]] && \
cp /var/www/html/.env.example /config/www/.env
# create symlinks
symlinks=( \
/var/www/html/storage/uploads/files \
/var/www/html/storage/uploads/images \
/var/www/html/public/uploads \
/var/www/html/.env \
/var/www/html/storage/logs/laravel.log
)
for i in "${symlinks[@]}"
do
[[ -e "$i" && ! -L "$i" ]] && rm -rf "$i"
[[ ! -L "$i" ]] && ln -s /config/www/"$(basename "$i")" "$i"
done
# Echo init finish for test runs
if [ -n "${TEST_RUN}" ]; then
echo '[services.d] done.'
fi
# Create API key if needed
if [ ! -f "/config/BOOKSTACK_APP_KEY.txt" ];
then
echo "Generating BookStack app key for first run"
key=$(php /var/www/html/artisan key:generate --show)
echo $key > /config/BOOKSTACK_APP_KEY.txt
echo "App Key set to $key you can modify the file to update /config/BOOKSTACK_APP_KEY.txt"
elif [ -f "/config/BOOKSTACK_APP_KEY.txt" ];
then
echo "App Key found - setting variable for seds"
key=$(cat /config/BOOKSTACK_APP_KEY.txt)
fi
# .env file setup
# check for the default app key or if it has been updated
if grep -Fxq "APP_KEY=SomeRandomString" /config/www/.env || \
! grep -Fxq "APP_KEY=${key}" /config/www/.env; then
sed -i "s#^APP_KEY=.*#APP_KEY=${key}#" /config/www/.env
fi
# check to see if db_user is set, if it is then run seds and if not then leave them
if [ "${DB_USER}" ];
then
echo "Running config - db_user set"
sed -i "s/DB_HOST=localhost/DB_HOST=${DB_HOST}/g" /config/www/.env
sed -i "s/DB_DATABASE=database_database/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env
sed -i "s/DB_USERNAME=database_username/DB_USERNAME=${DB_USER}/g" /config/www/.env
sed -i "s/DB_PASSWORD=database_user_password/DB_PASSWORD=${DB_PASS}/g" /config/www/.env
fi
# set appurl if detected
[[ "${APP_URL}" ]] && sed -i "s,#\sAPP_URL.*,APP_URL=${APP_URL},g" /config/www/.env
# check for the mysql endpoint for 30 seconds
END=$((SECONDS+30))
while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST+x}" ]; do
/usr/bin/nc -z ${DB_HOST} 3306 && \
if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} 3306)" ]; then
[ ! -z "${RUN}" ] && break
RUN="RAN"
# we sleep here again due to first run init on DB containers
[ ! -f /dbwait.lock ] && sleep 5
else
sleep 1
fi
sleep 1
done
# update database - will set up database if fresh, or, migrate existing
if [ -z "${CI_RUN+x}" ]; then
php /var/www/html/artisan migrate --force
fi
# set permissions
chown -R abc:abc \
/config \
/var/www/
# set lockfile to avoid DB waits for this specific container
touch /dbwait.lock