#!/bin/bash

# compile kernel
[ "$1" == "install" ] || nice make modules modules_install bzImage || exit

# copy kernel from / to /boot/dir
mf='Makefile'
cf='.config'
V0='/boot/'

V=$(grep -e '^VERSION *=' -e '^PATCHLEVEL *=' -e '^SUBLEVEL *=' $mf)
V1=$(sed -n '/^VERSION *=/{s/[^=]*= *\([0-9]*\)/\1/;p}' <<< "$V")
V2=$(sed -n '/^PATCHLEVEL *=/{s/[^=]*= *\([0-9]*\)/\1/;p}' <<< "$V")
V3=$(sed -n '/^SUBLEVEL *=/{s/[^=]*= *\([0-9]*\)/\1/;p}' <<< "$V")
V4=$(sed -n '/^CONFIG_LOCALVERSION *=/{s/[^=]*= *"\([^"]*\)"/\1/;p}' $cf)

ver=$V1.$V2.$V3$V4
dir=$V0$ver

echo
echo "Installing kernel to \"$dir\"..."

if [ -d "$dir" ]
then 
	echo "$dir alerady exists."
else
	mkdir "$dir" && echo "$dir created."
fi

( cp -v arch/i386/boot/bzImage "$dir/vmlinuz-$ver" \
&& cp -v .config "$dir/config-$ver" \
&& echo Done. ) || exit


echo
echo ----- Compilation Complete -----
echo

#beep \
#	-n -f  440	-d 80	-l 120	-r 2	\
#	-n -f  480	-D 40			\
#	-n -f  520				\
#	-n -f  660	-d 60	-l 120	-r 2	\
#	&


