#!/bin/sh
SRCPATH=/usr/src/linux
if [ ! -d ${SRCPATH} -o ! -L ${SRCPATH} ] ; then
    echo "Kann ${SRCPATH} nicht finden."
    exit -1
fi

if [ $UID -ne 0 ] ; then
    if ! groups | grep -q src ; then
       echo "Nutzer `whoami` ist nicht in der Gruppe src"
       exit -1
    fi
fi

FROOT=fakeroot
if ! which ${FROOT} > /dev/null ; then
    echo "${FROOT} not found."
    exit -1
fi

cd ${SRCPATH}

make-kpkg clean

INITRD=""

if [ _"$1" = _"" ] ; then
    ATREV=at
else
    if [ "$1" = "--initrd" ] ; then
	INITRD="--initrd"
	ATREV=at
    else
   	ATREV=$1
    fi
fi

if [ _"$2" != _"" ] ; then
    ATREV="$2"
fi

nice -n10 ${FROOT} make-kpkg $INITRD --append_to_version "-$ATREV" --revision=${ATREV}.1.7 kernel_image
# nice -n10 ${FROOT} make-kpkg $INITRD --append_to_version "-$ATREV" --revision=${ATREV}.1.7 kernel_image

if [ -d /usr/src/modules ] ; then
    ## nice -n10 fakeroot make-kpkg --revision=1:${SUB}.1.7 modules_image
    nice -n10 fakeroot make-kpkg modules_image
fi
