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="" |
grub2Config="" |
80 |
grub2EfiConfig="" |
grub2EfiConfig="" |
81 |
|
extlinuxConfig="" |
82 |
|
|
83 |
ARCH=$(uname -m) |
ARCH=$(uname -m) |
84 |
|
|
111 |
lilo=/sbin/zipl |
lilo=/sbin/zipl |
112 |
runLilo="yes" |
runLilo="yes" |
113 |
isx86="" |
isx86="" |
114 |
elif [[ ${ARCH} = armv7l ]] |
elif [[ ${ARCH} = armv7l ]] || [[ ${ARCH} = armv7hl ]] || [[ ${ARCH} = armv5tel ]] |
115 |
then |
then |
116 |
|
machine=$(grep "^Hardware" /proc/cpuinfo | sed 's/Hardware\s*:\s*//') |
117 |
liloConfig="" |
liloConfig="" |
118 |
bootPrefix=/boot |
bootPrefix=/boot |
119 |
ubootDir=${UBOOT_DIR:-"/boot/uboot"} |
ubootDir=${UBOOT_DIR:-"/boot/uboot"} |
125 |
mounted="" |
mounted="" |
126 |
liloFlag="" |
liloFlag="" |
127 |
isx86="" |
isx86="" |
128 |
|
if [[ ${machine} == "OMAP3 Beagle Board" ]] || [[ ${machine} == "OMAP4 Panda board" ]] |
129 |
|
then |
130 |
|
ubootAddress=0x80008000 |
131 |
|
else |
132 |
|
ubootAddress=0x00008000 |
133 |
|
fi |
134 |
else |
else |
135 |
# this leaves i?86 and x86_64 |
# this leaves i?86 and x86_64 |
136 |
liloConfig=/etc/lilo.conf |
liloConfig=/etc/lilo.conf |
137 |
grubConfig=/boot/grub/grub.conf |
grubConfig=/boot/grub/grub.conf |
138 |
grub2Config=/boot/grub/grub.cfg |
grub2Config=/boot/grub/grub.cfg |
139 |
grub2EfiConfig=/boot/grub/grub-efi.cfg |
grub2EfiConfig=/boot/grub/grub-efi.cfg |
140 |
|
extlinuxConfig=/boot/extlinux/extlinux.conf |
141 |
bootPrefix=/boot |
bootPrefix=/boot |
142 |
liloFlag=lilo |
liloFlag=lilo |
143 |
isx86="yes" |
isx86="yes" |
224 |
|
|
225 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
226 |
then |
then |
227 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
228 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
229 |
then |
then |
230 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
231 |
|
elif [[ $(read_os_release id) = magellan ]] |
232 |
|
then |
233 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
234 |
else |
else |
235 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
236 |
fi |
fi |
237 |
${grubby} --grub --add-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --grub -c ${grubConfig} \ |
238 |
|
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
239 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
240 |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
241 |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
248 |
|
|
249 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
250 |
then |
then |
251 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
252 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
253 |
then |
then |
254 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
255 |
|
elif [[ $(read_os_release id) = magellan ]] |
256 |
|
then |
257 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
258 |
else |
else |
259 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
260 |
fi |
fi |
261 |
${grubby} --grub2 -c ${grub2Config} \ |
${grubby} --grub2 -c ${grub2Config} \ |
262 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
273 |
|
|
274 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
275 |
then |
then |
276 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
277 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
278 |
then |
then |
279 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
280 |
|
elif [[ $(read_os_release id) = magellan ]] |
281 |
|
then |
282 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
283 |
else |
else |
284 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
285 |
fi |
fi |
286 |
${grubby} --grub2 -c ${grub2EfiConfig} \ |
${grubby} --grub2 -c ${grub2EfiConfig} \ |
287 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
316 |
else |
else |
317 |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
318 |
fi |
fi |
319 |
|
|
320 |
|
if [[ -n ${cfgExtlinux} ]] |
321 |
|
then |
322 |
|
[[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}" |
323 |
|
|
324 |
|
if [[ -n ${banner} ]] |
325 |
|
then |
326 |
|
title="${banner} [ ${version} ]" |
327 |
|
elif [ -f /etc/mageversion ] |
328 |
|
then |
329 |
|
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
330 |
|
elif [[ $(read_os_release id) = magellan ]] |
331 |
|
then |
332 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
333 |
|
else |
334 |
|
title="Magellan Linux [ ${version} ]" |
335 |
|
fi |
336 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
337 |
|
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
338 |
|
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
339 |
|
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
340 |
|
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
341 |
|
else |
342 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux" |
343 |
|
fi |
344 |
} |
} |
345 |
|
|
346 |
remove() |
remove() |
356 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
357 |
then |
then |
358 |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
359 |
${grubby} --grub --remove-kernel=${bootPrefix}/${kernelName}-${version} |
${grubby} --grub -c ${grubConfig} \ |
360 |
|
--remove-kernel=${bootPrefix}/${kernelName}-${version} |
361 |
else |
else |
362 |
[[ -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" |
363 |
fi |
fi |
445 |
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
446 |
fi |
fi |
447 |
else |
else |
448 |
[[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!" |
[[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!" |
449 |
fi |
fi |
450 |
else |
else |
451 |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
452 |
fi |
fi |
453 |
|
|
454 |
|
if [[ -n ${cfgExtlinux} ]] |
455 |
|
then |
456 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}" |
457 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
458 |
|
--remove-kernel=${bootPrefix}/${kernelName}-${version} |
459 |
|
else |
460 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux" |
461 |
|
fi |
462 |
} |
} |
463 |
|
|
464 |
update() |
update() |
484 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
485 |
then |
then |
486 |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
487 |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --grub -c ${grubConfig} \ |
488 |
|
--update-kernel=${bootPrefix}/${kernelName}-${version} \ |
489 |
${INITRD} \ |
${INITRD} \ |
490 |
${kernargs:+--args="${kernargs}"} \ |
${kernargs:+--args="${kernargs}"} \ |
491 |
${removeargs:+--remove-args="${removeargs}"} |
${removeargs:+--remove-args="${removeargs}"} |
545 |
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
546 |
|
|
547 |
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
548 |
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \ |
mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \ |
549 |
-n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
-e ${ubootAddress} -n ${version} \ |
550 |
|
-d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
551 |
|
|
552 |
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
553 |
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 \ |
572 |
else |
else |
573 |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}" |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}" |
574 |
fi |
fi |
575 |
|
|
576 |
|
if [[ -n ${cfgExtlinux} ]] |
577 |
|
then |
578 |
|
[[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}" |
579 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
580 |
|
--update-kernel=${bootPrefix}/${kernelName}-${version} \ |
581 |
|
${INITRD} \ |
582 |
|
${kernargs:+--args="${kernargs}"} \ |
583 |
|
${removeargs:+--remove-args="${removeargs}"} |
584 |
|
else |
585 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby" |
586 |
|
fi |
587 |
} |
} |
588 |
|
|
589 |
mkinitrd() |
makeinitrd() |
590 |
{ |
{ |
591 |
if [[ -n ${dracut} ]] |
if [[ -n ${dracut} ]] |
592 |
then |
then |
593 |
tool="/sbin/dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
594 |
else |
else |
595 |
tool="/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}" |
tool="mkinitrd --allow-missing -f ${initrdfile} ${version}" |
596 |
fi |
fi |
597 |
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
598 |
${tool} |
${tool} |
833 |
|
|
834 |
if [[ ${initrd} = make ]] |
if [[ ${initrd} = make ]] |
835 |
then |
then |
836 |
mkinitrd |
makeinitrd |
837 |
elif [[ ${initrd} = remove ]] |
elif [[ ${initrd} = remove ]] |
838 |
then |
then |
839 |
rminitrd |
rminitrd |
849 |
[[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1 |
[[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1 |
850 |
[[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1 |
[[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1 |
851 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
852 |
|
[[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
853 |
|
|
854 |
# 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 |
855 |
# 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. |
856 |
if [[ -n ${ubootDir} ]] |
if [[ -n ${ubootDir} ]] |
857 |
then |
then |
858 |
mountEntry=$(mount | grep ${ubootDir}) |
if [ -f ${ubootScript} ] |
|
if [[ -z ${mountEntry} ]] |
|
859 |
then |
then |
860 |
mount ${ubootDevice} ${ubootDir} |
cfguBoot=1 |
861 |
mounted=1 |
else |
862 |
|
mountEntry=$(mount | grep ${ubootDir}) |
863 |
|
if [[ -z ${mountEntry} ]] |
864 |
|
then |
865 |
|
mount ${ubootDevice} ${ubootDir} |
866 |
|
mounted=1 |
867 |
|
fi |
868 |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
869 |
fi |
fi |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
|
870 |
fi |
fi |
871 |
|
|
872 |
# 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 |
887 |
update |
update |
888 |
fi |
fi |
889 |
|
|
890 |
|
# if we mounted the U-Boot directory, unmount it. |
891 |
|
[[ -n ${mounted} ]] && umount ${ubootDir} |
892 |
|
|
893 |
exit 0 |
exit 0 |