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

Legend:
Removed from v.923  
changed lines
  Added in v.1716