--- trunk/mkinitrd-magellan/installkernel 2007/09/01 22:45:15 532
+++ trunk/grubby/installkernel 2012/02/18 01:09:18 1749
@@ -1,66 +1,98 @@
-#! /bin/sh
-
+#! /bin/bash
+#
+# /sbin/installkernel
+#
+# Copyright 2007-2008 Red Hat, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
#
-# /sbin/installkernel - written by tyson@rwii.com
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# Author(s): tyson@rwii.com
#
-usage() {
- echo "Usage: `basename $0` " >&2
- exit 1
+usage()
+{
+ echo "Usage: $(basename $0) " >&2
+ exit 1
}
cfgLoader=
-if [ -z "$INSTALL_PATH" -o "$INSTALL_PATH" == "/boot" ]; then
- INSTALL_PATH=/boot
- cfgLoader=1
+if [[ -z ${INSTALL_PATH} ]] || [[ ${INSTALL_PATH} = /boot ]]
+then
+ INSTALL_PATH=/boot
+ cfgLoader=1
fi
+LINK_PATH=/boot
+RELATIVE_PATH=$(echo "${INSTALL_PATH}/" | sed "s|^${LINK_PATH}/||")
KERNEL_VERSION=$1
BOOTIMAGE=$2
MAPFILE=$3
ARCH=$(uname -m)
-if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then
- KERNEL_NAME=vmlinux
+if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
+then
+ KERNEL_NAME=kernel
else
- KERNEL_NAME=vmlinuz
+ KERNEL_NAME=kernel
fi
-if [ -z "$KERNEL_VERSION" -o -z "$BOOTIMAGE" -o -z "$MAPFILE" ]; then
- usage
+if [[ -z ${KERNEL_VERSION} ]] || [[ -z ${BOOTIMAGE} ]] || [[ -z ${MAPFILE} ]]
+then
+ usage
fi
-if [ -f $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION ]; then
- mv $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION \
- $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION.old;
+if [[ -f ${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION} ]]
+then
+ mv ${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION} \
+ ${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION}.old
fi
-if [ ! -L $INSTALL_PATH/$KERNEL_NAME ]; then
- if [ -e $INSTALLPATH/$KERNEL_NAME ]; then
- mv $INSTALL_PATH/$KERNEL_NAME $INSTALL_PATH/$KERNEL_NAME.old
- fi
+if [ ! -L ${INSTALL_PATH}/${KERNEL_NAME} ]
+then
+ if [ -e ${INSTALLPATH}/${KERNEL_NAME} ]
+ then
+ mv ${INSTALL_PATH}/${KERNEL_NAME} ${INSTALL_PATH}/${KERNEL_NAME}.old
+ fi
fi
-ln -sf $KERNEL_NAME-$KERNEL_VERSION $INSTALL_PATH/$KERNEL_NAME
-
-if [ -f $INSTALL_PATH/System.map-$KERNEL_VERSION ]; then
- mv $INSTALL_PATH/System.map-$KERNEL_VERSION \
- $INSTALL_PATH/System.map-$KERNEL_VERSION.old;
+if [ -f ${INSTALL_PATH}/System.map-${KERNEL_VERSION} ]
+then
+ mv ${INSTALL_PATH}/System.map-${KERNEL_VERSION} \
+ ${INSTALL_PATH}/System.map-${KERNEL_VERSION}.old
fi
-if [ ! -L $INSTALL_PATH/System.map ]; then
- if [ -e $INSTALLPATH/System.map ]; then
- mv $INSTALL_PATH/System.map $INSTALL_PATH/System.map.old
- fi
+if [ ! -L ${INSTALL_PATH}/System.map ]
+then
+ if [ -e ${INSTALLPATH}/System.map ]
+ then
+ mv ${INSTALL_PATH}/System.map ${INSTALL_PATH}/System.map.old
+ fi
fi
-ln -sf System.map-$KERNEL_VERSION $INSTALL_PATH/System.map
+ln -sf ${RELATIVE_PATH}${INSTALL_PATH}/System.map-${KERNEL_VERSION} ${LINK_PATH}/System.map
-cat $BOOTIMAGE > $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION
-cp $MAPFILE $INSTALL_PATH/System.map-$KERNEL_VERSION
+cat ${BOOTIMAGE} > ${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION}
+cp ${MAPFILE} ${INSTALL_PATH}/System.map-${KERNEL_VERSION}
-ln -fs $KERNEL_NAME-$KERNEL_VERSION $INSTALL_PATH/$KERNEL_NAME
-ln -fs System.map-$KERNEL_VERSION $INSTALL_PATH/System.map
+ln -fs ${RELATIVE_PATH}${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION} ${LINK_PATH}/${KERNEL_NAME}
+ln -fs ${RELATIVE_PATH}${INSTALL_PATH}/System.map-${KERNEL_VERSION} ${LINK_PATH}/System.map
-if [ -n "$cfgLoader" -a -x /sbin/new-kernel-pkg ]; then
- /sbin/new-kernel-pkg --mkinitrd --depmod --install $KERNEL_VERSION
+if [[ -n ${cfgLoader} ]] && [[ -x /sbin/new-kernel-pkg ]]
+then
+ if [ -n "$(which dracut 2>/dev/null)" ]
+ then
+ new-kernel-pkg --mkinitrd --dracut --host-only --depmod --install ${KERNEL_VERSION}
+ else
+ new-kernel-pkg --mkinitrd --depmod --install ${KERNEL_VERSION}
+ fi
fi