#!/bin/sh
# vim:set sw=4 ts=4:
#
# $Id: make_boot,v 1.11 2005/04/11 14:14:39 fabian Exp $
#
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000 SuSE Linux Solutions AG, Eschborn, Germany
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: Fabian Herschel
#
############################################################################
#
# make_boot
# Configures the lilo and some more like initrd
#
# Sections: lilo
# Tags:     LILO_TEMPLATE, PROD_KERNEL, ROOT_DEVICE, BOOT_DEVICE
# 

test -n "$alice_dir" || alice_dir="/usr/lib/alice2/"
export alice_dir

while [ $# -gt 0 ]
do
   case $1 in
       -h | --help | -? ) usage
                          exit 1
                          ;;
       -fqhn ) export fqhn=$2; shift
            ;;

   esac
   shift
done   

. $alice_dir/lib/alicerc

WELCOME
GET_CONFIGURATION lilo $CFG_DEBUG

std_lilo_conf=/etc/lilo.conf
if [ -z "$LILO_TEMPLATE" ]
then
   # MESSAGE NOVALUE LILO_TEMPLATE $config_file
   #
   # no lilo template?
   # let's try the default one on the system
   #
   if [ -f ${std_lilo_conf} ]; then
     LILO_TEMPLATE=$(cat ${std_lilo_conf})
   else
     GOOD_BYE
   fi  
fi

# escape double quotes (or eval will remove them)
# als in some old tags they already escaped, remove the \" to " and then escape
# them again. Ugly, but this must be done for compatibility with versions before
# 0.9.5
LILO_TEMPLATE=$( echo "$LILO_TEMPLATE" | sed -e s+\\\\\"+\"+g | sed -e s+\"+\\\\\"+g )

#
############################################################################
#
# COPY NEEDED KERNELS (OLD STUFF, WE HAVE RPMS TODAY)
#
############################################################################
#
if [ -n "$PROD_KERNEL" ]
then
   SourceDir=/var/adm/mount/suse/images
   cp /boot/vmlinuz /boot/vmlinuz.suse
   cp $SourceDir/$PROD_KERNEL /boot/vmlinuz
fi
#
############################################################################
#
# CREATE THE INITIAL RAMDISK (INITRD)
#
############################################################################
#
THE_MK_INITRD=/sbin/mk_initrd
if [ -x $THE_MK_INITRD ]
then
   $THE_MK_INITRD 2>&1 >>/var/log/alice_log
fi
#
############################################################################
#
#  LILO CONFIGURATION
#
############################################################################
#
#
# save the old configuration
#
BACKUP --error ${std_lilo_conf} 
#
#
# if the config file has not fill out the variables for
# ROOT_DEVICE or BOOT_DEVICE let us try tio "guess" these
# values. The ROOT_DEVICE should be the partition or
# logical volume where / is mounted, the BOOT_DEVICE
# is the first scsi disk or the first ide disk
#
if [ -z "$ROOT_DEVICE" ]
then
   ROOT_DEVICE=$( df --local   / | awk '$6 == "/" { print $1 }' )
fi
if [ -z "$BOOT_DEVICE" ]
then
   #
   # a partition listed later in the for... list has "higher" priority
   #
   for PARTITION in hda sda
   do
      grep -q $PARTITION /proc/partitions && BOOT_DEVICE=/dev/$PARTITION
   done
fi
#
#  generating a new lilo.conf
#
(
    eval echo \""${LILO_TEMPLATE}"\"
)> ${std_lilo_conf}.alice
#
#  and also lilo should know the new config :))
#
CHANGED ${std_lilo_conf} || {
   BACKUP ${std_lilo_conf}
   mv ${std_lilo_conf}.alice ${std_lilo_conf} || FATAL NOSAVE lilo.conf ${std_lilo_conf}
   #
   # Now we invite lilo...
   #
   if [ -x /sbin/lilo ]
   then
      /sbin/lilo
   else
      FATAL NOEXE /sbin/lilo 
   fi
}
#
############################################################################
# Thats all
GOOD_BYE 
