3e90b9
#! /bin/sh
3e90b9
#
3e90b9
# /sbin/installkernel
3e90b9
#
3e90b9
# Copyright 2007-2008 Red Hat, Inc.  All rights reserved.
3e90b9
#
3e90b9
# This program is free software; you can redistribute it and/or modify
3e90b9
# it under the terms of the GNU General Public License as published by
3e90b9
# the Free Software Foundation; either version 2 of the License, or
3e90b9
# (at your option) any later version.
3e90b9
#
3e90b9
# This program is distributed in the hope that it will be useful,
3e90b9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
3e90b9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3e90b9
# GNU General Public License for more details.
3e90b9
#
3e90b9
# You should have received a copy of the GNU General Public License
3e90b9
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
3e90b9
#
3e90b9
# Author(s): tyson@rwii.com
3e90b9
#
3e90b9
3e90b9
usage() {
3e90b9
    echo "Usage: `basename $0` <kernel_version> <bootimage> <mapfile>" >&2
3e90b9
    exit 1
3e90b9
}
3e90b9
3e90b9
cfgLoader=
3e90b9
3e90b9
if [ -z "$INSTALL_PATH" -o "$INSTALL_PATH" == "/boot" ]; then
3e90b9
    INSTALL_PATH=/boot
3e90b9
    cfgLoader=1
3e90b9
fi
3e90b9
3e90b9
LINK_PATH=/boot
3e90b9
RELATIVE_PATH=`echo "$INSTALL_PATH/" | sed "s|^$LINK_PATH/||"`
3e90b9
KERNEL_VERSION=$1
3e90b9
BOOTIMAGE=$2
3e90b9
MAPFILE=$3
3e90b9
ARCH=$(uname -m)
3e90b9
if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then
3e90b9
    KERNEL_NAME=vmlinux
3e90b9
else
3e90b9
    KERNEL_NAME=vmlinuz
3e90b9
fi
3e90b9
3e90b9
if [ -z "$KERNEL_VERSION" -o -z "$BOOTIMAGE" -o -z "$MAPFILE" ]; then
3e90b9
    usage
3e90b9
fi
3e90b9
3e90b9
if [ -f $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION ]; then
3e90b9
      mv $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION \
3e90b9
              $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION.old;
3e90b9
fi
3e90b9
3e90b9
if [ ! -L $INSTALL_PATH/$KERNEL_NAME ]; then
3e90b9
    if [ -e $INSTALLPATH/$KERNEL_NAME ]; then
3e90b9
	mv $INSTALL_PATH/$KERNEL_NAME $INSTALL_PATH/$KERNEL_NAME.old
3e90b9
    fi
3e90b9
fi
3e90b9
3e90b9
if [ -f $INSTALL_PATH/System.map-$KERNEL_VERSION ]; then
3e90b9
      mv $INSTALL_PATH/System.map-$KERNEL_VERSION \
3e90b9
              $INSTALL_PATH/System.map-$KERNEL_VERSION.old;
3e90b9
fi
3e90b9
3e90b9
if [ ! -L $INSTALL_PATH/System.map ]; then
3e90b9
    if [ -e $INSTALLPATH/System.map ]; then
3e90b9
	mv $INSTALL_PATH/System.map $INSTALL_PATH/System.map.old
3e90b9
    fi
3e90b9
fi
3e90b9
ln -sf ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map
3e90b9
3e90b9
cat $BOOTIMAGE > $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION
3e90b9
cp $MAPFILE $INSTALL_PATH/System.map-$KERNEL_VERSION
3e90b9
3e90b9
ln -fs ${RELATIVE_PATH}$INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION $LINK_PATH/$KERNEL_NAME
3e90b9
ln -fs ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map
3e90b9
3e90b9
if [ -n "$cfgLoader" ]; then
3e90b9
	kernel-install add $KERNEL_VERSION $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION
3e90b9
	exit $?
3e90b9
fi