#!/bin/sh -e
# $Id: ide.apply,v 1.3 2000/11/18 04:19:04 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=ide

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/')
EXTRAVERSION=$(grep ^EXTRAVERSION Makefile 2>/dev/null | \
                  sed -e 's/[^=]*=[[:blank:]]*\([[:alnum:]]*\)/\1/')

if [ $VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION != 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
