dhilst

compiling the kernel

#!/bin/bash

# This script will download, check, compile and install modules of a chosen kernel
# at a setted directory. You must suply your password for root needed
# actions

# set variables
VERSION='2.6.35.4' # what is the kernel version
UNPACKDIR=/usr/src/ # where to unpack
EXTENSION=tar.bz2 # the kernel extension
RC=1 # this will be incremented at every compile
TARGET=/home/geckos/projects/goot # where to copy kernel
T_ROOT=${TARGET}/root # where to install modules
# stop here

SRC=linux-${VERSION}
SRCDIR=${UNPACKDIR}${SRC}
SRCFILE="${SRC}.${EXTENSION}"
CHECKSUM="${SRCFILE}.sign"
LINUX_URL="ftp://ftp.kernel.org/pub/linux/kernel/v2.6"
MAKEOPTION="menuconfig"

for ARG in $@; do
case $ARG in
makeopt=*)
MAKEOPTION=`echo $ARG | cut -f2 -d=`
;;
unpack)
sudo rm ${SRCDIR} -r
;;
download)
rm ${SRCFILE} ${CHECKSUM}
;;
esac
done

# check source
chk_src () {
echo "Checking source ..."
if [ ! -d "${SRCDIR}" ]; then
if [ ! -r "${SRCFILE}" ]; then
wget -c "${LINUX_URL}/${SRCFILE}" || return 1
fi
if [ ! -r "${CHECKSUM}" ]; then
wget -c "${LINUX_URL}/${CHECKSUM}" || return 1

fi
gpg2 --keyserver wwwkeys.pgp.net --recv-keys 0x517D0F0E
gpg2 --verify ${CHECKSUM} ${SRCFILE} || return 1
sudo tar vxf ${SRCFILE} -C ${UNPACKDIR} && return 0 || return 1
fi
echo "DONE"
return 0
}

# build kernel
build () {
echo "Starting build ..."
# to install modules at target
export INSTALL_MOD_PATH=${T_ROOT}
{ sudo make -C ${SRCDIR} mrproper ; } &&
{ sudo make -C ${SRCDIR} ${MAKEOPTION}; } &&
{ sudo make -C ${SRCDIR}; } &&
{ sudo make -C ${SRCDIR} modules_install; } || return 1;
echo "DONE"
}

# copy files
cpy_files () {
echo "Copying files..."
cp ${SRCDIR}/arch/x86/boot/bzImage ${TARGET}vmlinuz-${VERSION} -v;
cp ${SRCDIR}/.config ${TARGET}config-${VERSION} -v;
echo "DONE"
}

# increment the RC of this file at every execution
inc_rc () {
N=`sed -n 's|^RC=\([0-9]\{1,2\}\)$|\1|p' $0`
let N++
sed -e "s|^RC=.*$|RC=$N|" -i $0
}

# main
echo "Start.."
{
chk_src &&
build &&
cpy_files &&
inc_rc
} &&
echo "Finish" || echo "Fails"