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 |
223 |
|
|
224 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
225 |
then |
then |
226 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
227 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
228 |
then |
then |
229 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
230 |
|
elif [[ $(read_os_release id) = magellan ]] |
231 |
|
then |
232 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
233 |
else |
else |
234 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
235 |
fi |
fi |
236 |
${grubby} --grub -c ${grubConfig} \ |
${grubby} --grub -c ${grubConfig} \ |
237 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
247 |
|
|
248 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
249 |
then |
then |
250 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
251 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
252 |
then |
then |
253 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
254 |
|
elif [[ $(read_os_release id) = magellan ]] |
255 |
|
then |
256 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
257 |
else |
else |
258 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
259 |
fi |
fi |
260 |
${grubby} --grub2 -c ${grub2Config} \ |
${grubby} --grub2 -c ${grub2Config} \ |
261 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
272 |
|
|
273 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
274 |
then |
then |
275 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
276 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
277 |
then |
then |
278 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
279 |
|
elif [[ $(read_os_release id) = magellan ]] |
280 |
|
then |
281 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
282 |
else |
else |
283 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
284 |
fi |
fi |
285 |
${grubby} --grub2 -c ${grub2EfiConfig} \ |
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
286 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
287 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
288 |
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
322 |
|
|
323 |
if [[ -n ${banner} ]] |
if [[ -n ${banner} ]] |
324 |
then |
then |
325 |
title="${banner} (${version})" |
title="${banner} [ ${version} ]" |
326 |
elif [ -f /etc/mageversion ] |
elif [ -f /etc/mageversion ] |
327 |
then |
then |
328 |
title="Magellan Linux $(< /etc/mageversion) (${version})" |
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
329 |
|
elif [[ $(read_os_release id) = magellan ]] |
330 |
|
then |
331 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
332 |
else |
else |
333 |
title="Magellan Linux (${version})" |
title="Magellan Linux [ ${version} ]" |
334 |
fi |
fi |
335 |
${grubby} --extlinux -c ${extlinuxConfig} \ |
${grubby} --extlinux -c ${extlinuxConfig} \ |
336 |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
--add-kernel=${bootPrefix}/${kernelName}-${version} \ |
371 |
if [[ -n ${cfgGrub2Efi} ]] |
if [[ -n ${cfgGrub2Efi} ]] |
372 |
then |
then |
373 |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}" |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}" |
374 |
${grubby} --grub2 -c ${grub2EfiConfig} \ |
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
375 |
--remove-kernel=${bootPrefix}/${kernelName}-${version} |
--remove-kernel=${bootPrefix}/${kernelName}-${version} |
376 |
else |
else |
377 |
[[ -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" |
404 |
then |
then |
405 |
tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
406 |
curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
407 |
sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
408 |
newversion=$(tail -n1 ${tmpKList}) |
newversion=$(tail -n1 ${tmpKList}) |
409 |
if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
410 |
then |
then |
444 |
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
445 |
fi |
fi |
446 |
else |
else |
447 |
[[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!" |
[[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!" |
448 |
fi |
fi |
449 |
else |
else |
450 |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
507 |
if [[ -n ${cfgGrub2Efi} ]] |
if [[ -n ${cfgGrub2Efi} ]] |
508 |
then |
then |
509 |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}" |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}" |
510 |
${grubby} --grub2 -c ${grub2EfiConfig} \ |
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
511 |
--update-kernel=${bootPrefix}/${kernelName}-${version} \ |
--update-kernel=${bootPrefix}/${kernelName}-${version} \ |
512 |
${INITRD} \ |
${INITRD} \ |
513 |
${kernargs:+--args="${kernargs}"} \ |
${kernargs:+--args="${kernargs}"} \ |
544 |
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
545 |
|
|
546 |
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
547 |
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \ |
mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \ |
548 |
-n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
-e ${ubootAddress} -n ${version} \ |
549 |
|
-d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
550 |
|
|
551 |
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
552 |
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 \ |
585 |
fi |
fi |
586 |
} |
} |
587 |
|
|
588 |
mkinitrd() |
makeinitrd() |
589 |
{ |
{ |
590 |
if [[ -n ${dracut} ]] |
if [[ -n ${dracut} ]] |
591 |
then |
then |
800 |
# add dracut i18n, keyboard and plymouth kernel args if requested |
# add dracut i18n, keyboard and plymouth kernel args if requested |
801 |
if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]] |
if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]] |
802 |
then |
then |
803 |
[ -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} ]] |
|
804 |
then |
then |
805 |
kernargs="${kernargs} KEYTABLE=${KEYMAP}" |
. /etc/vconsole.conf |
806 |
|
|
807 |
|
for i in SYSFONT SYSFONTACM UNIMAP KEYTABLE |
808 |
|
do |
809 |
|
val=$(eval echo \$$i) |
810 |
|
[[ -n ${val} ]] && kernargs="${kernargs} ${i}=${val}" |
811 |
|
done |
812 |
|
else |
813 |
|
if [ -r /etc/conf.d/consolefont ] |
814 |
|
then |
815 |
|
. /etc/conf.d/consolefont |
816 |
|
|
817 |
|
if [[ -n ${CONSOLEFONT} ]] |
818 |
|
then |
819 |
|
kernargs="${kernargs} SYSFONT=${CONSOLEFONT}" |
820 |
|
fi |
821 |
|
fi |
822 |
|
|
823 |
|
if [ -r /etc/conf.d/keymap ] |
824 |
|
then |
825 |
|
. /etc/conf.d/keymap |
826 |
|
|
827 |
|
if [[ -n ${KEYMAP} ]] |
828 |
|
then |
829 |
|
kernargs="${kernargs} KEYTABLE=${KEYMAP}" |
830 |
|
fi |
831 |
|
fi |
832 |
fi |
fi |
833 |
|
|
834 |
if [[ -n ${CONSOLEFONT} ]] |
if [ -r /etc/locale.conf ] |
835 |
then |
then |
836 |
kernargs="${kernargs} SYSFONT=${CONSOLEFONT}" |
. /etc/locale.conf |
837 |
|
|
838 |
|
if [[ -n ${LANG} ]] |
839 |
|
then |
840 |
|
kernargs="${kernargs} LANG=${LANG}" |
841 |
|
fi |
842 |
fi |
fi |
843 |
fi |
fi |
844 |
|
|
860 |
|
|
861 |
if [[ ${initrd} = make ]] |
if [[ ${initrd} = make ]] |
862 |
then |
then |
863 |
mkinitrd |
makeinitrd |
864 |
elif [[ ${initrd} = remove ]] |
elif [[ ${initrd} = remove ]] |
865 |
then |
then |
866 |
rminitrd |
rminitrd |
878 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
879 |
[[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
[[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
880 |
|
|
881 |
# 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 |
882 |
# 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. |
883 |
if [[ -n ${ubootDir} ]] |
if [[ -n ${ubootDir} ]] |
884 |
then |
then |
885 |
mountEntry=$(mount | grep ${ubootDir}) |
if [ -f ${ubootScript} ] |
|
if [[ -z ${mountEntry} ]] |
|
886 |
then |
then |
887 |
mount ${ubootDevice} ${ubootDir} |
cfguBoot=1 |
888 |
mounted=1 |
else |
889 |
|
mountEntry=$(mount | grep ${ubootDir}) |
890 |
|
if [[ -z ${mountEntry} ]] |
891 |
|
then |
892 |
|
mount ${ubootDevice} ${ubootDir} |
893 |
|
mounted=1 |
894 |
|
fi |
895 |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
896 |
|
fi |
897 |
|
fi |
898 |
|
|
899 |
|
# if we're using U-Boot, check if the default load address should change |
900 |
|
if [[ -n ${cfguBoot} ]] && [[ -z ${UBOOT_IMGADDR} ]] |
901 |
|
then |
902 |
|
[[ ${version} =~ .([^.]*)$ ]] |
903 |
|
platform=${BASH_REMATCH[1]} |
904 |
|
# A few platforms use an alternate kernel load address |
905 |
|
if [[ ${platform} = omap ]] |
906 |
|
then |
907 |
|
ubootAddress=0x80008000 |
908 |
|
elif [[ ${platform} = imx ]] |
909 |
|
then |
910 |
|
ubootAddress=0x90008000 |
911 |
fi |
fi |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
|
912 |
fi |
fi |
913 |
|
|
914 |
# 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 |
929 |
update |
update |
930 |
fi |
fi |
931 |
|
|
932 |
|
# if we mounted the U-Boot directory, unmount it. |
933 |
|
[[ -n ${mounted} ]] && umount ${ubootDir} |
934 |
|
|
935 |
exit 0 |
exit 0 |