diff options
author | Phil Sutter <phil@nwl.cc> | 2023-01-09 16:26:34 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2023-01-10 07:53:42 +0100 |
commit | 7a7f6d2e42f3e074fc22df471aede53bd85aad98 (patch) | |
tree | 334da7e1748fda84cbef547f261802bc0a79fcda /package | |
parent | 191e8aaad69a822fbfbec12dd4b24ef5d244037d (diff) |
package: cfgfs: implement 'diff' command
Sometimes it is unclear how exactly files changed in /etc and the md5sum
is no help there. Implement a diff command for these situations. It is
pretty inefficient since it has to perform a second 'setup' before the
actual 'diff' call. To cover for missing recursion support (and also
exclude internal files) by calling diff for each file separately.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'package')
-rw-r--r-- | package/cfgfs/src/fwcf.sh | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/package/cfgfs/src/fwcf.sh b/package/cfgfs/src/fwcf.sh index c6008e93a..0d572595a 100644 --- a/package/cfgfs/src/fwcf.sh +++ b/package/cfgfs/src/fwcf.sh @@ -56,7 +56,7 @@ usage() { $what Usage: { halt | poweroff | reboot } [-Ffn] [-d delay] - cfgfs { commit | erase | setup | status | dump | restore } [flags] + cfgfs { commit | erase | setup | status | diff | dump | restore } [flags] EOF exit 1 } @@ -101,7 +101,7 @@ if [[ $me != cfgfs ]]; then fi case $1 in -(commit|erase|setup|status|dump|restore) ;; +(commit|erase|setup|status|diff|dump|restore) ;; (*) cat >&2 <<EOF $what Syntax: @@ -109,6 +109,7 @@ Syntax: $0 erase $0 setup [-N] $0 status [-rq] + $0 diff [<diff options>] $0 { dump | restore } [<filename>] EOF exit 1 ;; @@ -435,5 +436,42 @@ if test $1 = restore; then exit 0 fi +if test $1 = diff; then + if test ! -e /tmp/.cfgfs; then + cat >&2 <<-EOF + cfgfs: error: not yet initialised + explanation: "cfgfs setup" was not yet run + EOF + [[ $1 = -f ]] || exit 11 + fi + shift + tempd=/tmp/.cfgfs/temp + mount -t tmpfs none $tempd + (cd /tmp/.cfgfs/root; tar cf - .) | (cd $tempd; tar xpf - 2>/dev/null) + x=$(dd if="$part" bs=4 count=1 2>/dev/null) + [[ "$x" = "FWCF" ]] && cfgfs.helper -U $tempd <"$part" + + if test -e $tempd/.cfgfs_deleted; then + while IFS= read -r file; do + rm -f "$tempd/$file" + done <$tempd/.cfgfs_deleted + rm -f $tempd/.cfgfs_deleted + fi + (cd /etc; find . -type f; \ + cd $tempd; find . -type f \ + ) | grep -v -e '^./.cfgfs' -e '^./.rnd$' | sort -u | while read f; do + f=${f#./} + if [ ! -e "/etc/$f" ]; then + echo "Deleted: /etc/$f" + elif [ ! -e "$tempd/$f" ]; then + echo "New: /etc/$f" + else + diff "$@" "$tempd/$f" "/etc/$f" + fi + done + umount $tempd + exit 0 +fi + echo 'cfgfs: cannot be reached...' exit 255 |