1 |
#! /bin/sh |
#! /bin/bash |
2 |
|
# |
3 |
|
# /sbin/installkernel |
4 |
|
# |
5 |
|
# Copyright 2007-2008 Red Hat, Inc. All rights reserved. |
6 |
|
# |
7 |
|
# This program is free software; you can redistribute it and/or modify |
8 |
|
# it under the terms of the GNU General Public License as published by |
9 |
|
# the Free Software Foundation; either version 2 of the License, or |
10 |
|
# (at your option) any later version. |
11 |
# |
# |
12 |
# /sbin/installkernel - written by tyson@rwii.com |
# This program is distributed in the hope that it will be useful, |
13 |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
# GNU General Public License for more details. |
16 |
|
# |
17 |
|
# You should have received a copy of the GNU General Public License |
18 |
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 |
|
# |
20 |
|
# Author(s): tyson@rwii.com |
21 |
# |
# |
22 |
|
|
23 |
usage() { |
usage() |
24 |
echo "Usage: `basename $0` <kernel_version> <bootimage> <mapfile>" >&2 |
{ |
25 |
exit 1 |
echo "Usage: $(basename $0) <kernel_version> <bootimage> <mapfile>" >&2 |
26 |
|
exit 1 |
27 |
} |
} |
28 |
|
|
29 |
cfgLoader= |
cfgLoader= |
30 |
|
|
31 |
if [ -z "$INSTALL_PATH" -o "$INSTALL_PATH" == "/boot" ]; then |
if [[ -z ${INSTALL_PATH} ]] || [[ ${INSTALL_PATH} = /boot ]] |
32 |
INSTALL_PATH=/boot |
then |
33 |
cfgLoader=1 |
INSTALL_PATH=/boot |
34 |
|
cfgLoader=1 |
35 |
fi |
fi |
36 |
|
|
37 |
|
LINK_PATH=/boot |
38 |
|
RELATIVE_PATH=$(echo "${INSTALL_PATH}/" | sed "s|^${LINK_PATH}/||") |
39 |
KERNEL_VERSION=$1 |
KERNEL_VERSION=$1 |
40 |
BOOTIMAGE=$2 |
BOOTIMAGE=$2 |
41 |
MAPFILE=$3 |
MAPFILE=$3 |
42 |
ARCH=$(uname -m) |
ARCH=$(uname -m) |
43 |
if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then |
if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
44 |
KERNEL_NAME=vmlinux |
then |
45 |
|
KERNEL_NAME=kernel |
46 |
else |
else |
47 |
KERNEL_NAME=vmlinuz |
KERNEL_NAME=kernel |
48 |
fi |
fi |
49 |
|
|
50 |
if [ -z "$KERNEL_VERSION" -o -z "$BOOTIMAGE" -o -z "$MAPFILE" ]; then |
if [[ -z ${KERNEL_VERSION} ]] || [[ -z ${BOOTIMAGE} ]] || [[ -z ${MAPFILE} ]] |
51 |
usage |
then |
52 |
|
usage |
53 |
fi |
fi |
54 |
|
|
55 |
if [ -f $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION ]; then |
if [[ -f ${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION} ]] |
56 |
mv $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION \ |
then |
57 |
$INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION.old; |
mv ${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION} \ |
58 |
|
${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION}.old |
59 |
fi |
fi |
60 |
|
|
61 |
if [ ! -L $INSTALL_PATH/$KERNEL_NAME ]; then |
if [ ! -L ${INSTALL_PATH}/${KERNEL_NAME} ] |
62 |
if [ -e $INSTALLPATH/$KERNEL_NAME ]; then |
then |
63 |
mv $INSTALL_PATH/$KERNEL_NAME $INSTALL_PATH/$KERNEL_NAME.old |
if [ -e ${INSTALLPATH}/${KERNEL_NAME} ] |
64 |
fi |
then |
65 |
|
mv ${INSTALL_PATH}/${KERNEL_NAME} ${INSTALL_PATH}/${KERNEL_NAME}.old |
66 |
|
fi |
67 |
fi |
fi |
68 |
|
|
69 |
ln -sf $KERNEL_NAME-$KERNEL_VERSION $INSTALL_PATH/$KERNEL_NAME |
if [ -f ${INSTALL_PATH}/System.map-${KERNEL_VERSION} ] |
70 |
|
then |
71 |
if [ -f $INSTALL_PATH/System.map-$KERNEL_VERSION ]; then |
mv ${INSTALL_PATH}/System.map-${KERNEL_VERSION} \ |
72 |
mv $INSTALL_PATH/System.map-$KERNEL_VERSION \ |
${INSTALL_PATH}/System.map-${KERNEL_VERSION}.old |
|
$INSTALL_PATH/System.map-$KERNEL_VERSION.old; |
|
73 |
fi |
fi |
74 |
|
|
75 |
if [ ! -L $INSTALL_PATH/System.map ]; then |
if [ ! -L ${INSTALL_PATH}/System.map ] |
76 |
if [ -e $INSTALLPATH/System.map ]; then |
then |
77 |
mv $INSTALL_PATH/System.map $INSTALL_PATH/System.map.old |
if [ -e ${INSTALLPATH}/System.map ] |
78 |
fi |
then |
79 |
|
mv ${INSTALL_PATH}/System.map ${INSTALL_PATH}/System.map.old |
80 |
|
fi |
81 |
fi |
fi |
82 |
ln -sf System.map-$KERNEL_VERSION $INSTALL_PATH/System.map |
ln -sf ${RELATIVE_PATH}${INSTALL_PATH}/System.map-${KERNEL_VERSION} ${LINK_PATH}/System.map |
83 |
|
|
84 |
cat $BOOTIMAGE > $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION |
cat ${BOOTIMAGE} > ${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION} |
85 |
cp $MAPFILE $INSTALL_PATH/System.map-$KERNEL_VERSION |
cp ${MAPFILE} ${INSTALL_PATH}/System.map-${KERNEL_VERSION} |
86 |
|
|
87 |
ln -fs $KERNEL_NAME-$KERNEL_VERSION $INSTALL_PATH/$KERNEL_NAME |
ln -fs ${RELATIVE_PATH}${INSTALL_PATH}/${KERNEL_NAME}-${KERNEL_VERSION} ${LINK_PATH}/${KERNEL_NAME} |
88 |
ln -fs System.map-$KERNEL_VERSION $INSTALL_PATH/System.map |
ln -fs ${RELATIVE_PATH}${INSTALL_PATH}/System.map-${KERNEL_VERSION} ${LINK_PATH}/System.map |
89 |
|
|
90 |
if [ -n "$cfgLoader" -a -x /sbin/new-kernel-pkg ]; then |
if [[ -n ${cfgLoader} ]] && [[ -x /sbin/new-kernel-pkg ]] |
91 |
/sbin/new-kernel-pkg --mkinitrd --depmod --install $KERNEL_VERSION |
then |
92 |
|
if [ -n "$(which dracut 2>/dev/null)" ] |
93 |
|
then |
94 |
|
new-kernel-pkg --mkinitrd --dracut --host-only --depmod --install ${KERNEL_VERSION} |
95 |
|
else |
96 |
|
new-kernel-pkg --mkinitrd --depmod --install ${KERNEL_VERSION} |
97 |
|
fi |
98 |
fi |
fi |