@@ -9,29 +9,31 @@ readonly DFT_LOGGING_SQL=false
99readonly DFT_APP_PATH=" "
1010
1111file_env () {
12- local var=" $1 "
13- local fileVar=" ${var} _FILE"
14- local def=" ${2:- } "
15- local varValue=$( env | grep -E " ^${var} =" | sed -E -e " s/^${var} =//" )
16- local fileVarValue=$( env | grep -E " ^${fileVar} =" | sed -E -e " s/^${fileVar} =//" )
17- if [ -n " ${varValue} " ] && [ -n " ${fileVarValue} " ]; then
18- echo >&2 " error: both $var and $fileVar are set (but are exclusive)"
19- exit 1
20- fi
21- if [ -n " ${varValue} " ]; then
22- export " $var " =" ${varValue} "
23- elif [ -n " ${fileVarValue} " ]; then
24- export " $var " =" $( cat " ${fileVarValue} " ) "
25- elif [ -n " ${def} " ]; then
26- export " $var " =" $def "
27- fi
28- unset " $fileVar "
12+ local var=" $1 "
13+ local fileVar=" ${var} _FILE"
14+ local def=" ${2:- } "
15+ local varValue
16+ varValue=$( env | grep -E " ^${var} =" | sed -E -e " s/^${var} =//" )
17+ local fileVarValue
18+ fileVarValue=$( env | grep -E " ^${fileVar} =" | sed -E -e " s/^${fileVar} =//" )
19+ if [ -n " ${varValue} " ] && [ -n " ${fileVarValue} " ]; then
20+ echo >&2 " error: both $var and $fileVar are set (but are exclusive)"
21+ exit 1
22+ fi
23+ if [ -n " ${varValue} " ]; then
24+ export " $var " =" ${varValue} "
25+ elif [ -n " ${fileVarValue} " ]; then
26+ export " $var " =" $( cat " ${fileVarValue} " ) "
27+ elif [ -n " ${def} " ]; then
28+ export " $var " =" $def "
29+ fi
30+ unset " $fileVar "
2931}
3032
3133# Exit if incompatible mount (images prior to V2)
3234if [ " $( mount | grep /var/www/html) " = " /var/www/html" ]; then
33- echo " The volume must be mapped to container directory /config" > 2
34- exit 1
35+ echo " The volume must be mapped to container directory /config" >& 2
36+ exit 1
3537fi
3638
3739# Initialize variables
@@ -46,85 +48,85 @@ APP_PATH=${APP_PATH:-${DFT_APP_PATH}}
4648# If volume was used with images older than v2, then archive useless files
4749pushd /config
4850if [ -d Web ]; then
49- mkdir archive
50- mv $( ls --ignore=archive) archive
51- if [ -f archive/config/config.php ]; then
52- cp archive/config/config.php config.php
53- fi
51+ mkdir archive
52+ mv " $( ls --ignore=archive) " archive
53+ if [ -f archive/config/config.php ]; then
54+ cp archive/config/config.php config.php
55+ fi
5456fi
5557popd
5658
5759# No configuration file inside directory /config
5860if ! [ -f /config/config.php ]; then
59- echo " Initialize file config.php"
60- cp /var/www/html/config/config.dist.php /config/config.php
61+ echo " Initialize file config.php"
62+ cp /var/www/html/config/config.dist.php /config/config.php
6163fi
6264
6365# Link the configuration file
6466if ! [ -f /var/www/html/config/config.php ]; then
65- ln -s /config/config.php /var/www/html/config/config.php
67+ ln -s /config/config.php /var/www/html/config/config.php
6668fi
6769
6870# Set configuration settings for Librebooking < v4.0.0
6971sed \
70- -i /config/config.php \
71- -e " s:\(\['database'\]\['user'\].*\) '.*':\1 '${LB_DATABASE_USER} ':" \
72- -e " s:\(\['database'\]\['password'\].*\) '.*':\1 '${LB_DATABASE_PASSWORD} ':" \
73- -e " s:\(\['database'\]\['name'\].*\) '.*':\1 '${LB_DATABASE_NAME} ':" \
74- -e " s:\(\['install.password'\].*\) '.*':\1 '${LB_INSTALL_PASSWORD} ':" \
75- -e " s:\(\['default.timezone'\].*\) '.*':\1 '${LB_DEFAULT_TIMEZONE} ':" \
76- -e " s:\(\['database'\]\['hostspec'\].*\) '.*':\1 '${LB_DATABASE_HOSTSPEC} ':" \
77- -e " s:\(\['logging'\]\['folder'\].*\) '.*':\1 '${LB_LOGGING_FOLDER} ':" \
78- -e " s:\(\['logging'\]\['level'\].*\) '.*':\1 '${LB_LOGGING_LEVEL} ':" \
79- -e " s:\(\['logging'\]\['sql'\].*\) '.*':\1 '${LB_LOGGING_SQL} ':"
72+ -i /config/config.php \
73+ -e " s:\(\['database'\]\['user'\].*\) '.*':\1 '${LB_DATABASE_USER} ':" \
74+ -e " s:\(\['database'\]\['password'\].*\) '.*':\1 '${LB_DATABASE_PASSWORD} ':" \
75+ -e " s:\(\['database'\]\['name'\].*\) '.*':\1 '${LB_DATABASE_NAME} ':" \
76+ -e " s:\(\['install.password'\].*\) '.*':\1 '${LB_INSTALL_PASSWORD} ':" \
77+ -e " s:\(\['default.timezone'\].*\) '.*':\1 '${LB_DEFAULT_TIMEZONE} ':" \
78+ -e " s:\(\['database'\]\['hostspec'\].*\) '.*':\1 '${LB_DATABASE_HOSTSPEC} ':" \
79+ -e " s:\(\['logging'\]\['folder'\].*\) '.*':\1 '${LB_LOGGING_FOLDER} ':" \
80+ -e " s:\(\['logging'\]\['level'\].*\) '.*':\1 '${LB_LOGGING_LEVEL} ':" \
81+ -e " s:\(\['logging'\]\['sql'\].*\) '.*':\1 '${LB_LOGGING_SQL} ':"
8082
8183# Create the plugins configuration file inside the volume
82- for source in $( find /var/www/html/plugins -type f -name " *dist* " ) ; do
83- target=$( echo " $ {source} " | sed -e " s/ .dist// " )
84- if ! [ -f " /config/$( basename ${target} ) " ]; then
85- cp --no-clobber " ${source} " " /config/$( basename ${target} ) "
86- fi
87- if ! [ -f ${target} ]; then
88- ln -s " /config/$( basename ${target} ) " " ${target} "
89- fi
90- done
84+ while IFS= read -r -d ' ' source ; do
85+ target=${source// .dist/ }
86+ if ! [ -f " /config/$( basename " ${target} " ) " ]; then
87+ cp --no-clobber " ${source} " " /config/$( basename " ${target} " ) "
88+ fi
89+ if ! [ -f " ${target} " ]; then
90+ ln -s " /config/$( basename " ${target} " ) " " ${target} "
91+ fi
92+ done < <( find /var/www/html/plugins -type f -name " *dist* " -print0 )
9193
9294# Set the php timezone file
93- if [ -f /usr/share/zoneinfo/${LB_DEFAULT_TIMEZONE} ]; then
94- INI_FILE=" /usr/local/etc/php/conf.d/librebooking.ini"
95- echo " [Date]" >> ${INI_FILE}
96- echo " date.timezone=\" ${LB_DEFAULT_TIMEZONE} \" " >> ${INI_FILE}
95+ if [ -f /usr/share/zoneinfo/" ${LB_DEFAULT_TIMEZONE} " ]; then
96+ INI_FILE=" /usr/local/etc/php/conf.d/librebooking.ini"
97+ echo " [Date]" >> ${INI_FILE}
98+ echo " date.timezone=\" ${LB_DEFAULT_TIMEZONE} \" " >> ${INI_FILE}
9799fi
98100
99101# Missing log directory
100102if ! [ -d " ${LB_LOGGING_FOLDER} " ]; then
101- mkdir -p " ${LB_LOGGING_FOLDER} "
103+ mkdir -p " ${LB_LOGGING_FOLDER} "
102104fi
103105
104106# A URL path prefix was set
105- if ! [ -z " ${APP_PATH} " ]; then
106- # # Set server document root 1 directory up
107- sed \
108- -i /etc/apache2/sites-enabled/000-default.conf \
109- -e " s:/var/www/html:/var/www:"
110-
111- # # Create a link to the html directory
112- pushd /var/www
113- ln -s html " ${APP_PATH} "
114- popd
115-
116- # # Adapt the .htaccess file
117- sed \
118- -i /var/www/${APP_PATH} /.htaccess \
119- -e " s:\(RewriteCond .*\)/Web/:\1\.\*/Web/:" \
120- -e " s:\(RewriteRule .*\) /Web/:\1 /${APP_PATH} /Web/:"
107+ if [ -n " ${APP_PATH} " ]; then
108+ # # Set server document root 1 directory up
109+ sed \
110+ -i /etc/apache2/sites-enabled/000-default.conf \
111+ -e " s:/var/www/html:/var/www:"
112+
113+ # # Create a link to the html directory
114+ pushd /var/www
115+ ln -s html " ${APP_PATH} "
116+ popd
117+
118+ # # Adapt the .htaccess file
119+ sed \
120+ -i /var/www/" ${APP_PATH} " /.htaccess \
121+ -e " s:\(RewriteCond .*\)/Web/:\1\.\*/Web/:" \
122+ -e " s:\(RewriteRule .*\) /Web/:\1 /${APP_PATH} /Web/:"
121123fi
122124
123125# Send log files to /dev/stdout as background jobs
124126touch " ${LB_LOGGING_FOLDER} /app.log"
125- tail --follow " ${LB_LOGGING_FOLDER} /app.log" >> /dev/stdout &
127+ tail --follow " ${LB_LOGGING_FOLDER} /app.log" >> /dev/stdout &
126128touch " ${LB_LOGGING_FOLDER} /sql.log"
127- tail --follow " ${LB_LOGGING_FOLDER} /sql.log" >> /dev/stdout &
129+ tail --follow " ${LB_LOGGING_FOLDER} /sql.log" >> /dev/stdout &
128130
129131# Switch to the apache server
130132exec " $@ "
0 commit comments