Magellan Linux

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

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

revision 1702 by niro, Sat Feb 18 00:21:34 2012 UTC revision 1848 by niro, Mon Jul 2 13:07:56 2012 UTC
# Line 25  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 46  cfgGrub2="" Line 72  cfgGrub2=""
72  cfgGrub2Efi=""  cfgGrub2Efi=""
73  cfgGrub=""  cfgGrub=""
74  cfgLilo=""  cfgLilo=""
75    cfgExtlinux=""
76  cfguBoot=""  cfguBoot=""
77  runLilo=""  runLilo=""
78  grubConfig=""  grubConfig=""
79  grub2Config=""  grub2Config=""
80  grub2EfiConfig=""  grub2EfiConfig=""
81    extlinuxConfig=""
82    
83  ARCH=$(uname -m)  ARCH=$(uname -m)
84    
# Line 63  then Line 91  then
91  elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]  elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
92  then  then
93   liloConfig=/etc/yaboot.conf   liloConfig=/etc/yaboot.conf
94     grub2Config=/boot/grub/grub.cfg
95   bootPrefix=/boot   bootPrefix=/boot
96   lilo=/sbin/ybin   lilo=/sbin/ybin
97   liloFlag=yaboot   liloFlag=yaboot
# Line 83  then Line 112  then
112   lilo=/sbin/zipl   lilo=/sbin/zipl
113   runLilo="yes"   runLilo="yes"
114   isx86=""   isx86=""
115  elif [[ ${ARCH} = armv7l ]]  elif [[ ${ARCH} =~ armv[5|7].*l ]]
116  then  then
117   liloConfig=""   liloConfig=""
118   bootPrefix=/boot   bootPrefix=/boot
119   ubootDir=${UBOOT_DIR:-"/boot/uboot"}   ubootDir=${UBOOT_DIR:-"/boot"}
120   ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}   ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}
121   ubootKList=${UBOOT_KLIST:-"klist.txt"}   ubootKList=${UBOOT_KLIST:-"klist.txt"}
122   ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}   ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}
# Line 96  then Line 125  then
125   mounted=""   mounted=""
126   liloFlag=""   liloFlag=""
127   isx86=""   isx86=""
128     if [[ -z ${UBOOT_IMGADDR} ]]
129     then
130     machine=${MACHINE:-$(grep "^Hardware" /proc/cpuinfo | sed 's/Hardware\s*:\s*//')}
131     # A few machines use an alternate kernel load address
132     if [[ "${machine}" =~ ^OMAP[3|4].* ]]
133     then
134     ubootAddress=0x80008000
135     elif [[ "${machine}" =~ ^Efika\ MX.* ]]
136     then
137     ubootAddress=0x90008000
138     else
139     ubootAddress=0x00008000
140     fi
141     else
142     ubootAddress="${UBOOT_IMGADDR}"
143     fi
144  else  else
145   # this leaves i?86 and x86_64   # this leaves i?86 and x86_64
146   liloConfig=/etc/lilo.conf   liloConfig=/etc/lilo.conf
147   grubConfig=/boot/grub/grub.conf   grubConfig=/boot/grub/grub.conf
148   grub2Config=/boot/grub/grub.cfg   grub2Config=/boot/grub/grub.cfg
149   grub2EfiConfig=/boot/grub/grub-efi.cfg   grub2EfiConfig=/boot/grub/grub-efi.cfg
150     extlinuxConfig=/boot/extlinux/extlinux.conf
151   bootPrefix=/boot   bootPrefix=/boot
152   liloFlag=lilo   liloFlag=lilo
153   isx86="yes"   isx86="yes"
# Line 117  moddep="" Line 163  moddep=""
163  verbose=""  verbose=""
164  makedefault=""  makedefault=""
165  package=""  package=""
166  mbkernel=""  mbkernel="${HYPERVISOR}"
167  mbargs=""  mbargs="${HYPERVISOR_ARGS}"
168  adddracutargs=""  adddracutargs=""
169  addplymouthinitrd=""  addplymouthinitrd=""
170    
# Line 188  install() Line 234  install()
234    
235   if [[ -n ${banner} ]]   if [[ -n ${banner} ]]
236   then   then
237   title="${banner} (${version})"   title="${banner} [ ${version} ]"
238   elif [ -f /etc/mageversion ]   elif [ -f /etc/mageversion ]
239   then   then
240   title="Magellan Linux $(< /etc/mageversion) (${version})"   title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
241     elif [[ $(read_os_release id) = magellan ]]
242     then
243     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
244   else   else
245   title="Magellan Linux (${version})"   title="Magellan Linux [ ${version} ]"
246   fi   fi
247   ${grubby} --grub --add-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub -c ${grubConfig} \
248     --add-kernel=${bootPrefix}/${kernelName}-${version} \
249   ${INITRD} --copy-default ${makedefault} --title "${title}" \   ${INITRD} --copy-default ${makedefault} --title "${title}" \
250   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
251   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
# Line 208  install() Line 258  install()
258    
259   if [[ -n ${banner} ]]   if [[ -n ${banner} ]]
260   then   then
261   title="${banner} (${version})"   title="${banner} [ ${version} ]"
262   elif [ -f /etc/mageversion ]   elif [ -f /etc/mageversion ]
263   then   then
264   title="Magellan Linux $(< /etc/mageversion) (${version})"   title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
265     elif [[ $(read_os_release id) = magellan ]]
266     then
267     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
268   else   else
269   title="Magellan Linux (${version})"   title="Magellan Linux [ ${version} ]"
270   fi   fi
271   ${grubby} --grub2 -c ${grub2Config} \   ${grubby} --grub2 -c ${grub2Config} \
272   --add-kernel=${bootPrefix}/${kernelName}-${version} \   --add-kernel=${bootPrefix}/${kernelName}-${version} \
# Line 230  install() Line 283  install()
283    
284   if [[ -n ${banner} ]]   if [[ -n ${banner} ]]
285   then   then
286   title="${banner} (${version})"   title="${banner} [ ${version} ]"
287   elif [ -f /etc/mageversion ]   elif [ -f /etc/mageversion ]
288   then   then
289   title="Magellan Linux $(< /etc/mageversion) (${version})"   title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
290     elif [[ $(read_os_release id) = magellan ]]
291     then
292     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
293   else   else
294   title="Magellan Linux (${version})"   title="Magellan Linux [ ${version} ]"
295   fi   fi
296   ${grubby} --grub2 -c ${grub2EfiConfig} \   ${grubby} --grub2 -c ${grub2EfiConfig} \
297   --add-kernel=${bootPrefix}/${kernelName}-${version} \   --add-kernel=${bootPrefix}/${kernelName}-${version} \
# Line 270  install() Line 326  install()
326   else   else
327   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
328   fi   fi
329    
330     if [[ -n ${cfgExtlinux} ]]
331     then
332     [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}"
333    
334     if [[ -n ${banner} ]]
335     then
336     title="${banner} [ ${version} ]"
337     elif [ -f /etc/mageversion ]
338     then
339     title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
340     elif [[ $(read_os_release id) = magellan ]]
341     then
342     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
343     else
344     title="Magellan Linux [ ${version} ]"
345     fi
346     ${grubby} --extlinux -c ${extlinuxConfig} \
347     --add-kernel=${bootPrefix}/${kernelName}-${version} \
348     ${INITRD} --copy-default ${makedefault} --title "${title}" \
349     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
350     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
351     else
352     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
353     fi
354  }  }
355    
356  remove()  remove()
# Line 285  remove() Line 366  remove()
366   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
367   then   then
368   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
369   ${grubby} --grub --remove-kernel=${bootPrefix}/${kernelName}-${version}   ${grubby} --grub -c ${grubConfig} \
370     --remove-kernel=${bootPrefix}/${kernelName}-${version}
371   else   else
372   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
373   fi   fi
# Line 333  remove() Line 415  remove()
415   then   then
416   tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)   tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
417   curversion=$(tail -n1 ${ubootDir}/${ubootKList})   curversion=$(tail -n1 ${ubootDir}/${ubootKList})
418   sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList}   sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList}
419   newversion=$(tail -n1 ${tmpKList})   newversion=$(tail -n1 ${tmpKList})
420   if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]   if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
421   then   then
# Line 373  remove() Line 455  remove()
455   [ -f ${tmpKList} ] && rm -f ${tmpKList}   [ -f ${tmpKList} ] && rm -f ${tmpKList}
456   fi   fi
457   else   else
458   [[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!"   [[ -n ${verbose} ]] && echo "No previous kernel version.  U-Boot images not removed!"
459   fi   fi
460   else   else
461   [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"   [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
462   fi   fi
463    
464     if [[ -n ${cfgExtlinux} ]]
465     then
466     [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}"
467     ${grubby} --extlinux -c ${extlinuxConfig} \
468     --remove-kernel=${bootPrefix}/${kernelName}-${version}
469     else
470     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
471     fi
472  }  }
473    
474  update()  update()
# Line 403  update() Line 494  update()
494   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
495   then   then
496   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
497   ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub -c ${grubConfig} \
498     --update-kernel=${bootPrefix}/${kernelName}-${version} \
499   ${INITRD} \   ${INITRD} \
500   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args="${kernargs}"} \
501   ${removeargs:+--remove-args="${removeargs}"}   ${removeargs:+--remove-args="${removeargs}"}
# Line 463  update() Line 555  update()
555   [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."   [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
556    
557   [[ -n ${verbose} ]] && echo "creating uImage-${version}"   [[ -n ${verbose} ]] && echo "creating uImage-${version}"
558   mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \   mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \
559   -n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}   -e ${ubootAddress} -n ${version} \
560     -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}
561    
562   [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"   [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
563   mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \   mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
# Line 489  update() Line 582  update()
582   else   else
583   [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"   [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
584   fi   fi
585    
586     if [[ -n ${cfgExtlinux} ]]
587     then
588     [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}"
589     ${grubby} --extlinux -c ${extlinuxConfig} \
590     --update-kernel=${bootPrefix}/${kernelName}-${version} \
591     ${INITRD} \
592     ${kernargs:+--args="${kernargs}"} \
593     ${removeargs:+--remove-args="${removeargs}"}
594     else
595     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby"
596     fi
597  }  }
598    
599  mkinitrd()  makeinitrd()
600  {  {
601   if [[ -n ${dracut} ]]   if [[ -n ${dracut} ]]
602   then   then
603   tool="/sbin/dracut ${dracuthostonly} -f ${initrdfile} ${version}"   tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}"
604   else   else
605   tool="/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}"   tool="mkinitrd --allow-missing -f ${initrdfile} ${version}"
606   fi   fi
607   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
608   ${tool}   ${tool}
# Line 738  fi Line 843  fi
843    
844  if [[ ${initrd} = make ]]  if [[ ${initrd} = make ]]
845  then  then
846   mkinitrd   makeinitrd
847  elif [[ ${initrd} = remove ]]  elif [[ ${initrd} = remove ]]
848  then  then
849   rminitrd   rminitrd
# Line 754  fi Line 859  fi
859  [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1  [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
860  [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1  [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
861  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
862    [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1
863    
864  # if we have a uBoot directory, check if it is mounted.  # if we have a U-Boot directory, but no boot script, check if the directory
865  # if not, mount it. Then check if a boot script exists.  # is mounted.  If not, mount it, and then check if a boot script exists.
866  if [[ -n ${ubootDir} ]]  if [[ -n ${ubootDir} ]]
867  then  then
868   mountEntry=$(mount | grep ${ubootDir})   if [ -f ${ubootScript} ]
  if [[ -z ${mountEntry} ]]  
869   then   then
870   mount ${ubootDevice} ${ubootDir}   cfguBoot=1
871   mounted=1   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   fi
  [ -f ${ubootScript} ] && cfguBoot=1  
880  fi  fi
881    
882  # 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
# Line 786  then Line 897  then
897   update   update
898  fi  fi
899    
900    # if we mounted the U-Boot directory, unmount it.
901    [[ -n ${mounted} ]] && umount ${ubootDir}
902    
903  exit 0  exit 0

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