V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m44s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-10-19 09:06:27 +01:00
parent f7493e37e1
commit 0169be5527
14 changed files with 527 additions and 115 deletions

View File

@@ -13,9 +13,11 @@
guard_sourcing
#######################################
# Hardening logrotate.
# Hardening '/etc/logrotate'.
# Globals:
# RECOVERY
# TARGET
# VAR_RUN_RECOVERY
# Arguments:
# None
# Returns:
@@ -23,8 +25,6 @@ guard_sourcing
#######################################
hardening_logrotate() {
### Declare Arrays, HashMaps, and Variables.
declare -ar ary_logrotate=( "alternatives" "apt" "btmp" "chrony" "dpkg" "fail2ban" "rkhunter" "ufw" "unattended-upgrades" "usbguard")
declare var_file="" var_log=""
declare var_target="${TARGET}"
### Check for TARGET / RECOVERY.
@@ -39,8 +39,8 @@ hardening_logrotate() {
# rotate log files daily
daily
# keep 128 daily worth of backlogs
rotate 128
# keep 384 daily worth of backlogs
rotate 384
# hard cap: delete rotated logs older than 384 days
maxage 384
@@ -65,16 +65,6 @@ include /etc/logrotate.d
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF
for var_log in "${ary_logrotate[@]}"; do
var_file="${var_target}/etc/logrotate.d/${var_log}"
[[ -e "${var_file}" ]] || continue
### Replace leading 'monthly'/'weekly' directives with 'daily', preserving indentation and trailing comments.
sed -E -i \
-e 's/^([[:space:]]*)(monthly|weekly)([[:space:]]*)(#.*)?$/\1daily\3\4/' \
-e 's/^([[:space:]]*)rotate([[:space:]]+[0-9]+)?([[:space:]]*)(#.*)?$/\1rotate 128\3\4/' \
"${var_file}"
done
guard_dir && return 0
}
### Prevents accidental 'unset -f'.