#!/bin/bash

# authors:
#	  marco di antonio    #
#	  fabrizio di marco   #
# email: acetoneiso_at_gmail.com
# released under GPL2 license #
# copyright 2007 	      #
# script made to create a bootable ISO of a floppy bootable image #

if test ! -e /usr/bin/mkisofs
then
kdialog --caption "AcetoneISO" --error "The following package was not found: mkisofs"
exit
else
echo continua
fi

VAROUT=`kdialog --caption "Select Folder to transform in a bootable ISO" --getexistingdirectory $HOME/ `

if test -z $VAROUT
then
exit
else
echo continua
fi

if test ! -w "$VAROUT"
then
kdialog --caption "AcetoneISO" --error "The folder You selected is not writable\n1) If it is located on CDROM/DVD please copy it on your hardisk\n2) Check the folder permissions. Be sure your user can write on it"
exit
else
echo continua
fi

SAVE=`kdialog --caption "Select where to Save ISO and Name!" --getsavefilename $HOME/"acetoneiso_boot_cd_floppy" "*.iso |ISO Bootable Image"`

if test -z $SAVE
then
exit
else
echo continua
fi


#choose if bootable GRUB or manual generic

OPENFILE=`kdialog --icon /usr/share/pixmaps/aiso.png --caption "Select Boot File" --getopenfilename $HOME/`

if test -z $OPENFILE
then
exit
else
echo continua
fi

inf=`basename "$OPENFILE"`

mkdir -p "$VAROUT"/boot/

cp "$OPENFILE" "$VAROUT"/boot/


 konsole -e mkisofs -r -b boot/"$inf" -c boot/boot.catalog -o "$SAVE" "$VAROUT"

kdialog --caption "AcetoneISO2" --msgbox "Process Completed"



#If the boot image is not an image of a floppy, you need to add one of the options: -hard-disk-boot or -no-emul-boot. If the system should not boot off the emulated disk, use -no-boot.