-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathentrypoint.sh
152 lines (132 loc) · 4.53 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
set -ex
# Constants
readonly DFT_LOG_FLR="/var/log/librebooking"
readonly DFT_LOG_LEVEL="none"
readonly DFT_LOG_SQL=false
readonly DFT_LB_ENV="production"
readonly DFT_LB_PATH=""
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}}
LB_PATH=${LB_PATH:-${DFT_LB_PATH}}
# 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 directory /config
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'\]\['name'\]\) = '.*':\1 = '${LB_DB_NAME}':"
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
# Set secondary configuration settings
sed \
-i /config/config.php \
-e "s:\(\['install.password'\]\) = '.*':\1 = '${LB_INSTALL_PWD}':" \
-e "s:\(\['default.timezone'\]\) = '.*':\1 = '${TZ}':" \
-e "s:\(\['database'\]\['hostspec'\]\) = '.*':\1 = '${LB_DB_HOST}':" \
-e "s:\(\['logging'\]\['folder'\]\) = '.*':\1 = '${LB_LOG_FOLDER}':" \
-e "s:\(\['logging'\]\['level'\]\) = '.*':\1 = '${LB_LOG_LEVEL}':" \
-e "s:\(\['logging'\]\['sql'\]\) = '.*':\1 = '${LB_LOG_SQL}':"
# 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})"
fi
if ! [ -f ${target} ]; then
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
# A URL path prefix was set
if ! test -z "${LB_PATH}"; then
## Set server document root 1 directory up
sed \
-i /etc/apache2/sites-enabled/000-default.conf \
-e "s:/var/www/html:/var/www:"
## Rename the html directory as the URL prefix
ln -s /var/www/html "/var/www/${LB_PATH}"
chown www-data:www-data "/var/www/${LB_PATH}"
## Adapt the .htaccess file
sed \
-i /var/www/${LB_PATH}/.htaccess \
-e "s:\(RewriteCond .*\)/Web/:\1\.\*/Web/:" \
-e "s:\(RewriteRule .*\) /Web/:\1 /${LB_PATH}/Web/:"
fi
# Run the apache server
exec "$@"