This is a test script. See the comments at the head if you want to burn a real disc. (comment out one line)
Extra echo crap will eventually be removed.
- Code: Select all
#!/usr/bin/env bash
# burn_iso.sh
## This is a test version. Comment out dry_run="--dummy" on the
## next line to burn a real CD or DVD.
dry_run="--dummy"
# if yad is installed, use in preference
if [[ -f /usr/bin/yad ]]; then
DIALOG="yad"
INFO="image=gtk-dialog-info"
QUESTION="image=gtk-dialog-question"
WARNING="image=gtk-dialog-warning"
ERROR="image=gtk-dialog-error"
#buttons
BUTTON0="button"
BUTTON1="button"
BUTTON0NUM=":0"
BUTTON1NUM=":1"
#cancel button always returns 1 as $?
#ok button always returns 0 as $?
#ok is default (highlighted)
#buttons in yad dialog window may show reversed from zenity window, e.g.
#yad: ok -- cancel (0 -- 1)
#zenity: cancel -- ok (1 -- 0)
elif [[ -f /usr/bin/zenity ]]; then
# use zenity
DIALOG="zenity"
INFO="info"
QUESTION="question"
WARNING="warning"
ERROR="error"
#buttons
BUTTON0="ok-label"
BUTTON1="cancel-label"
BUTTON0NUM=""
BUTTON1NUM=""
else
echo " Neither Yad nor Zenity is installed."
fi
if ! [[ $DISPLAY ]] ; then
echo "Run this from an xsession."
exit 1
fi
TITLE="burn_iso.sh"
exit_dialog () {
$DIALOG --$INFO --width 360 --title="Exit Message" --text="Exiting...
$exit_message"
exit 1
}
select_iso () {
isofile=$($DIALOG --file-selection --file-filter="*.[iI][sS][oO]" --file-filter="*" --width=640 --height=640 --title=$"Select .iso file" --text="\n Select the CD/DVD image file to burn.\n")
if ! [[ "$isofile" =~ .[Ii][Ss][Oo]$ ]]; then
exit_message="\nYou did not select a CD/DVD image file."
exit_dialog
fi
echo "*** isofile is $isofile"
}
select_device () {
selection=$(wodim --devices | grep "/dev/" | $DIALOG --list --separator="" \
--column 'Optical Drives' --height 230 --width 500 --title="Select optical drive" \
--text="Put a blank disc in the drive and
select the CD/DVD burner from the list.
To skip this and exit, hit Cancel.")
if [[ $? -eq 0 ]]; then
if [[ -n "$selection" ]]; then
burn_device=$(echo $selection | awk -F"'" '{ print $2 }')
echo "********* selection is $selection"
echo "********* burn_device is $burn_device"
else
exit_message="No device was selected."
exit_dialog
fi
else
exit 0
fi
}
set_speed () {
supported_speeds=$(wodim -prcap dev="$burn_device" | tail |awk '/Write speed/ { printf $9 " " }' | sed 's/x,//g')
speed_list=($supported_speeds)
echo "Speed list is ${speed_list[@]}"
selected_speed=$($DIALOG --entry --entry-text="${speed_list[0]}" --text="Enter a valid burn speed. Default speed is maximum for your drive.
Supported Speeds:
$supported_speeds
")
if [[ $? -ne 0 ]]; then
exit_message="user canceled"
exit_dialog
fi
# if $(echo ${speed_list[@]} | grep -q $selected_speed); then # either test works.
if $(echo "$supported_speeds" | grep -q $selected_speed);then
echo "Selected speed is valid"
else
exit_message="Unsupported speed chosen: $selected_speed"
exit_dialog
fi
}
burn_disc () {
iso_size=$(du -h "$isofile" | awk '{ print $1 }')
$DIALOG --$QUESTION --title="Burn iso" --width=400 \
--text="Burn iso file to disk?
Image file: ${isofile##*/}
Size: $iso_size
Speed: ${selected_speed}x"
if [[ $? = 0 ]]; then
wodim ${dry_run} dev="$burn_device" -v -eject driveropts=burnfree "${burn_speed}" -data "$isofile" | tee >($DIALOG --title=\"Burning CD...\" --progress --pulsate --width=300 --auto-close)
if [[ $? -ne 0 ]]; then
exit_message="Error! Burn failed."
exit_dialog
fi
else
exit_message="user canceled"
exit_dialog
fi
}
# Make sure wodim is installed.
if ! [[ $(type -p wodim) ]]; then
exit_message="Error: Wodim is not installed."
exit_dialog
fi
select_iso
select_device
set_speed
burn_disc
exit 0