#!/bin/sh
. /etc/init.d/functions.sh

if [ -z "$1" ]; then
	KV=`ketchup -m 2>/dev/null`

	if [ -z "$KV" ]; then
		KV=`readlink $PWD`
		KV=`basename "$KV"`
		test -z "$KV" && KV=`basename $PWD`
		KV=${KV:6}
		if [ -z "$KV" ]; then
			eerror "Could not resolve kernel version"
			exit 1
		fi
	fi
else
	KV=$1
fi

einfo "I am now going to build kernel $KV"
einfo "Press C-c to stop or RET to continue..."
read

set -ex

make -j4
make modules_install
cp arch/*/boot/bzImage /boot/kernel-$KV
cp .config /boot/config-$KV
m4conf-update