added comments, removed old commented code.
[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 pushd "$dir1" &>/dev/null
27 find . >"$out1"
28 sort "$out1" >"$out1".sort
29 popd &>/dev/null
30
31 pushd "$dir2" &>/dev/null
32 find . >"$out2"
33 sort "$out2" >"$out2".sort
34 popd &>/dev/null
35
36 diff "$out1".sort "$out2".sort
37
38 rm "$out1" "$out1".sort "$out2" "$out2".sort
39