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 |
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="" |
205 |
fi |
fi |
206 |
|
|
207 |
# get the root filesystem to use |
# get the root filesystem to use |
208 |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab 2>/dev/null) |
209 |
|
if [[ -z $rootdevice ]] |
210 |
|
then |
211 |
|
rootdevice=$(grep -o -P "(?<=root=)\S+" /proc/cmdline) |
212 |
|
fi |
213 |
|
|
214 |
if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]] |
if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]] |
215 |
then |
then |
217 |
cfgLilo="" |
cfgLilo="" |
218 |
fi |
fi |
219 |
|
|
220 |
|
if [[ -n ${banner} ]] |
221 |
|
then |
222 |
|
title="${banner} [ ${version} ]" |
223 |
|
elif [[ $(read_os_release id) = magellan ]] |
224 |
|
then |
225 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
226 |
|
elif [ -f /etc/mageversion ] |
227 |
|
then |
228 |
|
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
229 |
|
else |
230 |
|
title="Magellan Linux [ ${version} ]" |
231 |
|
fi |
232 |
|
|
233 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
234 |
then |
then |
235 |
[[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}" |
[[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}" |
236 |
|
|
|
if [[ -n ${banner} ]] |
|
|
then |
|
|
title="${banner} (${version})" |
|
|
elif [ -f /etc/mageversion ] |
|
|
then |
|
|
title="Magellan Linux $(< /etc/mageversion) (${version})" |
|
|
else |
|
|
title="Magellan Linux (${version})" |
|
|
fi |
|
237 |
${grubby} --grub -c ${grubConfig} \ |
${grubby} --grub -c ${grubConfig} \ |
238 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
239 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
246 |
then |
then |
247 |
[[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}" |
[[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}" |
248 |
|
|
|
if [[ -n ${banner} ]] |
|
|
then |
|
|
title="${banner} (${version})" |
|
|
elif [ -f /etc/mageversion ] |
|
|
then |
|
|
title="Magellan Linux $(< /etc/mageversion) (${version})" |
|
|
else |
|
|
title="Magellan Linux (${version})" |
|
|
fi |
|
249 |
${grubby} --grub2 -c ${grub2Config} \ |
${grubby} --grub2 -c ${grub2Config} \ |
250 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
251 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
259 |
then |
then |
260 |
[[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}" |
[[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}" |
261 |
|
|
262 |
if [[ -n ${banner} ]] |
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
|
then |
|
|
title="${banner} (${version})" |
|
|
elif [ -f /etc/mageversion ] |
|
|
then |
|
|
title="Magellan Linux $(< /etc/mageversion) (${version})" |
|
|
else |
|
|
title="Magellan Linux (${version})" |
|
|
fi |
|
|
${grubby} --grub2 -c ${grub2EfiConfig} \ |
|
263 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
264 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
265 |
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
297 |
then |
then |
298 |
[[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}" |
[[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}" |
299 |
|
|
|
if [[ -n ${banner} ]] |
|
|
then |
|
|
title="${banner} (${version})" |
|
|
elif [ -f /etc/mageversion ] |
|
|
then |
|
|
title="Magellan Linux $(< /etc/mageversion) (${version})" |
|
|
else |
|
|
title="Magellan Linux (${version})" |
|
|
fi |
|
300 |
${grubby} --extlinux -c ${extlinuxConfig} \ |
${grubby} --extlinux -c ${extlinuxConfig} \ |
301 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
302 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
336 |
if [[ -n ${cfgGrub2Efi} ]] |
if [[ -n ${cfgGrub2Efi} ]] |
337 |
then |
then |
338 |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}" |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}" |
339 |
${grubby} --grub2 -c ${grub2EfiConfig} \ |
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
340 |
--remove-kernel=${bootPrefix}/${kernelName}-${version} |
--remove-kernel=${bootPrefix}/${kernelName}-${version} |
341 |
else |
else |
342 |
[[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI" |
[[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI" |
369 |
then |
then |
370 |
tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
371 |
curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
372 |
sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
373 |
newversion=$(tail -n1 ${tmpKList}) |
newversion=$(tail -n1 ${tmpKList}) |
374 |
if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
375 |
then |
then |
409 |
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
410 |
fi |
fi |
411 |
else |
else |
412 |
[[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!" |
[[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!" |
413 |
fi |
fi |
414 |
else |
else |
415 |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
472 |
if [[ -n ${cfgGrub2Efi} ]] |
if [[ -n ${cfgGrub2Efi} ]] |
473 |
then |
then |
474 |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}" |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}" |
475 |
${grubby} --grub2 -c ${grub2EfiConfig} \ |
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
476 |
--update-kernel=${bootPrefix}/${kernelName}-${version} \ |
--update-kernel=${bootPrefix}/${kernelName}-${version} \ |
477 |
${INITRD} \ |
${INITRD} \ |
478 |
${kernargs:+--args="${kernargs}"} \ |
${kernargs:+--args="${kernargs}"} \ |
509 |
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
510 |
|
|
511 |
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
512 |
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \ |
mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \ |
513 |
-n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
-e ${ubootAddress} -n ${version} \ |
514 |
|
-d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
515 |
|
|
516 |
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
517 |
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 \ |
550 |
fi |
fi |
551 |
} |
} |
552 |
|
|
553 |
mkinitrd() |
makeinitrd() |
554 |
{ |
{ |
555 |
if [[ -n ${dracut} ]] |
if [[ -n ${dracut} ]] |
556 |
then |
then |
765 |
# add dracut i18n, keyboard and plymouth kernel args if requested |
# add dracut i18n, keyboard and plymouth kernel args if requested |
766 |
if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]] |
if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]] |
767 |
then |
then |
768 |
[ -r /etc/conf.d/keymap ] && . /etc/conf.d/keymap |
if [ -r /etc/vconsole.conf ] |
|
[ -r /etc/conf.d/consolefont ] && . /etc/conf.d/consolefont |
|
|
|
|
|
if [[ -n ${KEYMAP} ]] |
|
769 |
then |
then |
770 |
kernargs="${kernargs} KEYTABLE=${KEYMAP}" |
. /etc/vconsole.conf |
771 |
|
|
772 |
|
for i in SYSFONT SYSFONTACM UNIMAP KEYTABLE |
773 |
|
do |
774 |
|
val=$(eval echo \$$i) |
775 |
|
[[ -n ${val} ]] && kernargs="${kernargs} ${i}=${val}" |
776 |
|
done |
777 |
|
else |
778 |
|
if [ -r /etc/conf.d/consolefont ] |
779 |
|
then |
780 |
|
. /etc/conf.d/consolefont |
781 |
|
|
782 |
|
if [[ -n ${CONSOLEFONT} ]] |
783 |
|
then |
784 |
|
kernargs="${kernargs} SYSFONT=${CONSOLEFONT}" |
785 |
|
fi |
786 |
|
fi |
787 |
|
|
788 |
|
if [ -r /etc/conf.d/keymap ] |
789 |
|
then |
790 |
|
. /etc/conf.d/keymap |
791 |
|
|
792 |
|
if [[ -n ${KEYMAP} ]] |
793 |
|
then |
794 |
|
kernargs="${kernargs} KEYTABLE=${KEYMAP}" |
795 |
|
fi |
796 |
|
fi |
797 |
fi |
fi |
798 |
|
|
799 |
if [[ -n ${CONSOLEFONT} ]] |
if [ -r /etc/locale.conf ] |
800 |
then |
then |
801 |
kernargs="${kernargs} SYSFONT=${CONSOLEFONT}" |
. /etc/locale.conf |
802 |
|
|
803 |
|
if [[ -n ${LANG} ]] |
804 |
|
then |
805 |
|
kernargs="${kernargs} LANG=${LANG}" |
806 |
|
fi |
807 |
fi |
fi |
808 |
fi |
fi |
809 |
|
|
825 |
|
|
826 |
if [[ ${initrd} = make ]] |
if [[ ${initrd} = make ]] |
827 |
then |
then |
828 |
mkinitrd |
makeinitrd |
829 |
elif [[ ${initrd} = remove ]] |
elif [[ ${initrd} = remove ]] |
830 |
then |
then |
831 |
rminitrd |
rminitrd |
843 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
844 |
[[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
[[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
845 |
|
|
846 |
# 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 |
847 |
# 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. |
848 |
if [[ -n ${ubootDir} ]] |
if [[ -n ${ubootDir} ]] |
849 |
then |
then |
850 |
mountEntry=$(mount | grep ${ubootDir}) |
if [ -f ${ubootScript} ] |
851 |
if [[ -z ${mountEntry} ]] |
then |
852 |
|
cfguBoot=1 |
853 |
|
else |
854 |
|
mountEntry=$(mount | grep ${ubootDir}) |
855 |
|
if [[ -z ${mountEntry} ]] |
856 |
|
then |
857 |
|
mount ${ubootDevice} ${ubootDir} |
858 |
|
mounted=1 |
859 |
|
fi |
860 |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
861 |
|
fi |
862 |
|
fi |
863 |
|
|
864 |
|
# if we're using U-Boot, check if the default load address should change |
865 |
|
if [[ -n ${cfguBoot} ]] && [[ -z ${UBOOT_IMGADDR} ]] |
866 |
|
then |
867 |
|
[[ ${version} =~ .([^.]*)$ ]] |
868 |
|
platform=${BASH_REMATCH[1]} |
869 |
|
# A few platforms use an alternate kernel load address |
870 |
|
if [[ ${platform} = omap ]] |
871 |
|
then |
872 |
|
ubootAddress=0x80008000 |
873 |
|
elif [[ ${platform} = imx ]] |
874 |
then |
then |
875 |
mount ${ubootDevice} ${ubootDir} |
ubootAddress=0x90008000 |
|
mounted=1 |
|
876 |
fi |
fi |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
|
877 |
fi |
fi |
878 |
|
|
879 |
# 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 |
894 |
update |
update |
895 |
fi |
fi |
896 |
|
|
897 |
|
# if we mounted the U-Boot directory, unmount it. |
898 |
|
[[ -n ${mounted} ]] && umount ${ubootDir} |
899 |
|
|
900 |
exit 0 |
exit 0 |