#!/bin/sh
#
# Copyright 1994, 1998, 1999 Patrick Volkerding, Moorhead, Minnesota USA
# Copyright 2002, 2003  Slackware Linux, Inc, Concord, CA
# Copyright 2007, 2008  Patrick Volkerding, Sebeka, 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.
#
TMP=/var/log/setup/tmp
CONSOLETYPE=standard
unset UTFVT

# Set the OS root directory (called T_PX for some unknown reason).
# If an argument is given to this script and it is a directory, it
# is taken to be the root directory.  First though, we check for a
# directory named $T_PX, and that gets the first priority.
if [ ! -d "$T_PX" ]; then
  if [ ! "$1" = "" ]; then
    if [ -d "$1" ]; then
      T_PX="$1"
    fi
  else
    # Are we on the installer image?
    if [ -r /usr/lib/setup/SeTpartitions ]; then
      T_PX=/mnt
    # Or, are we on a running system?
    elif [ -r /etc/slackware-version ]; then
      T_PX=/
    # One more installer-likely thing:
    elif [ -r /usr/lib/setup/setup ]; then
      T_PX=/mnt
    else
      # We will have to assume we've on an installed and running system.
      T_PX=/
    fi
  fi
fi

# If there's no boot_message.txt, start the header for one now:
if [ ! -r $T_PX/boot/boot_message.txt ]; then
 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
fi

# The default install location may be set here:
#DEFAULT=" --default-item MBR "

# This is a different 'probe' than the function below.
PROBE() {
  if [ -x /sbin/probe ]; then
    /sbin/probe -l
  elif fdisk -l | grep "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 2> /dev/null
    done
  elif fdisk -l | grep "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 2> /dev/null
    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 2> /dev/null
    done
  else # We got output without /dev/ide or /dev/scsi, so it can probably be trusted:
    fdisk -l 2> /dev/null
  fi
}

# Pointless for Sparc
# Function to ask if the Slackware logo boot screen should be used.
ask_boot_splash() {
  dialog --title "OPTIONAL SLACKWARE LOGO BOOT SCREEN" \
  --yesno \
"Would you like to use a boot screen with the Slackware logo \
against a black background?  If you answer no here, the standard \
LILO menu will be used.\n\
" 7 65 2> $TMP/reply
  RETVAL=$?
  return $RETVAL
}

# Pointless for Sparc
boot_bmp() {
  cat << EO_BMP
# Boot BMP Image.
# Bitmap in BMP format: 640x480x8
  bitmap = /boot/slack.bmp
# Menu colors (foreground, background, shadow, highlighted
# foreground, highlighted background, highlighted shadow):
  bmp-colors = 255,0,255,0,255,0
# Location of the option table: location x, location y, number of
# columns, lines per column (max 15), "spill" (this is how many
# entries must be in the first column before the next begins to
# be used.  We don't specify it here, as there's just one column.
  bmp-table = 60,6,1,16
# Timer location x, timer location y, foreground color,
# background color, shadow color.
  bmp-timer = 65,27,0,255
EO_BMP
}

# Not used for Sparc
# Menu to check if we want to use VESA framebuffer support:
use_framebuffer() {
if cat /proc/devices | grep "29 fb" 1> /dev/null ; then
  dialog --title "CONFIGURE LILO TO USE FRAME BUFFER CONSOLE?" \
  --default-item 1024x768x256 \
  --menu "Looking at /proc/devices, it seems your kernel has support for \
the Linux frame buffer console.  If we enable this in /etc/lilo.conf, it \
will allow more rows and columns of text on the screen and give you a cool \
penguin logo at boot time.  However, the frame buffer text console is \
slower than a standard text console.  In addition, not every video card \
or monitor supports all of these video modes.  Would you like to use the \
frame buffer console, or the standard Linux console?" 0 0 0 \
  "standard" "Use the standard Linux console (the safe choice)" \
  "640x480x256" "Frame buffer console, 640x480x256" \
  "800x600x256" "Frame buffer console, 800x600x256" \
  "1024x768x256" "Frame buffer console, 1024x768x256" \
  "640x480x32k" "Frame buffer console, 640x480x32k" \
  "800x600x32k" "Frame buffer console, 800x600x32k" \
  "1024x768x32k" "Frame buffer console, 1024x768x32k" \
  "640x480x64k" "Frame buffer console, 640x480x64k" \
  "800x600x64k" "Frame buffer console, 800x600x64k" \
  "1024x768x64k" "Frame buffer console, 1024x768x64k" \
  2> $TMP/reply
  if [ $? = 1 -o $? = 255 ]; then
    exit
  fi
# Frame buffer modes above 1024x768 look terrible except
# on LCD panels, and 32 bit color is slow.  Since we don't
# even need to run a framebuffer console to run framebuffer
# X anymore, these modes aren't of much real use.
#  "1280x1024x256" "Frame buffer console, 1280x1024x256" \
#  "1600x1200x256" "Frame buffer console, 1600x1200x256" \
#  "1280x1024x32k" "Frame buffer console, 1280x1024x32k" \
#  "1600x1200x32k" "Frame buffer console, 1600x1200x32k" \
#  "1280x1024x64k" "Frame buffer console, 1280x1024x64k" \
#  "1600x1200x64k" "Frame buffer console, 1600x1200x64k" \
#  "640x480x16m" "Frame buffer console, 640x480x16.8m" \
#  "800x600x16m" "Frame buffer console, 800x600x16.8m" \
#  "1024x768x16m" "Frame buffer console, 1024x768x16.8m" \
#  "1280x1024x16m" "Frame buffer console, 1280x1024x16.8m" \
#  "1600x1200x16m" "Frame buffer console, 1600x1200x16.8m"
  CONSOLETYPE="`cat $TMP/reply`"
  if [ "$CONSOLETYPE" = "1600x1200x16m" ]; then
    CONSOLENUM=799
  elif [ "$CONSOLETYPE" = "1600x1200x64k" ]; then
    CONSOLENUM=798
  elif [ "$CONSOLETYPE" = "1600x1200x32k" ]; then
    CONSOLENUM=797
  elif [ "$CONSOLETYPE" = "1600x1200x256" ]; then
    CONSOLENUM=796
  elif [ "$CONSOLETYPE" = "1280x1024x16m" ]; then
    CONSOLENUM=795
  elif [ "$CONSOLETYPE" = "1280x1024x64k" ]; then
    CONSOLENUM=794
  elif [ "$CONSOLETYPE" = "1280x1024x32k" ]; then
    CONSOLENUM=793
  elif [ "$CONSOLETYPE" = "1280x1024x256" ]; then
    CONSOLENUM=775
  elif [ "$CONSOLETYPE" = "1024x768x16m" ]; then
    CONSOLENUM=792
  elif [ "$CONSOLETYPE" = "1024x768x64k" ]; then
    CONSOLENUM=791
  elif [ "$CONSOLETYPE" = "1024x768x32k" ]; then
    CONSOLENUM=790
  elif [ "$CONSOLETYPE" = "1024x768x256" ]; then
    CONSOLENUM=773
  elif [ "$CONSOLETYPE" = "800x600x16m" ]; then
    CONSOLENUM=789
  elif [ "$CONSOLETYPE" = "800x600x64k" ]; then
    CONSOLENUM=788
  elif [ "$CONSOLETYPE" = "800x600x32k" ]; then
    CONSOLENUM=787
  elif [ "$CONSOLETYPE" = "800x600x256" ]; then
    CONSOLENUM=771
  elif [ "$CONSOLETYPE" = "640x480x16m" ]; then
    CONSOLENUM=786
  elif [ "$CONSOLETYPE" = "640x480x64k" ]; then
    CONSOLENUM=785
  elif [ "$CONSOLETYPE" = "640x480x32k" ]; then
    CONSOLENUM=784
  elif [ "$CONSOLETYPE" = "640x480x256" ]; then
    CONSOLENUM=769
  fi
fi
}

# A function to ask for append= parameters. 
ask_append() {
 dialog --title "OPTIONAL SILO append=\"<kernel perameters>\" LINE" --inputbox \
"Some systems might require extra parameters to be passed to the kernel. \
If you needed to pass parameters to the kernel when you booted the Splack \
bootdisk, 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.\n\
" 12 72 2> $TMP/reply
 RETVAL=$?
 return $RETVAL
}

ask_utf() {
 if [ "$(uname -r | cut -f 3 -d .)" -gt "23" ]; then
 dialog --defaultno --title "USE UTF-8 TEXT CONSOLE?" --yesno \
"Beginning with the 2.6.24 kernel, the text consoles default to UTF-8 mode.  \
Unless you are using a UTF-8 locale (\$LANG setting), using the old default \
of a non-UTF text console is safer until some issues with various console \
programs are addressed.  This option has no effect on the use of UTF-8 with X.  \
\"No\" is the safe choice here." 10 70
 fi
}

# 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 in either the superblock, or the MBR.
simplesilo()
{
# use_framebuffer;

 ask_append;
 if [ $? = 1 -o $? = 255 ]; then
  APPEND=""
 fi
 APPEND="`cat $TMP/reply`"

 ask_utf;
 if [ $? = 1 -o $? = 255 ]; then
  UTFVT="vt.default_utf8=0"
 else
  UTFVT="vt.default_utf8=1"
 fi

# Maybe later we can fix this to present a dialog asking 
# an install target later. By default, SILO installs to 
# the bootblock, cyl0 of 1st disk.

 cat << EOF > $T_PX/etc/silo.conf
# SILO configuration file
# generated by 'siloconfig'
#
# Start SILO global section
EOF
 if [ ! "$APPEND" = "" -o ! "$UTFVT" = "" ]; then
  echo "# Append any additional kernel parameters:" >> $T_PX/etc/silo.conf
  echo "append=\"$APPEND $UTFVT\"" >> $T_PX/etc/silo.conf
 fi
 cat << EOF >> $T_PX/etc/silo.conf

# Standard menu.
# Or, you can comment out the bitmap menu above and 
# use a boot message with the standard menu:
message = /boot/boot_message.txt

# Timeout before the first entry boots.
# This is given in tenths of a second, so 600 for every minute:
timeout = 1200

EOF

# vga seletion was here

 cat << EOF >> $T_PX/etc/silo.conf
# 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 | grep "Linux"`" 
 LNXP="`echo $LNXP | cut -f 1 -d ' ' | sort`"
 if [ ! "$LNXP" = "" ]; then
  cat << EOF >> $T_PX/etc/silo.conf
# Linux bootable partition config begins
image = $KERNEL
  root = $LNXP
  label = Linux
  read-only
# Linux bootable partition config ends
EOF
  echo "Linux    -  (Linux 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()
{
 dialog --infobox "\nInstalling the SPARC Improved Loader..." 5 40
 if [ "$T_PX" = "/" ]; then
  silo 1> /dev/null 2> /etc/silo-error.$$
  SUCCESS=$?
 else
  silo -f -r $T_PX -C /etc/silo.conf 1> /dev/null 2> /etc/silo-error.$$
  SUCCESS=$?
 fi

 sleep 1
 if [ ! "$SUCCESS" = "0" ]; then # some SILO error occured
  echo >> /etc/silo-error.$$
cat << EOF >> /etc/silo-error.$$
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.  \
The error message may be seen above.
EOF
  dialog --msgbox "$(cat /etc/silo-error.$$)" 0 0
 fi
}

installtext()
{
 echo "Installing the SPARC Improved Loader..."
 if [ "$T_PX" = "/" ]; then
  silo
  SUCCESS=$?
 else
  silo -f -r $T_PX -C /etc/silo.conf
  SUCCESS=$?
 fi

 sleep 1
 if [ ! "$SUCCESS" = "0" ]; then # some SILO error occured
  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
}

# 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 LILO 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 -f 1 -d " " | sed -n "1 p"`"
 fi
fi
# Figure out where the kernel is:
ARCHTYPE=i386
if [ -r $T_PX/vmlinux ]; then
  KERNEL=/vmlinux
elif [ -r $T_PX/boot/vmlinux ]; then
  KERNEL=/boot/vmlinux
#elif [ -r $T_PX/usr/src/linux/arch/$ARCHTYPE/boot/bzImage ]; then
#  KERNEL=/usr/src/linux/arch/$ARCHTYPE/boot/bzImage
#elif [ -r $T_PX/usr/src/linux/arch/$ARCHTYPE/boot/zImage ]; then
#  KERNEL=/usr/src/linux/arch/$ARCHTYPE/boot/zImage
else
  exit 99 # no kernel?  guess you couldn't read.  bye bye.
fi

 # 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 67 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" \
"Solaris" "Add a Solaris partition to the SILO config" \
"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" = "Begin" ]; then
   ask_append;
   if [ $? = 1 -o $? = 255 ]; then
    APPEND=""
    HDR="no"
    continue;
   else
    APPEND="`cat $TMP/reply`"
   fi
   ask_utf;
   if [ $? = 1 -o $? = 255 ]; then
    UTFVT="vt.default_utf8=0"
   else
    UTFVT="vt.default_utf8=1"
   fi
#   use_framebuffer;

# lilo target location setup was here

   dialog --title "CHOOSE SILO TIMEOUT" --menu "At boot time, how long would \
you like SILO to wait for you to hit left-shift to get a prompt?  If you \
let SILO time out, it will boot the first OS in the configuration file by \
default." 13 74 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
    TIMEOUT="`cat $TMP/reply`"
   fi
   rm -r $TMP/reply
   if [ "$TIMEOUT" = "None" ]; then 
    TIMEOUT="#timeout = 5"
   elif [ "$TIMEOUT" = "5" ]; then
    TIMEOUT="timeout = 50"
   elif [ "$TIMEOUT" = "30" ]; then
    TIMEOUT="timeout = 300" 
   elif [ "$TIMEOUT" = "Forever" ]; then
    TIMEOUT="#timeout = 300"
   else
    HDR="no"
    continue;
   fi
   cat << EOF > $TMP/silo.conf
# SILO configuration file
# generated by 'siloconfig'
#
# Start SILO global section
EOF

    cat << EOF >> $TMP/silo.conf
# Standard menu.
message = /boot/boot_message.txt

EOF

   if [ ! "$APPEND" = "" -o ! "$UTFVT" = "" ]; then
     echo "# Append any additional kernel parameters:" >> $TMP/silo.conf
     echo "append=\"$APPEND $UTFVT\"" >> $TMP/silo.conf
   fi
   cat << EOF >> $TMP/silo.conf
$TIMEOUT
EOF

   cat << EOF >> $TMP/silo.conf
# ramdisk = 0     # paranoia setting
# End SILO global section
EOF
    HDR="yes"
  elif [ "$REPLY" = "Linux" ]; then
   if [ "$HDR" = "yes" ]; then
    echo "These are your Linux partitions:" > $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "   Device Boot      Start         End      Blocks   Id  System" >> $TMP/tmpmsg
    PROBE -l | grep "Linux" | sort >> $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "Which one would you like SILO to boot?" >> $TMP/tmpmsg
    dialog --title "SELECT LINUX PARTITION" --no-collapse --inputbox \
"`cat $TMP/tmpmsg`" 21 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 60 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
  root = $LINUX_PART
  label = $LABEL
  read-only  # Partitions should be mounted read-only for checking
# 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
   if [ "$HDR" = "yes" ]; then
    echo "These are your Solaris root partitions. They will be treated" > $TMP/tmpmsg
    echo "as such if you install them using this menu." >> $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "   Device Boot      Start         End      Blocks   Id  System" >> $TMP/tmpmsg
    PROBE -l | grep "SunOS" | grep root | sort >> $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "Which one would you like SILO to boot?" >> $TMP/tmpmsg
    dialog --title "SELECT SOLARIS PARTITION" --no-collapse --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 60 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
   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" = "Skip" ]; then
   rm -f $TMP/tmpmsg $TMP/reply
   break
  elif [ "$REPLY" = "View" ]; then
   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
   dialog --title "SILO INSTALLATION HELP" --textbox "$T_PX/var/log/setup/text.silohelp" 22 68
  fi
 done

