Skip to content

Commit

Permalink
Fix shellcheck tests failing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheophileDiot committed Oct 2, 2023
1 parent e21e0c8 commit 5ed595b
Show file tree
Hide file tree
Showing 79 changed files with 595 additions and 290 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: (^LICENSE.md$|^src/VERSION$|^src/(bw/misc/root-ca.pem$|deps/src/|common/core/modsecurity/files/coreruleset/|ui/static/js/(editor/|utils/purify/|tsparticles\.bundle\.min\.js))|\.(svg|drawio|patch\d?|ascii|tf|tftpl)$)
exclude: (^LICENSE.md$|^src/VERSION$|^src/(bw/misc/root-ca.pem$|deps/src/|common/core/modsecurity/files|ui/static/js/(editor/|utils/purify/|tsparticles\.bundle\.min\.js))|\.(svg|drawio|patch\d?|ascii|tf|tftpl)$)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -17,12 +17,12 @@ repos:
- id: black
language_version: python3.9

- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.9.0
hooks:
- id: shellcheck

- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.0
hooks:
- id: gitleaks

- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.9.0
hooks:
- id: shellcheck
2 changes: 1 addition & 1 deletion examples/authelia/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/behind-reverse-proxy/cleanup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
6 changes: 3 additions & 3 deletions examples/behind-reverse-proxy/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi

DNF=$(which dnf)
APT=$(which apt)

if [ ! -z $DNF ] ; then
if [ -n "$DNF" ] ; then
dnf install -y haproxy
elif [ ! -z $APT ] ; then
elif [ -n "$APT" ] ; then
apt install -y haproxy
fi

Expand Down
2 changes: 1 addition & 1 deletion examples/certbot-dns-cloudflare/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

echo "Certbot started, domains = $DOMAINS"

first_domain="$(echo -n $DOMAINS | cut -d ',' -f 1 | sed 's/*\.//g')"
first_domain="$(echo "$DOMAINS" | tr -d '\n' | cut -d ',' -f 1 | sed 's/*\.//g')"
if [ "$EMAIL" = "" ] ; then
EMAIL="contact@${first_domain}"
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/certbot-dns-digitalocean/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

echo "Certbot started, domains = $DOMAINS"

first_domain="$(echo -n $DOMAINS | cut -d ',' -f 1 | sed 's/*\.//g')"
first_domain="$(echo "$DOMAINS" | tr -d '\n' | cut -d ',' -f 1 | sed 's/*\.//g')"
if [ "$EMAIL" = "" ] ; then
EMAIL="contact@${first_domain}"
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/certbot-dns-google/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

echo "Certbot started, domains = $DOMAINS"

first_domain="$(echo -n $DOMAINS | cut -d ',' -f 1 | sed 's/*\.//g')"
first_domain="$(echo "$DOMAINS" | tr -d '\n' | cut -d ',' -f 1 | sed 's/*\.//g')"
if [ "$EMAIL" = "" ] ; then
EMAIL="contact@${first_domain}"
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/certbot-dns-ovh/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

echo "Certbot started, domains = $DOMAINS"

first_domain="$(echo -n $DOMAINS | cut -d ',' -f 1 | sed 's/*\.//g')"
first_domain="$(echo "$DOMAINS" | tr -d '\n' | cut -d ',' -f 1 | sed 's/*\.//g')"
if [ "$EMAIL" = "" ] ; then
EMAIL="contact@${first_domain}"
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/certbot-dns-route53/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

echo "Certbot started, domains = $DOMAINS"

first_domain="$(echo -n $DOMAINS | cut -d ',' -f 1 | sed 's/*\.//g')"
first_domain="$(echo "$DOMAINS" | tr -d '\n' | cut -d ',' -f 1 | sed 's/*\.//g')"
if [ "$EMAIL" = "" ] ; then
EMAIL="contact@${first_domain}"
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/cors/setup-autoconf.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/cors/setup-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/cors/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
8 changes: 4 additions & 4 deletions examples/drupal/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand All @@ -16,11 +16,11 @@ fi
curl https://ftp.drupal.org/files/projects/drupal-9.5.3.tar.gz -Lo /tmp/drupal.tar.gz
tar -xzf /tmp/drupal.tar.gz -C /tmp
current_dir="$(pwd)"
cd /tmp/drupal-*
cp -r * /var/www/html
cd /tmp/drupal-* || exit 1
cp -r ./* /var/www/html
chown -R $user:nginx /var/www/html
find /var/www/html -type f -exec chmod 0640 {} \;
find /var/www/html -type d -exec chmod 0750 {} \;
cd "$current_dir"
cd "$current_dir" || exit 1
cp -r ./bw-data/configs/* /etc/bunkerweb/configs
chown -R nginx:nginx /etc/bunkerweb/configs
2 changes: 1 addition & 1 deletion examples/joomla/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/mattermost/setup-autoconf.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/mattermost/setup-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/moodle/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/nextcloud/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/php-cookie-flags/setup-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/php-cookie-flags/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/php-multisite/setup-autoconf.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/php-multisite/setup-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/php-multisite/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/php-singlesite/setup-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/php-singlesite/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/proxy-protocol/cleanup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
6 changes: 3 additions & 3 deletions examples/proxy-protocol/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi

DNF=$(which dnf)
APT=$(which apt)

if [ ! -z $DNF ] ; then
if [ -n "$DNF" ] ; then
dnf install -y haproxy
elif [ ! -z $APT ] ; then
elif [ -n "$APT" ] ; then
apt install -y haproxy
fi

Expand Down
2 changes: 1 addition & 1 deletion examples/wordpress/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
if [ "$(id -u)" -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
Expand Down
18 changes: 13 additions & 5 deletions misc/update-version.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
#/bin/bash
#!/bin/bash

if [ $# -ne 1 ] ; then
echo "Missing version argument"
exit 1
fi

OLD_VERSION="$(cat src/VERSION | tr -d '\n' | sed 's/\./\\./g' | sed 's/\-/\\-/g')"
OLD_VERSION="$(tr -d '\n' < src/VERSION | sed 's/\./\\./g' | sed 's/\-/\\-/g')"
NEW_VERSION="$(echo -n "$1" | sed 's/\./\\./g' | sed 's/\-/\\-/g')"

# VERSION
echo -en "$NEW_VERSION" | sed 's/\\//g' > src/VERSION
echo -en "$NEW_VERSION" | sed 's/\\//g' | tee src/VERSION
# integrations
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" misc/integrations/*.yml
# examples
shopt -s globstar
for example in examples/* ; do
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" ${example}/*.yml
if [ -d "$test" ] ; then
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" "$example/*.yml"
fi
done
shopt -u globstar
# docs
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" docs/*.md
# README
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" README.md
# tests
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" tests/ui/docker-compose.yml
shopt -s globstar
for test in tests/core/* ; do
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" ${test}/docker-compose.yml
if [ -d "$test" ] ; then
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" "$test/docker-compose.yml"
fi
done
shopt -u globstar
# linux
sed -i "s@${OLD_VERSION}@${NEW_VERSION}@g" src/linux/scripts/*.sh
# db
Expand Down
16 changes: 12 additions & 4 deletions src/bw/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/bash

# shellcheck disable=SC1091
. /usr/share/bunkerweb/helpers/utils.sh

ascii_array=($(ls /usr/share/bunkerweb/misc/*.ascii))
cat ${ascii_array[$(($RANDOM % ${#ascii_array[@]}))]}
shopt -s nullglob
ascii_array=(/usr/share/bunkerweb/misc/*.ascii)
shopt -u nullglob
cat "${ascii_array[$((RANDOM % ${#ascii_array[@]}))]}"

log "ENTRYPOINT" "ℹ️" "Starting BunkerWeb v$(cat /usr/share/bunkerweb/VERSION) ..."

Expand All @@ -12,18 +15,23 @@ log "ENTRYPOINT" "ℹ️" "Starting BunkerWeb v$(cat /usr/share/bunkerweb/VERSIO

# trap SIGTERM and SIGINT
function trap_exit() {
log "ENTRYPOINT" "ℹ️" "Catched stop operation"
log "ENTRYPOINT" "ℹ️" "Stopping nginx ..."
# shellcheck disable=SC2317
log "ENTRYPOINT" "ℹ️" "Catched stop operation, stopping nginx ..."
# shellcheck disable=SC2317
nginx -s stop
}
trap "trap_exit" TERM INT QUIT

# trap SIGHUP
function trap_reload() {
# shellcheck disable=SC2317
log "ENTRYPOINT" "ℹ️" "Catched reload operation"
# shellcheck disable=SC2317
if [ -f /var/run/bunkerweb/nginx.pid ] ; then
# shellcheck disable=SC2317
log "ENTRYPOINT" "ℹ️" "Reloading nginx ..."
nginx -s reload
# shellcheck disable=SC2181,SC2317
if [ $? -eq 0 ] ; then
log "ENTRYPOINT" "ℹ️" "Reload successful"
else
Expand Down
Loading

0 comments on commit 5ed595b

Please sign in to comment.