rm -f ${tm}*
usage="Usage: $tag <dir1> <dir2>"
# set `getopt -- vxh $*`
while [ $# -gt 0 ]; do case "$1" in -v|-x) set "$1" ;; -vi) vilock $tag && { vi $0; viunlock $tag; }; exit ;; -view) view $0; exit ;; -about) echo "$tag was written by David Ledger" echo "dledger@ivdcs.demon.co.uk" echo "Free to use at your own risk" echo "Copyright 2000" exit ;; -h) $0 --h | ${PAGER-more} exit ;; --h) echo "" echo "$usage" echo "" echo "$tag compares tree <arg1> with tree <arg2>." echo "" echo "Files that exist in one tree and not in the other are" echo "always reported. There are various other levels of check" echo "that are selected additively or subtractively by command" echo "arguments. The levels are the inclusion or exlusion of" echo "the individual fields of an 'ls -l' output. The actual" echo "contents of files are not compared." echo "" echo "-full = show any differences." echo "-mode = show differences in file mode." echo "-links = show differences in link count." echo "-owner = show differences in file ownership." echo "-group = show differences in file group." echo "-size = show differences in file size." echo "-dest = show differences in link destination." echo "-time = show differences in file date or time." echo "-date = show differences in file date." echo "+mode = ignore differences in file mode." echo "+links = ignore differences in link count." echo "+owner = ignore differences in file ownership." echo "+group = ignore differences in file group." echo "+size = ignore differences in file size." echo "+dest = ignore differences in link destination." echo "+time = ignore differences in file time." echo "+date = ignore differences in file date or time." echo "" echo "The above modifiers accumulate from left to right along" echo "the command line." echo "" echo "" echo "Any two different files of the same length in the same" echo "relative locations and with all other properties" echo "identical will not be found by ${tag}." echo "" echo "Unreadable directories will cause great ammounts of" echo "output." echo "" echo "" echo "" exit ;; -a) lsflgs="-a" ;; -full) lev=9 ;; -lev*) [ "${1#-lev}" ] && lev=${1#-lev}9 || { print $lev; exit; } ;; -mode) : ${lev="1234567890"}; lev=${lev%1*}${lev#*1} ;; -lin*) : ${lev="1234567890"}; lev=${lev%2*}${lev#*2} ;; -own*) : ${lev="1234567890"}; lev=${lev%3*}${lev#*3} ;; -gro*) : ${lev="1234567890"}; lev=${lev%4*}${lev#*4} ;; -grp) : ${lev="1234567890"}; lev=${lev%4*}${lev#*4} ;; -siz*) : ${lev="1234567890"}; lev=${lev%5*}${lev#*5} ;; -dest) : ${lev="1234567890"}; lev=${lev%0*}${lev#*0} ;; -time) : ${lev="1234567890"} lev=${lev%6*}${lev#*6} lev=${lev%7*}${lev#*7} lev=${lev%8*}${lev#*8} ;; -da*) : ${lev="1234567890"} lev=${lev%6*}${lev#*6} lev=${lev%7*}${lev#*7} ;; +mode) lev="1${lev-9}" ;; +lin*) lev="2${lev-9}" ;; +own*) lev="3${lev-9}" ;; +gro*) lev="4${lev-9}" ;; +grp) lev="4${lev-9}" ;; +siz*) lev="5${lev-9}" ;; +dest) lev="0${lev-9}" ;; +time) lev="8${lev-9}" ;; +da*) lev="678${lev-9}" ;; -i) shift || exit ign="${ign-}${ign+ } \$9 ~ a \"$1\" { next }" ign="${ign} \$9 ~ b \"$1\" { next }" ;; *) ppwd=$PWD cd "$1" || { print "$usage"; exit; } [ "$a" ] && b=$(pwd) || a=$(pwd) cd $ppwd ;; esac shift done
[ "$b" ] || { print "$usage"; exit; } llr() { ls -lR $lsflgs $* | awk -v d=. 'BEGIN { llfmt9 = "%s%4d %-9s%-9s%7d%4s%3d%6s %s\n" llfmt11 = "%s%4d %-9s%-9s%7d%4s%3d%6s %s -> %s\n" } $9 == "." { next } $9 == ".." { next } NF==1 { sub(/:$/,"") d=$1 } NF == 9 { $9=d "/" $9 printf(llfmt9, $1,$2,$3,$4,$5,$6,$7,$8,$9) } NF == 11 { $9=d "/" $9 printf(llfmt11, $1,$2,$3,$4,$5,$6,$7,$8,$9,$11) }' }
llr $a $b | awk 'BEGIN { a = "'"$a"'/"; b = "'"$b"'/" lev = "'"${lev--1}"'" } '"$ign"' $9 ~ a { x = $9 sub(a, "", x) A[x] = $0 } $9 ~ b { x = $9 sub(b, "", x) B[x] = $0 } END { for (x in A) { #print x, A[x] if (x in B) { if (lev + 1) { na = split(A[x], la) nb = split(B[x], lb) if (na != nb) { print "Column count:" print A[x] print B[x] continue } for (i=1; i<=na; i++) { #print lev, i if (index(lev, i==11?0:i)) { continue } if (la[i] != lb[i]) { printf("%s <> %s\n", la[i], lb[i]) print A[x] print B[x] break } } if (la[i] != lb[i]) { continue } } } else { print x " not in " b } } for (x in B) { #print x, B[x] if (x in A) { #print B[x], A[x] } else { print x " not in " a } } }' | |