#! /bin/sh # Grabs a linux-next kernel tarball and extracts it. # Based on "grab_kernel" script (which this should be a part of). # Randy.Dunlap, 2008.0222. barf() { echo "$@" >&2 exit 1 } pr_exists() { echo "$@ already exists" >&2 exit 0 } make_exec() { dir=$1 chmod +x $dir/scripts/*.sh $dir/scripts/*.pl } # Takes destination directory, and filename, tries each mirror. get_file() { get_file_dir=$1 get_file_name=$2 ###echo "### get_file: dir:$1; name:$2;" >&2 # Patch there already? if [ -f "$get_file_dir"/"$(basename "$get_file_name")" ]; then echo " Already have patch: [$get_file_dir/$(basename "$get_file_name")]" >&2 return 0 fi for get_file_server in $MIRRORS; do echo Trying to get file from: $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="$get_file_server"; cwd=`/bin/pwd` cd $get_file_dir curl -O $get_file_s/$get_file_name && return 0 # Leaves a zero-len file on failure 8( cd $cwd rm -f $get_file_dir/`basename $get_file_name` ;; local:*) get_file_s=`echo $get_file_server | cut -c9-`; scp -p $get_file_server/$get_file_name $get_file_dir && return 0 ;; esac done return 1 } # Given vanity kernel name, major version, & previous/base version, # produce pathname vanity_source() { ###echo "### vanity_source: series:$1; major:$2; base:$3;" >&2 case "$1" in next-2[0-9]*) # full tarball: echo people/sfr/linux-next/next-$VERSION.tar.tbz;; # or patch file: ##echo people/sfr/linux-next/patch-$3-next-$1.bz2;; *) barf "Unknown kernel series $1";; esac } # Given base name, new name and patch, do patch application. apply_patch() { base=$1 ver=$2 pfile=$3 ###echo "INFO: apply_patch: level: $level, base: $base; ver: $ver; pfile: $pfile" >&2 rm -rf $KDIR/.linux-$ver cp -al $KDIR/linux-$base $KDIR/.linux-$ver || barf "Couldn't clone $base dir" bunzip2 -t $pfile || barf "Corrupt patch $pfile" bzcat $pfile | patch -bs -p1 -d $KDIR/.linux-$ver || barf "Problem patching new kernel $ver" mv $KDIR/.linux-$ver $KDIR/linux-$ver ###echo "INFO: made new $KDIR/linux-$ver" >&2 if [ $level -eq 0 ]; then echo "rename /linux-$VERSION/ as needed....." >&2 fi ###echo "INFO: ready to rm $KDIR/linux-$base" >&2 rm -rf $KDIR/linux-$base } # for a given -next- version/date, determine whether to use full tarball or a patch # sets global variables 'use_patchfile', 'use_tarball', & 'use_baseline' (baseline for patchfile) tar_or_patch() { latest=next-$1 # addition for what baseline the -next- patch applies to: # patchfile will be null string if it is not found: ##echo "grep for patch-.*-$latest.bz2:" use_patchfile=`wget -q -O - http://www.kernel.org/pub/linux/kernel/people/sfr/linux-next/ | grep "patch-.*-$latest.bz2" | grep -v "bz2.sign"` ##echo "use_patchfile={$use_patchfile}" if [ "$use_patchfile" != "" ]; then # use use_patchfile instead of full tarball use_patchfile=`echo "$use_patchfile" | sed -e "s|.*||g" | sed -e "s/<.*>//g"` echo "use_patchfile={$use_patchfile}" use_baseline=`echo $use_patchfile | sed -e "s/patch-v//" | sed -e "s/-$latest.bz2//"` echo "baseline version: {$use_baseline}" else use_tarball=`wget -q -O - http://www.kernel.org/pub/linux/kernel/people/sfr/linux-next/ | grep "$latest.tar.bz2" | grep -v "bz2.sign"` ##echo "use_tarball.0={$use_tarball}" use_tarball=`echo "$use_tarball" | sed -e "s|.*||g" | sed -e "s/<.*>//g"` echo "use_tarball={$use_tarball}" fi } # main: # keep up with recursion level level=0 if [ -r /etc/crucible.cfg ] && [ "$HOME" == "/root" ]; then source /etc/crucible.cfg RCFILE="$ETC_DIR/grab-kernel.rc" else RCFILE="$HOME/.grabkernelrc" fi # set empty param strings PATCHDIR="" MIRRORS="" DEFPATCHDIR=/usr/src/kernel-archive DEFMIRRORS="http://www.kernel.org/pub/linux/kernel" # get base defaults from $RCFILE # Note: using '~' instead of $HOME fails; if [ -r $RCFILE ]; then #echo "debug: sourcing RCFILE=$RCFILE" source $RCFILE else echo "Warning: no RCFILE=$RCFILE" fi if [ "$PATCHDIR" == "" ]; then PATCHDIR=$DEFPATCHDIR fi #echo "debug: using PATCHDIR=$PATCHDIR" if [ "$MIRRORS" == "" ]; then # MIRRORS="rsync://rsync.kernel.org:/pub/linux/kernel http://www.kernel.org/pub/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" MIRRORS=$DEFMIRRORS fi #echo "debug: using MIRRORS=$MIRRORS" if [ $# -eq 3 ]; then level=$3 ###echo "INFO: level is: $level" >&2 else if [ $# -ne 2 ]; then echo Usage: `basename $0` date/version dest_kernel_dir >&2 echo " with other parameters in $RCFILE" >&2 exit 1 fi fi # for linux-next kernels, VERSION is actually date (yyyymmdd) VERSION=$1 KDIR=$2 if [ -d $KDIR/next-$VERSION ]; then pr_exists "$KDIR/next-$VERSION" ; fi if [ -d $KDIR/linux-next-$VERSION ]; then pr_exists "$KDIR/linux-next-$VERSION" ; fi MAJOR=$VERSION tar_or_patch $VERSION echo Grabbing $VERSION case "$VERSION" in # git snapshot *-git*) if [ -d $KDIR/linux-$VERSION ]; then pr_exists "$KDIR/linux-$VERSION" ; fi PREVIOUS=`echo "$VERSION" | sed 's/-git.*//'` $0 "$PREVIOUS" $KDIR $((level + 1)) || 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 ;; # *-pre* or *-rc*: This refers to the Linus or Marcelo pre-patches. *-pre*|*-rc*) # Linus or Marcelo pre-patch. if [ -d $KDIR/linux-$VERSION ]; then pr_exists "$KDIR/linux-$VERSION" ; 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 $((level + 1)) || 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 $((level + 1)) || 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 $((level + 1)) || 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 pr_exists "$KDIR/linux-$VERSION" ; fi LAST_VER=`echo "$VERSION" | cut -d. -f3` PREVIOUS=`echo "$VERSION" | cut -d. -f1,2`.`expr $LAST_VER - 1 || true` ###$0 "$PREVIOUS" $KDIR $((level + 1)) || ### barf "Couldn't get $PREVIOUS to build $VERSION" # Grab tarball get_file $PATCHDIR v$MAJOR/linux-$VERSION.tar.bz2 || barf "Couldn't get v$MAJOR/linux-$VERSION.tar.bz2" ###trap "rm -rf $KDIR/linux-$VERSION" 0 ###apply_patch $PREVIOUS $VERSION $PATCHDIR/linux-$VERSION.tar.bz2 cd $KDIR && echo "untar in $KDIR....." tar xjf $PATCHDIR/linux-$VERSION.tar.bz2 || barf "Problem with kernel tarball ($VERSION)" ###echo "INFO: level: $level" >&2 if [ $level -eq 0 ]; then echo "rename /linux-$VERSION/ as needed....." >&2 fi ;; 2[0-9]*) if [ -d $KDIR/next-$VERSION ]; then pr_exists "$KDIR/next-$VERSION" ; fi # Grab tarball TARDIR=people/sfr/linux-next ## /next-$VERSION.tar.tbz if [ "$use_tarball" != "" ]; then get_file $PATCHDIR $TARDIR/next-$VERSION.tar.bz2 || barf "Couldn't get $TARDIR/next-$VERSION.tar.bz2" ###trap "rm -rf $KDIR/linux-$VERSION" 0 cd $KDIR && echo "untar in $KDIR....." tar xjf $PATCHDIR/next-$VERSION.tar.bz2 || barf "Problem with kernel tarball ($VERSION)" ###echo "INFO: level: $level" >&2 if [ $level -eq 0 ]; then echo "rename /next-$VERSION/ as needed....." >&2 fi else # use baseline + patchfile get_file $PATCHDIR $TARDIR/$use_patchfile || barf "Couldn't get $TARDIR/$use_patchfile" grab_kernel $use_baseline $KDIR ##cwd=`/bin/pwd` ##echo "## check pwd: $cwd" cd $KDIR && echo "patch in $KDIR....." mv linux-$use_baseline linux-next-$VERSION echo "patching /linux-next-$VERSION/ with patchfile:$use_patchfile" bunzip2 -t $PATCHDIR/$use_patchfile || barf "Corrupt patch $use_patchfile" bzcat $PATCHDIR/$use_patchfile | patch -p1 -bs -d $KDIR/linux-next-$VERSION || barf "Problem patching new kernel $VERSION" fi ;; *) barf "Unknown kernel version $VERSION" ;; esac make_exec linux-next-$VERSION # sample ~/.grabkernelrc file (remove '#' to activate a line): #PATCHDIR=~/kernel-patches #MIRRORS="http://www.kernel.org/pub/linux/kernel"