Skip to content

Commit

Permalink
Merge pull request #11671 from mpurg/fix_sysctl_bash
Browse files Browse the repository at this point in the history
Fix non-idempotent bash remediation for sysctl template
  • Loading branch information
dodys authored Mar 12, 2024
2 parents cd56688 + c3dabe6 commit 7ab86c5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion shared/templates/sysctl/bash.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.con
{{% else %}}
for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf; do
{{% endif %}}

# skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf)
if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi

matching_list=$(grep -P '^(?!#).*[\s]*{{{ SYSCTLVAR }}}.*$' $f | uniq )
if ! test -z "$matching_list"; then
while IFS= read -r entry; do
escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry")
# comment out "{{{ SYSCTLVAR }}}" matches to preserve user data
sed -i "s/^${escaped_entry}$/# &/g" $f
sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f
done <<< "$matching_list"
fi
done
Expand Down

0 comments on commit 7ab86c5

Please sign in to comment.