#!/bin/bash
## You can manually add an alternative kernel to the puppy cd.
## Just run this script and add the 'altkernel' dir to the target ISO with ISO Master

## uncomment URL=... and specify a link to the desired huge_kernel tarball
## you can place the tarball in the current dir and the script will not download it

#URL=http://distro.ibiblio.org/puppylinux/huge_kernels/huge-3.4.103-tahr_nopae.tar.bz2

#=====================================================================================

#command line
if test $1 != ""  {
	setvar URL = "$1"
}

test -z $URL && exit 1

if touch ____aaaaa_____ &>/dev/null  {
	rm -f ____aaaaa_____
} else {
	echo "Need write access to $PWD"
	exit 1
}

setvar file = "$(basename "$URL")"

mkdir -p altkernel

setvar DOWNLOAD_TARBALL = '1'
if test -f $file  {
	echo "* Verifying $file"
	tar -taf $file &>/dev/null && setvar DOWNLOAD_TARBALL = '0'
}

if test $DOWNLOAD_TARBALL -eq 1  {
	wget -c --no-check-certificate $URL
	echo "* Verifying $file"
	tar -taf $file &>/dev/null || exit 1
}

echo "* Extracting $file to altkernel"
tar --directory=altkernel -xaf $file || exit 1

setvar kernel_ver = $(echo "$file" | cut -f2 -d '-')

mv -f altkernel/kernel-modules.sfs-* altkernel/zdrv.sfs
mv -f altkernel/vmlinuz-* altkernel/vmlinuz
echo $URL > altkernel/origin.txt
echo $kernel_ver > altkernel/kernel_ver.txt

if test -z $BUILDSYS  {
	isomaster &
	sleep 1
	echo
	echo "Done !"
	echo "Now with 'ISO Master', add the 'altkernel' directory to the target ISO"
}

### END ###