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 |
72 |
cfgGrub2Efi="" |
cfgGrub2Efi="" |
73 |
cfgGrub="" |
cfgGrub="" |
74 |
cfgLilo="" |
cfgLilo="" |
75 |
|
cfgExtlinux="" |
76 |
cfguBoot="" |
cfguBoot="" |
77 |
runLilo="" |
runLilo="" |
78 |
grubConfig="" |
grubConfig="" |
79 |
|
grub2Config="" |
80 |
|
grub2EfiConfig="" |
81 |
|
extlinuxConfig="" |
82 |
|
|
83 |
ARCH=$(uname -m) |
ARCH=$(uname -m) |
84 |
|
|
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 |
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"} |
123 |
ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"} |
ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"} |
124 |
ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"} |
ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"} |
125 |
|
ubootAddress=${UBOOT_IMGADDR:-"0x00008000"} |
126 |
mounted="" |
mounted="" |
127 |
liloFlag="" |
liloFlag="" |
128 |
isx86="" |
isx86="" |
132 |
grubConfig=/boot/grub/grub.conf |
grubConfig=/boot/grub/grub.conf |
133 |
grub2Config=/boot/grub/grub.cfg |
grub2Config=/boot/grub/grub.cfg |
134 |
grub2EfiConfig=/boot/grub/grub-efi.cfg |
grub2EfiConfig=/boot/grub/grub-efi.cfg |
135 |
|
extlinuxConfig=/boot/extlinux/extlinux.conf |
136 |
bootPrefix=/boot |
bootPrefix=/boot |
137 |
liloFlag=lilo |
liloFlag=lilo |
138 |
isx86="yes" |
isx86="yes" |
148 |
verbose="" |
verbose="" |
149 |
makedefault="" |
makedefault="" |
150 |
package="" |
package="" |
151 |
mbkernel="" |
mbkernel="${HYPERVISOR}" |
152 |
mbargs="" |
mbargs="${HYPERVISOR_ARGS}" |
153 |
adddracutargs="" |
adddracutargs="" |
154 |
addplymouthinitrd="" |
addplymouthinitrd="" |
155 |
|
|
219 |
|
|
220 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
221 |
then |
then |
222 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
223 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
224 |
then |
then |
225 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
226 |
|
elif [[ $(read_os_release id) = magellan ]] |
227 |
|
then |
228 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
229 |
else |
else |
230 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
231 |
fi |
fi |
232 |
${grubby} --grub --add-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --grub -c ${grubConfig} \ |
233 |
|
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
234 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
235 |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
236 |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
243 |
|
|
244 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
245 |
then |
then |
246 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
247 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
248 |
then |
then |
249 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
250 |
|
elif [[ $(read_os_release id) = magellan ]] |
251 |
|
then |
252 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
253 |
else |
else |
254 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
255 |
fi |
fi |
256 |
${grubby} --grub2 -c ${grub2Cfg} \ |
${grubby} --grub2 -c ${grub2Config} \ |
257 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
258 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
259 |
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
268 |
|
|
269 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
270 |
then |
then |
271 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
272 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
273 |
then |
then |
274 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
275 |
|
elif [[ $(read_os_release id) = magellan ]] |
276 |
|
then |
277 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
278 |
else |
else |
279 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
280 |
fi |
fi |
281 |
${grubby} --grub2 -c ${grub2EfiCfg} \ |
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
282 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
283 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
284 |
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
311 |
else |
else |
312 |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
313 |
fi |
fi |
314 |
|
|
315 |
|
if [[ -n ${cfgExtlinux} ]] |
316 |
|
then |
317 |
|
[[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}" |
318 |
|
|
319 |
|
if [[ -n ${banner} ]] |
320 |
|
then |
321 |
|
title="${banner} [ ${version} ]" |
322 |
|
elif [ -f /etc/mageversion ] |
323 |
|
then |
324 |
|
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
325 |
|
elif [[ $(read_os_release id) = magellan ]] |
326 |
|
then |
327 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
328 |
|
else |
329 |
|
title="Magellan Linux [ ${version} ]" |
330 |
|
fi |
331 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
332 |
|
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
333 |
|
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
334 |
|
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
335 |
|
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
336 |
|
else |
337 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux" |
338 |
|
fi |
339 |
} |
} |
340 |
|
|
341 |
remove() |
remove() |
351 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
352 |
then |
then |
353 |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
354 |
${grubby} --grub --remove-kernel=${bootPrefix}/${kernelName}-${version} |
${grubby} --grub -c ${grubConfig} \ |
355 |
|
--remove-kernel=${bootPrefix}/${kernelName}-${version} |
356 |
else |
else |
357 |
[[ -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" |
358 |
fi |
fi |
400 |
then |
then |
401 |
tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
402 |
curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
403 |
sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
404 |
newversion=$(tail -n1 ${tmpKList}) |
newversion=$(tail -n1 ${tmpKList}) |
405 |
if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
406 |
then |
then |
440 |
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
441 |
fi |
fi |
442 |
else |
else |
443 |
[[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!" |
[[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!" |
444 |
fi |
fi |
445 |
else |
else |
446 |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
447 |
fi |
fi |
448 |
|
|
449 |
|
if [[ -n ${cfgExtlinux} ]] |
450 |
|
then |
451 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}" |
452 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
453 |
|
--remove-kernel=${bootPrefix}/${kernelName}-${version} |
454 |
|
else |
455 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux" |
456 |
|
fi |
457 |
} |
} |
458 |
|
|
459 |
update() |
update() |
479 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
480 |
then |
then |
481 |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
482 |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --grub -c ${grubConfig} \ |
483 |
|
--update-kernel=${bootPrefix}/${kernelName}-${version} \ |
484 |
${INITRD} \ |
${INITRD} \ |
485 |
${kernargs:+--args="${kernargs}"} \ |
${kernargs:+--args="${kernargs}"} \ |
486 |
${removeargs:+--remove-args="${removeargs}"} |
${removeargs:+--remove-args="${removeargs}"} |
540 |
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
541 |
|
|
542 |
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
543 |
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \ |
mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \ |
544 |
-n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
-e ${ubootAddress} -n ${version} \ |
545 |
|
-d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
546 |
|
|
547 |
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
548 |
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 \ |
567 |
else |
else |
568 |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}" |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}" |
569 |
fi |
fi |
570 |
|
|
571 |
|
if [[ -n ${cfgExtlinux} ]] |
572 |
|
then |
573 |
|
[[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}" |
574 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
575 |
|
--update-kernel=${bootPrefix}/${kernelName}-${version} \ |
576 |
|
${INITRD} \ |
577 |
|
${kernargs:+--args="${kernargs}"} \ |
578 |
|
${removeargs:+--remove-args="${removeargs}"} |
579 |
|
else |
580 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby" |
581 |
|
fi |
582 |
} |
} |
583 |
|
|
584 |
mkinitrd() |
makeinitrd() |
585 |
{ |
{ |
586 |
if [[ -n ${dracut} ]] |
if [[ -n ${dracut} ]] |
587 |
then |
then |
588 |
tool="/sbin/dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
589 |
else |
else |
590 |
tool="/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}" |
tool="mkinitrd --allow-missing -f ${initrdfile} ${version}" |
591 |
fi |
fi |
592 |
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
593 |
${tool} |
${tool} |
828 |
|
|
829 |
if [[ ${initrd} = make ]] |
if [[ ${initrd} = make ]] |
830 |
then |
then |
831 |
mkinitrd |
makeinitrd |
832 |
elif [[ ${initrd} = remove ]] |
elif [[ ${initrd} = remove ]] |
833 |
then |
then |
834 |
rminitrd |
rminitrd |
844 |
[[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1 |
[[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1 |
845 |
[[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1 |
[[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1 |
846 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
847 |
|
[[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
848 |
|
|
849 |
# 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 |
850 |
# 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. |
851 |
if [[ -n ${ubootDir} ]] |
if [[ -n ${ubootDir} ]] |
852 |
then |
then |
853 |
mountEntry=$(mount | grep ${ubootDir}) |
if [ -f ${ubootScript} ] |
|
if [[ -z ${mountEntry} ]] |
|
854 |
then |
then |
855 |
mount ${ubootDevice} ${ubootDir} |
cfguBoot=1 |
856 |
mounted=1 |
else |
857 |
|
mountEntry=$(mount | grep ${ubootDir}) |
858 |
|
if [[ -z ${mountEntry} ]] |
859 |
|
then |
860 |
|
mount ${ubootDevice} ${ubootDir} |
861 |
|
mounted=1 |
862 |
|
fi |
863 |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
864 |
|
fi |
865 |
|
fi |
866 |
|
|
867 |
|
# if we're using U-Boot, check if the default load address should change |
868 |
|
if [[ -n ${cfguBoot} ]] && [[ -z ${UBOOT_IMGADDR} ]] |
869 |
|
then |
870 |
|
[[ ${version} =~ .([^.]*)$ ]] |
871 |
|
platform=${BASH_REMATCH[1]} |
872 |
|
# A few platforms use an alternate kernel load address |
873 |
|
if [[ ${platform} = omap ]] |
874 |
|
then |
875 |
|
ubootAddress=0x80008000 |
876 |
|
elif [[ ${platform} = imx ]] |
877 |
|
then |
878 |
|
ubootAddress=0x90008000 |
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 |
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 |