Skip to content

Commit 54d463a

Browse files
committed
Safer and flexible boolean env vars
1 parent a23dc24 commit 54d463a

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

docker/rootfs/etc/s6-overlay/s6-rc.d/prepare/30-ownership.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,27 @@ chownit() {
2828

2929
local have
3030
have="$(stat -c '%u:%g' "$dir")"
31-
echo -n "- $dir ... "
31+
echo "- $dir ... "
3232

3333
if [ "$have" != "$PUID:$PGID" ]; then
3434
if [ "$recursive" = 'true' ] && [ -d "$dir" ]; then
3535
chown -R "$PUID:$PGID" "$dir"
3636
else
3737
chown "$PUID:$PGID" "$dir"
3838
fi
39-
echo "DONE"
39+
echo " DONE"
4040
else
41-
echo "SKIPPED"
41+
echo " SKIPPED"
4242
fi
4343
}
4444

4545
for loc in "${locations[@]}"; do
4646
chownit "$loc"
4747
done
4848

49-
if [ "${SKIP_CERTBOT_OWNERSHIP:-}" != "true" ]; then
49+
if [ "$(is_true "${SKIP_CERTBOT_OWNERSHIP:-}")" = '1' ]; then
50+
log_info 'Skipping ownership change of certbot directories'
51+
else
5052
log_info 'Changing ownership of certbot directories, this may take some time ...'
5153
chownit "/opt/certbot" false
5254
chownit "/opt/certbot/bin" false
@@ -55,6 +57,4 @@ if [ "${SKIP_CERTBOT_OWNERSHIP:-}" != "true" ]; then
5557
find /opt/certbot/lib -type d -name "site-packages" | while read -r SITE_PACKAGES_DIR; do
5658
chownit "$SITE_PACKAGES_DIR"
5759
done
58-
else
59-
log_info 'Skipping ownership change of certbot directories'
6060
fi

docker/rootfs/etc/s6-overlay/s6-rc.d/prepare/40-dynamic.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ set -e
55

66
log_info 'Dynamic resolvers ...'
77

8-
DISABLE_IPV6=$(echo "${DISABLE_IPV6:-}" | tr '[:upper:]' '[:lower:]')
9-
108
# Dynamically generate resolvers file, if resolver is IPv6, enclose in `[]`
119
# thanks @tfmm
12-
if [ "$DISABLE_IPV6" == "true" ] || [ "$DISABLE_IPV6" == "on" ] || [ "$DISABLE_IPV6" == "1" ] || [ "$DISABLE_IPV6" == "yes" ];
13-
then
10+
if [ "$(is_true "$DISABLE_IPV6")" = '1' ]; then
1411
echo resolver "$(awk 'BEGIN{ORS=" "} $1=="nameserver" { sub(/%.*$/,"",$2); print ($2 ~ ":")? "["$2"]": $2}' /etc/resolv.conf) ipv6=off valid=10s;" > /etc/nginx/conf.d/include/resolvers.conf
1512
else
1613
echo resolver "$(awk 'BEGIN{ORS=" "} $1=="nameserver" { sub(/%.*$/,"",$2); print ($2 ~ ":")? "["$2"]": $2}' /etc/resolv.conf) valid=10s;" > /etc/nginx/conf.d/include/resolvers.conf

docker/rootfs/etc/s6-overlay/s6-rc.d/prepare/50-ipv6.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ set -e
88

99
log_info 'IPv6 ...'
1010

11-
# Lowercase
12-
DISABLE_IPV6=$(echo "${DISABLE_IPV6:-}" | tr '[:upper:]' '[:lower:]')
13-
1411
process_folder () {
1512
FILES=$(find "$1" -type f -name "*.conf")
1613
SED_REGEX=
1714

18-
if [ "$DISABLE_IPV6" == "true" ] || [ "$DISABLE_IPV6" == "on" ] || [ "$DISABLE_IPV6" == "1" ] || [ "$DISABLE_IPV6" == "yes" ]; then
15+
if [ "$(is_true "$DISABLE_IPV6")" = '1' ]; then
1916
# IPV6 is disabled
2017
echo "Disabling IPV6 in hosts in: $1"
2118
SED_REGEX='s/^([^#]*)listen \[::\]/\1#listen [::]/g'

docker/rootfs/usr/bin/common.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,13 @@ get_group_id () {
5656
getent group "$1" | cut -d: -f3
5757
fi
5858
}
59+
60+
# param $1: value
61+
is_true () {
62+
VAL=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]')
63+
if [ "$VAL" == 'true' ] || [ "$VAL" == 'on' ] || [ "$VAL" == '1' ] || [ "$VAL" == 'yes' ]; then
64+
echo '1'
65+
else
66+
echo '0'
67+
fi
68+
}

0 commit comments

Comments
 (0)