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

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