#!/bin/sh -e # written by Thomas Penteker Mon Sep 18 00:32:57 CEST 2006 # version 28686736 # this script possibly updates your current kernel (no 'installation' is done) # no responsibility is taken # depends on: wget, (g)unzip # main script routine main() { configfile=$(get_config) if [ "$configfile" = "none" ]; then echo Options echo " CONFIG=y" echo " CONFIG_PROC=y" echo "have to be set in your kernel config or provide your .config" echo "in the same directory as this script." exit 1 fi remote_version=${remote_version:-$(remote_v)} #if [ $force = 1 ];then # local_version=$remote_version #else local_version=$(local_v) #fi if [ "$remote_version" != "$local_version" ]; then echo "new kernel $remote_version" if [ "$test" = 1 ]; then exit 0 else echo "Fetching ${remote_version} from kernel.org" fi fetch_kernel echo " ..done" echo "Unpacking it to $PWD" tar xjf linux-${remote_version}.tar.bz2 echo " ..done" cd linux-${remote_version} if [ $force=1 ];then make clean fi if [ "$configfile" = ".config" ]; then cp ../.config . else zcat /proc/config > .config fi #dopatch make oldconfig echo "+ make -j$(($(grep -c MHz /proc/cpuinfo)-0))" make -j$(($(grep -c MHz /proc/cpuinfo)-1)) if grep -vq "# CONFIG_MODULES" .config; then echo "+ make modules" make modules fi echo "copying kernel to ../bzImage" cp arch/$(arch)/boot/bzImage ../ cd .. #if [ $dell = 1 ]; then # rm -rf linux-${remote_version} #elif [ $delall = 1 ]; then # rm -rf linux-${remote_version} linux-${remote_version}.tar.bz2 #fi echo " ..done" else echo "Kernel up-to-date.(local:$local_version remote:$remote_version)" fi } getoptions() { dell=1 delall=1 while getopts Ddhfr:tp:t option; do case $option in "t") export test=1 ;; "D") export delall=1 ;; "d") export dell=1 ;; "f") export force=1 ;; "r") export remote_version="$OPTARG" ;; "p") echo p $OPTARG ;; #"p") p1[$((${#p1[@]}+1))]=$OPTARG ;; # collect patches [?]|"h") echo "usage: " $(basename $0) "[OPTION] where [OPTION] may be a combination of: [-d] remove linux-x.y.z directory after operation [-D] remove linux-x.y.z directory and archive after opertaion [-t] test mode, check only for new kernel version [-f] force compilation of kernel [-r remote-version] set new kernel version to remote-version [-p diff1 -p diff2 ...] apply patches (i.e. patch -p1 -i diff1)";exit ;; esac done } local_v() { echo $(uname -r | cut -d '-' -f 1 | sed -e 's/\([0-9]\+\)\([\.0-9]\+\)\(.*\)/\1\2/g') } remote_v() { echo $(wget -qO - kernel.org/kdist/finger_banner | sort -n -r | \ awk -F: '/stable/ { gsub(" ","",$2); print $2; exit }') } #dopatch() { # if [ ${#p1[@]} -gt 0 ]; then # for i in ${p1[@]};do # echo "Applying patch $i" # patch -s -p1 -i ../"$i"; # done # fi #} get_config() { if [ -f "${PWD}"/.config ]; then echo .config elif [ -f /proc/config.gz ]; then echo /proc/config.gz else echo none fi } arch() { case $(uname -m) in i386|i486|i568|i686) arch=x86 ;; x86_64*) arch=x86 ;; amd64*) arch=x86 ;; alpha*) arch=alpha ;; ia64*) arch=ia64 ;; powerpc*) arch=powerpc ;; ppc*) arch=ppc ;; sparc64*) arch=sparc64 ;; sparc*) arch=sparc ;; mips*) arch=mips ;; *) arch=x86 ;; esac echo $arch } fetch_kernel() { wget -c --timestamping \ http://kernel.org/pub/linux/kernel/v3.0/linux-${remote_version}.tar.bz2 } getoptions $@ main