head	1.2;
access;
symbols
	RELEASE-1_4:1.2.0.2
	GENTOO_1_4_SNAP_2003010800:1.2;
locks; strict;
comment	@# @;


1.2
date	2002.10.25.21.36.39;	author lostlogic;	state Exp;
branches;
next	1.1;

1.1
date	2002.06.16.14.24.47;	author lamer;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2005.11.30.09.59.59;	author chriswhite;	state Exp;
branches;
next	;


desc
@@


1.2
log
@update cuz I fixored it.
@
text
@#! /bin/sh
#
# addpatches - a script to apply a kernel patch set.
#
# In a patch directory, the patches are organized with a numeric prefix:
#    00_*
#    01_*
#    02_*
#    ...
#    99_*
# They should be sortable by the wildcard expression '*_*'.
#
# Usage: addpatches [ patcharg [ sourcedir [ patchdir ] ] ]
#     The source directory defaults to /usr/src/linux, and the patch
#     directory defaults to the current directory
#
# addpatches determines the current kernel version from the top-level Makefile.
# It then looks for patches for the next sublevel in the patch directory.
# This is applied using "patch -p1 -s" from within the kernel directory.
# A check is then made for "*.rej" files to see if the patch was
# successful.  If it is, then all of the "*.orig" files are removed.
#
# Thanks to
#       Nick Holloway <Nick.Holloway@@alfie.demon.co.uk>
#       Adam Sulmicki <adam@@cfar.umd.edu>
#       Dave Gilbert <linux@@treblig.org>
# for the scripts/patch-kernel script.

# Set directories from arguments, or use defaults.
patcharg=${1-default}
sourcedir=${2-/usr/src/linux}
patchdir=${3-.}
PATCHES=""

# Find a file, first parameter is basename of file
# it tries many compression mechanisms and sets variables to say how to get it
function findFile {
  filebase=$1;

  if [ -r `basename ${filebase} .gz`.gz ]; then
		name="gzip format"
		uncomp="zcat"
  elif [ -r `basename ${filebase} .bz2`.bz2 ]; then
		name="bzip2 format"
		uncomp="bzcat"
  elif [ -r ${filebase} ]; then
		name="plain text format"
		uncomp="cat"
  else
	  return 1;
	fi

  return 0;
}

# Apply a patch and check it goes in cleanly
# First param is patch name 

function applyPatch {
  echo -n "Checking $1 (${name})... "
  if $uncomp ${patchdir}/$1 | patch -p1 --dry-run -s -N -E -d $sourcedir
  then
    echo -n "looks good. Applying... "
    $uncomp ${patchdir}/$1 | patch -p1 -s -N -E -d $sourcedir
	PATCHES="$1 $PATCHES"
    echo "done."
  else
    echo "can't be applied.  Please modify the patch."
	unroll="unroll"
	if [ $patcharg == $unroll ] ;
	then
		echo "Trying to unroll patches applied so far"
	    for i in $PATCHES
		do
			echo -n "Reverting $i ..."
	        findFile $patchdir/$i || break
	        $uncomp ${patchdir}/$i | patch -p1 -R -s -E -d $sourcedir
			echo "done."
	    done	
	fi
    return 1;
  fi
  if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
  then
    echo "Hmm.  Reject files found."
    return 1;
  fi
  # Remove backup files
  find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;

  return 0;
}

# set current VERSION, PATCHLEVEL, SUBLEVEL, EXTERVERSION
eval `sed -n -e 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' -e 's/^\([A-Z]*\) = \(-[-a-z0-9]*\)$/\1=\2/p' $sourcedir/Makefile`
if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ]
then
    echo "unable to determine current kernel version" >&2
    exit 1
fi

echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION}"

if [ -d $patchdir ]
then
	echo "Scanning patch directory: '$patchdir'"
	for i in `ls *_*`
		do
    	findFile $patchdir/$i || exit 1
	    applyPatch $i || exit 1
	done

else
	echo "Patch directory not found"
    exit 1
fi

@


1.1
log
@
Committed this at the request of mjc. Apparently it's a patch managment
script to be used in conjuction with his mjc-sources package.
@
text
@d79 1
a79 1
    	done	
d109 2
a110 2
    	findFile $patchdir/$i || break
	    applyPatch $i || break
@


1.1.1.1
log
@*** empty log message ***
@
text
@d79 1
a79 1
	    done	
d109 2
a110 2
    	findFile $patchdir/$i || exit 1
	    applyPatch $i || exit 1
@


