#!/bin/sh
# vim:set sw=4 ts=4:
#
# $Id: change_kernel,v 1.5 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
#
#############################################################################
#
# This module was sponsored by Bundesanstalt fuer Landwirtschaft und
# Ernaehrung (BLE)
#
# Author: Juergen Henge-Ernst (hernst@suse.de) 
#
############################################################################
#
# update_rpms
# Updates RPMs of the system, which contain newer versions or security fixes
#
# TODO: Check for SLES8 and above
# TODO: Implement http:// and ftp:// client
#
# Sections: kernel
# Tags:     CONFIG_MODE, KERNEL_RPM_LOCATION, ADDITIONAL_KERNEL_RPMS
#

test -n "$alice_dir" || alice_dir="/usr/lib/alice2/"
export alice_dir
usage()
{
   cat <<EOF
usage: $0 -h | --help | -?

EOF
}

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

   esac
   shift
done   

. $alice_dir/lib/alicerc

WELCOME

#
############################################################################
#
GET_CONFIGURATION --require kernel $CFG_DEBUG

# only do that action on installation mode, not configmode
if [ -z "$CONFIGMODE" ]; then
	if [ -n "${KERNEL_RPM_LOCATION}" ]; then

		# Get the files
		LOCAL_DIR="/tmp/kernel_rpm.$$"
		method=${KERNEL_RPM_LOCATION%%:*}
		method=$(echo $method | tr '[:lower:]' '[:upper:]')
		URL=${KERNEL_RPM_LOCATION#*:}
		URL=${URL#//}
		case $method in
		NFS ) # //server/path
			url_server=${URL%%/*}
			url_path="/${URL#*/}"
			mkdir $LOCAL_DIR
			mount $url_server:$url_path $LOCAL_DIR
			;;
		FILE ) # ///path
			url_path="/${URL#*/}"
			ln -s $url_path $LOCAL_DIR
			;;
		esac

		cd $LOCAL_DIR

		# install the kernel
		rpm --force --nodeps -U "${KERNEL_RPM}.rpm"
#
# TODO:
# mk_initrd
# lilo
# k_smp-2.4.10-24.i386.rpm enthlt die CALLS nicht :-(
#

		# update additional packages ??
		if [ "${ADDITIONAL_KERNEL_RPMS}" ]; then
			echo "${ADDITIONAL_KERNEL_RPMS}" | while read RPM; do
				rpm --force --nodeps -U "${RPM}.rpm"
			done
		fi
		
		cd -

		# Clean up the temporary files
		case $method in
		NFS ) # //server/path
			umount $LOCAL_DIR
			rmdir $LOCAL_DIR
			;;
		FILE ) # ///path
			rm $LOCAL_DIR
			;;
		esac
	fi
fi

#
############################################################################
# Thats all
GOOD_BYE 
