Cosmetics: Advanced - LAN access
[tomato.git] / toolchain / scripts / patch-kernel.sh
blob1427a28f2231772b330d3dbdba1486f3165f21eb
1 #! /bin/sh
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 patchpattern=${3-*}
13 if [ ! -d "${targetdir}" ] ; then
14 echo "Aborting. '${targetdir}' is not a directory."
15 exit 1
17 if [ ! -d "${patchdir}" ] ; then
18 echo "Aborting. '${patchdir}' is not a directory."
19 exit 1
22 for i in ${patchdir}/${patchpattern} ; do
23 case "$i" in
24 *.gz)
25 type="gzip"; uncomp="gunzip -dc"; ;;
26 *.bz)
27 type="bzip"; uncomp="bunzip -dc"; ;;
28 *.bz2)
29 type="bzip2"; uncomp="bunzip2 -dc"; ;;
30 *.zip)
31 type="zip"; uncomp="unzip -d"; ;;
32 *.Z)
33 type="compress"; uncomp="uncompress -c"; ;;
34 *.patch | *.diff)
35 type="plaintext"; uncomp="cat"; ;;
37 echo "Ignoring unknown ${i}"; continue; ;;
38 esac
39 [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue
40 echo ""
41 echo "Applying ${i} using ${type}: "
42 ${uncomp} ${i} | patch -p1 -E -d ${targetdir}
43 if [ $? != 0 ] ; then
44 echo "Patch failed! Please fix $i!"
45 exit 1
47 done
49 # Check for rejects...
50 if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
51 echo "Aborting. Reject files found."
52 exit 1
55 # Remove backup files
56 find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;