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