#!/bin/sh
#cd-burner wizard
#Barry Kauler (c) copyright 2003,2004,2005
#Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html). 2007 www.puppylinux.com
#updated for v1.0.5
#updated for 2.17
#v431 man, this script is ancient! have done some fixing.
#120323 partial replace 'xmessage' with 'pupmessage'.
#120507 L18L: internationalised. exit if SELECTIONS="" avoids "Usage of Xdialog"; gettext´ed
#130203 change probedisk2 to probedisk.

. gettext.sh
export TEXTDOMAIN=cdburner-wizard
export OUTPUT_CHARSET=UTF-8

DRIVESFND="`probedisk`"
OPTICALDRVSFND="`echo "$DRIVESFND" | grep '|optical|'`"

SELECTIONS="`echo "$OPTICALDRVSFND" | cut -f 1,3 -d "|" | tr " " "_" | tr "|" " " | tr '$' "_"`"
if [ -z "$SELECTIONS" ]; then #120507
 pupmessage -bg "red" -center -name "burnwiz" -title "$(gettext 'CD/DVD driver Wizard: FAILURE')" "$(gettext 'no optical drive found')"
 exit 0
fi

nothing="$(gettext 'nothing')" 
CDROMDEV=$nothing
CDROMLINK=$nothing
if [ -e /dev/cdrom ];then
 CDROMDEV="/dev/`readlink /dev/cdrom | sed -e 's%/dev/%%'`"
 CDROMLINK="`readlink /dev/cdrom`"
fi

DVDDEV=$nothing
DVDLINK=$nothing
if [ -e /dev/dvd ];then
 DVDDEV="/dev/`readlink /dev/dvd | sed -e 's%/dev/%%'`"
 DVDLINK="`readlink /dev/dvd`"
fi

MSG1="$(gettext 'Welcome to my CD and DVD Drive Wizard!')"
BGCOLOR1="#ffc0c0"

CHOSECD="$(gettext 'Choose_cdrom')"
CHOSEDVD="$(gettext 'Choose_dvd')"

while :; do

xmessage -bg "$BGCOLOR1" -center -name "burnwiz" -title "$(gettext 'Optical Drive Wizard')" -buttons \
 "${CHOSECD}":11,"${CHOSEDVD}":20,"$(gettext 'HELP')":15,"$(gettext 'EXIT')":13 \
 -file -<<FILETXT
 
$MSG1
$(gettext 'Puppy has probed your PC and found these CD/DVD drives:')
$SELECTIONS

`eval_gettext 'Puppy thinks the default CDROM drive is:     ${CDROMDEV}'`
`eval_gettext 'Puppy thinks the default DVD drive is:       ${DVDDEV}'`

DEVICE LINKS:
`eval_gettext '/dev/cdrom is currently linked to:  ${CDROMLINK}.'`
`eval_gettext '/dev/dvd is currently linked to:    ${DVDLINK}.'`

`eval_gettext 'If you disagree with these choices, click the "${CHOSECD}"
or "${CHOSEDVD}" button to change the selection.'`
FILETXT

XREPLY=$?

if [ $XREPLY -eq 11 ];then #choose cdrom
 BGCOLOR1="#c0e0ff"
  #v1.0.0
  CDROMD0="`Xdialog --wmclass "burnwiz" --title "$(gettext 'CD/DVD drive Wizard')" --stdout --menubox "$(gettext 'Choose which is the CDROM drive:')" 0 48 4 $SELECTIONS 2> /dev/null `"
 if [ ! $? -eq 0 ];then
  MSG1="`eval_gettext 'YOU MADE NO CHOICE FOR CDROM DRIVE, KEEPING ${CDROMDEV}'`"
 else
   MSG1="`eval_gettext 'YOU JUST CHOSE ${CDROMD0} AS THE CDROM DRIVE'`"
   CDROMDEV="$CDROMD0"
   CDROMLINK="$CDROMD0"
   #strip off the leading "/dev/"...
   echo -n $CDROMLINK | cut -f 3 -d '/' > /etc/cdromdevice
   rm -f /dev/cdrom
   ln -s $CDROMLINK /dev/cdrom
 fi 
fi
if [ $XREPLY -eq 20 ];then #choose dvd
 BGCOLOR1="#c0e0ff"
 #v1.0.0
 DVDD0="`Xdialog --wmclass "burnwiz" --title "$(gettext 'CD/DVD drive Wizard')" --stdout --menubox "$(gettext 'Choose which is the DVD drive:')" 0 48 4 $SELECTIONS 2> /dev/null `"
 if [ ! $? -eq 0 ];then
  MSG1="`eval_gettext 'YOU MADE NO CHOICE FOR DVD DRIVE, KEEPING ${DVDDEV}'`"
 else
  MSG1="`eval_gettext 'YOU JUST CHOSE ${DVDD0} AS THE DVD DRIVE'`"
  DVDDEV="$DVDD0"
  DVDLINK="$DVDD0"
   #strip off the leading "/dev/"...
   echo -n $DVDLINK | cut -f 3 -d '/' > /etc/dvddevice
   rm -f /dev/dvd
   ln -s $DVDLINK /dev/dvd
 fi 
fi

if [ $XREPLY -eq 15 ];then #help
 pupmessage -bg "SkyBlue" -center  -title "$(gettext 'CD/DVD driver Wizard: HELP')" "$(gettext '/dev/dvd and /dev/cdrom are links to the actual devices, for example, a link to /dev/sdc. These should point to the drives that you want to read from.
For example, my PC has two drives, a DVD read-only drive and a CD-burner drive. 
I point *both* /dev/dvd and /dev/cdrom to the DVD drive, although I could have pointed /dev/cdrom to the burner drive (a DVD drive can also read CDs, so I chose it as my default for reading both CDs and DVDs).

There are various applications for reading from CD or DVD. For example, Gxine can play audio CDs and video DVDs. Some of these applications require that /dev/cdrom 
or /dev/dvd point to the correct devices.')"
fi

if [ $XREPLY -eq 13 ];then #exit
 break
fi
if [ $XREPLY -eq 0 ];then #exit
 break
fi
if [ $XREPLY -eq 1 ];then #exit
 break
fi

done
##END##
