Magellan Linux

Diff of /trunk/grubby/new-kernel-pkg

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.532  
changed lines
  Added in v.1803