+build_tarball() {
+ local TARGET=$1
+ local SRPM=$2
+
+ if [ "$TARGET" = "rhel-2.6" -o "$TARGET" = "rhel-2.4" ]; then
+ local SPEC=""
+ if [ "$TARGET" = "rhel-2.6" ]; then
+ SPEC=kernel-2.6.spec
+ OLDCONFIG=nonint_oldconfig
+ elif [ "$TARGET" = "rhel-2.4" ]; then
+ SPEC=kernel-2.4.spec
+ OLDCONFIG=oldconfig
+ fi
+
+ RPMTOPDIR=$(mktemp -d $KERNELDIR/rpm_XXXXXX)
+ mkdir $RPMTOPDIR/BUILD/
+ rpm -ivh $KERNELDIR/$SRPM --define "_topdir $RPMTOPDIR" || \
+ { rm -rf $RPMTOPDIR; fatal 1 "Error installing kernel SRPM."; }
+ $RPMBUILD -bp --nodeps --target i686 $RPMTOPDIR/SPECS/$SPEC --define "_topdir $RPMTOPDIR"
+ pushd $RPMTOPDIR/BUILD/kernel-${lnxmaj}/linux-${lnxmaj} && {
+ make mrproper
+ cp configs/kernel-${lnxmaj}-i686-smp.config .config
+ if ! make $OLDCONFIG > /dev/null; then
+ fatal 1 "error trying to make $OLDCONFIG while building a tarball from SRPM."
+ fi
+ make include/linux/version.h
+ rm -f .config
+ cd ..
+ tar cjf $KERNEL_FILE linux-${lnxmaj}
+ }
+ popd
+ rm -rf $RPMTOPDIR
+ fi
+}
+
+download_and_build_tarball() {
+ local TARGET=$1
+ local KERNEL_FILE=$2
+
+ local SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
+
+ echo "Downloading http://ftp.lustre.org/kernels/$TARGET/old/$SRPM..."
+ if ! wget -nv "http://ftp.lustre.org/kernels/$TARGET/old/$SRPM" \
+ -O "$KERNELDIR/$SRPM" ; then
+ fatal 1 "Could not download target $TARGET's kernel SRPM $SRPM from ftp.lustre.org."
+ fi
+
+ build_tarball $TARGET $SRPM
+}
+