2007-01-24 19:51:08 +03:00
#!/bin/sh -efu
2002-03-25 23:16:26 +03:00
2007-01-24 18:30:57 +03:00
Usage()
{
2007-01-25 00:32:34 +03:00
[ $1 = 0 ] || exec >&2
2007-01-24 20:37:48 +03:00
echo "Usage: ${0##*/} [diff-options] <directory> <diff-suffix> [patch-name]"
2007-01-24 18:30:57 +03:00
exit $1
}
2007-01-24 17:56:02 +03:00
diff_options=-up
2007-01-24 18:30:57 +03:00
argv=`getopt -n "${0##*/}" -l help \
-o +i,E,b,w,B,a \
-l ignore-case,ignore-tab-expansion,ignore-space-change \
-l ignore-all-space,ignore-blank-lines,text -- "$@"` || Usage 2
eval set -- "$argv"
while :; do
case "$1" in
--help) Usage 0 ;;
--) shift; break ;;
-*) diff_options="$diff_options $1" ;;
*) echo "${0##*/}: unrecognized option $1" >&2; exit 2 ;;
esac
shift
done
if [ $# -lt 2 ]; then
echo "${0##*/}: not enough arguments" >&2
Usage 2
fi
if [ $# -gt 3 ]; then
echo "${0##*/}: too many arguments" >&2
Usage 2
2002-03-26 00:30:54 +03:00
fi
2007-01-24 18:50:59 +03:00
ls "$1"/ >/dev/null || Usage 2
2007-01-24 19:36:32 +03:00
patch=
if [ $# = 3 ]; then
patch="${1%/}"
if [ "$patch" = . ]; then
patch="${PWD##*/}"
fi
if [ -n "$3" ]; then
patch="$patch-$3"
fi
2003-09-27 21:51:39 +04:00
: ${SOURCEDIR:=`rpm --eval %_sourcedir`}
2007-01-24 19:36:32 +03:00
patch="$SOURCEDIR/$patch.patch"
: >"$patch"
2003-09-27 21:51:39 +04:00
fi
2002-03-26 00:30:54 +03:00
2003-09-27 21:51:39 +04:00
find "$1" -mindepth 1 \( -name "*$2" -o -name ".*$2" \) -print |
2007-01-24 17:40:19 +03:00
LC_COLLATE=C sort -u |
2007-01-24 17:41:51 +03:00
while read -r fin; do
2007-01-24 20:16:59 +03:00
fin="${fin#./}"
2007-01-24 20:15:34 +03:00
fou="${fin%$2}"
2003-09-27 21:51:39 +04:00
[ -r "$fin" ] || fin="/dev/null"
[ -r "$fou" ] || fou="/dev/null"
2007-01-24 19:36:32 +03:00
if [ -n "$patch" ]; then
diff $diff_options -- "$fin" "$fou" |tee -a "$patch"
2003-09-27 21:51:39 +04:00
else
2007-01-24 19:51:08 +03:00
diff $diff_options -- "$fin" "$fou" || [ $? = 1 ]
2003-09-27 21:51:39 +04:00
fi
done
2007-01-24 19:36:32 +03:00
2007-01-24 22:03:11 +03:00
if [ -n "$patch" ]; then
echo
ls -l "$patch"
fi