#!/bin/sh
#
# Copyright 1994, 1998 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.
#
#TMP=/var/log/setup/tmp
TMP=/tmp
# Set color menu mode by default:
COLOR=on
# This is a different 'probe' than the function below.
if [ -x /sbin/probe ]; then
 PROBE=/sbin/probe
else
 PROBE=/sbin/fdisk
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
# LILO in either the superblock, or the MBR.
simplelilo()
{
 if $PROBE -l | grep 'OS/2 Boot Manager' 1> /dev/null 2> /dev/null ; then
  dialog --title "OS/2 BOOT MANAGER FOUND" --yesno \
"ΥƥˤOS/2Partition MagicʤɤΥ֡ȥޥ͡㤬 \
󥹥ȡ뤵Ƥ褦ǤߤʤСץʥ֡ \
ޥ͡ǤLILOεư֥åLinuxѡƥƬ \
󥹥ȡǤޤξ硢Linuxѡƥ֡ȥޥ͡ \
Υ˥塼ϿС֡ȥޥ͡㤫Linuxư \
ȤǤޤLILO֡ȥޥ͡ȶ¸ޤ" 11 72
  FLAG=$?
  if [ ! $FLAG = 0 -a ! $FLAG = 1 ]; then
   exit 1
  fi
  if [ $FLAG = 0 ]; then # yes, use BM
   if [ -r $T_PX/etc/lilo.conf ]; then
    mv $T_PX/etc/lilo.conf $T_PX/etc/lilo.conf.orig
   fi
   cat << EOF > $T_PX/etc/lilo.conf
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
boot = $ROOT_DEVICE
#delay = 5
vga = normal
lba32
prompt
# add some funcy staff :-)
map = /boot/map-bmp
install = /boot/boot-bmp.b
bitmap = /boot/ins64a.bmp
bmp-colors = 14,11,,15,9,0
bmp-table = 21,287p,2,4,175p
bmp-timer = 73,29,12,8,0
# End LILO global section
# Linux root partition section
image = /vmlinuz
 root = $ROOT_DEVICE
 label = Linux
 read-only
# End root Linux partition section
EOF
   dialog --infobox "\nLinux Loader 򥤥󥹥ȡ..." 5 40
   if [ "$T_PX" = "/" ]; then
    lilo 1> /dev/null 2> /dev/null
   else
    lilo -r $T_PX -m /boot/map -C /etc/lilo.conf 1> /dev/null 2> /dev/null
   fi
   return
  fi # Use Boot Manager
 fi # Boot Manager detected
 # If we got here, we either don't have boot manager or don't want to use it
 dialog --title "LILOΥ󥹥ȡ" --menu \
"LILOϤĤξ˥󥹥ȡ뤹뤳ȤǤޤ:\n\
\n\
 1. ǽΥϡɥǥ(/dev/hda/dev/sda)MBR \n\
 2. Linux ΥѡƥƬ(DOSLinuxfdiskǤΥѡƥ \n\
   ưǽˤ뤫OS/2Υ֡ȥޥ͡ȤäƵưƤ) \n\
 3.եޥåȺѤΥեåԡǥ \n\
\n\
2  3 ٤аǤ2 ξϸǾȤɬפˤʤޤ \n\
(fdiskȤäƤΥѡƥưǽˤ)ɤӤޤ \n" \
20 74 3 \
"MBR" "Master Boot Recordإ󥹥ȡ" \
"Root" "LinuxѡƥƬ(fdiskǵưǽˤ뤳)" \
"Floppy" "/dev/fd0(A:)إ󥹥ȡ" 2> $TMP/reply
 if [ $? = 1 -o $? = 255 ]; then
  exit
 fi
 TG="`cat $TMP/reply`"
 rm -r $TMP/reply
 if [ "$TG" = "MBR" ]; then
  if [ -L $T_PX/dev/hda ]; then
   LILO_TARGET="/dev/sda"
  elif probe /dev/hda; then
   LILO_TARGET="/dev/hda"
  elif probe /dev/sda; then
   LILO_TARGET="/dev/sda"
  else
   dialog --title "MBR μư" --inputbox \
"LILO MBR 򥤥󥹥ȡ뤹 HDD 򸫤ĤޤǤ \
櫓ޤMBRHDDưǻꤷƤ" 10 72 2> $TMP/MBRreply
   if [ $? = 1 -o $? = 255 ]; then
    LILO_TARGET="/dev/null"
    continue;
   else
    LILO_TARGET="`cat $TMP/MBRreply`"
   fi
  fi
 elif [ "$TG" = "Root" ]; then
  LILO_TARGET=`echo $ROOT_DEVICE`
 elif [ "$TG" = "Floppy" ]; then
  LILO_TARGET="/dev/fd0"
 fi
 cat << EOF > $T_PX/boot/boot_message.txt

Welcome to the LILO 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/lilo.conf
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
boot = $LILO_TARGET
# message = /boot/boot_message.txt
prompt
timeout = 1200
vga = normal
lba32
# add some funcy staff :-)
map = /boot/map-bmp
install = /boot/boot-bmp.b
bitmap = /boot/ins64a.bmp
bmp-colors = 14,11,,15,9,0
bmp-table = 21,287p,2,4,175p
bmp-timer = 73,29,12,8,0
# End LILO global section
EOF
 # OK, now let's look for DOS partitions:
 DOSP="`$PROBE -l | grep "DOS
Win95"`"
 DOSP="`echo $DOSP | cut -f 1 -d ' '`"
 if [ ! "$DOSP" = "" ]; then
  TABLE="`echo $DOSP | cut -b1-8`"
  cat << EOF >> $T_PX/etc/lilo.conf
# DOS bootable partition config begins
other = $DOSP
  label = DOS
# DOS bootable partition config ends
EOF
  echo "DOS     - DOS or Windows (FAT/FAT32 partition)" >> $T_PX/boot/boot_message.txt
 fi
 # Next, we search for Linux partitions:
 LNXP="`$PROBE -l | grep "83  Linux"`" 
 LNXP="`echo $LNXP | cut -f 1 -d ' '`"
 if [ ! "$LNXP" = "" ]; then
  cat << EOF >> $T_PX/etc/lilo.conf
# Linux bootable partition config begins
image = /vmlinuz
  root = $ROOT_DEVICE
  label = Linux
  read-only
# Linux bootable partition config ends
EOF
  echo "Linux   - Linux (ext2fs partition)" >> $T_PX/boot/boot_message.txt
 fi
 # OK, hopefully we can remember how to deal with OS/2 :^)
 OS2P="`$PROBE -l | grep "NTFS"`"
 OS2P="`echo $OS2P | cut -f 1 -d ' '`"
 if [ ! "$OS2P" = "" ]; then
  TABLE="`echo $OS2P | cut -b1-8`"
  if [ "$TABLE" = "/dev/hda" ]; then
   cat << EOF >> $T_PX/etc/lilo.conf
# Win NT bootable partition config begins
other = $OS2P
  label = winnt
# OS/2 bootable partition config ends
EOF
  else
    cat << EOF >> $T_PX/etc/lilo.conf
# OS/2 bootable partition config begins
other = $OS2P
  label = OS2
  table = $TABLE
  loader = /boot/os2_d.b
  map-drive = 0x80
   to = 0x81
  map-drive = 0x81
   to = 0x80
# OS/2 bootable partition config ends
EOF
   echo "OS2     - OS/2 Warp (HPFS partition)" >> $T_PX/boot/boot_message.txt
  fi
 fi
 echo >> $T_PX/boot/boot_message.txt
 # Done, now we must install lilo:
 dialog --infobox "\nLILO򥤥󥹥ȡ..." 5 40
 if [ "$T_PX" = "/" ]; then
  lilo 1> /dev/null 2> /dev/null
  SUCCESS=$?
 else
  lilo -r $T_PX -m /boot/map -C /etc/lilo.conf 1> /dev/null 2> /dev/null
  SUCCESS=$?
 fi
 if [ ! "$SUCCESS" = "0" ]; then # some LILO error occured
  dialog --title "LILO󥹡륨顼 # $SUCCESS" --msgbox \
"ǰʤ顢LILO򥤥󥹥ȡ뤹ݤ˥顼ȯᡢLILO \
󥹥ȡ뤵ޤǤHDDľܵưǤʤΤǡFD˽ \
ФưǥȤäƥޥưƤ10Gۤ \
ѡƥ˥󥹥ȡ뤷褦ȤƤʤСFDǺƵư \
/etc/lilo.conf  lba32 ץɲä /sbi/lilo Ƽ¹ \
ФޤԤΤޤ󡣾ܺ٤ˤĤƤLILOΥޥ˥奢 \
/usr/doc/lilo/ˤɥ \
򻲾ȤƤ" 11 74
 fi
}

checkp_text()
{
 if [ ! -r $1 ]; then
  echo
  echo "'$1'ȤǥХϸĤޤ"
  echo
  echo -n "ΥǥХ̾Ǥ [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 "ǥХĤޤǤ" --yesno "'$1'ȤǥХ \
̾ϸĤޤǤΥǥХ̾Ǥ" 7 70
  return $?;
 fi
}

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

# liloconfig-color?
if [ "`basename $0`" = "liloconfig-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/lilo.conf has not yet
         # been configured
LNX="no" # this means no Linux partition has been defined as bootable
         # through LILO. 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 -b-10 | sed -n "1 p"`"
 fi
fi
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 "LILOΥ󥹥ȡ" --menu \
"LILO(Linux Loader)ϤĤOSưǤ֡ȥǤ \
ǤϡLILOLinux(ĤDOSWindowsOS/2)ư \
褦˴ñԤޤܤ͸ˤϥѡ \
ΥץꤹС٤ĴǽǤLILO \
äƥ󥹥ȡ뤹Хѡƥ˲Ƥޤǽ \
⤢ޤΤǡ軰()򡢤ʤֺLILO򥤥 \
ȡ뤷ʤפȤǽǤξ硢'liloconfig' \
ޥɤ¹Ԥƺꤹ뤳ȤǤޤɤޤ礦 " \
 20 72 3 \
 "simple" "LILOư󥹥ȡ" \
 "expert" "иԸ˥塼" \
 "skip" "LILO򥤥󥹥ȡ뤷ʤ" 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 LILO setup
  simplelilo
  exit
 fi
 # drop through to last option: (use the expert menus)
 while [ 0 ]; do
  dialog --title "LILO󥹥ȡηиԸ˥塼" --menu \
"Υ˥塼ǤLILOեǤlilo.confľܺޤ \
LILO򥤥󥹥ȡ뤹硢ޤǽˡưǽʥѡƥ \
Ͽ뤿ΥإåեɬפޤLILO򥤥󥹥ȡ \
뤹ݤϡޤ'Begin'ǡإåեƤ \
/etc/lilo.conf¸ߤ硢Ȥäƺƥ󥹥ȡ뤹뤳 \
ǽǤְ㤨ϡ'BEGIN'٤Сǽ餫ľ \
ȤǽǤ" 24 76 9 \
"Begin" "LILOΥإåäγ" \
"Linux" "LILOեLinuxѥѡƥɲ" \
"OS/2" "OS/2Υѡƥɲ" \
"DOS" "DOSΥѡƥɲ" \
"Install" "LILOΥ󥹥ȡ" \
"Recycle" "¸lilo.confȤäLILOκƥ󥹥ȡ" \
"Skip" "LILOΥ󥹥ȡߤƥ˥塼λ" \
"View" "ߤ/etc/lilo.confɽ" \
"Help" "Linux LoaderHELPեɽ" 2> $TMP/reply
  if [ $? = 1 -o $? = 255 ]; then
   REPLY="Skip"
  else
   REPLY="`cat $TMP/reply`"
  fi
  rm -r $TMP/reply
  if [ "$REPLY" = "Begin" ]; then
   dialog --title "append= Ԥɲ(̵Ƥ⹽ޤ)" --inputbox  \
"64MʾΥѤǤʤɡư̤Υͥѥ \
᡼錄ɬפ륷ƥबޤĤSCSIǥХ \
IBMΤĤΥޥܡɤξ硢hd=cyl,hds.secsץ \
ɬפΤޤ󡣥󥹥ȡFD鵯ưݤ˥ѥ᡼ \
ɬפä硢ǤƱѥ᡼ꤹФǤ礦 \
ۤȤɤΥƥǤϥͥѥ᡼̵Ƥ⤫ޤޤ \
פʾENTER򲡤ƿʤǤ" 14 72 2> $TMP/reply
   if [ $? = 1 -o $? = 255 ]; then
    HDR="no"
    continue;
   else
    APPEND="`cat $TMP/reply`"
   fi
   dialog --title "LILOΥ󥹥ȡ" --menu \
"LILOϺǽHDDMBRLinuxѡƥƬʬ(Υѡƥ \
fdiskǵưǽˤƤɬפޤ)뤤ϥե \
ޥåȺѤFDʤɡޤޤʾ˥󥹥ȡǤޤOS/2Υ֡ \
ȥޥ͡ȤäƤʤɤRootLinuxѡƥ \
ƬLILO򥤥󥹥ȡ뤷֡ȥޥ͡㤫餽Υѡƥ \
ư褦ˤƤLILOΥ󥹥ȡϤɤˤޤ" 17 74 3 \
"MBR" "ǽHDDƬʬ(Master Boot Record)" \
"Root" "LinuxѡƥƬ(ѡ֥å)" \
"Floppy" "եޥåȺѤΥեåԡǥ" 2> $TMP/reply
   if [ $? = 1 -o $? = 255 ]; then
    HDR="no"
    continue;
   else
    LNX="no"
    TG="`cat $TMP/reply`"
   fi
   rm -r $TMP/reply
   if [ "$TG" = "MBR" ]; then
    if [ -L $T_PX/dev/hda ]; then
     LILO_TARGET="/dev/sda"
    elif probe /dev/hda; then
     LILO_TARGET="/dev/hda"
    elif probe /dev/sda; then
     LILO_TARGET="/dev/sda"
    else
     dialog --msgbox "ǽHDD򸫤ĤޤǤ櫓ޤ \
LILOΥǡϽ񤭤ޤ..." 10 72
     LILO_TARGET="/dev/null"
    fi
   elif [ "$TG" = "Root" ]; then
    LILO_TARGET=`echo $ROOT_DEVICE` # Here, we use the partition superblock for OS/2 Boot Manager
   elif [ "$TG" = "Floppy" ]; then
    LILO_TARGET="/dev/fd0"    
   else
    HDR="no"
    continue;
   fi
   dialog --title "LILOԤ֤λ" --menu \
"ư˺SHIFT򲡤ХץץȤФޤޤǲäδԤ \
֤ߤޤꤷ֤᤮СLILOϼưŪ˺ǽOS \
ưޤ" 13 72 4 \
"None" "Ԥ֤򤪤˺ǽOSư" \
"5" "5ôԵ" \
"30" "30ôԵ" \
"Forever" "ưŪOSưԤĤŤ" 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="# delay = 5"
   elif [ "$DELAY" = "5" ]; then
    DELAY="delay = 50"
   elif [ "$DELAY" = "30" ]; then
    DELAY="delay = 300" 
   elif [ "$DELAY" = "Forever" ]; then
    DELAY="prompt"
   else
    HDR="no"
    continue;
   fi
   if [ "$APPEND" = "" ]; then
    cat << EOF > $TMP/lilo.conf
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
boot = $LILO_TARGET
#compact        # faster, but won't work on all systems.
$DELAY
vga = normal    # force sane state
lba32
# ramdisk = 0     # paranoia setting
# add some funcy staff :-)
map = /boot/map-bmp
install = /boot/boot-bmp.b
bitmap = /boot/ins64a.bmp
bmp-colors = 14,11,,15,9,0
bmp-table = 21,287p,2,4,175p
bmp-timer = 73,29,12,8,0
# End LILO global section
EOF
    HDR="yes"
   else
    cat << EOF > $TMP/lilo.conf
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
append="$APPEND"
boot = $LILO_TARGET
#compact        # faster, but won't work on all systems.
$DELAY
vga = normal    # force sane state
lba32
# ramdisk = 0     # paranoia setting
# End LILO global section
EOF
    HDR="yes"
   fi
  elif [ "$REPLY" = "Linux" ]; then
   if [ "$HDR" = "yes" ]; then
    echo "Τ褦LinuxѤΥѡƥ󤬸Ĥޤ:" > $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "   Device Boot  Begin   Start    End  Blocks   Id  System" >> $TMP/tmpmsg
    $PROBE -l | grep Linux | grep 83 >> $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "ɤΥѡƥLILO鵯ưޤ" >> $TMP/tmpmsg
    dialog --title "LINUXѡƥ" --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 "ѡƥ̾" --inputbox \
"Υѡƥû̾դɬפޤLILOΥץ \
ץȤФƤݤˡ̾ȤäƵưѡƥ \
ޤñ'Linux'ȤƤΤ뤯ޤ \
̾ϰĤñդƤ" 11 70 2> $TMP/reply
    if [ $? = 1 -o $? = 255 ]; then
     continue
    fi
    LABEL="`cat $TMP/reply`"
    cat << EOF >> $TMP/lilo.conf
# Linux bootable partition config begins
image = /vmlinuz
  root = $LINUX_PART
  label = $LABEL
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking
# Linux bootable partition config ends
EOF
   else
    dialog --title "LinuxѡƥɲäǤޤ" --msgbox  \
"LILOΥإåʤȥѡƥɲäǤޤ" 6 70
    continue
   fi
   LNX="yes"
  elif [ "$REPLY" = "OS/2" ]; then
   if [ "$HDR" = "yes" ]; then
    echo "ʲΤ褦 OS/2 ѡƥ󤬤ޤΥ˥塼顢" > $TMP/tmpmsg
    echo "ѡƥưǽˤǤޤ" >> $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "   Device Boot  Begin   Start    End  Blocks   Id  System" >> $TMP/tmpmsg
    $PROBE -l | grep HPFS >> $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "ɤΥѡƥLILO鵯ưޤ" >> $TMP/tmpmsg
    dialog --title "OS/2 ѡƥ" --inputbox \
"`cat $TMP/tmpmsg`" 20 74 2> $TMP/reply
    if [ $? = 1 -o $? = 255 ]; then
     rm $TMP/tmpmsg
     continue
    fi
    rm $TMP/tmpmsg
    OS_2_PART="`cat $TMP/reply`"
    checkp_dialog $OS_2_PART
    if [ ! $? = 0 ]; then
     continue;
    fi
    dialog --title "ѡƥ̾λ" --inputbox \
"Υѡƥû̾դɬפޤLILOΥץ \
ץȤФƤݤˡ̾ȤäƵưѡƥ \
ޤñ'OS/2'ȤƤΤ뤯ޤ \
̾ϰĤñΤߤǤ" 12 70 2> $TMP/reply
    if [ $? = 1 -o $? = 255 ]; then
     continue
    fi
    LABEL="`cat $TMP/reply`"
    TABLE="`echo $OS_2_PART | cut -b1-8`"
    if [ "`echo $TABLE | cut -b6-8`" = "hda" ]; then
     cat << EOF >> $TMP/lilo.conf
# OS/2 bootable partition config begins
other = $OS_2_PART
  label = $LABEL
  table = $TABLE
# OS/2 bootable partition config ends
EOF
    else
     cat << EOF >> $TMP/lilo.conf
# OS/2 bootable partition config begins
other = $OS_2_PART
  label = $LABEL
  table = $TABLE
  loader = /boot/os2_d.b
  map-drive = 0x80
   to = 0x81
  map-drive = 0x81
   to = 0x80
# OS/2 bootable partition config ends
EOF
    fi
   else
    dialog --title "OS/2ѡƥɲäǤޤ" --msgbox "LILOΥإå \
ʤOS/2ѡƥɲäǤޤ" 6 60
    continue
   fi
   LNX="yes"
  elif [ "$REPLY" = "DOS" ]; then
   if [ "$HDR" = "yes" ]; then
    echo "ʲΤ褦DOS/Win(餷)ѡƥ󤬤ޤΥ˥塼顢 " > $TMP/tmpmsg
    echo "ΥѡƥưǽˤǤޤ" >> $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "   Device Boot  Begin   Start    End  Blocks   Id  System" >> $TMP/tmpmsg
    $PROBE -l | grep DOS >> $TMP/tmpmsg
    $PROBE -l | grep Win >> $TMP/tmpmsg
    echo >> $TMP/tmpmsg
    echo "Which one would you like LILO to boot?" >> $TMP/tmpmsg
    dialog --title "DOSѡƥ" --inputbox \
"`cat $TMP/tmpmsg`" 20 74 2> $TMP/reply
    if [ $? = 1 -o $? = 255 ]; then
     rm $TMP/tmpmsg
     continue
    fi
    rm $TMP/tmpmsg
    DOSPART="`cat $TMP/reply`"
    checkp_dialog $DOSPART
    if [ ! $? = 0 ]; then
     continue;
    fi
    dialog --title "ѡƥ̾λ" --inputbox \
"Υѡƥû̾դɬפޤLILOΥץ \
ץȤФƤ֤ˡ̾ȤäƵưѡƥ \
ޤñ'DOS'ȤƤΤ뤯ޤ \
̾ϰĤñΤߤǤ" 11 70 2> $TMP/reply
    if [ $? = 1 -o $? = 255 ]; then
     continue
    fi
    LABEL="`cat $TMP/reply`"
    unset USE_LOADER
    TABLE="`echo $DOSPART | cut -b1-8`"
    if [ "`echo $TABLE | cut -b6-8`" = "hda" ]; then
     USE_LOADER="no"
    fi
    if [ "`echo $TABLE | cut -b6-8`" = "sda" ]; then
     if probe /dev/hda; then
      USE_LOADER="yes"
     else
      USE_LOADER="no"
     fi
    fi
    if [ "$USE_LOADER" = "no" ]; then
     cat << EOF >> $TMP/lilo.conf
# DOS bootable partition config begins
other = $DOSPART
  label = $LABEL
  table = $TABLE
# DOS bootable partition config ends
EOF
    else
     cat << EOF >> $TMP/lilo.conf
# DOS bootable partition config begins
other = $DOSPART
  label = $LABEL
  map-drive = 0x80
   to = 0x81
  map-drive = 0x81
   to = 0x80
  table = $TABLE
# DOS bootable partition config ends
EOF
    fi
   else
    dialog --title "DOSѡƥɲäǤޤǤ" --msgbox "LILOΥإå \
եʤDOSѡƥɲäǤޤ" 6 60
    continue
   fi
   LNX="yes"
  elif [ "$REPLY" = "Install" -o "$REPLY" = "Recycle" ]; then
   if [ "$REPLY" = "Recycle" -a -r $T_PX/etc/lilo.conf ]; then
    LNX="yes"
   fi
   if [ "$LNX" = "no" ]; then
    dialog --title "LILO󥹥ȡμ" --msgbox \
"LILO򥤥󥹥ȡǤޤǤ⤷إåե \
äƤʤäꡢʤȤĤεưǽѡƥإå \
եϿƤʤϡLILO򥤥󥹥ȡ뤹ˤޤ \
򤷤ƤʤФޤ󡣤⤷¸ե \
Ȥäƥ󥹥ȡ뤷褦ȤƤʤ顢ե뤬Ĥ \
ʤΤǡƤߤƤ " 10 72
    continue
   else
    if [ "$REPLY" = "Install" ]; then
     if [ -r $TMP/lilo.conf ]; then
      if [ -r $T_PX/etc/lilo.conf ]; then
       mv $T_PX/etc/lilo.conf $T_PX/etc/lilo.conf.bak
      fi
      cp $TMP/lilo.conf $T_PX/etc/lilo.conf
      chmod 644 $T_PX/etc/lilo.conf
     fi
    fi    
    dialog --infobox "\nInstalling the Linux Loader..." 5 40
    if [ "$T_PX" = "/" ]; then
     lilo 1> /dev/null 2> /dev/null
    else
     lilo -r $T_PX -m /boot/map -C /etc/lilo.conf 1> /dev/null 2> /dev/null
    fi
   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/lilo.conf ]; then
    dialog --title "/etc/lilo.conf" --textbox "$TMP/lilo.conf" 22 70
   else
    if [ -r /mnt/etc/lilo.conf ]; then
     dialog --title "Ť/etc/lilo.conf" --textbox "/mnt/etc/lilo.conf" 22 70
    elif [ "$T_PX" = "/" -a -r /etc/lilo.conf ]; then
     dialog --title "Ť/etc/lilo.conf" --textbox "/etc/lilo.conf" 22 70
    else
     dialog --title "ե뤬Ĥޤ" --msgbox "櫓ޤ󤬡ɽǽ \
LILOե뤬Ĥޤ" 6 60
    fi
   fi
  elif [ "$REPLY" = "Help" ]; then
   dialog --title "LILO INSTALLATION HELP" --textbox "$T_PX/usr/log/setup/text.lilohelp" 22 68
  fi
 done
else # don't use color!
 while [ 0 ]; do
  cat << EOF

LILOΥ󥹥ȡ

LILO(Linux Loader)ϤĤOSưǤ֡ȥǤǤϡ
LILOLinux(ĤDOSWindowsOS/2)ư褦ˤñ
Ԥޤܤ͸ˤϥѡѤΥץꤹ
С٤ĴǽǤǰʤLILOäƥ󥹥ȡ뤹
ѡƥ˲ƤޤΤޤΤǡ軰()
ʤֺLILO򥤥󥹥ȡ뤷ʤפȤǽǤξ硢
'liloconfig'ޥɤ¹Ԥƺꤹ뤳ȤǽǤɤޤ


1 --  LILO ΥإåѰդϤ
2 -- LILO եLinuxΥѡƥɲ
3 -- LILO ե OS/2Υѡƥɲ
4 -- LILO ե DOS Υѡƥɲ
5 -- LILO 򥤥󥹥ȡ
6 -- ¸ lilo.conf Ȥä LILO 򥤥󥹥ȡ
7 -- LILO Υ󥹥ȡ򥹥åפƥ˥塼λ
8 -- ߤ /etc/lilo.conf ɽ
9 -- LILOΥإץե򸫤

EOF

echo -n "ɤޤ(1 - 9)? "
  read REPLY;
  echo
  if [ "$REPLY" = "1" ]; then
   cat << EOF
OPTIONAL append="" LINE

64MʾΥѤǤʤɡư̤Υͥѥ᡼
Ϥɬפ륷ƥबޤĤSCSIǥХIBMΤ
ĤΥޥܡɤξ硢hd=cyl,hds.secsץɬפΤޤ
󡣥󥹥ȡFD鵯ưݤ˥ѥ᡼ɬפä硢
Ʊѥ᡼ꤹФǤ礦

ۤȤɤΥƥǤϥͥѥ᡼̵Ƥ⤫ޤޤפʾ
ENTER򲡤ƿʤǤ

EOF
   echo -n "Enter extra parameters==> "
   read APPEND;
   echo
   cat << EOF
LILOΥ󥹥ȡ

LILOϤĤξ˥󥹥ȡ뤹뤳ȤǤޤ:

1. ǽΥϡɥǥ(/dev/hda/dev/sda)MBR
2. Linux ΥѡƥƬ(DOSLinuxfdiskǤΥѡƥ
   ưǽˤ뤫OS/2Υ֡ȥޥ͡ȤäƵưƤ)
3.եޥåȺѤΥեåԡǥ

2  3 ٤аǤ2 ξϸǾȤɬפˤʤޤ
(fdiskȤäƤΥѡƥưǽˤ)ɤӤޤ

EOF
   echo -n "Please pick a target location (1 - 3): "
   read TG;
   echo
   if [ "$TG" = "1" ]; then
    if [ -L $T_PX/dev/hda ]; then
     LILO_TARGET="/dev/sda"
    elif probe /dev/hda; then
     LILO_TARGET="/dev/hda"
    elif probe /dev/sda; then
     LILO_TARGET="/dev/sda"
    else
     cat << EOF
***** ERROR probing for first hard drive.

LILOǽΥϡɥǥ򸫤ĤޤǤǰǤ
LILOΥǡ񤭹ޤ

EOF
     LILO_TARGET="/dev/null"
    fi
   elif [ "$TG" = "2" ]; then
    LILO_TARGET=`echo $ROOT_DEVICE` # Here, we use the partition superblock for OS/2 Boot Manager
   elif [ "$TG" = "3" ]; then
    LILO_TARGET="/dev/fd0"    
   else
    HDR="no"
    continue;
   fi
   cat << EOF
LILOԤ֤λ

ư˺SHIFT򲡤ХץץȤФޤޤǲäδԤ
֤ߤޤꤷ֤᤮СLILOϼưŪ˺ǽOS
ưޤ

1 -- Ԥ֤򤪤˺ǽOSư
2 -- 5ôԵ
3 -- 30ôԵ
4 -- OSưưԤĤŤ

EOF
   echo -n "ɤޤ礦(1 - 4) "
   read DELAY;
   echo
   if [ "$DELAY" = "1" ]; then 
    DELAY="# delay = 5"
   elif [ "$DELAY" = "2" ]; then
    DELAY="delay = 50"
   elif [ "$DELAY" = "3" ]; then
    DELAY="delay = 300" 
   elif [ "$DELAY" = "4" ]; then
    DELAY="prompt"
   else
    HDR="no"
    continue;
   fi
   if [ "$APPEND" = "" ]; then
    cat << EOF > $TMP/lilo.conf
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
boot = $LILO_TARGET
#compact        # faster, but won't work on all systems.
$DELAY
vga = normal    # force sane state
lba32
# ramdisk = 0     # paranoia setting
# End LILO global section
EOF
    HDR="yes"
   else
    cat << EOF > $TMP/lilo.conf
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
append="$APPEND"
boot = $LILO_TARGET
#compact        # faster, but won't work on all systems.
$DELAY
vga = normal    # force sane state
lba32
# ramdisk = 0     # paranoia setting
# End LILO global section
EOF
    HDR="yes"
   fi
  elif [ "$REPLY" = "2" ]; then
   if [ "$HDR" = "yes" ]; then
    while [ 0 ]; do
     cat << EOF
SELECT LINUX PARTITION

ʲΤ褦 Linux ѡƥ󤬸Ĥޤ:

   Device Boot  Begin   Start    End  Blocks   Id  System
`fdisk -l | grep Linux | grep 83` 

EOF
     echo -n "ɤΥѡƥLILO鵯ưǽˤޤ "
     read LINUX_PART;
     checkp_text $LINUX_PART
     if [ $? = 0 ]; then
      break;
     fi
    done
    echo
    cat << EOF
ѡƥ̾

Υѡƥû̾դɬפޤLILOΥץץȤ
ФƤݤˡ̾ȤäƵưѡƥǤޤñ'Linux'
ȤƤΤ뤯ޤ̾ϰĤñǤ

EOF
    echo -n "Enter name: "
    read LABEL;
    cat << EOF >> $TMP/lilo.conf
# Linux bootable partition config begins
image = /vmlinuz
  root = $LINUX_PART
  label = $LABEL
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking
# Linux bootable partition config ends
EOF
   else
    cat << EOF
LINUXѤΥѡƥɲäǤޤ

 LILO ΥإåեʤСѡƥɲäǤ


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
OS/2 ѥѡƥ

¿ʬ OS/2 ΥѡƥǤΥ˥塼ǥ󥹥ȡ뤹
СOS/2 ΥѡƥȤƼ갷ȤǤޤ

   Device Boot  Begin   Start    End  Blocks   Id  System
`fdisk -l | grep DOS`
`fdisk -l | grep HPFS`

EOF
     echo -n "ɤΥѡƥLILO鵯ưޤ"
     read OS_2_PART; 
     checkp_text $OS_2_PART
     if [ $? = 0 ]; then
      break;
     fi
    done
    echo
    cat << EOF
ѡƥ̾

Υѡƥû̾դɬפޤLILOΥץץȤ
ФƤݤˡ̾ȤäƵưѡƥǤޤñ'OS
/2'ȤƤΤ뤯ޤ̾ñĤΤߤǤ

EOF
    echo -n "̾: "
    read LABEL;
    echo
    TABLE="`echo $OS_2_PART | cut -b1-8`"
    if [ "`echo $TABLE | cut -b6-8`" = "hda" ]; then
     cat << EOF >> $TMP/lilo.conf
# OS/2 bootable partition config begins
other = $OS_2_PART
  label = $LABEL
  table = $TABLE
# OS/2 bootable partition config ends
EOF
    else
     cat << EOF >> $TMP/lilo.conf
# OS/2 bootable partition config begins
other = $OS_2_PART
  label = $LABEL
  table = $TABLE
  loader = /boot/os2_d.b
  map-drive = 0x80
   to = 0x81
  map-drive = 0x81
   to = 0x80
# OS/2 bootable partition config ends
EOF
    fi
   else
    cat << EOF
OS/2 ѡƥɲäǤޤ

LILOΥإåʤ OS/2 ΥѡƥɲäǤޤ

EOF
    echo -n "Press ENTER to continue."
    read JUNK;
    echo
    continue
   fi
   LNX="yes"
  elif [ "$REPLY" = "4" ]; then
   if [ "$HDR" = "yes" ]; then
    while [ 0 ]; do
     cat << EOF
DOS ѡƥ

¿ʬ DOS ΥѡƥǤΥ˥塼饤󥹥ȡ뤹
 DOS ѡƥȤѤǤޤ

   Device Boot  Begin   Start    End  Blocks   Id  System"
`fdisk -l | grep DOS`

EOF
     echo -n "Which one would you like LILO to boot? "
     read DOSPART;
     checkp_text $DOSPART
     if [ $? = 0 ]; then
      break;
     fi
    done
    cat << EOF

ѡƥ̾Ͽ

Υѡƥû̾դɬפޤLILOΥץץȤ
ФƤݤˡ̾ȤäƵưѡƥǤޤñ'
OS/2'ȤƤΤ뤯ޤ̾ñĤǤ

EOF
    echo -n "̾: "
    read LABEL;
    echo
    TABLE="`echo $DOSPART | cut -b1-8`"
    unset USE_LOADER
    if [ "`echo $TABLE | cut -b6-8`" = "hda" ]; then
     USE_LOADER="no"
    fi
    if [ "`echo $TABLE | cut -b6-8`" = "sda" ]; then
     if probe /dev/hda; then
      USE_LOADER="yes"
     else
      USE_LOADER="no"
     fi
    fi
    if [ "$USE_LOADER" = "no" ]; then
     cat << EOF >> $TMP/lilo.conf
# DOS bootable partition config begins
other = $DOSPART
  label = $LABEL
  table = $TABLE
# DOS bootable partition config ends
EOF
    else
     cat << EOF >> $TMP/lilo.conf
# DOS bootable partition config begins
other = $DOSPART
  label = $LABEL
  map-drive = 0x80
   to = 0x81
  map-drive = 0x81
   to = 0x80
  table = $TABLE
# DOS bootable partition config ends
EOF
    fi
   else
    cat << EOF
DOS ѡƥɲäǤޤ

 LILO ΥإåեʤȥѡƥɲäǤޤ

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

LILO򥤥󥹥ȡǤޤǤ⤷إåեäƤ
äꡢʤȤĤεưǽѡƥإåեϿ
ƤʤϡLILO򥤥󥹥ȡ뤹ˤޤ򤷤Ƥ
ʤФޤ󡣤⤷¸եȤäƥ󥹥ȡ뤷褦
Ƥʤ顢ե뤬ĤʤΤǡƤߤƤ


EOF
    echo -n "Press ENTER to continue."
    read JUNK;
    echo
    continue
   else
    if [ "$REPLY" = "5" ]; then
     if [ -r $TMP/lilo.conf ]; then
      if [ -r $T_PX/etc/lilo.conf ]; then
       mv $T_PX/etc/lilo.conf $T_PX/etc/lilo.conf.bak
      fi
      cp $TMP/lilo.conf $T_PX/etc/lilo.conf
      chmod 644 $T_PX/etc/lilo.conf
     fi
    fi    
    echo
    echo "Installing the Linux Loader..." 
    if [ "$T_PX" = "/" ]; then
     lilo
    else
     lilo -r $T_PX -m /boot/map -C /etc/lilo.conf
    fi
   fi
   rm -f $TMP/tmpmsg $TMP/reply
   break
  elif [ "$REPLY" = "7" ]; then
   rm -f $TMP/tmpmsg $TMP/reply
   break
  elif [ "$REPLY" = "8" ]; then
   if [ -r $TMP/lilo.conf ]; then
    if [ -r /bin/more ]; then
     cat $TMP/lilo.conf | more
    else
     cat $TMP/lilo.conf
    fi
    echo -n "Press ENTER to continue..."
    read JUNK;
    echo
   else
    if [ -r /mnt/etc/lilo.conf ]; then
     if [ -r /bin/more ]; then
      cat /mnt/etc/lilo.conf | more
     else
      cat /mnt/etc/lilo.conf
     fi
     echo -n "Press ENTER to continue..."
     read JUNK;
     echo
    elif [ "$T_PX" = "/" -a -r /etc/lilo.conf ]; then
     if [ -r /bin/more ]; then
      cat /etc/lilo.conf | more
     else
      cat /etc/lilo.conf
     fi
     echo -n "Press ENTER to continue..."
     read JUNK;
     echo
    else
     cat << EOF

ե뤬Ĥޤ

櫓ޤ󤬡ɽǽ LILO եϸޤ


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