#!/bin/sh
#
# Copyright 2000 David Cantrell, Concord, California USA
# All rights reserved.
#
# Parts of this script were adapted from Slackware's "liloconfig" utility.
#
# Copyright 1994, 1998, 1999 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.
#
# ChangeLog:
# 21-May-2001   Modifications to work with devfs enabled systems.  Simple
#               method no longer reports the Linux partition as an ext2fs.
#
# 11-Jan-2001   Now finds the kernel image to boot, either /vmlinux or
#               /vmlinux.gz
#
# 18-Dec-2000   Initial version.
#

### Some global variables
TMP=/var/log/setup/tmp

if [ "$COLOR" = "" ]
then
   # Set color menu mode unless we detect that we're on the text.gz disk:
   if [ ! -r /usr/lib/setup/setup.tty ]
   then
      COLOR=on
   fi
fi

# This is a different 'probe' than the function below.
PROBE() {
   if [ -x /sbin/probe ]; then
      /sbin/probe -l
   elif fdisk -l | fgrep "Disk /dev/ide" 1> /dev/null 2> /dev/null ; then # no devfs yet
      for devs in /dev/hda /dev/hdb /dev/hdc /dev/hdd /dev/hde /dev/hdf /dev/hdg \
         /dev/hdh /dev/hdi /dev/hdj /dev/hdk /dev/hdl /dev/hdm /dev/hdn /dev/hdo /dev/hdp \
         /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi \
         /dev/sdj /dev/sdk /dev/sdl /dev/sdm /dev/sdn /dev/sdo /dev/sdp ; do
         fdisk -l $devs
      done
   elif fdisk -l | fgrep "Disk /dev/scsi" 1> /dev/null 2> /dev/null ; then # no devfs yet
      for devs in /dev/hda /dev/hdb /dev/hdc /dev/hdd /dev/hde /dev/hdf /dev/hdg \
         /dev/hdh /dev/hdi /dev/hdj /dev/hdk /dev/hdl /dev/hdm /dev/hdn /dev/hdo /dev/hdp \
         /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi \
         /dev/sdj /dev/sdk /dev/sdl /dev/sdm /dev/sdn /dev/sdo /dev/sdp ; do
         fdisk -l $devs
      done
   elif [ -z "`fdisk -l`" ]; then
      for devs in /dev/hda /dev/hdb /dev/hdc /dev/hdd /dev/hde /dev/hdf /dev/hdg \
         /dev/hdh /dev/hdi /dev/hdj /dev/hdk /dev/hdl /dev/hdm /dev/hdn /dev/hdo /dev/hdp \
         /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi \
         /dev/sdj /dev/sdk /dev/sdl /dev/sdm /dev/sdn /dev/sdo /dev/sdp ; do
         fdisk -l $devs
      done
   else # We got output without /dev/ide or /dev/scsi, so it can probably be trusted:
      fdisk -l
   fi
}

### various support functions for the script

# This function scans for bootable partitions (making some assumptions along
# the way which may or may not be correct, but usually work), and sets up
# SILO.
simplesilo()
{
   cat << EOF > $T_PX/boot/boot_message.txt

Welcome to the SILO Boot Loader!

Please enter the name of the partition you would like to boot
at the prompt below.  The choices are:

EOF

   cat << EOF > $T_PX/etc/silo.conf
# SILO configuration file
# generated by 'siloconfig'
#
# Start SILO global section
message = /boot/boot_message.txt
timeout = 1200
# End SILO global section
EOF

   # OK, now let's look for Solaris partitions:
   SUNOSP="`PROBE -l | fgrep SunOS | fgrep root`"
   SUNOSP="`echo $SUNOSP | cut -f 1 -d ' '`"
   if [ ! "$SUNOSP" = "" ]
   then
      cat << EOF >> $T_PX/etc/silo.conf

# Solaris bootable partition config begins
other = $SUNOSP
   label = Solaris
   solaris
# Solaris bootable partition config ends
EOF
      echo "Solaris - Solaris (UFS filesystem)" >> $T_PX/boot/boot_message.txt
   fi

   # Next, we search for Linux partitions:
   LNXP="`PROBE -l | fgrep "Linux native"`"
   LNXP="`echo $LNXP | cut -f 1 -d ' '`"
   if [ ! "$LNXP" = "" ]
   then
      cat << EOF >> $T_PX/etc/silo.conf

# Linux bootable partition config begins
image = $KERNEL_IMAGE
   root = $ROOT_DEVICE
   label = Linux
   read-only # We mount filesystems ro, check them, then remount rw
# Linux bootable partition config ends
EOF
      echo "Linux   - Linux (Linux native partition)" >> $T_PX/boot/boot_message.txt
   fi

   echo >> $T_PX/boot/boot_message.txt
   # Done, now we must install silo:
   installcolor;
}

checkp_text()
{
   if [ ! -r $1 ]
   then
      echo
      echo "I can't find a device named '$1'!"
      echo
      echo -n "Are you sure you want to use this device name [y]es, [n]o? "
      read use_device;

      if [ ! "$use_device" = "y" ]
      then
         return 1;
      fi

      return 0;
   fi
}

checkp_dialog()
{
   if [ ! -r $1 ]
   then
      dialog --title "DEVICE FILE NOT FOUND" --yesno "I can't find a \
device named '$1'. Are you sure you want to use this device \
name?" 7 60
      return $?;
   fi
}

# installcolor installs SILO with dialog-based prompts
installcolor()
{
   dialog --infobox "\nInstalling SPARC Improved Loader..." 5 39
   if [ "$T_PX" = "/" ]
   then
      silo 1> /dev/null 2> /dev/null
      SUCCESS=$?
   else
      silo -r $T_PX 1> /dev/null 2> /dev/null
      SUCCESS=$?
   fi

   if [ ! "$SUCCESS" = "0" ]   # some SILO error occurred
   then
      dialog --title "SILO INSTALL ERROR # $SUCCESS" --msgbox \
      "Sorry, but the attempt to install SILO has returned an \
error, so SILO has not been correctly installed.  You'll have to use a \
CD-ROM or net boot to start your machine instead.  It should still be \
possible to get SILO working by editing the /etc/silo.conf and \
reinstalling SILO manually.  See the SILO man page and documentation in \
/usr/doc/silo/ for more help." 11 60
   else
      dialog --title "SILO INSTALLATION SUCCESS" --msgbox \
      "\n    SILO has been installed on your system." 7 50
   fi
}

# installtext installs SILO without using dialog-based prompts
installtext()
{
   echo "Installing the SPARC Improved Loader..."
   if [ "$T_PX" = "/" ]
   then
      silo
      SUCCESS=$?
   else
      silo -f -r $T_PX
      SUCCESS=$?
   fi

   if [ ! "$SUCCESS" = "0" ]   # some SILO error occurred
   then
      cat << EOF

SILO INSTALL ERROR # $SUCCESS

Sorry, but the attempt to install SILO has returned an error, so SILO
has not been correctly installed.  You'll have to use a CD-ROM or net
boot to start your machine instead.  It should still be possible to get
SILO working by editing the /etc/silo.conf and reinstalling SILO 
manually.  See the SILO man page and documentation in /usr/doc/silo/
for more help.

EOF
   else
      cat << EOF

SILO INSTALLATION SUCCESS

SILO has been installed on your system.

EOF
      read JUNK;
   fi
}

# 'probe()' borrowed from LILO QuickInst.
probe()
{
   [ ! -z "`dd if=$1 bs=1 count=1 2>/dev/null | tr '\0' x`" ]
      return
}


# siloconfig-color?
if [ "`basename $0`" = "siloconfig-color" ]
then
   COLOR=on
fi

# Figure out if we're installing from the hard drive
if [ -r $TMP/SeTT_PX ]
then
   T_PX="`cat $TMP/SeTT_PX`"
else
   if [ "$T_PX" = "" -a ! "$1" = "" ]
   then
      T_PX=$1
   else
      T_PX=/
   fi
fi

HDR="no" # this means the header section of /etc/silo.conf has not yet
         # been configured
LNX="no" # this means no Linux partition has been defined as bootable
         # through SILO. Both of these must change to "yes" before SILO will
         # install from this script.

# Determine the root partition (such as /dev/hda2)
ROOT_DEVICE=$2
if [ "$ROOT_DEVICE" = "" ]
then
   if [ -r $TMP/SeTrootdev ]
   then
      ROOT_DEVICE="`cat $TMP/SeTrootdev`"
   else
      ROOT_DEVICE="`mount | cut -b-10 | sed -n "1 p"`"
   fi
fi

# Find the kernel
if [ -r $T_PX/vmlinux ]
then
   KERNEL_IMAGE=/vmlinux
elif [ -r $T_PX/vmlinux.gz ]
then
   KERNEL_IMAGE=/vmlinux.gz
fi

### This is where siloconfig starts
if [ -r $TMP/SeTcolor -o "$COLOR" = "on" ]
then
   # use color menus, otherwise tty
   # OK, now let's see if we should automate things:
   dialog --title "INSTALL SILO" --menu "SILO (SPARC Improved Loader) is a generic \
boot loader.  There's a simple installation which tries to automatically \
set up SILO to boot Linux (also Solaris if found).  For more advanced users \
the expert option offers more control over the installation process. \
Since SILO does not work in all cases (and can damage partitions if \
incorrectly installed), there's the third (safe) option, which is to skip \
installing SILO for now.  You can always install it later with the \
'siloconfig' command.  Which option would you like?" \
18 66 3 \
"simple" "Try to install SILO automatically" \
"expert" "Use expert silo.conf setup menu" \
"skip" "Do not install SILO" 2> $TMP/reply

   if [ $? = 1 -o $? = 255 ]
   then
      exit
   fi

   REPLY="`cat $TMP/reply`"
   rm -f $TMP/reply

   if [ "$REPLY" = "skip" ]
   then
      exit
   elif [ "$REPLY" = "simple" ]
   then
      # Do simple SILO setup
      simplesilo
      exit
   fi

   # drop through to last option: (use the expert menus)
   while [ 0 ]
   do
      dialog --title "EXPERT SILO INSTALLATION" --menu \
"This menu directs the creation of the SILO config file, silo.conf. \
To install, you make a new SILO configuration file by creating a new header \
and then adding one or more bootable partitions to the file. Once you've done \
this, you can select the install option. Alternately, if you already have an \
/etc/silo.conf, you may reinstall using that. If you make a mistake, you can \
always start over by choosing 'Begin'. \
Which option would you like?" 21 73 8 \
"Begin" "Start SILO configuration with a new SILO header" \
"Linux" "Add a Linux partition to the SILO config file" \
"Solaris" "Add a Solaris partition to the SILO config file" \
"Install" "Install SILO" \
"Recycle" "Reinstall SILO using the existing silo.conf" \
"Skip" "Skip SILO installation and exit this menu" \
"View" "View your current /etc/silo.conf" \
"Help" "Read the SPARC Improved Loader HELP file"  2> $TMP/reply

      if [ $? = 1 -o $? = 255 ]
      then
         REPLY="Skip"
      else
         REPLY="`cat $TMP/reply`"
      fi
      rm -r $TMP/reply

      if [ "$REPLY" = "Skip" ]
      then
         rm -f $TMP/tmpmsg $TMP/reply
         break
      elif [ "$REPLY" = "Begin" ]
      then
         # Begin SILO configuration
         dialog --title "OPTIONAL append= LINE" --inputbox "Some systems might \
require extra parameters to be passed to the kernel in order to boot. An \
example would be the hd=cyl,hds,secs needed with some SCSI systems.  If you \
needed to pass parameters to the kernel when you booted the Slackware \
installation media, you'll probably want to enter the same ones here.  Most \
systems won't require any extra parameters. If you don't need any, just \
hit ENTER to continue." 14 71 2> $TMP/reply
         if [ $? = 1 -o $? = 255 ]
         then
            HDR="no"
            continue;
         else
            APPEND="`cat $TMP/reply`"
         fi

         dialog --title "CHOOSE SILO DELAY" --menu "How long would you like \
SILO to wait for you to hit left-shift to get a prompt after rebooting? If you \
let SILO time out, it will boot the first OS in the configuration file by \
default." 13 72 4 \
"None" "Don't wait at all - boot straight into the first OS" \
"5" "5 seconds" \
"30" "30 seconds" \
"Forever" "Present a prompt and wait until a choice is made" 2> $TMP/reply
         if [ $? = 1 -o $? = 255 ]
         then
            HDR="no"
            continue;
         else
            DELAY="`cat $TMP/reply`"
         fi
         rm -r $TMP/reply

         if [ "$DELAY" = "None" ]; then
            DELAY="# timeout = 5"
         elif [ "$DELAY" = "5" ]; then
            DELAY="timeout = 50"
         elif [ "$DELAY" = "30" ]; then
            DELAY="timeout = 300"
         elif [ "$DELAY" = "Forever" ]; then
            DELAY="# timeout = 50"
         else
            HDR="no"
            continue;
         fi

         if [ "$APPEND" = "" ]
         then
            cat << EOF > $TMP/silo.conf
# SILO configuration file
# generated by 'siloconfig'
#
# Start the SILO global section
$DELAY
# End SILO global section
EOF
            HDR="yes"
         else
            cat << EOF > $TMP/silo.conf
# SILO configuration file
# generated by 'siloconfig'
#
# Start the SILO global section
append = "$APPEND"
$DELAY
# End SILO global section
EOF
            HDR="yes"
         fi
      elif [ "$REPLY" = "Linux" ]
      then
         # Add Linux partition to SILO config file
         if [ "$HDR" = "yes" ]
         then
            echo "These are your Linux partitions:" > $TMP/tmpmsg
            echo >> $TMP/tmpmsg
            echo "   Device Boot  Begin   Start    End  Blocks   Id  System" >> $TMP/tmpmsg
            PROBE -l | fgrep Linux | fgrep native >> $TMP/tmpmsg
            echo >> $TMP/tmpmsg
            echo "Which one would you like SILO to boot?" >> $TMP/tmpmsg
            dialog --title "SELECT LINUX PARTITION" --inputbox "`cat $TMP/tmpmsg`" 20 74 2> $TMP/reply

            if [ $? = 1 -o $? = 255 ]
            then
               rm $TMP/tmpmsg
               continue
            fi
            rm $TMP/tmpmsg

            LINUX_PART="`cat $TMP/reply`"
            checkp_dialog $LINUX_PART
            if [ ! $? = 0 ]
            then
               continue
            fi

            dialog --title "SELECT PARTITION NAME" --inputbox \
"Now you must select a short, unique name for this partition. \
You'll use this name if you specify a partition to boot at the \
SILO prompt. 'Linux' might not be a bad choice. THIS MUST BE A \
SINGLE WORD." 11 55 2> $TMP/reply
            if [ $? = 1 -o $? = 255 ]
            then
               continue
            fi

            LABEL="`cat $TMP/reply`"
            cat << EOF >> $TMP/silo.conf

# Linux bootable partition config begins
image = $KERNEL_IMAGE
  root = $LINUX_PART
  label = $LABEL
  read-only # We mount filesystems ro, check them, then remount rw
# Linux bootable partition config ends
EOF
         else
            dialog --title "CAN'T ADD LINUX PARTITION" --msgbox "You can't add \
partitions unless you start over with a new SILO header." 6 60
            continue
         fi
         LNX="yes"
      elif [ "$REPLY" = "Solaris" ]
      then
         # Add Solaris partition to SILO config file
         if [ "$HDR" = "yes" ]
         then
            echo "These are your Solaris root partitions:" > $TMP/tmpmsg
            echo >> $TMP/tmpmsg
            echo "   Device Boot  Begin   Start    End  Blocks   Id  System" >> $TMP/tmpmsg
            PROBE -l | fgrep SunOS | fgrep root >> $TMP/tmpmsg
            echo >> $TMP/tmpmsg
            echo "Which one would you like SILO to boot?" >> $TMP/tmpmsg
            dialog --title "SELECT SOLARIS PARTITION" --inputbox "`cat $TMP/tmpmsg`" 20 74 2> $TMP/reply

            if [ $? = 1 -o $? = 255 ]
            then
               rm $TMP/tmpmsg
               continue
            fi
            rm $TMP/tmpmsg

            SUNOS_PART="`cat $TMP/reply`"
            checkp_dialog $SUNOS_PART
            if [ ! $? = 0 ]
            then
               continue
            fi

            dialog --title "SELECT PARTITION NAME" --inputbox \
"Now you must select a short, unique name for this partition. \
You'll use this name if you specify a partition to boot at the \
SILO prompt. 'Solaris' might not be a bad choice. THIS MUST BE A \
SINGLE WORD." 11 57 2> $TMP/reply
            if [ $? = 1 -o $? = 255 ]
            then
               continue
            fi
            LABEL="`cat $TMP/reply`"

            cat << EOF >> $TMP/silo.conf

# Solaris bootable partition config begins
other = $SUNOS_PART
   label = $LABEL
   solaris
# Solaris bootable partition config ends
EOF
         else
            dialog --title "CAN'T ADD SUNOS PARTITION" --msgbox "You can't add \
partitions unless you start over with a new SILO header." 6 60
            continue
         fi
         LNX="yes"
      elif [ "$REPLY" = "Install" -o "$REPLY" = "Recycle" ]
      then
         # Install SILO
         if [ "$REPLY" = "Recycle" -a -r $T_PX/etc/silo.conf ]
         then
            LNX="yes"
         fi
         if [ "$LNX" = "no" ]
         then
            dialog --title "CAN'T INSTALL SILO" --msgbox "SILO could not be \
installed. If you have not created a SILO configuration file by defining \
a new header and adding at least one bootable partition to it, you must do \
so before installing SILO. If you were attempting to use an existing SILO \
configuration file, it could not be found. Try making a new one." 9 70
            continue
         else
            if [ "$REPLY" = "Install" ]
            then
               if [ -r $TMP/silo.conf ]
               then
                  if [ -r $T_PX/etc/silo.conf ]
                  then
                     mv $T_PX/etc/silo.conf $T_PX/etc/silo.conf.bak
                  fi
                  cp $TMP/silo.conf $T_PX/etc/silo.conf
                  chmod 644 $T_PX/etc/silo.conf
               fi
            fi
            installcolor;
         fi
         rm -f $TMP/tmpmsg $TMP/reply
         break
      elif [ "$REPLY" = "View" ]
      then
         # View conf
         if [ -r $TMP/silo.conf ]
         then
            dialog --title "YOUR NEW /etc/silo.conf" \
                   --textbox "$TMP/silo.conf" 22 70
         else
            if [ -r /mnt/etc/silo.conf ]
            then
               dialog --title "YOUR OLD /etc/silo.conf" \
                      --textbox "/mnt/etc/silo.conf" 22 70
            elif [ "$T_PX" = "/" -a -r /etc/silo.conf ]
            then
               dialog --title "YOUR OLD /etc/silo.conf" \
                      --textbox "/etc/silo.conf" 22 70
            else
               dialog --title "NO CONFIG FILE FOUND" --msgbox "Sorry, but you don't have a SILO configuration file that can be viewed." 6 60
            fi
         fi
      elif [ "$REPLY" = "Help" ]
      then
         # Read help
         dialog --title "SILO INSTALLATION HELP" --textbox "$T_PX/var/log/setup/text.silohelp" 22 68
      fi
   done
else # don't use color!
   while [ 0 ]
   do
      cat << EOF

SILO INSTALLATION

SILO (SPARC Improved Loader) is the program that allows booting Linux directly
from the hard drive. To install, you make a new SILO configuration file by
creating a new header and then adding at least one bootable partition to the
file. Once you've done this, you can select the install option. Alternatively,
if you already have an /etc/silo.conf, you may reinstall using that. If you
make a mistake, just select (1) to start over.

1 -- Start SILO configuration with a new SILO header
2 -- Add a Linux partition to the SILO config file
3 -- Add a Solaris partition to the SILO config file
4 -- Install SILO
5 -- Reinstall SILO using the existing silo.conf
6 -- Skip SILO installation and exit this menu
7 -- View your current /etc/silo.conf
8 -- Read the SPARC Improved Loader HELP file

EOF
      echo -n "Which option would you like (1 - 8)? "
      read REPLY;
      echo
      if [ "$REPLY" = "1" ]
      then
         cat << EOF
OPTIONAL append="" LINE

Some systems might require extra parameters to be passed to the kernel in order
to boot. An example would be the hd=cyl,hds,secs needed with some SCSI systems.
If you needed to pass parameters to the kernel when you booted the Slackware
installation media, you'll probably want to enter the same ones here.

Most systems won't require any extra parameters. If you don't need any, just
hit ENTER to continue.

EOF
         echo -n "Enter extra parameters==> "
         read APPEND;
         echo

         cat << EOF
CHOOSE SILO DELAY

How long would you like SILO to wait for you to hit left-shift to 
get a prompt after rebooting? If you let SILO time out, it will boot
the first OS in the configuration file by default.

1 -- None, don't wait at all - boot straight into the first OS
2 -- 5 seconds
3 -- 30 seconds
4 -- Present a prompt and wait until a choice is made without timing out

EOF
         echo -n "Which choice would you like (1 - 4)? "
         read DELAY;
         echo

         if [ "$DELAY" = "1" ]
         then
            DELAY="# timeout = 5"
         elif [ "$DELAY" = "2" ]
         then
            DELAY="timeout = 50"
         elif [ "$DELAY" = "3" ]
         then
            DELAY="timeout = 300"
         elif [ "$DELAY" = "4" ]
         then
            DELAY="# timeout = 50"
         else
            HDR="no"
            continue;
         fi

         if [ "$APPEND" = "" ]
         then
            cat << EOF > $TMP/silo.conf
# SILO configuration file
# generated by 'siloconfig'
#
# Start SILO global section
$DELAY
# End SILO global section
EOF
            HDR="yes"
         else
            cat << EOF > $TMP/silo.conf
# SILO configuration file
# generated by 'siloconfig'
#
# Start the SILO global section
append = "$APPEND"
$DELAY
# End SILO global section
EOF
            HDR="yes"
         fi
      elif [ "$REPLY" = "2" ]
      then
         if [ "$HDR" = "yes" ]
         then
            while [ 0 ]
            do
               cat << EOF
SELECT LINUX PARTITION

These are your Linux partitions:

   Device Boot  Begin   Start    End  Blocks   Id  System
`fdisk -l | fgrep Linux | fgrep native`

EOF
               echo -n "Which one would you like SILO to boot? "

               read LINUX_PART;
               checkp_text $LINUX_PART
               if [ $? = 0 ]
               then
                  break;
               fi
            done

            echo
            cat << EOF
SELECT PARTITION NAME

Now you must select a short, unique name for this partition.
You'll use this name if you specify a partition to boot at the
SILO prompt. 'Linux' might not be a bad choice.

THIS MUST BE A SINGLE WORD.

EOF
            echo -n "Enter name: "
            read LABEL;

            cat << EOF >> $TMP/silo.conf

# Linux bootable partition config begins
image = $KERNEL_IMAGE
  root = $LINUX_PART
  label = $LABEL
  read-only # We mount filesystems ro, check them, then remount rw
# Linux bootable partition config ends
EOF
         else
            cat << EOF
CAN'T ADD LINUX PARTITION

You can't add partitions unless you start over
with a new SILO header.

EOF
            echo -n "Press ENTER to continue."
            read JUNK;
            echo
            continue
         fi
         LNX="yes"
      elif [ "$REPLY" = "3" ]
      then
         if [ "$HDR" = "yes" ]
         then
            while [ 0 ]
            do
               cat << EOF
SELECT SOLARIS PARTITION

These are your Solaris root partitions:

   Device Boot  Begin   Start    End  Blocks   Id  System"
`fdisk -l | fgrep SunOS | fgrep root`

EOF
               echo -n "Which one would you like SILO to boot? "

               read SUNOSPART;
               checkp_text $SUNOSPART
               if [ $? = 0 ]
               then
                  break;
               fi
            done

            cat << EOF

SELECT PARTITION NAME

Now you must select a short, unique name for this partition.
You'll use this name if you specify a partition to boot at the
SILO prompt. 'Solaris' might not be a bad choice.

THIS MUST BE A SINGLE WORD.

EOF
            echo -n "Enter name: "
            read LABEL;
            echo

            cat << EOF >> $TMP/silo.conf

# Solaris bootable partition config begins
other = $SUNOSPART
   label = $LABEL
   solaris
# Solaris bootable partition config ends
EOF
         else
            cat << EOF
CAN'T ADD SOLARIS PARTITION

You can't add partitions unless you start over
with a new SILO header.

EOF
            echo -n "Press ENTER to continue."
            read JUNK;
            echo
            continue
         fi
         LNX="yes"
      elif [ "$REPLY" = "4" -o "$REPLY" = "5" ]
      then
         if [ "$REPLY" = "5" -a -r $T_PX/etc/silo.conf ]
         then
            LNX="yes"
         fi
         if [ "$LNX" = "no" ]
         then
            cat << EOF

CAN'T INSTALL SILO

SILO could not be installed. If you have not created a SILO
configuration file by defining a new header and adding at least
one bootable partition to it, you must do so before installing
SILO. If you were attempting to use an existing SILO configuration
file, it could not be found. Try making a new one.

EOF
            echo -n "Press ENTER to continue."
            read JUNK;
            echo
            continue
         else
            if [ "$REPLY" = "4" ]
            then
               if [ -r $TMP/silo.conf ]
               then
                  if [ -r $T_PX/etc/silo.conf ]
                  then
                     mv $T_PX/etc/silo.conf $T_PX/etc/silo.conf.bak
                  fi
                  cp $TMP/silo.conf $T_PX/etc/silo.conf
                  chmod 644 $T_PX/etc/silo.conf
               fi
            fi
            echo
            installtext;
         fi
         rm -f $TMP/tmpmsg $TMP/reply
         break
      elif [ "$REPLY" = "6" ]
      then
         rm -f $TMP/tmpmsg $TMP/reply
         break
      elif [ "$REPLY" = "7" ]
      then
         if [ -r $TMP/silo.conf ]
         then
            if [ -r /bin/more ]
            then
               cat $TMP/silo.conf | more
            else
               cat $TMP/silo.conf
            fi
            echo -n "Press ENTER to continue..."
            read JUNK;
            echo
         else
            if [ -r /mnt/etc/silo.conf ]
            then
               if [ -r /bin/more ]
               then
                  cat /mnt/etc/silo.conf | more
               else
                  cat /mnt/etc/silo.conf
               fi
               echo -n "Press ENTER to continue..."
               read JUNK;
               echo
            elif [ "$T_PX" = "/" -a -r /etc/silo.conf ]
            then
               if [ -r /bin/more ]
               then
                  cat /etc/silo.conf | more
               else
                  cat /etc/silo.conf
               fi
               echo -n "Press ENTER to continue..."
               read JUNK;
               echo
            else
               cat << EOF

NO CONFIG FILE FOUND

Sorry, but you don't have a SILO configuration file that can be viewed.

EOF
               echo -n "Press ENTER to continue..."
               read JUNK;
               echo
            fi
         fi
      elif [ "$REPLY" = "8" ]
      then
         if [ -r /bin/more ]
         then
            cat $T_PX/var/log/setup/text.lilohelp | more
         else
            cat $T_PX/var/log/setup/text.lilohelp
            echo -n "Sorry... there's no pager. Press ENTER to continue."
            read JUNK;
            echo
         fi
      fi
   done
   echo
fi # are we using color?
