#! /bin/sh -e # Script to grab a given kernel version (stolen from Virtual Anton). barf() { echo "$@" >&2 exit 1 } PATCHDIR=~/devel/kernel/kernel-patches MIRRORS="rsync://kernel::kernel http://kernel.linux.pacific.net.au/linux/kernel/ rsync://master.kernel.org:/pub/linux/kernel" #MIRRORS="rsync.planetmirror.com::ftp.kernel.org/pub/linux/kernel master.kernel.org:/pub/linux/kernel" # Takes destination directory, and filename, tries each mirror. get_file() { get_file_dir=$1 get_file_name=$2 # Patch there already? if [ -f "$get_file_dir"/"$(basename "$get_file_name")" ]; then echo " Already have patch..." return 0 fi for get_file_server in $MIRRORS; do echo Trying $get_file_server... case $get_file_server in rsync://*) get_file_s=`echo $get_file_server | cut -c9-`; rsync $get_file_s/$get_file_name $get_file_dir && return 0 ;; http://*) get_file_s=`echo $get_file_server | cut -c8-`; wget -O $get_file_dir/`basename $get_file_name` $get_file_s/$get_file_name && return 0 # Leaves a zero-len file on failure 8( rm -f $get_file_dir/`basename $get_file_name` ;; esac done return 1 } if [ $# -ne 2 ]; then echo Usage: $0 version kerneldir >&2 exit 1 fi VERSION=$1 KDIR=$2 if [ -d $KDIR/linux-$VERSION ]; then exit 0; fi MAJOR=`echo $VERSION | cut -d. -f1-2` # Given vanity kernel name, major version, and previous version, produce pathname vanity_source() { case "$1" in *-ac*) echo people/alan/linux-$2/$3/patch-$1.bz2;; *-dj*) echo people/davej/patches/$2/$3/patch-$1.bz2;; *-mm*) echo people/akpm/patches/$2/$3/$1/$1.bz2;; *) barf "Unknown kernel series $1";; esac } # Given base name, new name and patch, do patch application. apply_patch() { rm -rf $KDIR/.linux-$2 cp -al $KDIR/linux-$1 $KDIR/.linux-$2 || barf "Couldn't clone $1 dir" bunzip2 -t $3 || barf "Corrupt patch $3" bzcat $3 | patch -s -d $KDIR/.linux-$2 -p1 || barf "Problem patching new kernel $2" mv $KDIR/.linux-$2 $KDIR/linux-$2 } echo Grabbing $VERSION case "$VERSION" in # Bitkeeper snapshot *-bk*) if [ -d $KDIR/linux-$VERSION ]; then exit 0; fi PREVIOUS=`echo "$VERSION" | sed 's/-bk.*//'` $0 "$PREVIOUS" $KDIR || barf "Couldn't get $PREVIOUS to build $VERSION" # Grab patch get_file $PATCHDIR v$MAJOR/snapshots/patch-$VERSION.bz2 || barf "Couldn't get v$MAJOR/snapshots/patch-$VERSION.bz2" apply_patch $PREVIOUS $VERSION $PATCHDIR/patch-$VERSION.bz2 ;; # Various vanity patches *-mm[0-9]*|*-ac[0-9]*|*-dj[0-9]*) # First make sure we have base tree BASE_KERNEL=`echo "$VERSION" | sed -e 's/-[a-z][a-z][0-9]*$//'` $0 "$BASE_KERNEL" $KDIR || barf "Couldn't get $BASE_KERNEL to build $VERSION" VANITY=`vanity_source $VERSION $MAJOR $BASE_KERNEL` get_file $PATCHDIR $VANITY || barf "Couldn't fetch $VANITY" apply_patch $BASE_KERNEL $VERSION $PATCHDIR/`basename $VANITY` ;; # *-pre*: This refers to the Linus or Marcelo pre-patches. *-pre*|*-rc*) # Linus or Marcelo pre-patch. if [ -d $KDIR/linux-$VERSION ]; then exit 0; fi PREVIOUS=`echo "$VERSION" | sed 's/-\(pre\|rc\).*//'` LAST_VER=`echo "$PREVIOUS" | cut -d. -f3` PREVIOUS=`echo "$PREVIOUS" | cut -d. -f1,2`.`expr $LAST_VER - 1 || true` $0 "$PREVIOUS" $KDIR || barf "Couldn't get $PREVIOUS to build $VERSION" # Grab patch get_file $PATCHDIR v$MAJOR/testing/patch-$VERSION.bz2 || get_file $PATCHDIR v$MAJOR/testing/old/patch-$VERSION.bz2 || barf "Couldn't get v$MAJOR/testing/patch-$VERSION.bz2" apply_patch $PREVIOUS $VERSION $PATCHDIR/patch-$VERSION.bz2 ;; # Linus 2.6.0 test patch. 2.6.0-test*) VER=`echo "$VERSION" | sed 's/.*test//'` PREVIOUS=2.6.0-test`expr $VER - 1 || true` if [ $PREVIOUS = 2.6.0-test0 ]; then PREVIOUS=2.5.75 fi $0 "$PREVIOUS" $KDIR || barf "Couldn't get $PREVIOUS to build $VERSION" # Grab patch get_file $PATCHDIR v$MAJOR/patch-$VERSION.bz2 || get_file $PATCHDIR v$MAJOR/old/patch-$VERSION.bz2 || barf "Couldn't get v$MAJOR/patch-$VERSION.bz2" apply_patch $PREVIOUS $VERSION $PATCHDIR/patch-$VERSION.bz2 ;; 2.6.0) PREVIOUS=2.6.0-test11 $0 "$PREVIOUS" $KDIR || barf "Couldn't get $PREVIOUS to build $VERSION" # Grab patch get_file $PATCHDIR v$MAJOR/patch-$VERSION.bz2 || get_file $PATCHDIR v$MAJOR/old/patch-$VERSION.bz2 || barf "Couldn't get v$MAJOR/patch-$VERSION.bz2" apply_patch $PREVIOUS $VERSION $PATCHDIR/patch-$VERSION.bz2 ;; # *.0: This refers to the base of the Linus kernels, fetched whole. *.0) # Linus' root of all trees. get_file $PATCHDIR v$MAJOR/linux-$VERSION.tar.bz2 || barf "Couldn't get v$MAJOR/linux-$VERSION.tar.bz2" bzcat $PATCHDIR/linux-$VERSION.tar.bz2 | (cd $KDIR && tar xf -) || barf "Problem unpacking linux-$VERSION.tar.bz2" mv $KDIR/linux $KDIR/linux-$VERSION ;; # [1-9].*.*: This refers to the any other Linus kernel. [1-9].*.*[0-9]) # Linus standard ? if [ -d $KDIR/linux-$VERSION ]; then exit 0; fi LAST_VER=`echo "$VERSION" | cut -d. -f3` PREVIOUS=`echo "$VERSION" | cut -d. -f1,2`.`expr $LAST_VER - 1 || true` $0 "$PREVIOUS" $KDIR || barf "Couldn't get $PREVIOUS to build $VERSION" # Grab patch get_file $PATCHDIR v$MAJOR/patch-$VERSION.bz2 || barf "Couldn't get v$MAJOR/patch-$VERSION.bz2" trap "rm -rf $KDIR/.linux-$VERSION" 0 apply_patch $PREVIOUS $VERSION $PATCHDIR/patch-$VERSION.bz2 ;; *) barf "Unknown kernel version $VERSION" ;; esac