Skip to content

Commit 673cd5f

Browse files
chore: resolve shellcheck issues with bin/*.sh
Also run `shfmt -i 4 -ci -w bin/*sh`
1 parent 8eec380 commit 673cd5f

3 files changed

Lines changed: 99 additions & 94 deletions

File tree

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ ARG APP_GH_ADD_SHA=false
2929
COPY setup.sh /usr/local/bin/setup.sh
3030
RUN <<EORUN
3131
set -xeu
32-
export APP_GH_REF=${APP_GH_REF}
33-
export APP_GH_ADD_SHA=${APP_GH_ADD_SHA}
32+
export APP_GH_REF="${APP_GH_REF}"
33+
export APP_GH_ADD_SHA="${APP_GH_ADD_SHA}"
3434
chmod +x /usr/local/bin/setup.sh
3535
/usr/local/bin/setup.sh
36+
rm /usr/local/bin/setup.sh
3637
EORUN
3738

3839
# Environment

bin/cron.sh

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -eu
33

44
# Constants
@@ -8,23 +8,25 @@ readonly DFT_LOGGING_SQL=false
88
readonly DFT_APP_PATH=""
99

1010
file_env() {
11-
local var="$1"
12-
local fileVar="${var}_FILE"
13-
local def="${2:-}"
14-
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
15-
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
16-
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
17-
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
18-
exit 1
19-
fi
20-
if [ -n "${varValue}" ]; then
21-
export "$var"="${varValue}"
22-
elif [ -n "${fileVarValue}" ]; then
23-
export "$var"="$(cat "${fileVarValue}")"
24-
elif [ -n "${def}" ]; then
25-
export "$var"="$def"
26-
fi
27-
unset "$fileVar"
11+
local var="$1"
12+
local fileVar="${var}_FILE"
13+
local def="${2:-}"
14+
local varValue
15+
varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
16+
local fileVarValue
17+
fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
18+
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
19+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
20+
exit 1
21+
fi
22+
if [ -n "${varValue}" ]; then
23+
export "$var"="${varValue}"
24+
elif [ -n "${fileVarValue}" ]; then
25+
export "$var"="$(cat "${fileVarValue}")"
26+
elif [ -n "${def}" ]; then
27+
export "$var"="$def"
28+
fi
29+
unset "$fileVar"
2830
}
2931

3032
# Initialize variables
@@ -36,15 +38,15 @@ LB_LOGGING_SQL=${LB_LOGGING_SQL:-${DFT_LOGGING_SQL}}
3638
APP_PATH=${APP_PATH:-${DFT_APP_PATH}}
3739

3840
# Set the php timezone file
39-
if [ -f /usr/share/zoneinfo/${LB_DEFAULT_TIMEZONE} ]; then
40-
INI_FILE="/usr/local/etc/php/conf.d/librebooking.ini"
41-
echo "[Date]" >> ${INI_FILE}
42-
echo "date.timezone=\"${LB_DEFAULT_TIMEZONE}\"" >> ${INI_FILE}
41+
if [ -f /usr/share/zoneinfo/"${LB_DEFAULT_TIMEZONE}" ]; then
42+
INI_FILE="/usr/local/etc/php/conf.d/librebooking.ini"
43+
echo "[Date]" >>${INI_FILE}
44+
echo "date.timezone=\"${LB_DEFAULT_TIMEZONE}\"" >>${INI_FILE}
4345
fi
4446

4547
# Link the configuration file
4648
if ! [ -f /var/www/html/config/config.php ]; then
47-
ln -s /config/config.php /var/www/html/config/config.php
49+
ln -s /config/config.php /var/www/html/config/config.php
4850
fi
4951

5052
# Load cron jobs under user www-data

bin/entrypoint.sh

Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,31 @@ readonly DFT_LOGGING_SQL=false
99
readonly DFT_APP_PATH=""
1010

1111
file_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)
3234
if [ "$(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
3537
fi
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
4749
pushd /config
4850
if [ -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
5456
fi
5557
popd
5658

5759
# No configuration file inside directory /config
5860
if ! [ -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
6163
fi
6264

6365
# Link the configuration file
6466
if ! [ -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
6668
fi
6769

6870
# Set configuration settings for Librebooking < v4.0.0
6971
sed \
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}
9799
fi
98100

99101
# Missing log directory
100102
if ! [ -d "${LB_LOGGING_FOLDER}" ]; then
101-
mkdir -p "${LB_LOGGING_FOLDER}"
103+
mkdir -p "${LB_LOGGING_FOLDER}"
102104
fi
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/:"
121123
fi
122124

123125
# Send log files to /dev/stdout as background jobs
124126
touch "${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 &
126128
touch "${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
130132
exec "$@"

0 commit comments

Comments
 (0)