#!/bin/bash

# Remove temporary build files
rm -rf build/*

# Build kernel
cd kernel
if ./build.sh
then
	true
else
	cd ..
	echo "ERROR: Kernel build failed"
	echo "Aborting build."
	echo "Cleaning up"
#	rm -rf build/*
fi
cd ..

# Create disk image
echo "Creating disk image"
cp -R isofiles_template build/isofiles
cp -f build/kernel.bin build/isofiles/boot/kernel/kernel.bin
cp -nR other_isofiles/* build/isofiles/
mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -A NZOS -o disk.iso build/isofiles

# Clean up after ourselves
echo "Cleaning up"
#rm -rf build/*

if [ -e disk.iso ]
then
	echo "Build complete"
else
	echo "Build error"
fi

