#!/bin/sh -e
# $Id: p3.apply,v 1.2 2000/04/12 06:29:32 herbert Exp $

if ! test -d kernel -a -d Documentation; then
	echo "Not in kernel top level directory. Exiting" >&2
	exit 1
fi

ARCHITECTURE=`dpkg --print-installation-architecture`
PATCHNAME=p3

PATCHDIR=/usr/src/kernel-patches/$ARCHITECTURE/2.2.19

# Example on how to get current kernel version number etc
VERSION=$(grep ^VERSION Makefile 2>/dev/null | \
                 sed -e 's/[^0-9]*\([0-9]*\)/\1/')
PATCHLEVEL=$( grep ^PATCHLEVEL Makefile 2>/dev/null | \
                    sed -e 's/[^0-9]*\([0-9]*\)/\1/')
SUBLEVEL=$(grep ^SUBLEVEL Makefile 2>/dev/null | \
                  sed -e 's/[^0-9]*\([0-9]*\)/\1/')

if [ $VERSION.$PATCHLEVEL.$SUBLEVEL != 2.2.19 ]; then
	echo "The kernel is incompatible with the patch." >&2
	exit 1
fi

if test -f APPLIED_$ARCHITECTURE_$PATCHNAME; then
	exit 0
fi

bzcat $PATCHDIR/$PATCHNAME.bz2 | patch -s -p1

touch APPLIED_$ARCHITECTURE_$PATCHNAME
exit 0
