From: Alexander Barton Date: Wed, 27 Mar 2019 13:07:21 +0000 (+0100) Subject: backup-audit: Enhance checking of systemd configuration X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=backup-script.git;a=commitdiff_plain;h=4082ce5be0965c0e9466dd749a444f0eb4783b47;hp=ce74631c73649093557b0201722c930d07cfd66f backup-audit: Enhance checking of systemd configuration This introduces the new ListFilesRecursive() function. Problem is, that time stamps of systemd unit files etc. often change when systemd settings are updated -- even when the file itself doesn't change. So just compare the file names, not the time stamps etc. --- diff --git a/bin/backup-audit b/bin/backup-audit index cb44382..146a955 100755 --- a/bin/backup-audit +++ b/bin/backup-audit @@ -91,6 +91,16 @@ ListDirectory() { | LC_ALL=C sort -k 9 | grep -Ev "($exclude)" } +ListFilesRecursive() { + local base_dir="$1" + local dir_name="$2" + + ( + cd "$base_dir" || return 1 + find ".$dir_name" -type f -o -type l | cut -d'/' -f2- + ) +} + HandleSystem() { local fname="$1" @@ -238,14 +248,37 @@ DiffGenerations() { /etc/cron.weekly/ \ /etc/init.d/ \ /etc/sudoers.d/ \ + /var/log/dumps/ \ + ; do + [[ ! -d "${gen1_d}${dir}" ]] && continue + [[ ! -d "${gen2_d}${dir}" ]] && continue + + # Make sure that this is a system root; comparing other + # root folders results in misleading output ... + [[ "$dir" == "/" && ! -d "${gen1_d}${dir}/etc" ]] && continue + + [[ $VERBOSE -ne 0 ]] && echo "Checking \"$dir\" ..." + ListDirectory "${gen1_d}" "${dir}" >"$tmp_1" + ListDirectory "${gen2_d}" "${dir}" >"$tmp_2" + if ! diff -U 0 "$tmp_1" "$tmp_2" >"$tmp_diff"; then + BeginDiff "\"$dir\" directory" + tail -n +3 "$tmp_diff" | grep -Ev '^@@ ' | PipeDiff + EndDiff + return_code=1 + fi + done + + for dir in \ /etc/systemd/network/ \ /etc/systemd/system/ \ /etc/systemd/user/ \ /lib/systemd/network/ \ /lib/systemd/system/ \ + /lib/systemd/user/ \ + /run/systemd/system/ \ /usr/lib/systemd/network/ \ + /usr/lib/systemd/system/ \ /usr/lib/systemd/user/ \ - /var/log/dumps/ \ ; do [[ ! -d "${gen1_d}${dir}" ]] && continue [[ ! -d "${gen2_d}${dir}" ]] && continue @@ -254,9 +287,9 @@ DiffGenerations() { # root folders results in misleading output ... [[ "$dir" == "/" && ! -d "${gen1_d}${dir}/etc" ]] && continue - [[ $VERBOSE -ne 0 ]] && echo "Checking \"$dir\" ..." - ListDirectory "${gen1_d}" "${dir}" >"$tmp_1" - ListDirectory "${gen2_d}" "${dir}" >"$tmp_2" + [[ $VERBOSE -ne 0 ]] && echo "Checking systemd hierarchy \"$dir\" ..." + ListFilesRecursive "${gen1_d}" "${dir}" >"$tmp_1" + ListFilesRecursive "${gen2_d}" "${dir}" >"$tmp_2" if ! diff -U 0 "$tmp_1" "$tmp_2" >"$tmp_diff"; then BeginDiff "\"$dir\" directory" tail -n +3 "$tmp_diff" | grep -Ev '^@@ ' | PipeDiff