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