#!/bin/dash
# attempt to download kernel $KERNEL_VERSION from ibiblio
# and then copy it as vmlinuz/kernel-modules.sfs

### configuration
SRC_URL=http://distro.ibiblio.org/fatdog/kernels/800
#KERNEL_VERSION=3.12.9 # default is blank - use "vmlinuz"
KVER=${KERNEL_VERSION:+-$KERNEL_VERSION} # prepend dash
MICROCODE_DATE=${MICROCODE_DATE:-20200905} # overriden by build-iso.sh

### main
mkdir -p kernel
if ! [ -e kernel/vmlinuz$KVER ]; then
	wget -P kernel -c $SRC_URL/vmlinuz$KVER
	wget -P kernel -c $SRC_URL/kernel-modules.sfs$KVER
	if [ "$KVER" ]; then
		rm -f vmlinuz kernel-modules.sfs
		ln -f kernel/vmlinuz$KVER kernel/vmlinuz
		ln -f kernel/kernel-modules.sfs$KVER kernel/kernel-modules.sfs
	fi	
fi
if ! [ -e kernel/microcode-update-${MICROCODE_DATE}.cpio ]; then
	wget -N -P kernel -c $SRC_URL/microcode-update-${MICROCODE_DATE}.cpio
fi

echo vmlinuz$KVER ready.
