really tasty addition of remote compares using ssh syntax, e.g. host:path notation.
[feisty_meow.git] / scripts / files / compare_dirs.sh
1 #!/bin/bash
2
3 # compares the files and directory names in two different top-level directories
4 # and prints a report of the differences.
5
6 dir1="$1"; shift
7 dir2="$1"; shift
8
9 if [ -z "$dir1" -o -z "$dir2" ]; then
10   echo This script needs two directory names for which it will create a
11   echo list of differences in the two directory hierarchies.
12   exit 1
13 fi
14 #if [ ! -d "$dir1/" -o ! -d "$dir2/" ]; then
15 #  echo The directories to be compared must already exist.
16 #  exit 1
17 #fi
18 if [ "$dir1" == "$dir2" ]; then
19   echo "The two directories are the exact same folder name.  So that's silly."
20   exit 1
21 fi
22
23 out1="$(mktemp "$TMP/compare_dirs_output.XXXXXX")"
24 out2="$(mktemp "$TMP/compare_dirs_output.XXXXXX")"
25
26
27
28
29 #hmmm: need error checking here!!!!
30
31
32
33
34
35 if [[ $dir1 == *":"* ]]; then
36   # host processing on first dir.
37   host1=${dir1%:*}
38   dir1=${dir1#*:}
39 echo "got host1 as $host1"
40 echo "got new dir1 as $dir1"
41 fi
42 if [[ $dir2 == *":"* ]]; then
43   # host processing on second dir.
44   host2=${dir2%:*}
45   dir2=${dir2#*:}
46 echo "got host2 as $host2"
47 echo "got new dir2 as $dir2"
48 fi
49 if [ -z "$host1" ]; then
50   # fully local compare location for first dir.
51   pushd "$dir1" &>/dev/null
52   find . >"$out1"
53   popd &>/dev/null
54 else
55   # remote compare location for first dir.
56   ssh "$host1" "cd \"$dir1\" && find ." >"$out1"
57 fi
58 # sort the output from that find.
59 sort "$out1" >"$out1".sort
60
61 if [ -z "$host2" ]; then
62   # fully local compare location for second dir.
63   pushd "$dir2" &>/dev/null
64   find . >"$out2"
65   popd &>/dev/null
66 else
67   # remote compare location for second dir.
68   ssh "$host2" "cd \"$dir2\" && find ." >"$out2"
69 fi
70 sort "$out2" >"$out2".sort
71
72 diff "$out1".sort "$out2".sort
73
74 rm "$out1" "$out1".sort "$out2" "$out2".sort
75