| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Default value for the RMGDIFF_GUI environment variable. |
| 4 |
: ${RMGDIFF_GUI:=/usr/bin/mgdiff} |
| 5 |
|
| 6 |
# |
| 7 |
# You shouldn't need to edit beneath here. |
| 8 |
# |
| 9 |
|
| 10 |
SHOW_FILE_TYPES="TRUE" |
| 11 |
USE_CVS="" |
| 12 |
DEBUG="" |
| 13 |
USE_GUI="TRUE" |
| 14 |
RMGDIFF_VERSION="" |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
Usage() { |
| 19 |
cat <<-EOF |
| 20 |
|
| 21 |
Usage: `basename "$0"` [-b] [-c] [-d] [-g <gui>] [-n] [-v] <dir1> <dir2> |
| 22 |
|
| 23 |
-b: basic reporting (no file type info will be printed) |
| 24 |
-c: cvs files will be included in diff |
| 25 |
-d: print debugging information |
| 26 |
-g: which gui to use |
| 27 |
-n: no gui will pop up |
| 28 |
-v: version |
| 29 |
|
| 30 |
EOF |
| 31 |
} |
| 32 |
|
| 33 |
verify_exec () { |
| 34 |
type "$1" 1>/dev/null 2>&1 |
| 35 |
if [ $? -ne 0 ] ; then |
| 36 |
echo "$progname: Error: Unable to find executable for \"$1\"." >&2 |
| 37 |
exit 1 |
| 38 |
fi |
| 39 |
} |
| 40 |
|
| 41 |
# Some machines don't have a "readlink" command. |
| 42 |
read_link_via_ls() { |
| 43 |
if [ $# -ne 1 ] ; then |
| 44 |
echo "$progname: Internal Error: Invalid args for" \ |
| 45 |
"readlink_via_ls: $@" >&2 |
| 46 |
exit 1 |
| 47 |
fi |
| 48 |
|
| 49 |
\ls -l "$1" | sed -e 's|.*-> ||' |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
# Some machines don't have a "realpath" command. follow_link_via_ls |
| 54 |
# does not pretend to be "realpath" because it will leave all sorts of |
| 55 |
# cruft in the path string, but it should eventuall reach a regular |
| 56 |
# file. |
| 57 |
follow_link_via_ls() { |
| 58 |
|
| 59 |
if [ $# -ne 1 ] ; then |
| 60 |
echo "$progname: Internal Error: Invalid args for" \ |
| 61 |
"follow_link_via_ls: $@" >&2 |
| 62 |
exit 1 |
| 63 |
fi |
| 64 |
|
| 65 |
local_iteration_count=0 |
| 66 |
local_iteration_max=1024 |
| 67 |
|
| 68 |
# Prime the pump. |
| 69 |
local_tmp= |
| 70 |
local_rv="$1" |
| 71 |
|
| 72 |
while [ $local_iteration_count -lt $local_iteration_max ] ; do |
| 73 |
|
| 74 |
if [ ! -h "$local_rv" ] ; then |
| 75 |
break |
| 76 |
fi |
| 77 |
|
| 78 |
local_tmp=`read_link_via_ls "$local_rv"` |
| 79 |
|
| 80 |
# The "read_link_via_ls" above could result in an absolute |
| 81 |
# path or a relative one. The Solaris /bin/sh does not |
| 82 |
# support "${PSTREE_AWK_SCRIPT#/}". So, use grep instead. |
| 83 |
echo "$local_tmp" | grep '^/' >/dev/null 2>&1 |
| 84 |
if [ $? -ne 0 ] ; then |
| 85 |
# The path given by readlink was relative. So, we have a |
| 86 |
# little more work to do because we need to prepend the |
| 87 |
# same path used to reach the original symlink. |
| 88 |
local_tmp=`dirname "$local_rv"`/"$local_tmp" |
| 89 |
fi |
| 90 |
|
| 91 |
local_rv="$local_tmp" |
| 92 |
|
| 93 |
local_iteration_count=`expr $local_iteration_count + 1` |
| 94 |
|
| 95 |
done |
| 96 |
|
| 97 |
if [ $local_iteration_count -ge $local_iteration_max ] ; then |
| 98 |
echo "$progname: Error: Symbolic link nesting is too deep when" \ |
| 99 |
"following \"$1\"." >&2 |
| 100 |
exit 1 |
| 101 |
fi |
| 102 |
|
| 103 |
echo "$local_rv" |
| 104 |
|
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
# |
| 109 |
# Script starts here. |
| 110 |
# |
| 111 |
|
| 112 |
progname="rmgdiff" |
| 113 |
verify_exec "basename" |
| 114 |
progname=`basename "$0"` |
| 115 |
|
| 116 |
verify_exec "awk" |
| 117 |
verify_exec "diff" |
| 118 |
verify_exec "dirname" |
| 119 |
verify_exec "expr" |
| 120 |
verify_exec "file" |
| 121 |
verify_exec "grep" |
| 122 |
verify_exec "ls" |
| 123 |
verify_exec "$RMGDIFF_GUI" |
| 124 |
verify_exec "sed" |
| 125 |
|
| 126 |
while getopts "bcdg:nv" OPT ; do |
| 127 |
case "$OPT" in |
| 128 |
b) SHOW_FILE_TYPES="" |
| 129 |
;; |
| 130 |
c) USE_CVS="TRUE" |
| 131 |
;; |
| 132 |
d) DEBUG="TRUE" |
| 133 |
;; |
| 134 |
g) RMGDIFF_GUI="$OPTARG" |
| 135 |
;; |
| 136 |
n) USE_GUI="" |
| 137 |
;; |
| 138 |
v) RMGDIFF_VERSION="TRUE" |
| 139 |
;; |
| 140 |
\?) Usage |
| 141 |
exit 1 |
| 142 |
;; |
| 143 |
esac |
| 144 |
done |
| 145 |
shift `expr $OPTIND - 1` |
| 146 |
|
| 147 |
# |
| 148 |
# Find the rmgdiff awk script. It is located in the same directory as |
| 149 |
# this shell script after following all the symlinks. |
| 150 |
# |
| 151 |
lib_dir=`follow_link_via_ls "$0"` |
| 152 |
RMGDIFF_AWK=`dirname "$lib_dir"`/rmgdiff.awk |
| 153 |
|
| 154 |
|
| 155 |
# If the user just wants the version ... |
| 156 |
if [ -n "$RMGDIFF_VERSION" ] ; then |
| 157 |
exec awk -v version="$RMGDIFF_VERSION" -f "$RMGDIFF_AWK" |
| 158 |
fi |
| 159 |
|
| 160 |
if [ $# -lt 2 ] || [ $# -gt 2 ] ; then |
| 161 |
Usage |
| 162 |
exit 1 |
| 163 |
fi |
| 164 |
|
| 165 |
if [ ! -d "$1" ] ; then |
| 166 |
echo "$progname: dir1=\"$1\" is not a directory." 1>&2 |
| 167 |
exit 1 |
| 168 |
fi |
| 169 |
|
| 170 |
if [ ! -d "$2" ] ; then |
| 171 |
echo "$progname: dir2=\"$2\" is not a directory." 1>&2 |
| 172 |
exit 1 |
| 173 |
fi |
| 174 |
|
| 175 |
LC_MESSAGES=C exec diff -rq "$1" "$2" | awk -v debug="$DEBUG" \ |
| 176 |
-v dir1="$1" \ |
| 177 |
-v dir2="$2" \ |
| 178 |
-v rmgdiff_gui="$RMGDIFF_GUI" \ |
| 179 |
-v show_file_types="$SHOW_FILE_TYPES" \ |
| 180 |
-v use_cvs="$USE_CVS" \ |
| 181 |
-v use_gui="$USE_GUI" \ |
| 182 |
-v version="$RMGDIFF_VERSION" \ |
| 183 |
-f "$RMGDIFF_AWK" |