From 5f7a207f112bae91cf61192cbeae3c9e631db6b0 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sun, 26 Nov 2023 17:33:01 +0100 Subject: [PATCH] replace any '__VAR__' by their real variable using ynh_replace_vars --- helpers/fail2ban | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/helpers/fail2ban b/helpers/fail2ban index 6c9fb22c7..a2d068364 100644 --- a/helpers/fail2ban +++ b/helpers/fail2ban @@ -103,10 +103,15 @@ ignoreregex = # if "$logpath" doesn't exist (as if using --use_template argument), assign # "$logpath" using the one in the package's conf/f2b_jail.conf template if [ -z "$logpath" ]; then - # the first sed deleteds possibles spaces and the second one extract the path + # the first sed deletes possibles spaces and the second one extract the path logpath=$(grep logpath "$YNH_APP_BASEDIR/conf/f2b_jail.conf" | sed "s/ //g" | sed "s/logpath=//g") - # replace the '__APP__' by the real app name in the path - logpath=${logpath//__APP__/$app} + # replace any '__VAR__' by their real variable using ynh_replace_vars + # in some hacky way because ynh_replace_vars supports only files ^^' + tempdir="$(mktemp -d)" + echo "$logpath" > "$tempdir/process-logpath" + ynh_replace_vars --file="$tempdir/process-logpath" + logpath="$(cat "$tempdir/process-logpath")" + rm -r "$tempdir" fi # Create the folder and logfile if they doesn't exist, @@ -114,9 +119,10 @@ ignoreregex = mkdir -p "/var/log/$app" if [ ! -f "$logpath" ]; then touch "$logpath" - chown -R "$app:$app" "/var/log/$app" - chmod -R u=rwX,g=rX,o= "/var/log/$app" fi + # Make sure log folder's permissions are correct + chown -R "$app:$app" "/var/log/$app" + chmod -R u=rwX,g=rX,o= "/var/log/$app" ynh_systemd_action --service_name=fail2ban --action=reload --line_match="(Started|Reloaded) Fail2Ban Service" --log_path=systemd