Merge branch 'qtopia-fixes' of git://git.busybox.net/~tpetazzoni/git/buildroot
[avatt.git] / toolchain / patch-kernel.sh
blobe2e89486d3781e25f2dc4bc1849eb382981be071
1 #! /bin/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) 2002 Erik Andersen <andersen@codepoet.org>
8 # Set directories from arguments, or use defaults.
9 targetdir=${1-.}
10 patchdir=${2-../kernel-patches}
11 shift 2
12 patchpattern=${@-*}
14 if [ ! -d "${targetdir}" ] ; then
15 echo "Aborting. '${targetdir}' is not a directory."
16 exit 1
18 if [ ! -d "${patchdir}" ] ; then
19 echo "Aborting. '${patchdir}' is not a directory."
20 exit 1
23 for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do
24 case "$i" in
25 *.gz)
26 type="gzip"; uncomp="gunzip -dc"; ;;
27 *.bz)
28 type="bzip"; uncomp="bunzip -dc"; ;;
29 *.bz2)
30 type="bzip2"; uncomp="bunzip2 -dc"; ;;
31 *.zip)
32 type="zip"; uncomp="unzip -d"; ;;
33 *.Z)
34 type="compress"; uncomp="uncompress -c"; ;;
36 type="plaintext"; uncomp="cat"; ;;
37 esac
38 echo ""
39 echo "Applying ${i} using ${type}: "
40 echo ${i} | cat >> ${targetdir}/.applied_patches_list
41 ${uncomp} ${patchdir}/${i} | patch -p1 -E -d ${targetdir}
42 if [ $? != 0 ] ; then
43 echo "Patch failed! Please fix $i!"
44 exit 1
46 done
48 # Check for rejects...
49 if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
50 echo "Aborting. Reject files found."
51 exit 1
54 # Remove backup files
55 find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;