1#! /bin/sh 2# Script to apply kernel patches. 3# usage: patch-kernel [ sourcedir [ patchdir ] ] 4# The source directory defaults to /usr/src/linux, and the patch 5# directory defaults to the current directory. 6# 7# It determines the current kernel version from the top-level Makefile. 8# It then looks for patches for the next sublevel in the patch directory. 9# This is applied using "patch -p1 -s" from within the kernel directory. 10# A check is then made for "*.rej" files to see if the patch was 11# successful. If it is, then all of the "*.orig" files are removed. 12# 13# Nick Holloway <Nick.Holloway@alfie.demon.co.uk>, 2nd January 1995. 14 15# Set directories from arguments, or use defaults. 16sourcedir=${1-/usr/src/linux} 17patchdir=${2-.} 18 19# set current VERSION, PATCHLEVEL, SUBLEVEL 20eval `sed -n 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' $sourcedir/Makefile` 21if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] 22then 23 echo "unable to determine current kernel version" >&2 24 exit 1 25fi 26 27echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL" 28 29while : 30do 31 SUBLEVEL=`expr $SUBLEVEL + 1` 32 patch=patch-$VERSION.$PATCHLEVEL.$SUBLEVEL.gz 33 if [ ! -r $patchdir/$patch ] 34 then 35 break 36 fi 37 38 echo -n "Applying $patch... " 39 if gunzip -dc $patchdir/$patch | patch -p1 -s -N -E -d $sourcedir 40 then 41 echo "done." 42 else 43 echo "failed. Clean up yourself." 44 break 45 fi 46 if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] 47 then 48 echo "Aborting. Reject files found." 49 break 50 fi 51 # Remove backup files 52 find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \; 53done 54

