source: freewrt/scripts/patch-kernel.sh@ e840b97

Last change on this file since e840b97 was eab0bcd, checked in by Thorsten Glaser <tg@…>, 19 years ago

these shall not be executable nor use absolute pathnames,
since perl doesn't always live in /usr/bin (e.g. NetBSD®)

git-svn-id: svn://www.freewrt.org/trunk/freewrt@2585 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 1.7 KB
Line 
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
5#
6# (c) 2006, 2007 Thorsten Glaser <tg@freewrt.org>
7# (c) 2002 Erik Andersen <andersen@codepoet.org>
8
9[[ -n $BASH_VERSION ]] && shopt -s extglob
10
11# Set directories from arguments, or use defaults.
12targetdir=${1-.}
13patchdir=${2-../kernel-patches}
14patchpattern=${3-*}
15
16if [ ! -d "${targetdir}" ] ; then
17 echo "Aborting. '${targetdir}' is not a directory."
18 exit 1
19fi
20if [ ! -d "${patchdir}" ] ; then
21 echo "Aborting. '${patchdir}' is not a directory."
22 exit 1
23fi
24
25wd=$(pwd)
26cd $patchdir
27rm -f $targetdir/.patch.tmp
28for 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"; ;;
43 *)
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
56 fi
57 cd $patchdir
58done
59
60# Check for rejects...
61if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
62 echo "Aborting. Reject files found."
63 exit 1
64fi
65
66# Remove backup files
67find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
Note: See TracBrowser for help on using the repository browser.