2 # A little script I whipped up to make it easy to
3 # patch source trees and have sane error handling
6 # (c) 2006, 2007 Thorsten Glaser <tg@freewrt.org>
7 # (c) 2002 Erik Andersen <andersen@codepoet.org>
9 [[ -n $BASH_VERSION ]] && shopt -s extglob
11 # Set directories from arguments, or use defaults.
13 patchdir
=${2-../patches}
16 if [ ! -d "${targetdir}" ] ; then
17 echo "Aborting. '${targetdir}' is not a directory."
20 if [ ! -d "${patchdir}" ] ; then
21 echo "Aborting. '${patchdir}' is not a directory."
27 rm -f $targetdir/.
patch.tmp
28 for i
in $
(eval echo ${patchpattern}); do
29 test -e "$i" ||
continue
34 type="gzip"; uncomp
="gunzip -dc"; ;;
36 type="bzip"; uncomp
="bunzip -dc"; ;;
38 type="bzip2"; uncomp
="bunzip2 -dc"; ;;
40 type="zip"; uncomp
="unzip -d"; ;;
42 type="compress"; uncomp
="uncompress -c"; ;;
44 type="plaintext"; uncomp
="cat"; ;;
46 [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue
48 echo "Applying ${i} using ${type}: "
49 ${uncomp} ${i} | tee $targetdir/.patch.tmp | patch -p1 -E -d ${targetdir}
50 fgrep
'@@ -0,0 ' $targetdir/.
patch.tmp
>/dev
/null
2>&1 && \
51 touch $targetdir/.patched-newfiles
52 rm -f $targetdir/.
patch.tmp
54 echo "Patch failed! Please fix $i!"
60 # Check for rejects...
61 if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
62 echo "Aborting. Reject files found."
67 find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \
;