diff --git a/hooks/conf_regen/34-mysql b/hooks/conf_regen/34-mysql
index 3f38c05e07..306e9f3e10 100755
--- a/hooks/conf_regen/34-mysql
+++ b/hooks/conf_regen/34-mysql
@@ -18,8 +18,12 @@
# along with this program. If not, see .
#
-set -e
-. /usr/share/yunohost/helpers
+# Exit hook on subcommand error or unset variable
+set -Eeuo pipefail
+
+# Source YNH helpers
+# shellcheck source=../../helpers/helpers
+source /usr/share/yunohost/helpers
if ! dpkg --list | grep -q 'ii *mariadb-server '; then
echo 'mysql/mariadb is not installed, skipping'
@@ -27,11 +31,8 @@ if ! dpkg --list | grep -q 'ii *mariadb-server '; then
fi
do_pre_regen() {
- pending_dir=$1
-
- #cd /usr/share/yunohost/conf/mysql
-
# Nothing to do
+ :
}
do_post_regen() {
@@ -44,12 +45,14 @@ do_post_regen() {
MYSQL_PKG="$(dpkg --list | sed -ne 's/^ii \(mariadb-server-[[:digit:].]\+\) .*$/\1/p')"
dpkg-reconfigure -freadline -u "$MYSQL_PKG" 2>&1
- systemctl -q is-active mariadb.service \
- || systemctl start mariadb
-
+ if ! systemctl -q is-active mariadb.service; then
+ systemctl start mariadb
+ fi
sleep 5
- echo "" | mysql && echo "Can't connect to mysql using unix_socket auth ... something went wrong during initial configuration of mysql !?" >&2
+ if ! echo "" | mysql; then
+ echo "Can't connect to mysql using unix_socket auth ... something went wrong during initial configuration of mysql !?" >&2
+ fi
fi
# mysql is supposed to be an alias to mariadb... but in some weird case is not
@@ -60,11 +63,14 @@ do_post_regen() {
systemctl disable mysql -q
systemctl disable mariadb -q
systemctl enable mariadb -q
- systemctl is-active mariadb -q || systemctl start mariadb
+ if ! systemctl is-active mariadb -q; then
+ systemctl start mariadb
+ fi
fi
- [[ -z "$regen_conf_files" ]] \
- || systemctl restart mysql
+ if [[ -n "$regen_conf_files" ]]; then
+ systemctl restart mysql
+ fi
}
-do_$1_regen ${@:2}
+"do_$1_regen" "${@:2}"
diff --git a/hooks/conf_regen/35-postgresql b/hooks/conf_regen/35-postgresql
index 35f07c3984..f0c33bf996 100755
--- a/hooks/conf_regen/35-postgresql
+++ b/hooks/conf_regen/35-postgresql
@@ -18,8 +18,12 @@
# along with this program. If not, see .
#
-set -e
-. /usr/share/yunohost/helpers
+# Exit hook on subcommand error or unset variable
+set -Eeuo pipefail
+
+# Source YNH helpers
+# shellcheck source=../../helpers/helpers
+source /usr/share/yunohost/helpers
if ! dpkg --list | grep -q "ii *postgresql-$PSQL_VERSION "; then
echo 'postgresql is not installed, skipping'
@@ -31,7 +35,8 @@ if [ ! -e "/etc/postgresql/$PSQL_VERSION" ]; then
fi
do_pre_regen() {
- return 0
+ # Nothing to do
+ :
}
do_post_regen() {
@@ -41,21 +46,22 @@ do_post_regen() {
# (N.B. : to check the active state, we check the cluster state because
# postgresql could be flagged as active even though the cluster is in
# failed state because of how the service is configured..)
- systemctl is-active postgresql@$PSQL_VERSION-main -q || ynh_systemd_action --service_name=postgresql --action=restart
- systemctl is-enabled postgresql -q || systemctl enable postgresql --quiet
+ if ! systemctl is-active "postgresql@$PSQL_VERSION-main" -q; then
+ ynh_systemd_action --service_name=postgresql --action=restart
+ fi
+ if ! systemctl is-enabled postgresql -q; then
+ systemctl enable postgresql --quiet
+ fi
# If this is the very first time, we define the root password
# and configure a few things
- if [ ! -f "$PSQL_ROOT_PWD_FILE" ] || [ -z "$(cat $PSQL_ROOT_PWD_FILE)" ]; then
- ynh_string_random > $PSQL_ROOT_PWD_FILE
+ if [ ! -f "$PSQL_ROOT_PWD_FILE" ] || [ ! -s "$PSQL_ROOT_PWD_FILE" ]; then
+ ynh_string_random > "$PSQL_ROOT_PWD_FILE"
fi
+ chown root:postgres "$PSQL_ROOT_PWD_FILE"
+ chmod 440 "$PSQL_ROOT_PWD_FILE"
- [ ! -e $PSQL_ROOT_PWD_FILE ] || {
- chown root:postgres $PSQL_ROOT_PWD_FILE
- chmod 440 $PSQL_ROOT_PWD_FILE
- }
-
- sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$(cat $PSQL_ROOT_PWD_FILE)'" postgres
+ sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$(cat "$PSQL_ROOT_PWD_FILE")'" postgres
# force all user to connect to local databases using hashed passwords
# https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF
@@ -67,4 +73,4 @@ do_post_regen() {
ynh_systemd_action --service_name=postgresql --action=reload
}
-do_$1_regen ${@:2}
+"do_$1_regen" "${@:2}"
diff --git a/hooks/conf_regen/37-mdns b/hooks/conf_regen/37-mdns
index c566622138..3fa3501e5f 100755
--- a/hooks/conf_regen/37-mdns
+++ b/hooks/conf_regen/37-mdns
@@ -53,7 +53,9 @@ do_pre_regen() {
mkdir -p "${pending_dir}/etc/systemd/system/"
cp yunomdns.service "${pending_dir}/etc/systemd/system/"
- getent passwd mdns &> /dev/null || useradd --no-create-home --shell /usr/sbin/nologin --system --user-group mdns
+ if ! getent passwd mdns &>/dev/null; then
+ useradd --no-create-home --shell /usr/sbin/nologin --system --user-group mdns
+ fi
mkdir -p "$pending_dir/etc/yunohost"
_generate_config > "$pending_dir/etc/yunohost/mdns.yml"
@@ -75,8 +77,9 @@ do_post_regen() {
sleep 2
fi
- [[ -z "$regen_conf_files" ]] \
- || systemctl restart yunomdns
+ if [[ -n "$regen_conf_files" ]]; then
+ systemctl restart yunomdns
+ fi
}
"do_$1_regen" "${@:2}"
diff --git a/hooks/conf_regen/52-fail2ban b/hooks/conf_regen/52-fail2ban
index 42eacd9dd6..eb549009ca 100755
--- a/hooks/conf_regen/52-fail2ban
+++ b/hooks/conf_regen/52-fail2ban
@@ -51,8 +51,9 @@ do_post_regen() {
chmod 644 /etc/fail2ban/jail.d/*.conf
fi
- [[ -z "$regen_conf_files" ]] \
- || systemctl reload fail2ban
+ if [[ -n "$regen_conf_files" ]]; then
+ systemctl reload fail2ban
+ fi
}
"do_$1_regen" "${@:2}"