forked from LibreBooking/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
125 lines (109 loc) · 3.87 KB
/
entrypoint.sh
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
set -ex
# Constants
readonly DFT_LOG_FLR="/var/log/librebooking/log"
readonly DFT_LOG_LEVEL="debug"
readonly DFT_LOG_SQL=false
readonly DFT_LB_ENV="production"
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
if [ -n "${varValue}" ]; then
export "$var"="${varValue}"
elif [ -n "${fileVarValue}" ]; then
export "$var"="$(cat "${fileVarValue}")"
elif [ -n "${def}" ]; then
export "$var"="$def"
fi
unset "$fileVar"
}
# Exit if incompatible mount (images prior to V2)
if [ "$(mount | grep /var/www/html)" = "/var/www/html" ]; then
echo "The volume must be mapped to container directory /config" >2
exit 1
fi
# Initialize variables
file_env LB_INSTALL_PWD
file_env LB_DB_USER_PWD
LB_LOG_FOLDER=${LB_LOG_FOLDER:-${DFT_LOG_FLR}}
LB_LOG_LEVEL=${LB_LOG_LEVEL:-${DFT_LOG_LEVEL}}
LB_LOG_SQL=${LB_LOG_SQL:-${DFT_LOG_SQL}}
LB_ENV=${LB_ENV:-${DFT_LB_ENV}}
# If volume was used with images older than v2, then archive useless files
pushd /config
if [ -d Web ]; then
mkdir archive
chown www-data:www-data archive
mv $(ls --ignore=archive) archive
if [ -f archive/config/config.php ]; then
cp archive/config/config.php config.php
chown www-data:www-data config.php
fi
fi
popd
# No configuration file inside the volume
if ! [ -f /config/config.php ]; then
echo "Initialize file config.php"
if [ "${LB_ENV}" = "dev" ]; then
cp /var/www/html/config/config.devel.php /config/config.php
else
cp /var/www/html/config/config.dist.php /config/config.php
fi
chown www-data:www-data /config/config.php
sed \
-i /config/config.php \
-e "s:\(\['registration.captcha.enabled'\]\) = 'true':\1 = 'false':" \
-e "s:\(\['database'\]\['user'\]\) = '.*':\1 = '${LB_DB_USER}':" \
-e "s:\(\['database'\]\['password'\]\) = '.*':\1 = '${LB_DB_USER_PWD}':" \
-e "s:\(\['database'\]\['hostspec'\]\) = '127.0.0.1':\1 = '${LB_DB_HOST}':" \
-e "s:\(\['database'\]\['name'\]\) = '.*':\1 = '${LB_DB_NAME}':" \
-e "s:\(\['install.password'\]\) = '.*':\1 = '${LB_INSTALL_PWD}':" \
-e "s:\(\['default.timezone'\]\) = '.*':\1 = '${TZ}':" \
-e "s:\(\['logging'\]\['folder'\]\) = '/var/log/librebooking/log':\1 = '${LB_LOG_FOLDER}':" \
-e "s:\(\['logging'\]\['level'\]\) = 'debug':\1 = '${LB_LOG_LEVEL}':" \
-e "s:\(\['logging'\]\['sql'\]\) = 'false':\1 = '${LB_LOG_SQL}':"
fi
# Link the configuration file
if ! [ -f /var/www/html/config/config.php ]; then
ln -s /config/config.php /var/www/html/config/config.php
fi
# Create the plugins configuration file inside the volume
for source in $(find /var/www/html/plugins -type f -name "*dist*"); do
target=$(echo "${source}" | sed -e "s/.dist//")
if ! [ -f "/config/$(basename ${target})" ]; then
cp --no-clobber "${source}" "/config/$(basename ${target})"
chown www-data:www-data "/config/$(basename ${target})"
ln -s "/config/$(basename ${target})" "${target}"
fi
done
# Set timezone
if test -f /usr/share/zoneinfo/${TZ}; then
ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
INI_FILE="/usr/local/etc/php/conf.d/librebooking.ini"
echo "[date]" > ${INI_FILE}
echo "date.timezone=\"${TZ}\"" >> ${INI_FILE}
fi
# Get log directory
log_flr=$(grep \
-e "\['logging'\]\['folder'\]" \
/var/www/html/config/config.php \
| cut -d " " -f3 | cut -d "'" -f2)
log_flr=${log_flr:-${DFT_LOG_FLR}}
# Missing log directory
if ! test -d "${log_flr}"; then
mkdir -p "${log_flr}"
chown -R www-data:www-data "${log_flr}"
fi
# Missing log file
if ! test -f "${log_flr}/app.log"; then
touch "${log_flr}/app.log"
chown www-data:www-data "${log_flr}/app.log"
fi
exec "$@"