#!/bin/sh
yes () {
    while [ 0 ];do
 	echo -n " (Y, N, or Q): ";
	read answer;
	case $answer in
	q|Q|quit) return 2;;
	y|Y|yes) return 0;;
	n|N|no) return 1;;
	*) ;;
	esac;
    done; }

readblock () { while [ 0 ];do
 echo -n "Give me the name of a block device.  The default is $default: ";
 read answer;
 if [ -n "$answer" ];then if [ -b $answer ];then return;else
  echo "$answer is not a block device.";fi;else answer=$default;return;fi;
 done; }

/bin/cat <<EOF >/etc/lilo/config
# /etc/lilo/config created by newinstall `/usr/bin/date`.
install = /etc/lilo/boot.b
compact
delay = 20	# optional, for systems that boot very quickly
#prompt		# use instead of delay to force response to boot prompt
#vga = normal	# force sane state
#ramdisk = 0	# paranoia setting
#root = current	# use "current" root
EOF
/bin/chown bin.bin /etc/lilo/config
/bin/chmod 644 /etc/lilo/config

default=`/bin/rdev|/usr/bin/cut -c -7`a
rdefault=`/bin/rdev|/usr/bin/cut -f 1 -d ' '`
if [ -n "$DEV" ];then floppy="$DEV";
 if [ "`echo $DEV|/usr/bin/cut -c 6`" != "f" ];then floppy="";fi
 if [ "`echo $DEV|/usr/bin/cut -c 8`" != "0" ];then floppy="";fi;fi
if [ -z "$floppy" ];then floppy=/dev/fd0;fi
echo
echo "Where should the boot code go?  You may override this later to write a"
echo "test floppy before installing LILO on the hard disk.  Possible choices"
echo "include $default (the master boot record on your first hard disk),"
echo "$rdefault (the partition you are installing Linux on),"
echo "or $floppy (floppy disk 0, DOS floppy A:)."
readblock;boot=$answer;echo "boot = $boot" >>/etc/lilo/config

first="first";quit="quit"
while [ 0 ];do
 if [ "$first" = "first" ];then
  echo "LILO will boot by default the first system you specify."
  echo "Others must be selected by taking special action at boot time."
 fi
 echo "Is the $first system you wish to add a version of Linux or not?"
 echo -n "Answer 'n' for other operating systems or 'q' to $quit: "
 yes
 case $? in
 0)
  default=linux
  echo "The default Linux image in this installation is /etc/Image."
  echo "Press <RETURN> if you are using this image, or if you have a"
  echo "different image somewhere else which is currently mounted,"
  echo -n "give its pathname: "
  read answer
  if [ -z "$answer" ];then answer=/etc/Image;fi
  if [ ! -f $answer ];then
   echo "I cannot find the file $answer.";continue;fi
  echo "image = $answer" >>/etc/lilo/config;;
 1)
  echo "In what partition does this other system live?  Press <RETURN> if"
  echo "you do not wish to add this option.  Otherwise give an answer"
  echo -n "like /dev/hda1: "
  read other
  if [ -z "$other" ];then continue;fi
  if [ ! -b $other ];then echo "$other is not a block device."
   continue;fi
  default=`echo $other|/usr/bin/cut -c -8`
  echo "What is the name of the device where this partition lives?"
  echo "I want the block device which is the whole of the disk."
  echo -e "Press <RETURN> to accept the default $default, or 'q' to give up: "
  read disk
  if [ -z "$disk" ];then disk=$default;else
   if [ "$disk" = "q" -o "disk" = "Q" ];then continue;fi;fi
  if [ ! -b $disk ];then echo "$disk is not a block device";continue;fi
  default=dos
  if [ "a" = "`echo $disk|/usr/bin/cut -c 8`" ];then loader=""
  else echo -n "Is this operating system OS/2: ";yes
   case $? in
    0) loader=/etc/lilo/os2_d.b
       default=os2;;
    1) loader=/etc/lilo/any_d.b;;
    *) continue;;
   esac
  fi
  echo "other = $other" >>/etc/lilo/config
  if [ -n "$loader" ];then echo "  loader = $loader" >>/etc/lilo/config;fi
  echo "  table = $disk" >>/etc/lilo/config;;
 *) break;;
 esac

 echo "What would you like to call this option?  The default is '$default'."
 echo -n "Remember, you may not give the same name to two options: "
 read label;if [ -z "$label" ];then label=$default;fi
 echo "  label = $label" >>/etc/lilo/config
 first="next";quit="install"
done

if [ "$first" = "next" ];then
 if /usr/bin/egrep linux.old /etc/lilo/config >>/dev/null;then :
 else echo -e "image = /etc/Image.old\n  label = linux.old\n  optional" \
  >>/etc/lilo/config;fi

 default=$floppy
 echo "Now where would you like to install LILO at this time?  You may put"
 echo "it on $default to be safe; be sure you have a formatted floppy disk"
 echo "in this drive NOW, and that it is a device you can boot from, not"
 echo "your DOS B: drive.  Or you may install it in $boot."
 readblock
 if [ "$answer" = "$boot" ];then boot="";else boot="-b $answer";fi
 /etc/lilo/lilo -r / $boot
fi
