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# Added support for handling multiple types of compression. What includes 16# gzip, bzip, bzip2, zip, compress, and plaintext. 17# 18# Adam Sulmicki <adam@cfar.umd.edu>, 1st January 1997. 19 20# Set directories from arguments, or use defaults. 21sourcedir=${1-/usr/src/linux} 22patchdir=${2-.} 23 24# set current VERSION, PATCHLEVEL, SUBLEVEL 25eval `sed -n 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' $sourcedir/Makefile` 26if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] 27then 28 echo "unable to determine current kernel version" >&2 29 exit 1 30fi 31 32echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL" 33 34while : 35do 36 SUBLEVEL=`expr $SUBLEVEL + 1` 37 patch=patch-$VERSION.$PATCHLEVEL.$SUBLEVEL 38 if [ -r $patchdir/${patch}.gz ]; then 39 ext=".gz" 40 name="gzip" 41 uncomp="gunzip -dc" 42 elif [ -r $patchdir/${patch}.bz ]; then 43 ext=".bz" 44 name="bzip" 45 uncomp="bunzip -dc" 46 elif [ -r $patchdir/${patch}.bz2 ]; then 47 ext=".bz2" 48 name="bzip2" 49 uncomp="bunzip2 -dc" 50 elif [ -r $patchdir/${patch}.zip ]; then 51 ext=".zip" 52 name="zip" 53 uncomp="unzip -d" 54 elif [ -r $patchdir/${patch}.Z ]; then 55 ext=".Z" 56 name="uncompress" 57 uncomp="uncompress -c" 58 elif [ -r $patchdir/${patch} ]; then 59 ext="" 60 name="plaintext" 61 uncomp="cat" 62 else 63 break 64 fi 65 66 echo -n "Applying ${patch} (${name})... " 67 if $uncomp ${patchdir}/${patch}${ext} | patch -p1 -s -N -E -d $sourcedir 68 then 69 echo "done." 70 else 71 echo "failed. Clean up yourself." 72 break 73 fi 74 if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] 75 then 76 echo "Aborting. Reject files found." 77 break 78 fi 79 # Remove backup files 80 find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \; 81done 82

