add basic support for raspberry pi2
[openadk.git] / scripts / patch.sh
blob863de3cfb1362055552f79e046d714039cb172f7
1 #!/usr/bin/env bash
2 # A little script I whipped up to make it easy to
3 # patch source trees and have sane error handling
4 # -Erik
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.
12 targetdir=${1-.}
13 patchdir=${2-../patches}
14 patchpattern=${3-*}
16 if [ ! -d "${targetdir}" ] ; then
17 echo "Aborting. '${targetdir}' is not a directory."
18 exit 1
20 if [ ! -d "${patchdir}" ] ; then
21 echo "Aborting. '${patchdir}' is not a directory."
22 exit 0
25 wd=$(pwd)
26 cd $patchdir
27 rm -f $targetdir/.patch.tmp
28 for i in $(eval echo ${patchpattern}); do
29 test -e "$i" || continue
30 i=$patchdir/$i
31 cd $wd
32 case $i in
33 *.gz)
34 type="gzip"; uncomp="gunzip -dc"; ;;
35 *.bz)
36 type="bzip"; uncomp="bunzip -dc"; ;;
37 *.bz2)
38 type="bzip2"; uncomp="bunzip2 -dc"; ;;
39 *.zip)
40 type="zip"; uncomp="unzip -d"; ;;
41 *.Z)
42 type="compress"; uncomp="uncompress -c"; ;;
44 type="plaintext"; uncomp="cat"; ;;
45 esac
46 [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue
47 echo ""
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
53 if [ $? != 0 ] ; then
54 echo "Patch failed! Please fix $i!"
55 exit 1
57 cd $patchdir
58 done
60 # Check for rejects...
61 if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
62 echo "Aborting. Reject files found."
63 exit 1
66 # Remove backup files
67 find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;