-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-petitboot.sh
98 lines (83 loc) · 2.05 KB
/
update-petitboot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
set -e -u
if test -r /boot/update-petitboot.conf
then
. /boot/update-petitboot.conf
fi
: "${os_name:=Linux}"
: "${console:=hvc0}"
: "${default_console:=${consoles%%[= ]*}}"
{
printf 'default %s (%s)\n\n' "${os_name}" "${default_console}"
if test -e /boot/kernel
then
default_kernel_file=kernel
elif test -e /boot/vmlinuz
then
default_kernel_file=vmlinuz
elif test -e /boot/vmlinux
then
default_kernel_file=vmlinux
fi
if test -e /boot/initramfs
then
default_initramfs_file=initramfs
elif test -e /boot/initrd.img
then
default_initramfs_file=initrd.img
fi
for kernel in vmlinuz-* ${default_kernel_file:+${default_kernel_file}.old ${default_kernel_file}}
do
unset -v kernel_suffix kernel_version id console initrd args
case ${kernel}
in
(*.old)
kernel_suffix=old
kernel=${kernel%.${kernel_suffix}}
;;
esac
case ${kernel}
in
(vmlinuz-*)
kernel_version=${kernel#vmlinuz-}
;;
(${default_kernel_file-})
kernel_version=''
;;
esac
for console in ${consoles}
do
id=${kernel_version:+-${kernel_version}}${kernel_suffix:+.${kernel_suffix}}
image=${kernel}${kernel_suffix:+.${kernel_suffix}}
initrd=${default_initramfs_file}${id}${kernel_version:+.img}
test -f "/boot/${image}" || continue
args=$(
for c in ${consoles}
do
test "${c}" != "${console}" || continue
printf 'console=%s ' "${c#*=}"
done
# primary console
printf 'console=%s ' "${console#*=}"
)
printf 'name %s (%s%s)\n' "${os_name}" "${console%%=*}" "${id:+, ${id#?}}"
printf 'image %s\n' "/${image}"
if test -n "${initrd-}" -a -f "/boot/${initrd-}"
then
printf 'initrd %s\n' "/${initrd}"
else
: # error?
fi
printf 'args %s%s\n' "${args}" "${append-}"
printf '\n'
done
done
} >/boot/petitboot.conf.tmp || {
# petitboot.conf generation failed
rc=$?
test ! -f /boot/petitboot.conf.tmp || rm /boot/petitboot.conf.tmp
exit $((rc))
}
cp -p /boot/petitboot.conf /boot/petitboot.conf-
cat /boot/petitboot.conf.tmp >/boot/petitboot.conf
rm /boot/petitboot.conf.tmp