Magellan Linux

Contents of /tags/grubby-8_36/new-kernel-pkg

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1778 - (show annotations) (download)
Sat Mar 3 16:05:42 2012 UTC (12 years, 2 months ago) by niro
Original Path: trunk/grubby/new-kernel-pkg
File size: 23494 byte(s)
-support /etc/os-release
1 #!/bin/bash
2 # $Id$
3 #
4 # new-kernel-pkg
5 # Invoked upon installation or removal of a kernel package, the following
6 # tasks are/can be done here:
7 # creation/removal of initrd
8 # run of depmod/removal of depmod generated files
9 # addition/removal of kernel images from grub/lilo configuration (via grubby)
10 #
11 # Copyright 2002-2008 Red Hat, Inc. All rights reserved.
12 # modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de>
13 #
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #
27
28 read_os_release()
29 {
30 local NAME
31 local ID
32 local Version
33 local Version_ID
34 local PRETTY_NAME
35 local ANSI_COLOR
36 local CPE_NAME
37
38 if [[ -f /etc/os-release ]]
39 then
40 source /etc/os-release
41
42 case $1 in
43 name) echo "${NAME}" ;;
44 id) echo "${ID}" ;;
45 version) echo "${Version}" ;;
46 version_id) echo "${Version_ID}" ;;
47 pretty_name) echo "${PRETTY_NAME}" ;;
48 ansi_color) echo "${ANSI_COLOR}" ;;
49 cpe_name) echo "${CPE_NAME}" ;;
50 esac
51 fi
52 }
53
54 PATH=/sbin:/bin:$PATH
55
56 lilo=/sbin/lilo
57
58 # some defaults that are sane for most arches
59 kernelName=kernel
60
61 if [ -x ./grubby ]
62 then
63 grubby=./grubby
64 else
65 grubby=/sbin/grubby
66 fi
67
68 [ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby
69 [ -f /etc/conf.d/grubby-uboot ] && . /etc/conf.d/grubby-uboot
70
71 cfgGrub2=""
72 cfgGrub2Efi=""
73 cfgGrub=""
74 cfgLilo=""
75 cfgExtlinux=""
76 cfguBoot=""
77 runLilo=""
78 grubConfig=""
79 grub2Config=""
80 grub2EfiConfig=""
81 extlinuxConfig=""
82
83 ARCH=$(uname -m)
84
85 if [[ ${ARCH} = ia64 ]]
86 then
87 liloConfig=/boot/efi/EFI/redhat/elilo.conf
88 bootPrefix=/boot/efi/EFI/redhat
89 liloFlag=elilo
90 isx86=""
91 elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
92 then
93 liloConfig=/etc/yaboot.conf
94 bootPrefix=/boot
95 lilo=/sbin/ybin
96 liloFlag=yaboot
97 runLilo="yes"
98 isx86=""
99 elif [[ ${ARCH} = sparc ]] || [[ ${ARCH} = sparc64 ]]
100 then
101 liloConfig=/etc/silo.conf
102 bootPrefix=/boot
103 liloFlag=silo
104 lilo=/sbin/silo
105 isx86=""
106 elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]]
107 then
108 liloConfig=/etc/zipl.conf
109 bootPrefix=/boot
110 liloFlag=zipl
111 lilo=/sbin/zipl
112 runLilo="yes"
113 isx86=""
114 elif [[ ${ARCH} = armv7l ]] || [[ ${ARCH} = armv7hl ]] || [[ ${ARCH} = armv5tel ]]
115 then
116 machine=$(grep "^Hardware" /proc/cpuinfo | sed 's/Hardware\s*:\s*//')
117 liloConfig=""
118 bootPrefix=/boot
119 ubootDir=${UBOOT_DIR:-"/boot/uboot"}
120 ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}
121 ubootKList=${UBOOT_KLIST:-"klist.txt"}
122 ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}
123 ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"}
124 ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"}
125 mounted=""
126 liloFlag=""
127 isx86=""
128 if [[ ${machine} == "OMAP3 Beagle Board" ]] || [[ ${machine} == "OMAP4 Panda board" ]]
129 then
130 ubootAddress=0x80008000
131 else
132 ubootAddress=0x00008000
133 fi
134 else
135 # this leaves i?86 and x86_64
136 liloConfig=/etc/lilo.conf
137 grubConfig=/boot/grub/grub.conf
138 grub2Config=/boot/grub/grub.cfg
139 grub2EfiConfig=/boot/grub/grub-efi.cfg
140 extlinuxConfig=/boot/extlinux/extlinux.conf
141 bootPrefix=/boot
142 liloFlag=lilo
143 isx86="yes"
144 fi
145
146 mode=""
147 version=""
148 initrd=""
149 dracut=""
150 dracuthostonly=""
151 initrdfile=""
152 moddep=""
153 verbose=""
154 makedefault=""
155 package=""
156 mbkernel="${HYPERVISOR}"
157 mbargs="${HYPERVISOR_ARGS}"
158 adddracutargs=""
159 addplymouthinitrd=""
160
161 usage()
162 {
163 echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2
164 echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2
165 echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2
166 echo " [--banner=<banner>] [--multiboot=multiboot]" >&2
167 echo " [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2
168 echo " [--add-plymouth-initrd]" >&2
169 echo " [--host-only]" >&2
170 echo " <--install | --remove | --update> <kernel-version>" >&2
171 echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2
172 exit 1
173 }
174
175 install()
176 {
177 # XXX kernel should be able to be specified also (or work right on ia64)
178 if [ ! -f ${bootPrefix}/${kernelName}-${version} ]
179 then
180 [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
181 return
182 fi
183
184 INITRD=""
185 if [ -f ${initrdfile} ]
186 then
187 [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
188 INITRD="--initrd ${initrdfile}"
189
190 if [[ -n ${addplymouthinitrd} ]]
191 then
192 INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
193 fi
194 fi
195
196 # FIXME: is this a good heuristic to find out if we're on iSeries?
197 if [ -d /proc/iSeries ]
198 then
199 [[ -n ${verbose} ]] && echo "On an iSeries, just making img file"
200 if [[ -z ${initrdfile} ]]
201 then
202 [[ -n ${verbose} ]] && echo "No initrd, just adding system map"
203 /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinitrd-${version}
204 else
205 /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinux.sm-${version}
206 /sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null
207 rm ${bootPrefix}/vmlinux.sm-${version}
208 fi
209 return
210 fi
211
212 # get the root filesystem to use
213 rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)
214
215 if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]
216 then
217 [[ -n ${verbose} ]] && echo "multiboot specified, not updating lilo.conf"
218 cfgLilo=""
219 fi
220
221 if [[ -n ${cfgGrub} ]]
222 then
223 [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}"
224
225 if [[ -n ${banner} ]]
226 then
227 title="${banner} [ ${version} ]"
228 elif [ -f /etc/mageversion ]
229 then
230 title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
231 elif [[ $(read_os_release id) = magellan ]]
232 then
233 title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
234 else
235 title="Magellan Linux [ ${version} ]"
236 fi
237 ${grubby} --grub -c ${grubConfig} \
238 --add-kernel=${bootPrefix}/${kernelName}-${version} \
239 ${INITRD} --copy-default ${makedefault} --title "${title}" \
240 ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
241 --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
242 else
243 [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
244 fi
245 if [[ -n ${cfgGrub2} ]]
246 then
247 [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}"
248
249 if [[ -n ${banner} ]]
250 then
251 title="${banner} [ ${version} ]"
252 elif [ -f /etc/mageversion ]
253 then
254 title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
255 elif [[ $(read_os_release id) = magellan ]]
256 then
257 title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
258 else
259 title="Magellan Linux [ ${version} ]"
260 fi
261 ${grubby} --grub2 -c ${grub2Config} \
262 --add-kernel=${bootPrefix}/${kernelName}-${version} \
263 ${INITRD} --copy-default ${makedefault} --title "${title}" \
264 ${mbkernel:+--add-multiboot="${mbkernel}"} \
265 ${mbargs:+--mbargs="${mbargs}"} \
266 --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
267 else
268 [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
269 fi
270 if [[ -n ${cfgGrub2Efi} ]]
271 then
272 [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}"
273
274 if [[ -n ${banner} ]]
275 then
276 title="${banner} [ ${version} ]"
277 elif [ -f /etc/mageversion ]
278 then
279 title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
280 elif [[ $(read_os_release id) = magellan ]]
281 then
282 title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
283 else
284 title="Magellan Linux [ ${version} ]"
285 fi
286 ${grubby} --grub2 -c ${grub2EfiConfig} \
287 --add-kernel=${bootPrefix}/${kernelName}-${version} \
288 ${INITRD} --copy-default ${makedefault} --title "${title}" \
289 ${mbkernel:+--add-multiboot="${mbkernel}"} \
290 ${mbargs:+--mbargs="${mbargs}"} \
291 --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
292 else
293 [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI"
294 fi
295
296 if [[ -n ${cfgLilo} ]]
297 then
298 [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}"
299
300 ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} ${INITRD} \
301 --copy-default ${makedefault} --title ${version} \
302 ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
303 --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \
304 --${liloFlag}
305
306 if [[ -n ${runLilo} ]]
307 then
308 [[ -n ${verbose} ]] && echo "running ${lilo}"
309 if [ ! -x ${lilo} ]
310 then
311 [[ -n ${verbose} ]] && echo "${lilo} does not exist"
312 else
313 ${lilo} > /dev/null
314 fi
315 fi
316 else
317 [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
318 fi
319
320 if [[ -n ${cfgExtlinux} ]]
321 then
322 [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}"
323
324 if [[ -n ${banner} ]]
325 then
326 title="${banner} [ ${version} ]"
327 elif [ -f /etc/mageversion ]
328 then
329 title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
330 elif [[ $(read_os_release id) = magellan ]]
331 then
332 title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
333 else
334 title="Magellan Linux [ ${version} ]"
335 fi
336 ${grubby} --extlinux -c ${extlinuxConfig} \
337 --add-kernel=${bootPrefix}/${kernelName}-${version} \
338 ${INITRD} --copy-default ${makedefault} --title "${title}" \
339 ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
340 --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
341 else
342 [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
343 fi
344 }
345
346 remove()
347 {
348 # FIXME: is this a good heuristic to find out if we're on iSeries?
349 if [ -d /proc/iSeries ]
350 then
351 [[ -n ${verbose} ]] && echo "On an iSeries, remove img file"
352 rm -f ${bootPrefix}/${kernelName}-${version}.img 2>/dev/null
353 return
354 fi
355
356 if [[ -n ${cfgGrub} ]]
357 then
358 [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
359 ${grubby} --grub -c ${grubConfig} \
360 --remove-kernel=${bootPrefix}/${kernelName}-${version}
361 else
362 [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
363 fi
364 if [[ -n ${cfgGrub2} ]]
365 then
366 [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}"
367 ${grubby} --grub2 -c ${grub2Config} \
368 --remove-kernel=${bootPrefix}/${kernelName}-${version}
369 else
370 [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
371 fi
372 if [[ -n ${cfgGrub2Efi} ]]
373 then
374 [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"
375 ${grubby} --grub2 -c ${grub2EfiConfig} \
376 --remove-kernel=${bootPrefix}/${kernelName}-${version}
377 else
378 [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
379 fi
380
381 if [[ -n ${cfgLilo} ]]
382 then
383 [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}"
384 ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} --${liloFlag}
385
386 if [[ -n ${runLilo} ]]
387 then
388 [[ -n ${verbose} ]] && echo "running ${lilo}"
389 if [ ! -x ${lilo} ]
390 then
391 [[ -n ${verbose} ]] && echo "${lilo} does not exist"
392 else
393 ${lilo} > /dev/null
394 fi
395 fi
396 else
397 [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
398 fi
399
400 if [[ -n ${cfguBoot} ]]
401 then
402 [[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..."
403
404 if [ -f ${ubootDir}/${ubootKList} ]
405 then
406 tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
407 curversion=$(tail -n1 ${ubootDir}/${ubootKList})
408 sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList}
409 newversion=$(tail -n1 ${tmpKList})
410 if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
411 then
412 if [[ ${curversion} != ${newversion} ]]
413 then
414 cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage}
415 if [ $? -ne 0 ]
416 then
417 [[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit
418 fi
419 cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd}
420 if [ $? -ne 0 ]
421 then
422 [[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit
423 fi
424 fi
425
426 [[ -n ${verbose} ]] && echo "removing uImage-${version}"
427 if [ -f ${ubootDir}/uImage-${version} ]
428 then
429 rm -f ${ubootDir}/uImage-${version}
430 else
431 [[ -n ${verbose} ]] && echo "uImage-${version} did not exist!"
432 fi
433
434 [[ -n ${verbose} ]] && echo "removing uInitrd-${version}"
435 if [ -f ${ubootDir}/uInitrd-${version} ]
436 then
437 rm -f ${ubootDir}/uInitrd-${version}
438 else
439 [[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!"
440 fi
441
442 mv ${tmpKList} ${ubootDir}/${ubootKList}
443 else
444 [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!"
445 [ -f ${tmpKList} ] && rm -f ${tmpKList}
446 fi
447 else
448 [[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!"
449 fi
450 else
451 [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
452 fi
453
454 if [[ -n ${cfgExtlinux} ]]
455 then
456 [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}"
457 ${grubby} --extlinux -c ${extlinuxConfig} \
458 --remove-kernel=${bootPrefix}/${kernelName}-${version}
459 else
460 [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
461 fi
462 }
463
464 update()
465 {
466 if [ ! -f ${bootPrefix}/${kernelName}-${version} ]
467 then
468 [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
469 return
470 fi
471
472 INITRD=""
473 if [ -f ${initrdfile} ]
474 then
475 [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
476 INITRD="--initrd ${initrdfile}"
477
478 if [[ -n ${addplymouthinitrd} ]]
479 then
480 INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
481 fi
482 fi
483
484 if [[ -n ${cfgGrub} ]]
485 then
486 [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
487 ${grubby} --grub -c ${grubConfig} \
488 --update-kernel=${bootPrefix}/${kernelName}-${version} \
489 ${INITRD} \
490 ${kernargs:+--args="${kernargs}"} \
491 ${removeargs:+--remove-args="${removeargs}"}
492 else
493 [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
494 fi
495
496 if [[ -n ${cfgGrub2} ]]
497 then
498 [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}"
499 ${grubby} --grub2 -c ${grub2Config} \
500 --update-kernel=${bootPrefix}/${kernelName}-${version} \
501 ${INITRD} \
502 ${kernargs:+--args="${kernargs}"} \
503 ${removeargs:+--remove-args="${removeargs}"}
504 else
505 [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby"
506 fi
507
508 if [[ -n ${cfgGrub2Efi} ]]
509 then
510 [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"
511 ${grubby} --grub2 -c ${grub2EfiConfig} \
512 --update-kernel=${bootPrefix}/${kernelName}-${version} \
513 ${INITRD} \
514 ${kernargs:+--args="${kernargs}"} \
515 ${removeargs:+--remove-args="${removeargs}"}
516 else
517 [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby"
518 fi
519
520 if [[ -n ${cfgLilo} ]]
521 then
522 [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
523 ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \
524 ${INITRD} \
525 ${kernargs:+--args="${kernargs}"} \
526 ${removeargs:+--remove-args="${removeargs}"} \
527 --${liloFlag}
528
529 if [[ -n ${runLilo} ]]
530 then
531 [[ -n ${verbose} ]] && echo "running ${lilo}"
532 if [ ! -x ${lilo} ]
533 then
534 [[ -n ${verbose} ]] && echo "${lilo} does not exist"
535 else
536 ${lilo} > /dev/null
537 fi
538 fi
539 else
540 [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
541 fi
542
543 if [[ -n ${cfguBoot} ]]
544 then
545 [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
546
547 [[ -n ${verbose} ]] && echo "creating uImage-${version}"
548 mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \
549 -e ${ubootAddress} -n ${version} \
550 -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}
551
552 [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
553 mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
554 -n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version}
555
556 if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ]
557 then
558 cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage}
559 if [ $? -ne 0 ]
560 then
561 [[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit
562 fi
563 cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd}
564 if [ $? -ne 0 ]
565 then
566 [[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit
567 fi
568 echo ${version} >> ${ubootDir}/${ubootKList}
569 else
570 [[ -n ${verbose} ]] && echo "cannot make ${version} the default"
571 fi
572 else
573 [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
574 fi
575
576 if [[ -n ${cfgExtlinux} ]]
577 then
578 [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}"
579 ${grubby} --extlinux -c ${extlinuxConfig} \
580 --update-kernel=${bootPrefix}/${kernelName}-${version} \
581 ${INITRD} \
582 ${kernargs:+--args="${kernargs}"} \
583 ${removeargs:+--remove-args="${removeargs}"}
584 else
585 [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby"
586 fi
587 }
588
589 makeinitrd()
590 {
591 if [[ -n ${dracut} ]]
592 then
593 tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}"
594 else
595 tool="mkinitrd --allow-missing -f ${initrdfile} ${version}"
596 fi
597 [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
598 ${tool}
599 rc=$?
600 if [ ${rc} != 0 ]
601 then
602 echo "mkinitrd failed" >&2
603 exit 1
604 fi
605 }
606
607 rminitrd()
608 {
609 [[ -n ${verbose} ]] && echo "removing initrd ${initrdfile}"
610 [ -f ${initrdfile} ] && rm -f ${initrdfile}
611 }
612
613 doDepmod()
614 {
615 [[ -n ${verbose} ]] && echo "running depmod for ${version}"
616 depmod -ae -F /boot/System.map-${version} ${version}
617 }
618
619 doRmmoddep()
620 {
621 [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}"
622 [ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.*
623 }
624
625
626 while [ $# -gt 0 ]
627 do
628 case $1 in
629 --mkinitrd)
630 initrd="make"
631 ;;
632
633 --rminitrd)
634 initrd="remove"
635 ;;
636
637 --dracut)
638 dracut=--dracut
639 ;;
640
641 --host-only)
642 dracuthostonly=-H
643 ;;
644
645 --initrdfile*)
646 if echo $1 | grep '=' >/dev/null
647 then
648 initrdfile=$(echo $1 | sed 's/^--initrdfile=//')
649 else
650 initrdfile=$2
651 shift
652 fi
653 ;;
654
655 --kernel-args*)
656 if echo $1 | grep '=' >/dev/null
657 then
658 kernargs=$(echo $1 | sed 's/^--kernel-args=//')
659 else
660 kernargs=$2
661 shift
662 fi
663 ;;
664
665 --remove-args*)
666 if echo $1 | grep '=' >/dev/null
667 then
668 removeargs=$(echo $1 | sed 's/^--remove-args=//')
669 else
670 removeargs=$2
671 shift
672 fi
673 ;;
674
675 --banner*)
676 if echo $1 | grep '=' >/dev/null
677 then
678 banner=$(echo $1 | sed 's/^--banner=//')
679 else
680 banner=$2
681 shift
682 fi
683 ;;
684
685 --multiboot*)
686 if echo $1 |grep '=' >/dev/null
687 then
688 mbkernel=$(echo $1 | sed 's/^--multiboot=//')
689 else
690 # can't really support having an optional second arg here
691 # sorry!
692 mbkernel="/boot/xen.gz"
693 fi
694 ;;
695
696 --mbargs*)
697 if echo $1 |grep '=' >/dev/null
698 then
699 mbargs=$(echo $1 | sed 's/^--mbargs=//')
700 else
701 mbargs="$2"
702 shift
703 fi
704 ;;
705
706 --depmod)
707 moddep="make"
708 ;;
709
710 --rmmoddep)
711 moddep="remove"
712 ;;
713
714 --make-default)
715 makedefault="--make-default"
716 ;;
717
718 --package)
719 if echo $1 | grep '=' >/dev/null
720 then
721 package=$(echo $1 | sed 's/^--package=//')
722 else
723 package=$2
724 shift
725 fi
726 ;;
727
728 --add-dracut-args)
729 adddracutargs=--add-dracut-args
730 ;;
731
732 --add-plymouth-initrd)
733 addplymouthinitrd=--add-plymouth-initrd
734 ;;
735
736 -v)
737 verbose=-v
738 ;;
739
740 *)
741 if [[ -z ${mode} ]]
742 then
743 mode=$1
744 elif [[ -z ${version} ]]
745 then
746 version=$1
747 else
748 usage
749 fi
750 ;;
751 esac
752
753 shift
754 done
755
756 # make sure the mode is valid
757 if [[ ${mode} != --install ]] && [[ ${mode} != --remove ]] && [[ ${mode} != --update ]]
758 then
759 usage
760 fi
761
762 if [[ -z ${version} ]]
763 then
764 usage
765 fi
766
767 if [ "${mode}" != "--install" -a "${makedefault}" ]
768 then
769 usage
770 fi
771
772 kernelmajor=$(echo ${kernel} | cut -d . -f 1,2)
773
774 # kernel image for 2.4 is kernel
775 if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
776 then
777 if [[ ${kernelmajor} = 2.4 ]]
778 then
779 kernelName=kernel
780 fi
781 fi
782
783 # set the initrd file based on arch; ia64 is the only currently known oddball
784 if [[ -z ${initrdfile} ]]
785 then
786 INITRD_NAME_PREFIX="initrd"
787 if [[ -n ${dracut} ]]
788 then
789 INITRD_NAME_PREFIX="initramfs"
790 fi
791
792 if [[ $(uname -m) = ia64 ]]
793 then
794 initrdfile="/boot/efi/EFI/redhat/${INITRD_NAME_PREFIX}-${version}.img"
795 else
796 initrdfile="/boot/${INITRD_NAME_PREFIX}-${version}.img"
797 fi
798 fi
799 [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"
800
801 # add dracut i18n, keyboard and plymouth kernel args if requested
802 if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]]
803 then
804 [ -r /etc/conf.d/keymap ] && . /etc/conf.d/keymap
805 [ -r /etc/conf.d/consolefont ] && . /etc/conf.d/consolefont
806
807 if [[ -n ${KEYMAP} ]]
808 then
809 kernargs="${kernargs} KEYTABLE=${KEYMAP}"
810 fi
811
812 if [[ -n ${CONSOLEFONT} ]]
813 then
814 kernargs="${kernargs} SYSFONT=${CONSOLEFONT}"
815 fi
816 fi
817
818 # set this as the default if we have the package and it matches
819 if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] &&
820 [[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]]
821 then
822 makedefault="--make-default"
823 [[ -n ${verbose} ]] && echo "making it the default based on config"
824 fi
825
826 if [[ ${moddep} = make ]]
827 then
828 doDepmod
829 elif [[ ${moddep} = remove ]]
830 then
831 doRmmoddep
832 fi
833
834 if [[ ${initrd} = make ]]
835 then
836 makeinitrd
837 elif [[ ${initrd} = remove ]]
838 then
839 rminitrd
840 fi
841
842 if [ ! -x ${grubby} ]
843 then
844 [[ -n ${verbose} ]] && echo "${grubby} does not exist"
845 exit 0
846 fi
847
848 [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
849 [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
850 [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
851 [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
852 [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1
853
854 # if we have a U-Boot directory, but no boot script, check if the directory
855 # is mounted. If not, mount it, and then check if a boot script exists.
856 if [[ -n ${ubootDir} ]]
857 then
858 if [ -f ${ubootScript} ]
859 then
860 cfguBoot=1
861 else
862 mountEntry=$(mount | grep ${ubootDir})
863 if [[ -z ${mountEntry} ]]
864 then
865 mount ${ubootDevice} ${ubootDir}
866 mounted=1
867 fi
868 [ -f ${ubootScript} ] && cfguBoot=1
869 fi
870 fi
871
872 # if we have a lilo config on an x86 box, see if the default boot loader
873 # is lilo to determine if it should be run
874 if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]]
875 then
876 runLilo=$(${grubby} --bootloader-probe | grep lilo)
877 fi
878
879 if [[ ${mode} = --install ]]
880 then
881 install
882 elif [[ ${mode} = --remove ]]
883 then
884 remove
885 elif [[ ${mode} = --update ]]
886 then
887 update
888 fi
889
890 # if we mounted the U-Boot directory, unmount it.
891 [[ -n ${mounted} ]] && umount ${ubootDir}
892
893 exit 0

Properties

Name Value
svn:executable *