#!/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
		touch boot_idiot.img part_idiot.img
		su -c 'mkdir idiot-partimg ; cp -p syslinux-parts/bald.img part_idiot.img ; mount -o loop part_idiot.img idiot-partimg ; cp syslinux-parts/libutil.c32 syslinux-parts/menu.c32 syslinux-parts/extlinux.conf initrd_idiot.img vmlinuz_idiot idiot-partimg ; umount idiot-partimg ; rm -rf idiot-partimg ; cat syslinux-parts/mbr.bin part_idiot.img > boot_idiot.img'
	fi
fi
