From 27fec6958beba7777d592750a396c458a2bcf47f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 7 Sep 2016 18:51:26 +0200 Subject: scripts: improve config diff to support directories and removed files There were several issues with the config diff. First, it used to recurse into sub-directories regardless of the fact that -r was not specified to diff. Second, removed files wouldn't be printed, which is problematic when comparing with the flash as it can reveal an operator mistake. The comparison has now changed to use grep instead of tar to search for files to be ignored. We now dump everything but directories in the output to fix the double outputs and to ensure that even missing files are listed. --- scripts/restore-etc | 9 +++++---- scripts/save-etc | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/restore-etc b/scripts/restore-etc index a5231ec..2e55690 100755 --- a/scripts/restore-etc +++ b/scripts/restore-etc @@ -297,10 +297,11 @@ if [ $DIFF -eq 1 ]; then restore_config flx check --ignore-dot --ignore-link --ignore-date "$ROOTDIR"/etc=etc /etc=etc \ - | awk '/^[+>]/ { print $9 }' \ - | tar -C / -T - --one-file-system --numeric-owner --no-recursion --exclude-from $EXCLUDE -cf - \ - | tar tf - \ - | while read; do diff -puN "$ROOTDIR/etc"${REPLY#etc} /etc${REPLY#etc}; done + | awk '/^. [^d]/ { print $9 }' | sort -u \ + | while read; do + grep -qxF "$REPLY" "$EXCLUDE" && continue + diff --label="flash/${REPLY}" --label="running/${REPLY}" -puN "$ROOTDIR/etc"${REPLY#etc} /etc${REPLY#etc} + done # remove the temporary dir. Better add some checks to avoid a dangerous # reuse of this code our of context... diff --git a/scripts/save-etc b/scripts/save-etc index 911417f..7b6600a 100755 --- a/scripts/save-etc +++ b/scripts/save-etc @@ -118,14 +118,14 @@ archive_etc() { | gzip -c9 } -# emits a diff between factory and /etc on stdout. Note that tar is only used -# to comply with ignore-files here. +# emits a diff between factory and /etc on stdout. diff_etc() { flx check --ignore-dot --ignore-link --ignore-date $REFERENCE=etc /etc=etc \ - | awk '/^[+>]/ { print $9 }' \ - | tar -C / -T - --one-file-system --numeric-owner --no-recursion --exclude-from $EXCLUDE -cf - \ - | tar tf - \ - | while read; do diff -puN ${REFERENCE}${REPLY#etc} /etc${REPLY#etc}; done + | awk '/^. [^d]/ { print $9 }' | sort -u \ + | while read; do + grep -qxF "$REPLY" "$EXCLUDE" && continue + diff --label="factory/${REPLY}" --label="running/${REPLY}" -puN "${REFERENCE}${REPLY#etc}" "/etc${REPLY#etc}" + done } # creates a secure empty temporary directory and returns its full path name. -- 1.7.12.1