#!/bin/sh # # fstreediff.sh # # Author: Tomi Ollila # # Copyright (c) 1999 Tomi Ollila # All rights reserved # # Created: Sat Jul 10 10:33:05 1999 too # Last modified: Wed Jun 07 22:15:39 EEST 2006 too # # # Requires in addition to usual commands: perl, xargs, md5sum # LC_ALL=C LANG=C; export LC_ALL LANG # Quick hack for debian. [ -f /usr/bin/md5sum.textutils ] \ && md5sum=/usr/bin/md5sum.textutils || md5sum=md5sum usage () { [ x"$1" != x ] && echo $0: "$@" echo Usage: $0 "[md5file|dir1]" dir2 exit 1 } [ x"$2" = x ] && usage [ ! -d "$2" ] && usage $2: not a directory. if [ -d "$1" ] then trap "rm -f /tmp/fstdf-$USER-$$" 0 rm -f /tmp/fstdf-$USER-$$ /bin/sh $0 /tmp/fstdf-$USER-$$ $1 /bin/sh $0 /tmp/fstdf-$USER-$$ $2 exit 0 fi if [ ! -f "$1" ] then echo "fstreediff.sh md5sum file: directory $2" >$1 ( cd $2; find . -fstype proc -o -fstype sysfs -prune -o -type f -print0 | xargs -0 $md5sum ) >> $1 # ( cd $2; find . -type f -print | sed 's/.*/"&"/' | xargs $md5sum ) >> $1 exit 0 fi tmpdir=/tmp/fstd-$USER-$$ trap "rm -rf $tmpdir" 0 rm -rf $tmpdir mkdir $tmpdir SUMFILE=$tmpdir/sums MD5OUTFILE=$tmpdir/md5out MD5ERRFILE=$tmpdir/md5err sumfile=$1 cmpdir=$2 set x `head -1 "$sumfile"` [ x"$2$3$4$5" != xfstreediff.shmd5sumfile:directory ] && { shift; echo $0: $sumfile: unknown header format "(or not a directory)": echo " <<<<" "$@" ">>>>"; exit 1 } shift 5 [ x$1 != x ] && firstcmp="$@" || firstcmp=$sumfile tail -n +2 "$sumfile" | sort -k 2 > $SUMFILE || exit 1 cd $cmpdir $md5sum -c $SUMFILE > $MD5OUTFILE 2> $MD5ERRFILE [ ! -s $MD5OUTFILE ] && exit 1 echo echo "===" Files that differ "===" grep 'FAILED$' $MD5OUTFILE | cut -d: -f1 echo echo "<<<" Files that are only in $firstcmp "<<<" #grep -v WARNING $MD5ERRFILE | cut -d: -f2 sed -n '/No such file/ s/.*: \(\.\/\)*\(.*\):.*/\2/p' $MD5ERRFILE echo echo ">>>" Files that are only in $cmpdir ">>>" find . -fstype proc -o -fstype sysfs -prune -o -type f -print | sort | perl -e ' open(F, "'$SUMFILE'") || die "Cannot open '$SUMFILE': $!\n"; while() { m|\S+\s+(\./)?(.*)|; $assoc{$2} = 1; #print "* $2\n"; } close F; while (<>) { chop; s|\./||; # next if /\.thumbnails/; print "$_\n" if (! $assoc{$_}); } ' echo