1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-07 17:47:14 +00:00

Improve bash quoting, and other similar best practices

This patch updates the shell scripts with some of the common best
practices, which should make them more resilient to unusual failures and
unexpected environments (in particular, directories with spaces).

Most of these were identified by shellcheck.
This commit is contained in:
Alberto Bertogli
2022-11-13 00:37:28 +00:00
parent e2481b07a9
commit 948cee1ce1
32 changed files with 133 additions and 126 deletions

View File

@@ -7,7 +7,7 @@
set -e
read -p "Email (full user@domain format): " EMAIL
read -r -p "Email (full user@domain format): " EMAIL
if ! echo "${EMAIL}" | grep -q @; then
echo "Error: email should have '@'."
@@ -15,7 +15,7 @@ if ! echo "${EMAIL}" | grep -q @; then
fi
read -p "Password: " -s PASSWORD
read -r -p "Password: " -s PASSWORD
echo
DOMAIN=$(echo echo "${EMAIL}" | cut -d '@' -f 2)
@@ -33,7 +33,7 @@ mkdir -p /data/dovecot
touch /data/dovecot/users
if grep -q "^${EMAIL}:" /data/dovecot/users; then
cp /data/dovecot/users /data/dovecot/users.old
cat /data/dovecot/users.old | grep -v "^${EMAIL}:" \
grep -v "^${EMAIL}:" /data/dovecot/users.old \
> /data/dovecot/users
fi

View File

@@ -28,15 +28,16 @@ if [ "$AUTO_CERTS" != "" ]; then
MAIL_OPTS="-m $CERTS_MAIL"
fi
for DOMAIN in $(echo $AUTO_CERTS); do
for DOMAIN in $AUTO_CERTS; do
# If it has never been set up, then do so.
if ! [ -e /etc/letsencrypt/live/$DOMAIN/fullchain.pem ]; then
if ! [ -e "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" ]; then
# shellcheck disable=SC2086
certbot certonly \
--non-interactive \
--standalone \
--agree-tos \
$MAIL_OPTS \
-d $DOMAIN
-d "$DOMAIN"
else
echo "$DOMAIN certificate already set up."
fi
@@ -53,9 +54,10 @@ if [ "$AUTO_CERTS" != "" ]; then
fi
CERT_DOMAINS=""
for i in $(ls /etc/letsencrypt/live/); do
if [ -e "/etc/letsencrypt/live/$i/fullchain.pem" ]; then
CERT_DOMAINS="$CERT_DOMAINS $i"
for i in /etc/letsencrypt/live/*; do
D="${i##*/}" # Extract the last component of the path.
if [ -e "/etc/letsencrypt/live/$D/fullchain.pem" ]; then
CERT_DOMAINS="$CERT_DOMAINS $D"
fi
done
@@ -104,4 +106,5 @@ echo "hostname: '$ONE_DOMAIN'" >> /etc/chasquid/chasquid.conf
start-stop-daemon --start --quiet --pidfile /run/dovecot.pid \
--exec /usr/sbin/dovecot -- -c /etc/dovecot/dovecot.conf
# shellcheck disable=SC2086
sudo -u chasquid -g chasquid /usr/bin/chasquid $CHASQUID_FLAGS