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