#!/bin/bash
# Receive as first argument the image that will be written, as secong the
# CD writter number and third the variable name that contais the SCSI ID 
# parameters of writter
#
source /usr/lib/cdcontrol/check-cdcontrol-codes
if [ "${IMG_TYPE}" = "A" ];then

 if [ ${VERBOSE} = 0 ];then
  cdrecord -dev=`eval echo ${3}` -speed=${W_SPEED} -fs=${CACHE}m \
       ${EXTRA_AREC_OPT} ${1} &>${TMP_DIR}/recorder${2}-out
 else
  if uname -s|grep -i 'Linux';then
   cdrecord -dev=`eval echo ${3}` -speed=${W_SPEED} -fs=${CACHE}m \
        ${EXTRA_AREC_OPT} ${1} |tee /tmp/v-recorder${2}-out &>/dev/tty$[${2}+1]
  elif uname -s|grep -i 'bsd';then
    cdrecord -dev=`eval echo ${3}` -speed=${W_SPEED} -fs=${CACHE}m \
        ${EXTRA_AREC_OPT} ${1} |tee /tmp/v-recorder${2}-out &>/dev/ttyv$[${2}+1]
  else
    ${DIALOG} --backtitle $"CDcontrol v${CDC_VERSION}" \
         --msgbox $"Operating system yet not supported by CDControl, aborting." 7 60
  fi
 fi

elif [ "${IMG_TYPE}" = "D" ];then

 if [ ${VERBOSE} = 0 ];then
  cdrecord -dev=`eval echo ${3}` -speed=${W_SPEED} -fs=${CACHE}m \
       ${EXTRA_DREC_OPT} ${1} &>${TMP_DIR}/recorder${2}-out
 else
  if uname -s|grep -i 'Linux';then
   cdrecord -dev=`eval echo ${3}` -speed=${W_SPEED} -fs=${CACHE}m \
        ${EXTRA_DREC_OPT} ${1} |tee /tmp/v-recorder${2}-out &>/dev/tty$[${2}+1]
  elif uname -s|grep -i 'bsd';then
    cdrecord -dev=`eval echo ${3}` -speed=${W_SPEED} -fs=${CACHE}m \
        ${EXTRA_DREC_OPT} ${1} |tee /tmp/v-recorder${2}-out &>/dev/ttyv$[${2}+1]
  else
    ${DIALOG} --backtitle $"CDcontrol v${CDC_VERSION}" \
         --msgbox $"Operating system yet not supported by CDControl." 7 60
  fi
 fi
 
fi
check_cdcontrol_codes $2 $3
if [ ${VERBOSE} = 0 ];then rm -f ${TMP_DIR}/recorder$2-out;fi
rm -f ${TMP_DIR}/recorder$2-busy

