#!/bin/sh
# SeTpartition user-friendly rewrite Fri Dec 15 13:17:40 CST 1995 pjv
# More updates for Slackware 3.5: Wed Apr 29 22:43:28 CDT 1998
# Updated for Slackware 7.x (new fdisk tags) Fri Sep 10 13:17:18 CDT 1999
# Modified for DeLi Linux
TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
REDIR=/dev/tty4
NDIR=/dev/null
rm -f $TMP/SeTDOS
touch $TMP/SeTDOS
crunch () { # remove extra whitespace
 read STRING;
 echo $STRING
}
DOSLIST="`probe -l | fgrep "DOS
Win95 F
Win98 F
FAT12
FAT16
HPFS" | fgrep -v "Ext'd" | fgrep -v "Extend"`"
if [ "$DOSLIST" = "" ]; then # no FAT/FAT32/HPFS partitions
 exit
fi
dialog --title "FAT/FAT32/HPFS PARTITIONS DETECTED" \
--yesno "Partitions of type FAT or FAT32 (commonly used by DOS and \
Windows) or of type HPFS (used by OS/2) have been found on your \
system.  Would you like to add these partitions to your /etc/fstab \
so that these partitions are visible from Linux?" \
8 70
if [ ! $? = 0 ]; then
 exit
fi
while [ 0 ]; do # main partition selection loop
 rm -f $TMP/SeTSKIP
 echo "true" > $TMP/SeTSKIP
 cat << EOF > $TMP/tempscript
dialog --title "SELECT PARTITION TO ADD TO /etc/fstab" \\
--menu "In order to make these partitions visible from Linux, we \\
need to add them to your /etc/fstab.  Please pick a partition to \\
add to /etc/fstab, or select '---' to continue with the installation \\
process." \\
15 70 5 \\
EOF
 echo "$DOSLIST" | while read PARTITION ; do
  NAME=`echo $PARTITION | crunch | cut -f 1 -d ' '`
  SIZE=`echo "$PARTITION" | tr -d "*" | tr -d "+" | crunch | cut -f 4 -d ' '`
  if echo $PARTITION | fgrep Win9 1> $NDIR 2> $NDIR ; then
   TYPE="Win9x FAT32"
  elif echo $PARTITION | fgrep FAT 1> $NDIR 2> $NDIR ; then
   TYPE="DOS FAT"
  elif echo $PARTITION | fgrep HPFS 1> $NDIR 2> $NDIR ; then
   TYPE="OS/2 HPFS"
  fi
  if cat $TMP/SeTDOS | fgrep $NAME 1> $NDIR 2> $NDIR ; then
   ON=`cat $TMP/SeTDOS | fgrep $NAME | crunch | cut -f 2 -d ' '`
   echo "\"(IN USE)\" \"$NAME on $ON $TYPE ${SIZE}K\" \\" >> $TMP/tempscript
  else
   echo "\"$NAME\" \"$TYPE ${SIZE}K\" \\" >> $TMP/tempscript
   echo "false" > $TMP/SeTSKIP
  fi
 done
 echo "\"---\" \"(done, continue with setup)\" \\" >> $TMP/tempscript
 echo "\"---\" \"(done, continue with setup)\" \\" >> $TMP/tempscript
 echo "\"---\" \"(done, continue with setup)\" \\" >> $TMP/tempscript
 echo "\"---\" \"(done, continue with setup)\" \\" >> $TMP/tempscript
 echo "\"---\" \"(done, continue with setup)\" \\" >> $TMP/tempscript
 echo "2> $TMP/return" >> $TMP/tempscript
 if [ "`cat $TMP/SeTSKIP`" = "true" ]; then
  break
 fi
 . $TMP/tempscript
 if [ $? = 1 -o $? = 255 ]; then
  rm $TMP/tempscript
  exit 255 # user abort
 fi
 DOS_PART="`cat $TMP/return`"
 rm -f $TMP/tempscript
 if [ "$DOS_PART" = "---" ]; then
  break
 elif [ "$DOS_PART" = "(IN USE)" ]; then
  continue
 fi
 dialog --title "PICK MOUNT POINT FOR $DOS_PART" \
 --inputbox "Now this partition must be mounted somewhere in your \
 directory tree. Please enter the directory under which \
 you would like to put it. For instance, you might want to \
 enter /fat-c or /fat-d or something similar. NOTE: This \
 partition won't actually be mounted until you reboot. \
 Where would you like to mount $DOS_PART?" \
 13 65 2> $TMP/mount-point
 if [ $? = 1 -o $? = 255 ]; then
  rm -f $TMP/tempmsg $TMP/mount-point $TMP/SeTDOS
  exit
 fi
 NEW_DIR="`cat $TMP/mount-point`"
 rm -f $TMP/mount-point
 if [ ! "`echo $NEW_DIR | cut -b1`" = "/" ]; then
  NEW_DIR="/$NEW_DIR"
 fi
 mkdir -p /mnt$NEW_DIR
 chmod 755 /mnt$NEW_DIR
 if echo "$DOSLIST" | fgrep $DOS_PART | fgrep HPFS 1> $NDIR 2> $NDIR ; then
  echo "$DOS_PART      $NEW_DIR       hpfs     ro        1    0" >> $TMP/SeTDOS
 else
  echo "$DOS_PART      $NEW_DIR       vfat     defaults  1    0" >> $TMP/SeTDOS
 fi
done # partition adding loop
rm -f $TMP/SeTSKIP
cat << EOF > $TMP/tempmsg

Adding this information to your /etc/fstab:

EOF
cat $TMP/SeTDOS >> $TMP/tempmsg
dialog --title "DONE ADDING FAT/FAT32/HPFS PARTITIONS" \
--textbox $TMP/tempmsg 15 70
