Sun Oct 27, 2013 8:45 pm
#!/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
Mon Oct 28, 2013 4:02 am
# 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
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
containsElement "$selected_speed" "${speed_list[@]}"
if [[ $? != 0 ]]; then
echo "Unsupported speed chosen: $burn_speed
Supported Speeds:
$supported_speeds"
exit 1
else
blah
Mon Oct 28, 2013 1:28 pm
burn_iso.sh 4
#!/usr/bin/env bash
# burn_iso.sh
exit_dialog () {
echo -e "\n$exit_message\n"
exit 1
}
# Select isofile from cli...
echo "
Run this script from the directory that contains the iso files.
First argument can be a burn speed. No argument uses maximum speed.
Example:
burn_iso.sh 4
Select file:
"
for i in *.iso ; do
options=( "${options[@]}" "${i[@]}" )
done
select isofile in "${options[@]}"; do
break
done
iso_size=$(du -h "$isofile" | awk '{ print $1 }')
# Select the optical drive
echo
wodim --devices
sleep 1
echo "
Select the burner or ctrl-c to exit.
"
for i in $(wodim --devices | awk -F"'" '/\/dev\// { print $2 }') ; do
devices=( "${devices[@]}" "${i[@]}" )
done
select burn_device in "${devices[@]}" ; do
echo " burn device is $burn_device"
break
done
# Check that the chosen burning speed is supported by the device.
# If speed not specified on command line, use maximum.
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[@]}"
if [[ $1 ]]; then
burn_speed="speed=$1"
else
burn_speed="speed=${speed_list[0]}"
fi
selected_speed=$(echo $burn_speed | awk -F"=" '{ print $2 }')
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
containsElement "$selected_speed" "${speed_list[@]}"
if [[ $? != 0 ]]; then
echo " Unsupported speed chosen: $burn_speed
Supported Speeds:
$supported_speeds"
exit 1
else
echo "
Image file: $isofile
Size: $iso_size
Burn Speed: ${selected_speed}x
"
read -p " Press the ENTER key to proceed or crtl-c to exit.
"
wodim --dummy dev="$burn_device" -v -eject driveropts=burnfree "${burn_speed}" -data "$isofile"
if [[ $? -ne 0 ]]; then
exit_message="Error! Burn failed."
exit_dialog
fi
fi
exit 0
Mon Oct 28, 2013 3:08 pm
Mon Oct 28, 2013 3:42 pm
golinux wrote:FWIW, I always burn at 4x to have the best chance of a 'good' burn. Maybe that's a myth but I still do it.