1 |
#!/bin/bash |
#!/bin/bash |
2 |
# |
# |
3 |
|
# new-kernel-pkg |
4 |
# Invoked upon installation or removal of a kernel package, the following |
# Invoked upon installation or removal of a kernel package, the following |
5 |
# tasks are/can be done here: |
# tasks are/can be done here: |
6 |
# creation/removal of initrd |
# creation/removal of initrd |
7 |
# run of depmod/removal of depmod generated files |
# run of depmod/removal of depmod generated files |
8 |
# addition/removal of kernel images from grub/lilo configuration (via grubby) |
# addition/removal of kernel images from grub/lilo configuration (via grubby) |
9 |
# |
# |
10 |
# Copyright (C) 2002-2005 Red Hat, Inc. |
# Copyright 2002-2008 Red Hat, Inc. All rights reserved. |
|
# |
|
11 |
# modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de> |
# modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de> |
12 |
# |
# |
13 |
|
# This program is free software; you can redistribute it and/or modify |
14 |
|
# it under the terms of the GNU General Public License as published by |
15 |
|
# the Free Software Foundation; either version 2 of the License, or |
16 |
|
# (at your option) any later version. |
17 |
|
# |
18 |
|
# This program is distributed in the hope that it will be useful, |
19 |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 |
|
# GNU General Public License for more details. |
22 |
|
# |
23 |
|
# You should have received a copy of the GNU General Public License |
24 |
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 |
|
# |
26 |
|
|
27 |
PATH=/sbin:/bin:$PATH |
PATH=/sbin:/bin:$PATH |
28 |
|
|
94 |
usage() { |
usage() { |
95 |
echo "Usage: `basename $0` [-v] [--mkinitrd] [--rminitrd]" >&2 |
echo "Usage: `basename $0` [-v] [--mkinitrd] [--rminitrd]" >&2 |
96 |
echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
97 |
echo " [--kernel-args=<args>] [--banner=<banner>]" >&2 |
echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
98 |
echo " [--multiboot=multiboot] [--mbargs=mbargs]" >&2 |
echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
99 |
echo " [--make-default] <--install | --remove> <kernel-version>" >&2 |
echo " [--mbargs=mbargs] [--make-default]" >&2 |
100 |
|
echo " <--install | --remove | --update> <kernel-version>" >&2 |
101 |
echo " (ex: `basename $0` --mkinitrd --depmod --install 2.4.7-2)" >&2 |
echo " (ex: `basename $0` --mkinitrd --depmod --install 2.4.7-2)" >&2 |
102 |
exit 1 |
exit 1 |
103 |
} |
} |
108 |
[ -n "$verbose" ] && echo "kernel for $version does not exist, not running grubby" |
[ -n "$verbose" ] && echo "kernel for $version does not exist, not running grubby" |
109 |
return |
return |
110 |
fi |
fi |
111 |
|
|
112 |
INITRD="" |
INITRD="" |
113 |
if [ -f $initrdfile ]; then |
if [ -f $initrdfile ]; then |
114 |
[ -n "$verbose" ] && echo "found $initrdfile and using it with grubby" |
[ -n "$verbose" ] && echo "found $initrdfile and using it with grubby" |
129 |
return |
return |
130 |
fi |
fi |
131 |
|
|
132 |
# get the root filesystem to use; if it's on a label make sure it's |
# get the root filesystem to use |
|
# been configured. if not, get the root device from mount |
|
133 |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
|
short=$(echo $rootdevice | cut -d= -f1) |
|
|
if [ "$short" == "LABEL" ]; then |
|
|
label=$(echo $rootdevice | cut -d= -f2 |head -n 1) |
|
|
device=$(echo "showlabels" | /sbin/nash --force --quiet | |
|
|
awk '$2 == "'$label'" {print $1}') |
|
|
if [ -z "$device" ]; then |
|
|
rootdevice=$(mount | awk '$3 == "/" { print $1 }') |
|
|
fi |
|
|
fi |
|
134 |
|
|
135 |
if [ -n "$mbkernel" ]; then |
if [ -n "$mbkernel" -a -n "$cfgLilo" -a "$liloFlag" != "elilo" ]; then |
|
mb="--add-multiboot=$mbkernel" |
|
|
if [ -n "$mbargs" ]; then |
|
|
mb="$mb --mbargs=$mbargs" |
|
|
fi |
|
136 |
[ -n "$verbose" ] && echo "multiboot specified, not updating lilo.conf" |
[ -n "$verbose" ] && echo "multiboot specified, not updating lilo.conf" |
137 |
cfgLilo="" |
cfgLilo="" |
138 |
fi |
fi |
143 |
if [ -n "$banner" ]; then |
if [ -n "$banner" ]; then |
144 |
title="$banner ($version)" |
title="$banner ($version)" |
145 |
elif [ -f /etc/mageversion ]; then |
elif [ -f /etc/mageversion ]; then |
146 |
title="Magellan Linux $(< /etc/mageversion) ($version)" |
title="Magellan Linux $(< /etc/mageversion) ($version)" |
147 |
else |
else |
148 |
title="Magellan Linux ($version)" |
title="Magellan Linux ($version)" |
149 |
fi |
fi |
150 |
/sbin/grubby --add-kernel=$bootPrefix/$kernelName-$version $INITRD \ |
$grubby --add-kernel=$bootPrefix/$kernelName-$version \ |
151 |
--copy-default $makedefault $mb --title "$title" \ |
$INITRD --copy-default $makedefault --title "$title" \ |
152 |
--args="root=$rootdevice $kernargs" \ |
${mbkernel:+--add-multiboot="$mbkernel"} ${mbargs:+--mbargs="$mbargs"} \ |
153 |
--remove-kernel="TITLE=$title" |
--args="root=$rootdevice $kernargs" --remove-kernel="TITLE=$title" |
154 |
else |
else |
155 |
[ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby" |
[ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby" |
156 |
fi |
fi |
158 |
if [ -n "$cfgLilo" ]; then |
if [ -n "$cfgLilo" ]; then |
159 |
[ -n "$verbose" ] && echo "adding $version to $liloConfig" |
[ -n "$verbose" ] && echo "adding $version to $liloConfig" |
160 |
|
|
161 |
/sbin/grubby --add-kernel=$bootPrefix/$kernelName-$version $INITRD \ |
$grubby --add-kernel=$bootPrefix/$kernelName-$version $INITRD \ |
162 |
--copy-default $makedefault --title $version \ |
--copy-default $makedefault --title $version \ |
163 |
--args="root=$rootdevice $kernargs" \ |
${mbkernel:+--add-multiboot="$mbkernel"} ${mbargs:+--mbargs="$mbargs"} \ |
164 |
--remove-kernel="TITLE=$version" \ |
--args="root=$rootdevice $kernargs" --remove-kernel="TITLE=$version" \ |
165 |
--$liloFlag |
--$liloFlag |
166 |
|
|
167 |
if [ -n "$runLilo" ]; then |
if [ -n "$runLilo" ]; then |
168 |
[ -n "$verbose" ] && echo "running $lilo" |
[ -n "$verbose" ] && echo "running $lilo" |
188 |
|
|
189 |
if [ -n "$cfgGrub" ]; then |
if [ -n "$cfgGrub" ]; then |
190 |
[ -n "$verbose" ] && echo "removing $version from $grubConfig" |
[ -n "$verbose" ] && echo "removing $version from $grubConfig" |
191 |
/sbin/grubby --remove-kernel=$bootPrefix/$kernelName-$version |
$grubby --remove-kernel=$bootPrefix/$kernelName-$version |
192 |
else |
else |
193 |
[ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby" |
[ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby" |
194 |
fi |
fi |
195 |
|
|
196 |
if [ -n "$cfgLilo" ]; then |
if [ -n "$cfgLilo" ]; then |
197 |
[ -n "$verbose" ] && echo "removing $version from $liloConfig" |
[ -n "$verbose" ] && echo "removing $version from $liloConfig" |
198 |
/sbin/grubby --remove-kernel=$bootPrefix/$kernelName-$version \ |
$grubby --remove-kernel=$bootPrefix/$kernelName-$version \ |
199 |
|
--$liloFlag |
200 |
|
|
201 |
|
if [ -n "$runLilo" ]; then |
202 |
|
[ -n "$verbose" ] && echo "running $lilo" |
203 |
|
if [ ! -x $lilo ] ; then |
204 |
|
[ -n "$verbose" ] && echo "$lilo does not exist" |
205 |
|
else |
206 |
|
$lilo > /dev/null |
207 |
|
fi |
208 |
|
fi |
209 |
|
else |
210 |
|
[ -n "$verbose" ] && echo "$liloConfig does not exist, not running grubby" |
211 |
|
fi |
212 |
|
} |
213 |
|
|
214 |
|
update() { |
215 |
|
if [ -n "$cfgGrub" ]; then |
216 |
|
[ -n "$verbose" ] && echo "updating $version from $grubConfig" |
217 |
|
$grubby --update-kernel=$bootPrefix/$kernelName-$version \ |
218 |
|
${kernargs:+--args="$kernargs"} \ |
219 |
|
${removeargs:+--remove-args="$removeargs"} |
220 |
|
else |
221 |
|
[ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby" |
222 |
|
fi |
223 |
|
|
224 |
|
if [ -n "$cfgLilo" ]; then |
225 |
|
[ -n "$verbose" ] && echo "updating $version from $liloConfig" |
226 |
|
$grubby --update-kernel=$bootPrefix/$kernelName-$version \ |
227 |
|
${kernargs:+--args="$kernargs"} \ |
228 |
|
${removeargs:+--remove-args="$removeargs"} \ |
229 |
--$liloFlag |
--$liloFlag |
230 |
|
|
231 |
if [ -n "$runLilo" ]; then |
if [ -n "$runLilo" ]; then |
295 |
fi |
fi |
296 |
;; |
;; |
297 |
|
|
298 |
|
--remove-args*) |
299 |
|
if echo $1 | grep '=' >/dev/null ; then |
300 |
|
removeargs=`echo $1 | sed 's/^--remove-args=//'` |
301 |
|
else |
302 |
|
removeargs=$2 |
303 |
|
shift |
304 |
|
fi |
305 |
|
;; |
306 |
|
|
307 |
--banner*) |
--banner*) |
308 |
if echo $1 | grep '=' >/dev/null ; then |
if echo $1 | grep '=' >/dev/null ; then |
309 |
banner=`echo $1 | sed 's/^--banner=//'` |
banner=`echo $1 | sed 's/^--banner=//'` |
327 |
if echo $1 |grep '=' >/dev/null; then |
if echo $1 |grep '=' >/dev/null; then |
328 |
mbargs=`echo $1 | sed 's/^--mbargs=//'` |
mbargs=`echo $1 | sed 's/^--mbargs=//'` |
329 |
else |
else |
330 |
mbargs=$2 |
mbargs="$2" |
331 |
shift |
shift |
332 |
fi |
fi |
333 |
;; |
;; |
350 |
else |
else |
351 |
package=$2 |
package=$2 |
352 |
shift |
shift |
353 |
fi |
fi |
354 |
;; |
;; |
355 |
|
|
356 |
-v) |
-v) |
372 |
done |
done |
373 |
|
|
374 |
# make sure the mode is valid |
# make sure the mode is valid |
375 |
if [ "$mode" != "--install" -a "$mode" != "--remove" ] ; then |
if [ "$mode" != "--install" -a "$mode" != "--remove" -a "$mode" != "--update" ] ; then |
376 |
usage |
usage |
377 |
fi |
fi |
378 |
|
|
384 |
usage |
usage |
385 |
fi |
fi |
386 |
|
|
|
# make sure that /dev/loop exist |
|
|
[[ ! -e /dev/loop ]] && modprobe loop |
|
|
|
|
387 |
kernelmajor=`echo $kernel | cut -d . -f 1,2` |
kernelmajor=`echo $kernel | cut -d . -f 1,2` |
388 |
|
|
389 |
# kernel image for 2.4 is vmlinux |
# kernel image for 2.4 is vmlinux |
390 |
if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then |
if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then |
391 |
if [ "$kernelmajor" == "2.4" ]; then |
if [ "$kernelmajor" == "2.4" ]; then |
392 |
kernelName=vmlinux |
kernelName=kernel |
393 |
fi |
fi |
394 |
fi |
fi |
395 |
|
|
396 |
|
|
397 |
# set the initrd file based on arch; ia64 is the only currently known oddball |
# set the initrd file based on arch; ia64 is the only currently known oddball |
398 |
if [ -z "$initrdfile" ]; then |
if [ -z "$initrdfile" ]; then |
399 |
|
INITRD_NAME_PREFIX="initrd" |
400 |
|
|
401 |
if [ `uname -m` = "ia64" ]; then |
if [ `uname -m` = "ia64" ]; then |
402 |
initrdfile="/boot/efi/EFI/redhat/initrd-$version.img" |
initrdfile="/boot/efi/EFI/redhat/$INITRD_NAME_PREFIX-$version.img" |
403 |
else |
else |
404 |
initrdfile="/boot/initrd-$version.img" |
initrdfile="/boot/$INITRD_NAME_PREFIX-$version.img" |
405 |
fi |
fi |
406 |
|
|
407 |
fi |
fi |
430 |
exit 0 |
exit 0 |
431 |
fi |
fi |
432 |
|
|
|
|
|
433 |
[ -n "$grubConfig" ] && [ -f "$grubConfig" ] && cfgGrub=1; |
[ -n "$grubConfig" ] && [ -f "$grubConfig" ] && cfgGrub=1; |
434 |
[ -n "$liloConfig" ] && [ -f "$liloConfig" ] && cfgLilo=1; |
[ -n "$liloConfig" ] && [ -f "$liloConfig" ] && cfgLilo=1; |
435 |
|
|
443 |
install |
install |
444 |
elif [ "$mode" == "--remove" ]; then |
elif [ "$mode" == "--remove" ]; then |
445 |
remove |
remove |
446 |
|
elif [ "$mode" == "--update" ]; then |
447 |
|
update |
448 |
fi |
fi |
449 |
|
|
450 |
exit 0 |
exit 0 |