#!/bin/sh

if [ ! -f initrd_idiot.img ] ; then
	echo "No initial ramdisk! This is what the kernel loads at boot time. Attempting to make one..."
	helper-scripts/geninitrd
fi

if [ -f initrd_idiot.img ] ; then
	if [ ! -f syslinux-parts/bald.img ] ; then
		echo "No bald Syslinux image! This is what allows us to boot. Attempting to make one..."
		helper-scripts/genbaldimg
	fi
	if [ -f syslinux-parts/bald.img ] ; then
		if [ $(whoami) != "root" ] ; then echo " I need root to copy files into the image." ; fi
		su -c 'mkdir idiot-bootimg ; cp -p syslinux-parts/bald.img boot_idiot.img ; mount -o loop boot_idiot.img idiot-bootimg ; cp syslinux-parts/libutil.c32 syslinux-parts/menu.c32 syslinux-parts/extlinux.conf initrd_idiot.img vmlinuz_idiot idiot-bootimg ; umount idiot-bootimg ; rm -rf idiot-bootimg' ; fatlabel boot_idiot.img IDIOTLNX
	fi
fi
