Hi Phil,
nice patch. Tested and pushed,
best regards
Waldemar
Phil Sutter wrote,
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(a)nwl.cc>
---
package/cfgfs/src/fwcf.sh | 42 +++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/package/cfgfs/src/fwcf.sh b/package/cfgfs/src/fwcf.sh
index c6008e93ad7c6..0d572595a50d6 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 @@ $what
$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
--
2.38.0