#! /bin/sh
# grab_patch_kernel:
# download and patch/merge a given kernel version

. run_profile.txt
. $base_dir/plans/commands/common.fns
[ -f /etc/crucible.cfg ] && source /etc/crucible.cfg

[ -f $ETC_DIR/global.cfg ] && source $ETC_DIR/global.cfg
if [ "$SRC_DIR" == "" ]; then
	SRC_DIR="/usr/local/src"
fi

kernel_info	# gives kernel_id, kernel_label

SUT=`hostname -s`
out_dir=$run_dir/logs/$SUT
[ -d $out_dir ] || mkdir -p $out_dir

sut_type=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc/ -e s/arm.*/arm/ \
     -e s/s390.*/s390/ -e s/sa110/arm/ -e s/ppc64/powerpc/ -e s/parisc64/parisc/`

if [ -e "$all_suts_dir/$SUT/profile.txt" ]; then
    sut_type=`grep ^sut_type= $all_suts_dir/$SUT/profile.txt | cut -d '=' -f 2`
fi

karch=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc/ -e s/arm.*/arm/ \
     -e s/s390.*/s390/ -e s/sa110/arm/ -e s/ppc64/powerpc/ -e s/parisc64/parisc/`

pwd=`/bin/pwd`

src_dir="$SRC_DIR/linux-$kernel_id"

# clear out src_dir for no collisions
echo "clear out: $src_dir"
[ -d $src_dir ] && rm -rf $src_dir

# use "$ETC_DIR/grab-kernel.rc" file and run 'grab-kernel $version $SRC_DIR'

echo "now run: grab_kernel '$kernel_id' '$SRC_DIR'"
grab_kernel "$kernel_id" "$SRC_DIR"

cd $pwd
