Magellan Linux

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

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