#!/bin/sh
#
# Copyright 1993, 1994, 1995,  Patrick Volkerding, Moorhead, Minnesota USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is 
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# As always, bug reports, suggestions, etc: volkerdi@mhd1.moorhead.msus.edu
# or bf703@cleveland.freenet.edu, or (if you absolutely must) (218) 233-4349.
# 
#
reset
rm -f /tmp/SeT*
touch /tmp/SeTcolor
PATH="$PATH:/usr/lib/setup"
export PATH;
PARTLIST="`fdisk -l | fgrep "Linux native"`" 2> /dev/null
echo "$PARTLIST" > /tmp/SeTplist
T_PX="/"
echo "$T_PX" > /tmp/SeTT_PX
#DISTRIBUTION_SOURCE="/var/adm/mount"
#echo "$DISTRIBUTION_SOURCE" > /tmp/SeTDS
#SOURCE_DEVICE="/dev/fd0"
# We may want to force the issue...
# echo "$SOURCE_DEVICE" > /tmp/SeTsource
ROOT_DEVICE="`mount | fgrep "on / " | cut -b-10`"
echo "$ROOT_DEVICE" > /tmp/SeTrootdev
if mount | fgrep /var/adm/mount 1> /dev/null 2> /dev/null ; then # clear source
 umount /var/adm/mount                                           # location
fi
#if [ -d /mnt/etc -o /mnt/lost+found ]; then # nothing should be on /mnt here!
# umount -a 1> /dev/null 2> /dev/null
# mount /proc /proc -t proc
#fi
rm -f /var/adm/mount 2> /dev/null
rmdir /var/adm/mount 2> /dev/null
mkdir /var/adm/mount 2> /dev/null

while [ 0 ]; do
 if [ -r /tmp/SeTQUICK ]; then
  QUICK="QUICK"
 else
  QUICK="VERBOSE"
 fi

 dialog --title "Slackware Linux Setup (version HD-2.2.0)" --menu "\nWelcome\
 to Slackware Linux Setup.\n\
\nHint: If you have trouble using the arrow keys on your keyboard,\n\
you can use '+', '-', and TAB instead. Which option would you like?" 22 74 11 \
"HELP" "Read the Slackware Setup HELP file" \
"KEYMAP" "Remap your keyboard" \
"QUICK" "Choose QUICK or VERBOSE install mode [now: $QUICK]" \
"MAKE TAGS" "Tagfile customization program" \
"TARGET" "Select target directory [now: $T_PX]" \
"SOURCE" "Select source media" \
"DISK SETS" "Decide which disk sets you wish to install" \
"INSTALL" "Install selected disk sets" \
"CONFIGURE" "Reconfigure your Linux system" \
"PKGTOOL" "Install or remove packages with Pkgtool" \
"EXIT" "Exit Slackware Linux Setup" 2> /tmp/hdset
 if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/hdset /tmp/SeT*
  reset
  exit
 fi
 MAINSELECT="`cat /tmp/hdset`"
 rm /tmp/hdset

 # Start checking what to do. Some modules may reset MAINSELECT to run the
 # next item in line.

 if [ "$MAINSELECT" = "HELP" ]; then
  SeTHELP
 fi
 
 if [ "$MAINSELECT" = "QUICK" ]; then
  SeTquick
 fi

 if [ "$MAINSELECT" = "MAKE TAGS" ]; then
  SeTmaketag
 fi

 if [ "$MAINSELECT" = "KEYMAP" ]; then
  SeTkeymap
  if [ -r /tmp/SeTkeymap ]; then
   dialog --title "CONTINUE?" --yesno "We're done with the KEYMAP section, \
would you like to \
go on to the SOURCE section?" 7 40
   if [ $? = 0 ]; then
    MAINSELECT="SOURCE" 
   fi
  fi
 fi

 if [ "$MAINSELECT" = "SOURCE" ]; then
  SeTmedia 
  if [ -r /tmp/SeTsource -a ! -r /tmp/SeTSERIES ]; then
   dialog --title "CONTINUE?" --yesno "Now that you've set up your source \
location, would you like \
to go on to the DISK SETS section and decide which disk sets you wish to \
install?" 9 40
   if [ $? = 0 ]; then
    MAINSELECT="DISK SETS"
   fi
  elif [ -r /tmp/SeTsource -a -r /tmp/SeTSERIES ]; then
   dialog --title "CONTINUE?" --yesno "Now that you've indicated \
your source location and selected \
the disk sets you want, you may begin the installation process, or you may \
return to the main menu. Would you like to begin the installation?" 9 50
   if [ $? = 0 ]; then
    MAINSELECT="INSTALL"
   fi
  fi
 fi

 if [ "$MAINSELECT" = "TARGET" ]; then
  dialog --title "CHANGE TARGET DIRECTORY?" --yesno "The target \
directory is the one the packages will be untarred \
from. In most cases, there is no need to change this from the default \
value of '/', but if you are installing Slackware Linux into a subdirectory \
for some reason, then you'll want to change it. It's unlikely that the system \
will run in a directory other \
than '/', though. Are you sure you want to change \
the target directory? " 11 70
  if [ $? = 1 ]; then
   continue;
  fi
  dialog --inputbox "What directory would you like \
to install Slackware into?" \
  9 40 2> /tmp/slackdir
  if [ $? = 0 ]; then
   T_PX="`cat /tmp/slackdir`"
   mkdir -p $T_PX
   echo "$T_PX" > /tmp/SeTT_PX
  else
   rm -f /tmp/slackdir 
   continue
  fi 
  rm -f /tmp/slackdir
 fi

 if [ "$MAINSELECT" = "DISK SETS" ]; then
  SeTPKG
  if [ -r /tmp/SeTSERIES -a -r /tmp/SeTsource ]; then
   dialog --title "CONTINUE?" --yesno "Now that you've set up \
the source location and decided \
what you want to install, you can go ahead and begin the installation \
process, or you can go back to the main menu. Do you want to start the INSTALL \
section and begin installing software?" 10 55
   if [ $? = 0 ]; then
    MAINSELECT="INSTALL"
   fi
  fi
 fi

 if [ "$MAINSELECT" = "INSTALL" ]; then
  if [ ! -r /tmp/SeTSERIES -o ! -r /tmp/SeTsource -o ! /tmp/SeTnative ]; then
   dialog --title "CANNOT INSTALL SOFTWARE YET" --msgbox "\
\n\
Before you can install software, complete the following tasks:\n\
\n\
1. Select your source media.\n\
2. Select which disk sets to install.\n\
\n\
You may also optionally remap your keyboard or select a\n\
different target directory than '/'.\n\
\n\
Press ENTER to return to the main menu." 15 68
   continue
  fi
  SERIES="-sets `cat /tmp/SeTSERIES`"
  SOURCE_DEVICE="`cat /tmp/SeTsource`"
  IGNORE_TAGFILES=""
  while [ 0 ]; do
   if [ -r /tmp/SeTQUICK ]; then
    MODE="Normal"
    break;
   fi
   dialog --title "SELECT PROMPTING MODE" --menu "\
\n\
Now you must select which type of prompting you would like to\n\
use while installing your software packages. If you're not\n\
sure which mode to use, read the help file.\n\n\
Which type of prompting would you like to use?\
" 17 70 5 \
"Normal" "Use the default tagfiles" \
"Custom" "Use custom tagfiles in the package directories" \
"Path" "Use tagfiles in the subdirectories of a custom path" \
"None" "Use no tagfiles - install everything" \
"HELP" "Read the prompt mode help file" 2> /tmp/SeTpmode
   if [ $? = 1 -o $? = 255 ]; then
    rm -f /tmp/SeTpmode
    exit
   fi
   MODE="`cat /tmp/SeTpmode`"
   rm -f /tmp/SeTtagext

   if [ "$MODE" = "Path" ]; then
    dialog --title "PROVIDE A CUSTOM PATH TO YOUR TAGFILES" --inputbox "If \
you're installing from CD-ROM, it's impossible to edit the tagfiles that are \
in the package directories. In this case, you might want to provide a path to \
your custom tagfiles. As an example, you could create a /tagfiles directory \
and mount a floppy disk containing the tagfiles on that directory. Then you'd \
enter '/tagfiles' at the prompt below. The setup program will look for your \
tagfile in SUBDIRECTORIES of the path you provide, such as /tagfiles/a1, \
/tagfiles/ap1, /tagfiles/d1, and so on. You only need to provide a \
subdirectory and tagfile for the first disk of each series to be installed. \
If a custom tagfile is not found at the path you provide, setup will revert to \
the default tagfiles. Please enter the path to your custom tagfiles:" \
20 70 2> /tmp/SeTtagpath
    if [ $? = 1 -o $? = 255 ]; then
     continue
    fi                                                              
    if [ -r /tmp/SeTtagpath ]; then
     if [ "`cat /tmp/SeTtagpath`" = "" ]; then
      rm -f /tmp/SeTtagpath
     fi
    fi
    break;
   fi

   if [ "$MODE" = "HELP" ]; then
    SeTprHELP
   fi
  
   if [ "$MODE" = "Normal" ]; then 
    break;
   fi 

   if [ "$MODE" = "Custom" ]; then
    dialog --title "ENTER CUSTOM EXTENSION" --inputbox "Now, enter the custom \
extension you have used for your tagfiles. This must be a valid MS-DOS format \
file extension consisting of a period followed by three characters. For \
example, I use '.pat'. You might see my tagfiles on your disks. :^)" \
13 60 2> /tmp/SeTtagext
    if [ $? = 1 -o $? = 255 ]; then
     continue
    fi
    if [ -r /tmp/SeTtagext ]; then
     if [ "`cat /tmp/SeTtagext`" = "" ]; then
      rm -f /tmp/SeTtagext
     fi
    fi
    break;
   fi

   if [ "$MODE" = "None" ]; then
    dialog --title "WARNING" --yesno "You should be advised that installing \
*everything* is often a bad plan. If you're just putting the base system in \
place and planning to install things like X and Emacs a little more \
selectively from your hard drive later, then there's no problem. Otherwise, \
if you try to install the whole thing without prompts you will not get as \
optimal an installation as you might like. Are you sure you want to install \
without prompts?" 13 60
    if [ ! $? = 0 ]; then
     continue
    fi
    IGNORE_TAGFILES="-ignore_tagfiles"
    break;
   fi

  done

  if [ "$IGNORE_TAGFILES" = "" ]; then
   if [ "$QUICK" = "QUICK" ]; then
    dialog --infobox "QUICK mode selected. Using menus for individual \
package selection." 4 50
   else
    dialog --infobox "PROMPT mode selected. Using prompting defaults \
found in tagfiles along the way." 4 50
   fi
   sleep 3
  else
   IGNORE_TAGFILES="-ignore_tagfiles"
   dialog --infobox "PROMPT mode not selected. Installing all the packages \
on the selected disk sets." 4 50
   sleep 3
  fi
  SOURCE_MOUNTED="`cat /tmp/SeTmount`"
  DISTRIBUTION_SOURCE="`cat /tmp/SeTDS`"
  if [ "$DISTRIBUTION_SOURCE" != "" ]; then
   cpkgtool $SOURCE_MOUNTED $IGNORE_TAGFILES -source_device $SOURCE_DEVICE -source_dir $DISTRIBUTION_SOURCE -target_dir $T_PX $SERIES
  else
   cpkgtool $SOURCE_MOUNTED $IGNORE_TAGFILES -source_device $SOURCE_DEVICE -target_dir $T_PX $SERIES
  fi
  dialog --title "EXTRA CONFIGURATION" --yesno "If you wish, you may \
now go through the options to reconfigure your hardware, make a \
bootdisk, and install LILO, and run any other system scripts that \
have been installed for you, such as the one to configure your \
timezone, or set up your default baud rate.  If you've installed \
a new kernel image, you should definately go through these steps \
again. \
Otherwise, it's up to you. \
Reconfigure your system? " 12 60
  if [ ! "$?" = "0" ]; then
   continue
  else
   MAINSELECT="CONFIGURE"
  fi
 fi

 if [ "$MAINSELECT" = "CONFIGURE" ]; then
  SeTconfig
 fi

 if [ "$MAINSELECT" = "PKGTOOL" ]; then
  cpkgtool
 fi

 if [ "$MAINSELECT" = "EXIT" ]; then
  rm -f /tmp/SeT*
  reset
  break
 fi

done # end of main loop

rm -f /tmp/tagfile /tmp/SeT*
 
sync
if mount | fgrep /var/adm/mount 1> /dev/null 2> /dev/null ; then
 umount /var/adm/mount 
fi
rm -f /var/adm/mount 2> /dev/null
rmdir /var/adm/mount 2> /dev/null
mkdir /var/adm/mount 2> /dev/null
chmod 755 /var/adm/mount
if [ -r /tagfile ]; then
 rm -f /tagfile
fi
chmod 755 $T_PX
if [ -d $T_PX/tmp ]; then
 chmod 1777 $T_PX/tmp
fi
# end slackware setup script
