2 # patch-if-change - Copy FILES to the current directory, apply PATCH,
3 # and restore timestamps on files that weren't changed.
4 # Gordon Matzigkeit <gord@fig.org>, 2001-09-25
6 # Usage: patch-if-change [PATCHFLAGS]... PATCH FILES...
11 # Arguments beginning with a dash are interpreted as options for
13 # The first non-option is the patch file, and the rest are files to be
18 -*) PATCHFLAGS="$PATCHFLAGS $arg" ;;
20 if test -z "$PATCH"; then
29 # Make backups of all the affected files.
30 for file in $FILES; do
31 oldfile=`echo "$file" | sed -e 'sX.*/XX'`
32 test -f $oldfile && { cp -p $oldfile $oldfile.backup || exit $?; }
37 patch $PATCHFLAGS < $PATCH
39 # Revert the files that didn't change.
40 for file in $FILES; do
41 oldfile=`echo "$file" | sed -e 'sX.*/XX'`
42 test -f $oldfile.backup || continue
43 if cmp -s $oldfile $oldfile.backup; then
44 mv -f $oldfile.backup $oldfile