Skip to content

Commit e3f875d

Browse files
chore: resolve shellcheck issues with bin/*.sh
Also run `shfmt -i 4 -ci -w bin/*sh`
1 parent 88179d4 commit e3f875d

5 files changed

Lines changed: 105 additions & 97 deletions

File tree

.github/workflows/build_pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
run: |
4242
set -euo pipefail
4343
mapfile -t scripts < <(git ls-files '*.sh')
44-
shfmt -d -i 4 -ci "${scripts[@]}"
44+
shfmt -d -i 2 -ci "${scripts[@]}"
4545
4646
check_build:
4747
runs-on: ubuntu-latest

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: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
# vim: set expandtab ts=2 sw=2 ai :
23
set -eu
34

45
# Constants
@@ -11,18 +12,20 @@ file_env() {
1112
local var="$1"
1213
local fileVar="${var}_FILE"
1314
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}=//")
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}=//")
1619
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
17-
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
18-
exit 1
20+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
21+
exit 1
1922
fi
2023
if [ -n "${varValue}" ]; then
21-
export "$var"="${varValue}"
24+
export "$var"="${varValue}"
2225
elif [ -n "${fileVarValue}" ]; then
23-
export "$var"="$(cat "${fileVarValue}")"
26+
export "$var"="$(cat "${fileVarValue}")"
2427
elif [ -n "${def}" ]; then
25-
export "$var"="$def"
28+
export "$var"="$def"
2629
fi
2730
unset "$fileVar"
2831
}
@@ -36,10 +39,10 @@ LB_LOGGING_SQL=${LB_LOGGING_SQL:-${DFT_LOGGING_SQL}}
3639
APP_PATH=${APP_PATH:-${DFT_APP_PATH}}
3740

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

4548
# Link the configuration file

bin/entrypoint.sh

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
# vim: set expandtab ts=2 sw=2 ai :
23

34
set -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)
3235
if [ "$(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
3538
fi
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
4750
pushd /config
4851
if [ -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}
97100
fi
98101

99102
# Missing log directory
@@ -102,7 +105,7 @@ if ! [ -d "${LB_LOGGING_FOLDER}" ]; then
102105
fi
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/:"
121124
fi
122125

123126
# Send log files to /dev/stdout as background jobs
124127
touch "${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 &
126129
touch "${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
130133
exec "$@"

setup.sh

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#!/bin/bash
2+
# vim: set expandtab ts=2 sw=2 ai :
23

34
set -e
45
set -u
56
set -o pipefail
67
trap 'echo "Exit status $? at line $LINENO from: $BASH_COMMAND"' ERR
78

8-
export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: '
9+
PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: '
910
set -x
1011

1112
apt-get update
1213
apt-get upgrade --yes
1314
apt-get install --yes --no-install-recommends \
14-
cron \
15-
git \
16-
libjpeg-dev \
17-
libldap-dev \
18-
libpng-dev \
19-
libfreetype6-dev \
20-
unzip
15+
cron \
16+
git \
17+
libjpeg-dev \
18+
libldap-dev \
19+
libpng-dev \
20+
libfreetype6-dev \
21+
unzip
2122
apt-get clean
2223
rm -rf /var/lib/apt/lists/*
2324

@@ -42,72 +43,72 @@ chown --recursive www-data:root /var/log/librebooking
4243
chmod --recursive g+rwx /var/log/librebooking
4344
touch /usr/local/etc/php/conf.d/librebooking.ini
4445
sed \
45-
-i /etc/apache2/ports.conf \
46-
-e 's/Listen 80/Listen 8080/' \
47-
-e 's/Listen 443/Listen 8443/'
46+
-i /etc/apache2/ports.conf \
47+
-e 's/Listen 80/Listen 8080/' \
48+
-e 's/Listen 443/Listen 8443/'
4849
sed \
49-
-i /etc/apache2/sites-available/000-default.conf \
50-
-e 's/<VirtualHost *:80>/<VirtualHost *:8080>/'
50+
-i /etc/apache2/sites-available/000-default.conf \
51+
-e 's/<VirtualHost *:80>/<VirtualHost *:8080>/'
5152

5253
set -xeuo pipefail
5354
LB_TARBALL_URL="https://api.github.com/repos/LibreBooking/librebooking/tarball/${APP_GH_REF}"
5455
curl \
55-
--fail \
56-
--silent \
57-
--location "${LB_TARBALL_URL}" |
58-
tar --extract --gzip --directory=/var/www/html --strip-components=1
56+
--fail \
57+
--silent \
58+
--location "${LB_TARBALL_URL}" |
59+
tar --extract --gzip --directory=/var/www/html --strip-components=1
5960
if [ "${APP_GH_ADD_SHA}" = "true" ]; then
60-
LB_SHORT_SHA=""
61-
# TARBALL_FILENAME will be like the result of a `git describe` For
62-
# example: 'LibreBooking-librebooking-v4.1.0-126-g6cc8a4c.tar.gz' where
63-
# 'g6cc8a4c' is the short SHA prefixed with 'g'. So the short SHA is
64-
# '6cc8a4c'
65-
TARBALL_FILENAME=$(
66-
curl \
67-
--head \
68-
--fail \
69-
--silent \
70-
--show-error \
71-
--location "${LB_TARBALL_URL}" |
72-
sed -nE 's/.*filename="?([^";]+)"?.*/\1/p'
73-
)
74-
LB_SHORT_SHA=$(echo "${TARBALL_FILENAME}" | sed -E 's/.*-g([0-9a-f]+)\.tar\.gz/\1/')
75-
if [ -n "${LB_SHORT_SHA}" ]; then
76-
printf '%s\n' "${LB_SHORT_SHA}" >/var/www/html/config/version-suffix.txt
77-
else
78-
echo "ERROR determining the LB_SHORT_SHA value from TARBALL_FILENAME ${TARBALL_FILENAME}" >&2
79-
exit 1
80-
fi
61+
LB_SHORT_SHA=""
62+
# TARBALL_FILENAME will be like the result of a `git describe` For
63+
# example: 'LibreBooking-librebooking-v4.1.0-126-g6cc8a4c.tar.gz' where
64+
# 'g6cc8a4c' is the short SHA prefixed with 'g'. So the short SHA is
65+
# '6cc8a4c'
66+
TARBALL_FILENAME=$(
67+
curl \
68+
--head \
69+
--fail \
70+
--silent \
71+
--show-error \
72+
--location "${LB_TARBALL_URL}" |
73+
sed -nE 's/.*filename="?([^";]+)"?.*/\1/p'
74+
)
75+
LB_SHORT_SHA=$(echo "${TARBALL_FILENAME}" | sed -E 's/.*-g([0-9a-f]+)\.tar\.gz/\1/')
76+
if [ -n "${LB_SHORT_SHA}" ]; then
77+
printf '%s\n' "${LB_SHORT_SHA}" >/var/www/html/config/version-suffix.txt
78+
else
79+
echo "ERROR determining the LB_SHORT_SHA value from TARBALL_FILENAME ${TARBALL_FILENAME}" >&2
80+
exit 1
81+
fi
8182
fi
8283
if [ -f /var/www/html/composer.json ]; then
83-
sed \
84-
-i /var/www/html/composer.json \
85-
-e "s:\(.*\)nickdnk/graph-sdk\(.*\)7.0\(.*\):\1joelbutcher/facebook-graph-sdk\26.1\3:"
86-
composer install
84+
sed \
85+
-i /var/www/html/composer.json \
86+
-e "s:\(.*\)nickdnk/graph-sdk\(.*\)7.0\(.*\):\1joelbutcher/facebook-graph-sdk\26.1\3:"
87+
composer install
8788
fi
8889
sed \
89-
-i /var/www/html/database_schema/create-user.sql \
90-
-e "s:^DROP USER ':DROP USER IF EXISTS ':g" \
91-
-e "s:booked_user:schedule_user:g" \
92-
-e "s:localhost:%:g"
90+
-i /var/www/html/database_schema/create-user.sql \
91+
-e "s:^DROP USER ':DROP USER IF EXISTS ':g" \
92+
-e "s:booked_user:schedule_user:g" \
93+
-e "s:localhost:%:g"
9394
if ! [ -d /var/www/html/tpl_c ]; then
94-
mkdir /var/www/html/tpl_c
95+
mkdir /var/www/html/tpl_c
9596
fi
9697
mkdir /var/www/html/Web/uploads/reservation
9798

9899
chown www-data:root \
99-
/var/www/html/config \
100-
/var/www/html/tpl_c \
101-
/var/www/html/Web/uploads/images \
102-
/var/www/html/Web/uploads/reservation \
103-
/usr/local/etc/php/conf.d/librebooking.ini
100+
/var/www/html/config \
101+
/var/www/html/tpl_c \
102+
/var/www/html/Web/uploads/images \
103+
/var/www/html/Web/uploads/reservation \
104+
/usr/local/etc/php/conf.d/librebooking.ini
104105
chmod g+rwx \
105-
/var/www/html/config \
106-
/var/www/html/tpl_c \
107-
/var/www/html/Web/uploads/images \
108-
/var/www/html/Web/uploads/reservation \
109-
/usr/local/etc/php/conf.d/librebooking.ini
106+
/var/www/html/config \
107+
/var/www/html/tpl_c \
108+
/var/www/html/Web/uploads/images \
109+
/var/www/html/Web/uploads/reservation \
110+
/usr/local/etc/php/conf.d/librebooking.ini
110111
chown --recursive www-data:root \
111-
/var/www/html/plugins
112+
/var/www/html/plugins
112113
chmod --recursive g+rwx \
113-
/var/www/html/plugins
114+
/var/www/html/plugins

0 commit comments

Comments
 (0)