#!/bin/bash
#
# Copyright (C) 1995 Debian Association, Inc.
# Written by Ian A. Murdock <imurdock@debian.org>
#
# Install the kernel on a Debian Linux system.
#
# This script is called from /usr/src/linux/arch/i386/boot/install.sh.
# If you install it as /sbin/installkernel, you can do a "make install"
# from a generic kernel source tree, and the image will be installed to
# the proper place for Debian Linux.

if [ $# = 4 ] ; then
    img="$2"
    map="$3"
    ver="$1"
    # $(INSTALL_PATH), passed as $4, is ignored--Debian Linux uses /boot.
else
    echo "Usage: installkernel <version> <zImage> <System.map> <directory>"
    exit 1
fi

if [ -f /boot/vmlinuz-$ver ] ; then
    mv /boot/vmlinuz-$ver /boot/vmlinuz-$ver.old
fi
if [ -f /boot/System.map-$ver ] ; then
    mv /boot/System.map-$ver /boot/System.map-$ver.old
fi
cat $img > /boot/vmlinuz-$ver

if [ -f /boot/vmlinuz ] ; then
    if [ -L /boot/vmlinuz -a $(ls -l /boot/vmlinuz | awk '{print $11}') \
	    = vmlinuz-$ver ] ; then
	ln -sf vmlinuz-$ver.old /boot/vmlinuz.old
    else
	mv /boot/vmlinuz /boot/vmlinuz.old
    fi
fi
ln -sf vmlinuz-$ver /boot/vmlinuz

if [ $map ] ; then
    cp $map /boot/System.map-$ver
fi

mkboot -installkernel

if [ -x /sbin/psupdate -a -f /usr/src/linux/vmlinux ] ; then
    /sbin/psupdate
fi
