#!/bin/sh
T_PX="`cat /tmp/SeTT_PX`"
rm -f /tmp/SeTmount /tmp/SeTDS /tmp/SeTCDdev
cat << EOF > /tmp/tmpmsg

In order to install Slackware Linux from a CD-ROM, it must 
contain the distribution arranged beneath a source directory
in the same way as if you were to install it from a hard 
drive or NFS. The source directory must contain subdirectories
for each floppy disk. Your CD-ROM should be compatible with 
this format if it contains a mirror of the Slackware FTP site. 

What type of CD-ROM drive do you have?

EOF
dialog --title "INSTALLING FROM CD-ROM" \
--menu "`cat /tmp/tmpmsg`" 21 70 5 \
"1" "SCSI [ /dev/sr0, /dev/sr1, /dev/scd0, or /dev/scd1 ]" \
"2" "Sony CDU31A [ /dev/cdu31a ]" \
"3" "Sony 535 [ /dev/sonycd ]" \
"4" "Mitsumi  [ /dev/mcd ]" \
"5" "Sound Blaster Pro (Panasonic) [ /dev/sbpcd ]" 2> /tmp/cdtype
if [ $? = 1 -o $? = 255 ]; then
 rm -f /tmp/tmpmsg /tmp/cdtype
 exit
fi
CD_ROM_TYPE="`cat /tmp/cdtype`"
rm -f /tmp/tmpmsg /tmp/cdtype
if [ "$CD_ROM_TYPE" = "1" ]; then
 dialog --title "SELECT SCSI DEVICE" --menu "\
\n\
Which SCSI CD-ROM are you using? (If you're not sure, \n\
select /dev/sr0)" 14 60 4 \
"/dev/sr0" "SCSI cd 0" \
"/dev/sr1" "SCSI cd 1" \
"/dev/scd0" "SCSI cd 0 (might not work)" \
"/dev/scd1" "SCSI cd 1 (might not work) " 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/cdu31a"
elif [ "$CD_ROM_TYPE" = "3" ]; then
 CD_DEVICE="/dev/sonycd"
elif [ "$CD_ROM_TYPE" = "4" ]; then
 CD_DEVICE="/dev/mcd"
elif [ "$CD_ROM_TYPE" = "5" ]; then
 CD_DEVICE="/dev/sbpcd"
fi
dialog --title "SELECT SOURCE DIRECTORY" --menu "Now we need to know which \
directory on the CD contains the Slackware sources. This location may vary \
depending on the cd you have. There are two default selections, one for the \
TransAmeritech CD and one for the JANA CD. There may be other directories \
containing other versions - enter a custom directory name if you like. \
Which option would you like?" 15 70 3 \
"slackware.111" "Default TranAmeritech directory" \
"SLACK" "Default JANA directory" \
"Custom" "Enter your own directory name" \
2> /tmp/SeTreturn
if [ $? = 1 -o $? = 255 ]; then
 rm -f /tmp/cdtype /tmp/SeTreturn
 exit
fi
SLACK_SOURCE_LOCATION="`cat /tmp/SeTreturn`"
if [ "$SLACK_SOURCE_LOCATION" = "Custom" ]; then
 cat << EOF > /tmp/tmpmsg

EOF
dialog --title "SELECT SOURCE DIRECTORY" --inputbox "Now we need to know \
which directory on the CD contains the Slackware sources.  This location \
may vary depending on the CD you have. You may omit the leading '/' if \
you like.  What directory are the Slackware sources in?" 11 67 \
2> /tmp/slacksource
 if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/cdtype /tmp/slacksource
  exit
 fi
 rm -f /tmp/tmpmsg
 SLACK_SOURCE_LOCATION="`cat /tmp/slacksource`"
 rm -f /tmp/slacksource
fi
while [ 0 ]; do
 mount -o ro -t iso9660 $CD_DEVICE /var/adm/mount 1> /dev/null 2> /dev/null
 if [ ! $? = 0 ]; then
  dialog --title "MOUNT ERROR" --menu "There was an error attempting to mount the CD-ROM device." \
11 60 3 \
"1" "Abort CD installation" \
"2" "Attempt to mount the CD-ROM device again" \
"3" "Ignore the error and continue" 2> /tmp/errordo
  if [ $? = 1 -o $? = 255 ]; then
   rm -f /tmp/SeTDS /tmp/SeTmount /tmp/SeTCDdev /tmp/errordo
   exit;
  fi
  DOWHAT="`cat /tmp/errordo`"
  rm -f /tmp/errordo
  if [ $DOWHAT = 1 ]; then
   rm -f /tmp/SeTDS /tmp/SeTmount /tmp/SeTCDdev
   exit;
  elif [ $DOWHAT = 3 ]; then
   break;
  fi
 else
  if [ ! -d /var/adm/mount/$SLACK_SOURCE_LOCATION ]; then
   dialog --title "ERROR: DIRECTORY NOT FOUND" --msgbox "The Slackware source directory could not be found. You'll \
have to reconfigure your source media before you can install." 8 60
   rm -f /tmp/SeTmount /tmp/SeTDS /tmp/SeTCDdev   
   exit
  fi
  break;
 fi
done
# since we've mounted successfully, let's refresh the link:
if [ ! -d $T_PX/dev ]; then
 mkdir $T_PX/dev
 chown root.root $T_PX/dev
 chmod 755 $T_PX/dev
fi
( cd $T_PX/dev ; ln -sf $CD_DEVICE cdrom )
echo "/var/adm/mount/$SLACK_SOURCE_LOCATION" > /tmp/SeTDS
echo "-source_mounted" > /tmp/SeTmount
echo "$CD_DEVICE" > /tmp/SeTCDdev
echo "/dev/null" > /tmp/SeTsource
