#!/usr/bin/bash

failed() {
	echo "Failed"
	umount /mnt/loop
	rmdir /mnt/loop
	exit;
}

cd $(dirname $0)
#ISO=focal-live-server-amd64.iso
#URL=http://cdimage.ubuntu.com/ubuntu-server/focal/daily-live/current/${ISO}
ISO=ubuntu-20.04.4-live-server-amd64.iso
URL=http://releases.ubuntu.com/20.04/${ISO}

echo "Checking ${ISO}"
curl --remote-time --silent --time-cond ${ISO} -o ${ISO} $URL

mkdir /mnt/loop || failed
mount -o loop ${ISO} /mnt/loop || failed

cp /mnt/loop/casper/vmlinuz . || failed
cp /mnt/loop/casper/initrd . || failed

umount /mnt/loop
rmdir /mnt/loop

echo "Done"
