Magellan Linux

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

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