#!/bin/sh
while [ 0 ]; do
rm -f /tmp/SeTDS /tmp/SeTmount

while [ 0 ]; do
 cat << EOF > /tmp/tmpmsg

In order to install directly from the hard disk you must
have a partition with a directory containing the Slackware
distribution such that each disk other than the boot disk
is contained in a subdirectory. For example, if the 
distribution is in /stuff/slack, then you have to have
directories named /stuff/slack/a1, /stuff/slack/a2, and so
on each containing the files that would be on that disk.
You may install from DOS, HPFS, or Linux partitions.
Please enter the partition where the Slackware sources can 
be found, or [enter] to see a partition list: \n
EOF
 dialog --title "INSTALLING FROM HARD DISK" --inputbox \
"`cat /tmp/tmpmsg`" 20 70 2> /tmp/source.part
 if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/source.part /tmp/tmpmsg
  exit
 fi
 rm -f /tmp/tmpmsg
 SLACK_DEVICE="`cat /tmp/source.part`"
 rm -f /tmp/source.part
 if [ "$SLACK_DEVICE" = "" ]; then
  dialog --title "PARTITION LIST" --msgbox "`fdisk -l | fgrep -v cylind | fgrep dev 2> /dev/null`" 22 75 
  continue;
 fi
 break;
done

dialog --title "SELECT SOURCE DIRECTORY" --inputbox \
"\n\
Now we need to know what directory on this partition \n\
the Slackware sources can be found in. (The directory \n\
in which the subdirectories for each disk is found) \n\
NOTE: You must give the directory name relative to the \n\
top of the partition.  So, for example, if you're going \n\
to mount this partition under /usr, don't include the \n\
'/usr'at the beginning of the pathname. \n\n\
What directory are the Slackware sources in? \n" \
19 65 2> /tmp/source.dir
if [ $? = 1 -o $? = 255 ]; then
 rm -f /tmp/source.dir
 exit
fi
SLACK_SOURCE_LOCATION="`cat /tmp/source.dir`"
rm -f /tmp/source.dir
if mount | fgrep $SLACK_DEVICE 1> /dev/null 2> /dev/null ; then
 # This partition is already mounted, so we will have to
 # tweak things funny.
 rm -f /var/adm/mount 2> /dev/null
 rmdir /var/adm/mount 2> /dev/null
 PREFIX="`mount | fgrep $SLACK_DEVICE`"
 PREFIX="`echo "$PREFIX" | cut -b14-`"
 end_of_line="1"
 while [ 0 ]; do
  end_of_line="`expr $end_of_line + 1`"
  if [ "`echo "$PREFIX" | cut -b$end_of_line`" = " " ]; then  # Found it!
   end_of_line="`expr $end_of_line - 1`"
   break;
  fi
 done
 PREFIX="`echo "$PREFIX" | cut -b1-$end_of_line`"
 ln -sf $PREFIX /var/adm/mount 
else
 while [ 0 ]; do
  dialog --title "SELECT FILESYSTEM TYPE" --menu "What type of filesystem does your Slackware \
source partition contain?" 13 65 5 \
"1" "FAT (MS-DOS, DR-DOS, OS/2)" \
"2" "Linux Second Extended Filesystem" \
"3" "Linux Xiafs" \
"4" "Linux MINIX" \
"5" "OS/2 HPFS" 2> /tmp/filesys
  if [ $? = 1 -o $? = 255 ]; then
   rm -f /tmp/filesys
   exit
  fi
  FILESYS="`cat /tmp/filesys`"
  rm -f /tmp/filesys
  if [ "$FILESYS" = "1" ]; then 
   SLACK_FS_TYPE="msdos"
   break;
  elif [ "$FILESYS" = "2" ]; then 
   SLACK_FS_TYPE="ext2"
   break;
  elif [ "$FILESYS" = "3" ]; then 
   SLACK_FS_TYPE="xiafs"
   break;
  elif [ "$FILESYS" = "4" ]; then 
   SLACK_FS_TYPE="minix"
   break;
  elif [ "$FILESYS" = "5" ]; then 
   SLACK_FS_TYPE="hpfs"
   break;
  fi
 done
 if [ "$FILESYS" = "5" ]; then
  mount -o ro -t $SLACK_FS_TYPE $SLACK_DEVICE /var/adm/mount 1> /dev/null 2> /dev/null
 else
  mount -t $SLACK_FS_TYPE $SLACK_DEVICE /var/adm/mount 1> /dev/null 2> /dev/null
 fi
 if [ ! $? = 0 ]; then # there was a mount error
  cat << EOF > /tmp/tmpmsg

There was a problem mounting your partition. Would you like to:

EOF
  dialog --title "MOUNT ERROR" --menu "`cat /tmp/tmpmsg`" 10 68 2 \
"Restart" "Start over" \
"Ignore " "Ignore the error and continue" 2> /tmp/dowhat
  if [ $? = 1 -o $? = 255 ]; then
   rm -f /tmp/dowhat
   exit
  fi
  DOWHAT="`cat /tmp/dowhat`"
  rm -f /tmp/dowhat
  if [ "$DOWHAT" = "Restart" ]; then
   continue;
  fi
  echo
 fi # mount error
fi

if [ -d /var/adm/mount/$SLACK_SOURCE_LOCATION ]; then
 echo "/var/adm/mount/$SLACK_SOURCE_LOCATION" > /tmp/SeTDS
 echo "-source_mounted" > /tmp/SeTmount
 echo "/dev/null" > /tmp/SeTsource
 exit
else
 cat << EOF > /tmp/tmpmsg

Sorry, but the directory $SLACK_SOURCE_LOCATION does not exist
on partition $SLACK_DEVICE.

Would you like to try again?
EOF
 dialog --title "SOURCE DIRECTORY NOT FOUND" --yesno "`cat /tmp/tmpmsg`" 10 70
 if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/tmpmsg
  exit
 fi
 rm -r /tmp/tmpmsg
fi

done
