#!/bin/sh
# vliloconf
# This is a rewrite of liloconf, from Slackware 9.1 by Patrick V.
# Only the SIMPLE method was taken
# The following has been added:
# - add Xdialog
# - suggest MBR 
# - make boot-message.txt ONLY if not exist 
# - change menu-scheme to blue
# - add graphics mode if /boot/boot.bmp exist
# - Fix autodetect bootable DOS partition
# - Fix autodetect root device 
# - Autodetect other Linux partitions
# - Add menu to add partitions
# - Can include initrd
# - Always run from root directory !
# - Detects ide-scsi for APPEND parameters
# - Detect multiple vmlinuz
# - Can use /boot/lilo.label in other partition
# 
# By Eko M. Budi, 2005
# License: GNU GPL
#
# Several fixes and spell checking by uelsk8s and Joe1962 for SOHO 5.1
#
#


vdir=$(dirname $0)
. $vdir/vasm-functions

check_root

TMP=/var/log/setup/tmp
mkdir -p $TMP

# VARIABLES
TP_X=${1:-/}
if [ "$TP_X" = "/" ]; then
    ROOT_DIR=""
else
    ROOT_DIR=$TP_X
fi

BOOT_DIR=$ROOT_DIR/boot
FRIEND_DIR=$BOOT_DIR/tamu
BITMAP_DIR=$BOOT_DIR/bitmaps
BITMAP_MENU=$BOOT_DIR/bitmap/boot.bmp
LILO_CONF="$ROOT_DIR/etc/lilo.conf"

CONSOLETYPE="standard"
SPLASH=""

## For testing, simulate DMESG
#dmesg()
#{
#echo "hdc: LTN9999 CD/DVD drive"
#echo "hdd: LTN9999 CD-RW drive"
#}

## For testing, simulate probedisk
#probedisk()
#{
#cat << _EOF
#hda|disk|AAAA
#hdc|cdrom|CCCC CDROM
#hdd|cdrom|DDDD CD-RW
#_EOF
#}

# Determine the root partition (such as /dev/hda2)
ROOT_DEVICE=$2
if [ -z "$ROOT_DEVICE" ]; then
  ROOT_DEVICE=`cat /etc/fstab | awk '{if ($2 == "/") {print $1}}' `
  # This must be successful
  if [ -z "$ROOT_DEVICE" ]; then
    ROOT_DEVICE=`mount | awk '{if ($3 == "/") {print $1}}'`
  fi
fi

# Figure out where the kernel is:
mkdir -p $BOOT_DIR
if [ -r $BOOT_DIR/vmlinuz ]; then
  KERNEL=$BOOT_DIR/vmlinuz
elif [ -r $ROOT_DIR/vmlinuz ]; then
  KERNEL=$ROOT_DIR/vmlinuz
else
  errorbox "Cannot find kernel (vmlinuz). Aborting LILO install"
  clean_exit 1
fi

# Get old append
APPEND=""
if [ -r $LILO_CONF ]; then
    LINE=`grep -m 1 -E "^[^#].*append *=" $LILO_CONF`
    if [ "$LINE" ]; then
	APPEND=`echo $LINE | cut -f2 -d '"'`
    fi
fi 

append_ide_scsi()
{
    while read LINE; do
	echo $LINE
        DEV=`echo $LINE|cut -f1 -d'|'`
	DEV=${DEV##*/}
	if grep "$DEV=ide-scsi" /proc/cmdline; then
	    APPEND="$APPEND $DEV=ide-scsi"
	elif dmesg | egrep "^${DEV}:" | grep -q "RW"; then
	    APPEND="$APPEND $DEV=ide-scsi"
	fi
    done
}

# do we need ide-scsi ?
if ! echo $APPEND | grep -q "ide-scsi"; then
    if [ `kernelversion` == 2.4 ] && \
	probedisk | grep -qE '(cdrom|cdwriter)' > $freply; then
	append_ide_scsi < $freply
    fi
fi

APPEND=`echo $APPEND`
#echo $APPEND
#read pause

installcolor()
{
 if [ "$ROOT_DIR" ]; then
  lilo -r $T_PX -m /boot/map -C /etc/lilo.conf 1> /dev/null 2> /dev/null
 else
  lilo 1> /dev/null 2> /dev/null
 fi
 SUCCESS=$?

 if [ ! "$SUCCESS" = "0" ]; then # edit file to try lba32 mode:
  cat $T_PX/etc/lilo.conf | while read line ; do
   echo $line
   if [ "$line" = "# Start LILO global section" ] ; then
     echo "lba32 # Allow booting past 1024th cylinder with a recent BIOS"
   fi
  done > $T_PX/etc/lilo.conf.lba32
  mv $T_PX/etc/lilo.conf.lba32 $T_PX/etc/lilo.conf
  if [ "$ROOT_DIR" ]; then
   lilo -r $T_PX -m /boot/map -C /etc/lilo.conf 1> /dev/null 2> /dev/null
  else
   lilo 1> /dev/null 2> $tmp/liloerror
  fi
  SUCCESS=$?
 fi

 if [ ! "$SUCCESS" = "0" ]; then # some LILO error occurred
   liloerror=`cat $tmp/liloerror | grep Fatal`

  $DCMD --backtitle "$BACKTITLE" --title "LILO INSTALL ERROR # $SUCCESS" --msgbox \
  "Sorry, but the attempt to install LILO has returned an error, so LILO \
has not been correctly installed.  You'll have to use a bootdisk \
to start your \
machine instead.  It should still be possible to get LILO working by \
editing the /etc/lilo.conf and reinstalling LILO manually.  See the \
LILO man page and documentation in /usr/doc/lilo/ for more help.\n 
lilo error=$liloerror    " 0 0
  clean_exit 1
 fi
}

menu_boot()
{
$DCMD --backtitle "$BACKTITLE" --title "LILO INSTALL" --menu "\n
LILO (Linux Loader) allows you to boot various operating systems on
multiple partitions. To use it, you must install LILO on either:\n
 1. The Master Boot Record of your first hard drive. Use this unless\n
    you are using another boot manager (e.g GRUB, PQMagic, NT Loader)\n
 2. The boot sector of your Linux partition. Then you need to:\n
      a) make the partition bootable (using fdisk for example).\n
      b) use another boot manager to boot this partition.\n
 3. A formatted floppy disk. The safest and the slowest.\n
Which option would you like?" \
0 0 4 \
"MBR" "install to Master Boot Record (simplest)" \
"SECTOR" "install to boot sector (needs extra manual steps)" \
"FLOPPY" "install to a formatted floppy in /dev/fd0 (A:)" \
"SKIP" "do not install LILO" \
2> $freply

 result=$?
 [ $result != 0 ] && return $result

reply="`cat $freply`"
case "$reply" in
  ##if the user chose MBR check to see if more than 1 mbr is available if only 1 use it 
  MBR)
   HardDisk=$(fdisk -l | grep Disk | cut -d " " -f 2 | cut -c 1-8|grep ^/dev)
   x=$(echo $HardDisk | wc -w)
   if [ $x != 1 ]; then  
     j="0"
     for i in $HardDisk; do
     hd[$j]="$i"
     ((j++))
     done
     $DCMD --backtitle "$BACKTITLE" --title "MBR INSTALL" --menu "\n
     LILO (Linux Loader) install lilo to mbr \n
     you chose to install lilo to the MBR, and \n
     you have multiple hard disks\n
     we need to know where you would like the mbr to be written \n
     Choose which hard disk you would like to use" \
     0 0 4 \
     ${hd[0]} ${hd[0]} \
     ${hd[1]} ${hd[1]} \
     ${hd[2]} ${hd[2]} \
     ${hd[3]} ${hd[3]} \
     ${hd[4]} ${hd[4]} \
     ${hd[5]} ${hd[5]} \
     2> $freply

     result=$?
     [ $result != 0 ] && return $result

     LILO_TARGET="`cat $freply`"
   else
    LILO_TARGET="$HardDisk"
   fi
  ;;
 SECTOR)
  LILO_TARGET="$ROOT_DEVICE"
  ;;
 FLOPPY)
  LILO_TARGET="/dev/fd0"
  ;;
 *)
  clean_exit
  ;;
esac 
return 0
}

# Menu to check if we want to use VESA framebuffer support:
menu_fb() {

  # if FB is not supported, skip
  if ! cat /proc/devices | grep "29 fb" 1> /dev/null ; then
    return $1
  fi

  $WCMD --backtitle "$BACKTITLE" --title "LILO FRAME BUFFER CONSOLE" \
  --default-item $CONSOLETYPE --menu "\n
It seems that your kernel supports the Linux frame buffer console.
If we enable this, it will allow more rows and columns of text on
the screen and give you a cool penguin logo at boot time.\n
However, the frame buffer console needs more memory and is slower 
than the standard mode. Moreover, not every video card or monitor
support all of these video modes. Many blank-screen problems have
been reported on Linux kernel 2.6 (earlier release).\n
If you are going to use GUI mode more often, better stick with
the standard mode:" 0 0 4 \
  "standard" "Use the standard Linux console (the safe choice)" \
  "bootsplash-high" "Show graphical image during boot, 1024x768" \
  "bootsplash-med" "Show graphical image during boot, 800x600" \
  "bootsplash-Xhigh" "Show graphical image during boot, 1280x1024" \
  "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> $freply
  
  result=$?
  [ $result != 0 ] && return $result
  
  CONSOLETYPE="`cat $freply`"
  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
  elif [ "$CONSOLETYPE" = "bootsplash-high" ]; then
    CONSOLENUM=791
    SPLASH="splash=silent"
    RAMDISK="/boot/initrd"
  elif [ "$CONSOLETYPE" = "bootsplash-med" ]; then
    CONSOLENUM=788
    SPLASH="splash=silent"
    RAMDISK="/boot/initrd"        
  elif [ "$CONSOLETYPE" = "bootsplash-Xhigh" ]; then
    CONSOLENUM=794
    SPLASH="splash=silent"
    RAMDISK="/boot/initrd"        
  fi
  return 0
}

menu_param()
{

$WCMD --backtitle "$BACKTITLE" --title "LILO OPTIONAL PARAMETERS" \
--inputbox "\n
This is a bit technical but optional. So you may skip it without
reading on. Hit <OK> now.\n\n
Still with me? Alright, this dialog allows you to set boot parameters.
For example, if you want to try hibernation, type:\n
  resume=/dev/hdax : where /dev/hdax is the swap partition\n
If your system hung during initialization, bypass it by using:\n
  nohotplug    : do not set up hotplug devices (USB/PCI)\n
  nohwclock    : do not use realtime clock\n
  noapic       : turn off Advanced Programmable Interrupt Controller\n
You may enter many parameters separated by space. Empty is fine:" \
0 0 2> $freply

result=$?
[ $result != 0 ] && return $result
 
     APPEND="`cat $freply`"
    return 0
  
}

menu_os()
{
###########################
## Build array of
#LILO_TYPE
#LILO_PART
#LILO_LABEL
#LILO_DESC
#LILO_TABLE

infobox "Detecting operating systems ..."

count1=0
## Bootable windows partition first
PARTS=`fdisk -l 2>/dev/null | grep -E '^/dev/.* \* .*(FAT16)' | cut -f 1 -d ' '`
index=""
for PART in $PARTS; do
  let count1=count1+1
  LILO1_PART[$count1]="$PART"
  LILO1_LABEL[$count1]="dos$index"
  LILO1_DESC[$count1]="DOS ($PART)"
  if [ "$index" ]; then
    let index=$index+1
  else
    index=1
  fi
done

PARTS=`fdisk -l 2>/dev/null | grep -E '^/dev/.* \* .*(FAT32|HPFS|NTFS|Win)' | cut -f 1 -d ' '`
index=""
for PART in $PARTS; do
  let count1=count1+1
  LILO1_PART[$count1]="$PART"
  LILO1_LABEL[$count1]="Win$index"
  LILO1_DESC[$count1]="Windows ($PART)"
  if [ "$index" ]; then
    let index=$index+1
  else
    index=1
  fi
done

## Add current root
LILO_LABEL="linux"
LILO_DESCRIPTION="Linux"
if [ -f /boot/lilo.label ]; then
    . /boot/lilo.label
fi
DEFAULT_LABEL=$LILO_LABEL

count2=1
LILO2_PART[$count2]="$ROOT_DEVICE"
LILO2_LABEL[$count2]="$DEFAULT_LABEL"
LILO2_DESC[$count2]="$LILO_DESCRIPTION ($ROOT_DEVICE)"

## Add current root
let count2=count2+1
LILO2_PART[$count2]="$ROOT_DEVICE"
LILO2_LABEL[$count2]="$DEFAULT_LABEL-tui"
LILO2_DESC[$count2]="$LILO_DESCRIPTION Text mode ($ROOT_DEVICE)"

## Add current root
let count2=count2+1
LILO2_PART[$count2]="$ROOT_DEVICE"
LILO2_LABEL[$count2]="$DEFAULT_LABEL-gui"
LILO2_DESC[$count2]="$LILO_DESCRIPTION Graphic mode ($ROOT_DEVICE)"

## Add other vmlinuzes
if [ -h /boot/vmlinuz ]; then
    MAIN_VMLINUZ=`readlink /boot/vmlinuz`
    MAIN_VMLINUZ=`basename $MAIN_VMLINUZ`
else
    MAIN_VMLINUZ=vmlinuz
fi

for VMLINUZ in /boot/vmlinuz-*; do
    BVMLINUZ=`basename $VMLINUZ`
    if [ "$BVMLINUZ" = "$MAIN_VMLINUZ" ]; then
	continue
    fi
    BVMLINUZ=${BVMLINUZ#*-}
    # skip if more than 12 chars
    if [ ${#BVMLINUZ} -gt 12 ]; then
	continue
    fi
    let count2=count2+1
    LILO2_PART[$count2]="$ROOT_DEVICE"
    LILO2_DESC[$count2]="Linux $BVMLINUZ ($ROOT_DEVICE)"
    LILO2_LABEL[$count2]="$BVMLINUZ"
done

## Add additional Linux
count3=0
mkdir -p /tmp/lilo_mount &> /dev/null
for PART in `fdisk -l 2>/dev/null | grep -E '83 *Linux' | cut -f 1 -d ' '`; do
  if [ "$PART" != "$ROOT_DEVICE" ]; then
     if mount $PART /tmp/lilo_mount &> /dev/null; then
	if [ -r /tmp/lilo_mount/boot/vmlinuz ]; then
	    # Find out the distro
	    # Check for GNU/Linux distributions
	    if [ -f /tmp/lilo_mount/etc/vlocity-version ]; then
	      LILO_LABEL="vlocity"
	      LILO_DESCRIPTION="VLocity Linux"
	    elif [ -f /tmp/lilo_mount/etc/sysconfig/vlocity ]; then
	      LILO_LABEL="vlocity"
	      LILO_DESCRIPTION="VLocity Linux"
	    elif [ -f /tmp/lilo_mount/etc/sysconfig/vector ]; then
	      LILO_LABEL="vector"
	      LILO_DESCRIPTION="Vector Linux"
	    elif [ -f /tmp/lilo_mount/etc/vector-version ]; then
	      LILO_LABEL="vector"
	      LILO_DESCRIPTION="Vector Linux"
	    elif [ -f /tmp/lilo_mount/etc/slackware-version ]; then
	      LILO_LABEL="slackware"
	      LILO_DESCRIPTION="Slackware Linux"
	    elif [ -f /tmp/lilo_mount/etc/SuSE-release -o -f /etc/UnitedLinux-release ]; then
	      LILO_LABEL="suse"
	      LILO_DESCRIPTION="Suse Linux"
	    elif [ -f /tmp/lilo_mount/etc/gentoo-release ]; then
	      LILO_LABEL="gentoo"
	      LILO_DESCRIPTION="Gentoo Linux"
	    elif [ -f /tmp/lilo_mount/etc/debian_version ]; then
	      LILO_LABEL="debian"
	      LILO_DESCRIPTION="Debian Linux"
	    elif [ -f /tmp/lilo_mount/etc/mandrake-release ]; then
	      LILO_LABEL="mandrake"
	      LILO_DESCRIPTION="Mandrake Linux"
	    elif [ -f /tmp/lilo_mount/etc/redhat-release ]; then
	      LILO_LABEL="redhat"
	      LILO_DESCRIPTION="Redhat Linux"
	    elif [ -f /tmp/lilo_mount/etc/fedora-release ]; then
	      LILO_LABEL="fedora"
	      LILO_DESCRIPTION="Fedora Linux"
	    else
	      LILO_LABEL="linux"
	      LILO_DESCRIPTION="Linux"
	    fi
	    # if there is a label, use it
	    if [ -f /tmp/lilo_mount/boot/lilo.label ]; then
		. /tmp/lilo_mount/boot/lilo.label
	    fi
	    let count3=count3+1
	    num="`echo $PART | cut -b6-`"
	    LILO3_PART[$count3]="$PART"
	    LILO3_LABEL[$count3]="$LILO_LABEL-$num"
	    LILO3_DESC[$count3]="$LILO_DESCRIPTION ($PART)"
	fi 
	umount /tmp/lilo_mount     
     fi
  fi  
done

## Show menu for selection
TEXT="\n
The following operating systems have been detected on this computer.
Please choose the ones to be included in the LILO boot menu:"
TITLE="LILO SELECT OPERATING SYSTEMS"

echo '$WCMD --backtitle "$BACKTITLE" --title "$TITLE" \
--checklist "$TEXT" 0 0 8 \' > $fmenu
for (( ii=1; ii <= $count1 ; ii=ii+1 )); do
  echo "'${LILO1_LABEL[$ii]}' '${LILO1_DESC[$ii]}' on \\" >> $fmenu
done
for (( ii=1; ii <= $count2 ; ii=ii+1 )); do
  echo "'${LILO2_LABEL[$ii]}' '${LILO2_DESC[$ii]}' on \\" >> $fmenu
done
for (( ii=1; ii <= $count3 ; ii=ii+1 )); do
  echo "'${LILO3_LABEL[$ii]}' '${LILO3_DESC[$ii]}' on \\" >> $fmenu
done
echo '2> $freply' >> $fmenu

. $fmenu

result=$?
[ $result != 0 ] && return $result

if [ "$CMD" = "" ]; then
  LILO_CHOICES=`cat $freply | sed -e 's/"/ /g' -e 's/  / /g'`
else
  LILO_CHOICES=`cat $freply | sed -e 's!/! !g' -e 's/  / /g'`
fi
return 0
}

############################################################
# Here we go 
menu_finish()
{
# Make a new boot_message if not exist
cat << EOF > $T_PX/etc/lilo.conf
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
EOF
if [ "$APPEND" ]; then
  echo "append=\"$APPEND\"" >> $T_PX/etc/lilo.conf
fi
 cat << EOF >> $T_PX/etc/lilo.conf
boot = $LILO_TARGET
default = $DEFAULT_LABEL
compact
prompt
timeout = 100
# Override dangerous defaults that rewrite the partition table:
change-rules
  reset
EOF

# USE bitmap if exist, otherwise text mode
if [ -r $T_PX/boot/bitmap/boot.bmp ]; then
  echo "bitmap = /boot/bitmap/boot.bmp" >> $T_PX/etc/lilo.conf
else
  ## make boot message
  if [ ! -f $T_PX/boot/boot_message.txt ]; then
    cat << EOF > $T_PX/boot/boot_message.txt
Please select the partition you would like to boot then press [enter].
If you want to boot another Linux partition, you may type
boot: linux root=<partition-name>

EOF
  fi

  cat << EOF >> $T_PX/etc/lilo.conf
menu-scheme = wb:bw:wb:bw
menu-title = "Welcome to LILO boot menu"
message = /boot/boot_message.txt
EOF
fi

 if [ "$CONSOLETYPE" = "standard" ]; then
   cat << EOF >> $T_PX/etc/lilo.conf
# Normal VGA console
vga = normal
EOF
else
   cat << EOF >> $T_PX/etc/lilo.conf
# VESA framebuffer console @ $CONSOLETYPE
vga = $CONSOLENUM
# Normal VGA console
# vga = normal
EOF
fi

   cat << EOF >> $T_PX/etc/lilo.conf
# VESA framebuffer console @ 1024x768x64k
# vga=791
# VESA framebuffer console @ 1024x768x32k
# vga=790
# VESA framebuffer console @ 1024x768x256
# vga=773
# VESA framebuffer console @ 800x600x64k
# vga=788
# VESA framebuffer console @ 800x600x32k
# vga=787
# VESA framebuffer console @ 800x600x256
# vga=771
# VESA framebuffer console @ 640x480x64k
# vga=785
# VESA framebuffer console @ 640x480x32k
# vga=784
# VESA framebuffer console @ 640x480x256
# vga=769


# End LILO global section
EOF

# Detect initrd
ROOT_INITRD=""
if [ -f /boot/initrd.gz ]; then
    ROOT_INITRD="initrd = /boot/initrd.gz"
    fi
if [ -f /boot/initrd ]; then
if [ ! "$SPLASH" = "" ]; then 
    ROOT_INITRD="initrd = /boot/initrd"
    fi    
    fi
mkdir -p $FRIEND_DIR

infobox "Making lilo.conf and installing LILO ..." "LILO"
number=0
for (( ii=1; ii <= $count1 ; ii=ii+1 )); do
  # Skip if not chosen
  if ! echo $LILO_CHOICES | grep -qw ${LILO1_LABEL[$ii]}; then
    continue
  fi
  let number=$number+1 

  TABLE="`echo ${LILO1_PART[$ii]} | cut -b1-8`"
cat << EOF >> $T_PX/etc/lilo.conf
# Partition $number : DOS/Windows 
other = ${LILO1_PART[$ii]}
    label = ${LILO1_LABEL[$ii]}
    table = $TABLE
EOF

done

for (( ii=1; ii <= $count2 ; ii=ii+1 )); do
  # Skip if not chosen
  if ! echo $LILO_CHOICES | grep -qw ${LILO2_LABEL[$ii]}; then
    continue
  fi
  let number=$number+1 

  case ${LILO2_LABEL[$ii]} in
     "$DEFAULT_LABEL")
  cat << EOF >> $T_PX/etc/lilo.conf
# Partition $number: Linux GUI mode
image = $KERNEL
    root = $ROOT_DEVICE
    label = $DEFAULT_LABEL
    append = "$SPLASH $APPEND"
    read-only
    $ROOT_INITRD
EOF
    ;;

     "${DEFAULT_LABEL}-tui")
  cat << EOF >> $T_PX/etc/lilo.conf
# Partition $number: Linux TUI mode
image = $KERNEL
    root = $ROOT_DEVICE
    label = ${DEFAULT_LABEL}-tui
    append = "2 $SPLASH $APPEND"
    read-only
    $ROOT_INITRD
EOF
    ;;

     "${DEFAULT_LABEL}-gui")
  cat << EOF >> $T_PX/etc/lilo.conf
# Partition $number: Linux GUI mode
image = $KERNEL
    root = $ROOT_DEVICE
    label = ${DEFAULT_LABEL}-gui
    append = "4 $SPLASH $APPEND"
    read-only
    $ROOT_INITRD
EOF
    ;;

    *)

    if [ -f /boot/vmlinuz-${LILO2_LABEL[$ii]} ]; then
	cat << EOF >> $T_PX/etc/lilo.conf
# Partition $number: Linux
image = /boot/vmlinuz-${LILO2_LABEL[$ii]}
    root = $ROOT_DEVICE
    label = ${LILO2_LABEL[$ii]}
    append = "$SPLASH $APPEND"
    read-only
EOF
    else
	infobox "Cannot install ${LILO2_LABEL[$ii]}. Skipped." "WARNING"
	sleep 3  
    fi
    ;;
esac
done

for (( ii=1; ii <= $count3 ; ii=ii+1 )); do
    # Skip if not chosen
    if ! echo $LILO_CHOICES | grep -qw ${LILO3_LABEL[$ii]}; then
	continue
    fi
    let number=$number+1 
    INITRD=""
    if mount ${LILO3_PART[$ii]} /tmp/lilo_mount; then
	if cp -u /tmp/lilo_mount/boot/vmlinuz $FRIEND_DIR/vmlinuz-${LILO3_LABEL[$ii]}; then
	    INITRD=`ls -1 /tmp/lilo_mount/boot/initrd.* 2>/dev/null | head -n1`
	    if [ "$INITRD" ]; then
		cp -u $INITRD $FRIEND_DIR/initrd-${LILO3_LABEL[$ii]}
		INITRD="initrd = $FRIEND_DIR/initrd-${LILO3_LABEL[$ii]}"
	    fi
	    cat << EOF >> $T_PX/etc/lilo.conf
# Partition $number: Linux
image = $FRIEND_DIR/vmlinuz-${LILO3_LABEL[$ii]}
    root = ${LILO3_PART[$ii]}
    label = ${LILO3_LABEL[$ii]}
    read-only
    $INITRD
EOF
	else
	    infobox "Cannot install ${LILO_LABEL[$ii]}. Skipped." "WARNING"
	    sleep 3
	fi
	umount /tmp/lilo_mount
    fi
done
rmdir /tmp/lilo_mount

# Done, now we must install lilo:
installcolor;
# cat /etc/lilo.conf
infobox "SUCCESS LILO has been installed /
DONE"
sleep 4
 
clean_exit 0
}


############################
# MAIN MENU
wizard menu_boot menu_os menu_fb menu_param menu_finish

