Skip to content

Commit

Permalink
replace any '__VAR__' by their real variable using ynh_replace_vars
Browse files Browse the repository at this point in the history
  • Loading branch information
OniriCorpe committed Nov 26, 2023
1 parent 8eed421 commit 5f7a207
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions helpers/fail2ban
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,26 @@ 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,
# as fail2ban require an existing logfile before configuration
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

Expand Down

0 comments on commit 5f7a207

Please sign in to comment.