#!/bin/bash
# Vmakeiso a small script to create iso from files on HD
# Written By Uelsk8s for VLocitylinux
 
zenity --info --title="ISO Maker" --text="This program Makes an ISO from files on your HD.
It requires mkisofs to be installed.
 
USAGE:
Give a name for your ISO
Select the file/folder you want to add
Make the ISO
If the ISO is too large remove a file/folder
Remake the ISO
The ISO will be saved in your Home directory.
 
Copyright(C) 2008 Uelsk8s for VLocityLinux."
 
CDLABEL=Vmakeiso
ISONAME=$(zenity --entry --title "Name your ISO" --text "Enter a name for the ISO, ex.: MyBackup")
if [ "$?" = 1 ];then
  exit 0
fi
TMP=$HOME/.tmpiso
mkdir $TMP
cd $HOME
#type=$(zenity --list --title "CD or DVD" --radiolist --column choice \
# --column CD/DVD --text "Choose either CD for 700mb or DVD for 4.3G iso size" \
# TRUE CD FALSE DVD)
 
#case $type in
#  CD)
#    size=690700
#    ;;
#  DVD)
#    size=4300000
#    ;;
#esac
 
add=yes
while [ ! $add = no ];do
  #zenity --question --text "would you like to add another file to the ISO?"
  todo=$(zenity --list --title "What to do?" --radiolist --column choice \
  --column CHOICE --text "What would you like to do now?" --height 400 --width 350 \
  TRUE  "Select folder to be added to the ISO" \
  FALSE "Select file to be added to the ISO" \
  FALSE "Select Folder to be removed from the ISO" \
  FALSE "Select File to be removed from the ISO" \
  FALSE "List already selected files/dirs" \
  FALSE "Make the ISO" \
  FALSE "Burn ISO to disk" \
  FALSE "Find another ISO to burn" \
  FALSE "Cleanup and Exit.")
  if [ "$?" = 1 ];then
    exit 0
  fi
 
  do=$(echo $todo|cut -f2 -d " ")
  if [ "$do" = "folder" ];then
    file=$(zenity --file-selection --directory)
    if [ "$?" = 1 ];then
      exit 0
    fi
    echo $file
    $(cp -ax $file $TMP)| $(zenity --progress --pulsate --text "adding folder and contents" --auto-close)
  elif [ "$do" = "file" ];then
    file=$(zenity --file-selection)
    if [ "$?" = 1 ];then
      exit 0
    fi
    echo $file
    cp -ax $file $TMP
  elif [ "$do" = "Folder" ];then
    cd $TMP
    file=$(zenity --file-selection --directory)
    if [ "$?" = 1 ];then
      exit 0
    fi
    echo $file
    rm -r $file
    cd $HOME
  elif [ "$do" = "File" ];then
    cd $TMP
    file=$(zenity --file-selection)
    if [ "$?" = 1 ];then
      exit 0
    fi
    echo $file
    rm $file
    cd $HOME
  elif [ "$do" = "already" ];then
    tree $TMP|zenity --text-info --width 500 --height 300
  elif [ "$do" = "and" ];then
    rm -rf $TMP
    add=no
  elif [ "$do" = "ISO" ];then
    cdrom=$(zenity --entry --title "Device" --text "Enter your burner device, ie: /dev/hdc")
    if [ "$?" = 1 ];then
      exit 0
    fi
    cdrecord -dao -data -eject -v speed=30 dev=ATAPI:$cdrom $ISONAME.iso
  elif [ "$do" = "another" ];then
    iso=$(zenity --file-selection --filename *.iso)
    if [ "$?" = 1 ];then
      exit 0
    fi
    cdrom=$(zenity --entry --title "Device" --text "Enter your burner device, ie: /dev/hdc")
    if [ "$?" = 1 ];then
      exit 0
    fi
    cdrecord -dao -data -eject -v speed=30 dev=ATAPI:$cdrom $iso
  elif [ "$do" = "the" ];then 
    $(mkisofs -o "$ISONAME.iso" -v -J -R -D -A "$CDLABEL" $TMP &> .iso.txt)|$(zenity --progress --text "Making ISO" --auto-close)
    zenity --text-info --width 300 --height 450 --filename .iso.txt
  fi
done
 
exit 0