11#! /bin/bash
2+ # vim: set expandtab ts=2 sw=2 ai :
23
34set -ex
45
@@ -12,25 +13,27 @@ file_env() {
1213 local var=" $1 "
1314 local fileVar=" ${var} _FILE"
1415 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} =//" )
16+ local varValue
17+ varValue=$( env | grep -E " ^${var} =" | sed -E -e " s/^${var} =//" )
18+ local fileVarValue
19+ fileVarValue=$( env | grep -E " ^${fileVar} =" | sed -E -e " s/^${fileVar} =//" )
1720 if [ -n " ${varValue} " ] && [ -n " ${fileVarValue} " ]; then
18- echo >&2 " error: both $var and $fileVar are set (but are exclusive)"
19- exit 1
21+ echo >&2 " error: both $var and $fileVar are set (but are exclusive)"
22+ exit 1
2023 fi
2124 if [ -n " ${varValue} " ]; then
22- export " $var " =" ${varValue} "
25+ export " $var " =" ${varValue} "
2326 elif [ -n " ${fileVarValue} " ]; then
24- export " $var " =" $( cat " ${fileVarValue} " ) "
27+ export " $var " =" $( cat " ${fileVarValue} " ) "
2528 elif [ -n " ${def} " ]; then
26- export " $var " =" $def "
29+ export " $var " =" $def "
2730 fi
2831 unset " $fileVar "
2932}
3033
3134# Exit if incompatible mount (images prior to V2)
3235if [ " $( mount | grep /var/www/html) " = " /var/www/html" ]; then
33- echo " The volume must be mapped to container directory /config" > 2
36+ echo " The volume must be mapped to container directory /config" >& 2
3437 exit 1
3538fi
3639
@@ -46,8 +49,8 @@ APP_PATH=${APP_PATH:-${DFT_APP_PATH}}
4649# If volume was used with images older than v2, then archive useless files
4750pushd /config
4851if [ -d Web ]; then
49- mkdir archive
50- mv $( ls --ignore= archive) archive
52+ mkdir -p archive
53+ find . -mindepth 1 -maxdepth 1 ! -name archive -exec mv -t archive -- {} +
5154 if [ -f archive/config/config.php ]; then
5255 cp archive/config/config.php config.php
5356 fi
@@ -79,21 +82,21 @@ sed \
7982 -e " s:\(\['logging'\]\['sql'\].*\) '.*':\1 '${LB_LOGGING_SQL} ':"
8083
8184# 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} ) "
85+ while IFS= read -r -d ' ' source ; do
86+ target=${source// .dist/ }
87+ if ! [ -f " /config/$( basename " ${target} " ) " ]; then
88+ cp --no-clobber " ${source} " " /config/$( basename " ${target} " ) "
8689 fi
87- if ! [ -f ${target} ]; then
88- ln -s " /config/$( basename ${target} ) " " ${target} "
90+ if ! [ -f " ${target} " ]; then
91+ ln -s " /config/$( basename " ${target} " ) " " ${target} "
8992 fi
90- done
93+ done < <( find /var/www/html/plugins -type f -name " *dist* " -print0 )
9194
9295# Set the php timezone file
93- if [ -f /usr/share/zoneinfo/${LB_DEFAULT_TIMEZONE} ]; then
96+ if [ -f /usr/share/zoneinfo/" ${LB_DEFAULT_TIMEZONE} " ]; then
9497 INI_FILE=" /usr/local/etc/php/conf.d/librebooking.ini"
95- echo " [Date]" >> ${INI_FILE}
96- echo " date.timezone=\" ${LB_DEFAULT_TIMEZONE} \" " >> ${INI_FILE}
98+ echo " [Date]" >> ${INI_FILE}
99+ echo " date.timezone=\" ${LB_DEFAULT_TIMEZONE} \" " >> ${INI_FILE}
97100fi
98101
99102# Missing log directory
@@ -102,7 +105,7 @@ if ! [ -d "${LB_LOGGING_FOLDER}" ]; then
102105fi
103106
104107# A URL path prefix was set
105- if ! [ -z " ${APP_PATH} " ]; then
108+ if [ -n " ${APP_PATH} " ]; then
106109 # # Set server document root 1 directory up
107110 sed \
108111 -i /etc/apache2/sites-enabled/000-default.conf \
@@ -115,16 +118,16 @@ if ! [ -z "${APP_PATH}" ]; then
115118
116119 # # Adapt the .htaccess file
117120 sed \
118- -i /var/www/${APP_PATH} /.htaccess \
121+ -i /var/www/" ${APP_PATH} " /.htaccess \
119122 -e " s:\(RewriteCond .*\)/Web/:\1\.\*/Web/:" \
120123 -e " s:\(RewriteRule .*\) /Web/:\1 /${APP_PATH} /Web/:"
121124fi
122125
123126# Send log files to /dev/stdout as background jobs
124127touch " ${LB_LOGGING_FOLDER} /app.log"
125- tail --follow " ${LB_LOGGING_FOLDER} /app.log" >> /dev/stdout &
128+ tail --follow " ${LB_LOGGING_FOLDER} /app.log" >> /dev/stdout &
126129touch " ${LB_LOGGING_FOLDER} /sql.log"
127- tail --follow " ${LB_LOGGING_FOLDER} /sql.log" >> /dev/stdout &
130+ tail --follow " ${LB_LOGGING_FOLDER} /sql.log" >> /dev/stdout &
128131
129132# Switch to the apache server
130133exec " $@ "
0 commit comments