]> arthur.barton.de Git - backup-script.git/commitdiff
backup-audit: Enhance checking of systemd configuration
authorAlexander Barton <alexander.barton@thomas-daily.de>
Wed, 27 Mar 2019 13:07:21 +0000 (14:07 +0100)
committerAlexander Barton <alexander.barton@thomas-daily.de>
Wed, 27 Mar 2019 13:07:21 +0000 (14:07 +0100)
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.

bin/backup-audit

index cb44382a45a7cf0639f34caef5dcb085328ee52b..146a9559c6be32ea5bf6f1b456697c00935af10a 100755 (executable)
@@ -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