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