#!/bin/sh
if [ -r /tmp/SeTcolor -o "$COLOR" = "on" ]; then

T_PX="`cat /tmp/SeTT_PX`"
if [ -r /tmp/SeTCDdev ]; then
 ( cd $T_PX/dev ; ln -sf `cat /tmp/SeTCDdev` cdrom )
 exit
fi
if mount | fgrep iso9660 1> /dev/null 2> /dev/null ; then # CD is mounted
  DEVICE=`mount | fgrep iso9660 | cut -d ' ' -f 1`
  ( cd $T_PX/dev ; ln -sf $DEVICE cdrom )
  exit
fi
dialog --title "CONFIGURE CD-ROM?" --yesno "\n    Do you have a CD-ROM?" 7 35
if [ $? = 1 -o $? = 255 ]; then 
 exit
fi
rm -f /tmp/SeTmount /tmp/SeTDS /tmp/SeTCDdev
dialog --title "Configuring CD-ROM link (/dev/cdrom)" \
--menu "\nWhat type of CD-ROM drive do you have?" 15 66 7 \
"1" "SCSI (/dev/scd0 or /dev/scd1)" \
"2" "Sony CDU31A (/dev/sonycd)" \
"3" "Sony 531/535 (/dev/cdu535)" \
"4" "Mitsumi (/dev/mcd)" \
"5" "Sound Blaster Pro/Panasonic (/dev/sbpcd)" \
"6" "Aztech/Orchid/Okano/Wearnes with interface card" \
"7" "Most IDE-interface CD drives" 2> /tmp/cdtype
if [ $? = 1 -o $? = 255 ]; then
 rm -f /tmp/cdtype
 exit
fi
CD_ROM_TYPE="`cat /tmp/cdtype`"
rm -f /tmp/cdtype
if [ "$CD_ROM_TYPE" = "1" ]; then
 dialog --title "SELECT SCSI DEVICE" --menu "Which SCSI CD-ROM are you \
using? (If you're not sure, select /dev/scd0)" 10 60 2 \
"/dev/scd0" "SCSI CD 0" \
"/dev/scd1" "SCSI CD 1" 2> /tmp/whichscsi
 if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/tmpmsg /tmp/cdtype /tmp/whichscsi
  exit
 fi
 CD_DEVICE="`cat /tmp/whichscsi`"
 rm -f /tmp/whichscsi
elif [ "$CD_ROM_TYPE" = "2" ]; then
 CD_DEVICE="/dev/sonycd"
elif [ "$CD_ROM_TYPE" = "3" ]; then
 CD_DEVICE="/dev/cdu535"
elif [ "$CD_ROM_TYPE" = "4" ]; then
 CD_DEVICE="/dev/mcd"
elif [ "$CD_ROM_TYPE" = "5" ]; then
 CD_DEVICE="/dev/sbpcd"
elif [ "$CD_ROM_TYPE" = "6" ]; then
 CD_DEVICE="/dev/aztcd"
elif [ "$CD_ROM_TYPE" = "7" ]; then
  dialog --title "SELECT IDE DEVICE" --menu \
"Which IDE device is your CD-ROM drive connected to? \
Devices hda and hdb are the possible drives on the \
primary IDE interface, and hdc and hdd are the drives \
on the secondary IDE interface. If you're not sure, we can try to \
scan for your drive." \
15 70 5 \
"scan" "Try to scan for your drive" \
"/dev/hda" "Primary IDE drive 1 (unlikely)" \
"/dev/hdb" "Primary IDE drive 2 (common)" \
"/dev/hdc" "Secondary IDE drive 1 (common)" \
"/dev/hdd" "Secondary IDE drive 2" 2> /tmp/idecd
 if [ ! "`cat /tmp/idecd`" = "scan" ]; then
  CD_DEVICE="`cat /tmp/idecd`"
 else
  for device in /dev/hdb /dev/hdc /dev/hdd /dev/hda ; do
   dialog --infobox "Scanning $device..." 3 30
   mount -o ro -t iso9660 $device /var/adm/mount 1> /dev/null 2> /dev/null
   if [ $? = 0 ]; then
    DRIVE_FOUND=$device
    break
   fi
  done
  umount /var/adm/mount 1> /dev/null 2> /dev/null
  if [ "$DRIVE_FOUND" = "" ]; then
   dialog --title "DRIVE NOT FOUND" --msgbox \
"An IDE CD-ROM drive could not be found on any of the devices that were \
scanned.  Please consult the BOOTING file for more information on \
forcing the detection of your drive, and then reattempt installation. \
If all else fails, see the SLAKWARE.FAQ for information about copying \
parts of this CD to your DOS partition to allow you to install." \
12 55
  else
   dialog --title "IDE CD-ROM DRIVE DETECTED SUCCESSFULLY" --msgbox \
"An IDE CD-ROM drive was found on device $DRIVE_FOUND." 5 65
   CD_DEVICE="$DRIVE_FOUND"
  fi
 fi
fi
( cd $T_PX/dev ; ln -sf $CD_DEVICE cdrom )
# The CD will be mounted automatically later on:
# echo "$CD_DEVICE       /cdrom        iso9660       ro" > /tmp/SeTcdfstab

else

T_PX=$1
if [ -r /tmp/SeTCDdev ]; then
 ( cd $T_PX/dev ; ln -sf `cat /tmp/SeTCDdev` cdrom )
 exit
fi
if mount | fgrep iso9660 1> /dev/null 2> /dev/null ; then # CD is mounted
  DEVICE=`mount | fgrep iso9660 | cut -d ' ' -f 1`
  ( cd $T_PX/dev ; ln -sf $DEVICE cdrom )
  exit
fi
while [ 0 ]; do
 echo
 echo -n "Do you have a CD-ROM ([y]es, [n]o)? "
 read REPLY;
 if [ "$REPLY" = "y" ]; then
  break;
 elif [ "$REPLY" = "n" ]; then
  exit;
 fi
done
echo
rm -f /tmp/SeTmount /tmp/SeTDS /tmp/SeTCDdev
while [ 0 ]; do
 echo "Configuring CD-ROM link (/dev/cdrom)." 
 echo
 echo "What type of CD-ROM drive do you have?"
 echo "1 - SCSI [ /dev/scd0, or /dev/scd1 ]" 
 echo "2 - Sony CDU31A [ /dev/sonycd ]" 
 echo "3 - Sony 535 [ /dev/cdu535 ]" 
 echo "4 - Mitsumi  [ /dev/mcd ]" 
 echo "5 - Sound Blaster Pro (Panasonic) [ /dev/sbpcd ]" 
 echo "6 - Aztech/Orchid/Okano/Wearnes with interface card"
 echo "7 - Most IDE-interface CD drives"
 echo -n "Enter the number that matches your CD type: "
 read CD_ROM_TYPE;
 echo
 if [ "$CD_ROM_TYPE" = "1" -o "$CD_ROM_TYPE" = "2" -o \
 "$CD_ROM_TYPE" = "3" -o "$CD_ROM_TYPE" = "4" -o \
 "$CD_ROM_TYPE" = "5" -o "$CD_ROM_TYPE" = "6" -o \
 "$CD_ROM_TYPE" = "7" ]; then
  break;
 fi  
done
if [ "$CD_ROM_TYPE" = "1" ]; then
 while [ 0 ]; do
  echo "Which SCSI CD-ROM are you using? /dev/scd0 is a good guess if you"
  echo "aren't sure." 
  echo "0 - /dev/scd0 (SCSI CD 0)"
  echo "1 - /dev/scd1 (SCSI CD 1)"
  echo "Which one (0/1)? "
  read CD_DEVICE;
  echo
  if [ "$CD_DEVICE" = "0" -o "$CD_DEVICE" = "1" ]; then
   break;
  fi
 done
 if [ "$CD_DEVICE" = "0" ]; then
  CD_DEVICE="/dev/scd0"
 else
  CD_DEVICE="/dev/scd1"
 fi
elif [ "$CD_ROM_TYPE" = "2" ]; then
 CD_DEVICE="/dev/sonycd"
elif [ "$CD_ROM_TYPE" = "3" ]; then
 CD_DEVICE="/dev/cdu535"
elif [ "$CD_ROM_TYPE" = "4" ]; then
 CD_DEVICE="/dev/mcd"
elif [ "$CD_ROM_TYPE" = "5" ]; then
 CD_DEVICE="/dev/sbpcd"
elif [ "$CD_ROM_TYPE" = "6" ]; then
 CD_DEVICE="/dev/aztcd"
elif [ "$CD_ROM_TYPE" = "7" ]; then
 echo "SELECT IDE DEVICE"
 echo
 echo "Enter the device name that represents your IDE CD-ROM drive."
 echo "This will probably be one of these (in the order of most to least"
 echo "likely):  /dev/hdb /dev/hdc /dev/hdd /dev/hda"
 echo
 echo -n "Enter device name: "
 read CD_DEVICE;
 echo
fi
( cd $T_PX/dev ; ln -sf $CD_DEVICE cdrom )

# The CD will be mounted automatically later on:
# echo "$CD_DEVICE       /cdrom        iso9660       ro" > /tmp/SeTcdfstab

fi
