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