#!/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`" 20 70 5 \
"1" "SCSI [ /dev/scd0 or /dev/scd1 ]" \
"2" "Sony CDU31A [ /dev/sonycd ]" \
"3" "Sony 535 [ /dev/cdu535 ]" \
"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 "\
Which SCSI CD-ROM are you using? (If you're not sure, \n\
select /dev/sr0)" 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"
fi
# The CD will be mounted automatically later on:
echo "$CD_DEVICE       /cdrom        iso9660       ro" > /tmp/SeTcdfstab
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 default selections for the \
Slackware Professional CD (including an option to run mostly from the CD), \
InfoMagic CD, TransAmeritech CD, and the Linux \
Quarterly CD-ROM. There may be other directories \
containing other versions - enter a custom directory name if you like. \
Which option would you like?" 19 74 6 \
"slakware" "Slackware Pro: install to HD" \
"slackpro" "Slackware Pro: run from CD" \
"slackware.111" "TransAmeritech CD" \
"packages/slackware" "Linux Quarterly CD-ROM" \
"distributions/slackware" "InfoMagic CD-ROM" \
"Custom" "Enter your own directory name" \
2> /tmp/SeTreturn
if [ $? = 1 -o $? = 255 ]; then
 rm -f /tmp/cdtype /tmp/SeTreturn
 exit
fi
#
# These guys might get added back to the menu if I see better reports on
# the net, but I doubt it.
# "SLACK" "CD-ROM A MONTH" \
#
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
if [ -r /tmp/CDdebug ]; then # we're testing an image here @ Slackware labs,
                             # and must do our own mount.
echo
echo "Source location -> $SLACK_SOURCE_LOCATION"
echo
echo "Shelling out to let you do your own mount. The command that would have"
echo "been used here is:"
echo
echo "mount -o ro -t iso9660 $CD_DEVICE /var/adm/mount"
echo
echo "To test correctly, be sure to mount read-only ( -o ro )."
echo
echo "It addition, this line will be in /tmp/SeTcdfstab so the disk is"
echo "mounted at boot time:"
echo
echo "$CD_DEVICE       /cdrom        iso9660       ro"
echo
echo "You might want to echo your own to there for testing."
echo
echo "When done, type 'exit' to return to the setup program."
echo
/bin/sh
else 
 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
fi # debug
# 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
