projects/aports·blob master · refs

293 lines · 6.9 KiB

1#!/bin/sh
2
3version=
4default=0
5timeout=5
6verbose=0
7
8conf=/boot/extlinux.conf
9myconf=/etc/update-extlinux.conf
10
11# read in extlinux settings
12if [ -f "$myconf" ]; then
13 . $myconf
14fi
15
16everbose() {
17 if [ "$verbose" = "0" ]; then
18 return
19 fi
20
21 echo $*
22}
23
24ewarn() {
25 echo "WARNING:" $@ >&2
26}
27
28eerror() {
29 echo "ERROR:" $@ >&2
30 return 1
31}
32
33usage() {
34 echo "usage: $0 [-v|--verbose] [--warn-only]"
35}
36
37while [ $# -gt 0 ]; do
38 opt="$1"
39 shift
40 case "$opt" in
41 -v|--verbose)
42 verbose=1
43 ;;
44 --warn-only)
45 warn_only=1
46 ;;
47 --)
48 break
49 ;;
50 -*)
51 usage
52 exit 1
53 ;;
54 esac
55done
56
57everbose "Updating extlinux configuration."
58
59if [ "x$root" = "x" ]; then
60 ewarn "Root device is not specified in $myconf."
61 blkid_export=$(blkid -o export /dev/root)
62 if [ -n "$blkid_export" ]; then
63 export $blkid_export
64 fi
65 if [ -z "$UUID" ]; then
66 # try parse /proc/mount for mounted /
67 dev=$(awk '$2 == "/" {dev=$1} END {print dev}' /proc/mounts)
68 if [ -n "$dev" ]; then
69 blkid_export=$(blkid -o export $dev)
70 if [ -n "$blkid_export" ]; then
71 export "$blkid_export"
72 fi
73 fi
74 fi
75 if [ -z "$UUID" ]; then
76 if [ -z "$dev" ]; then
77 if [ -n "$warn_only" ]; then
78 ewarn "Failed to detect root device. extlinux.conf is not updated"
79 exit 0
80 else
81 eerror "Failed to detect root device"
82 exit 1
83 fi
84 else
85 root=$dev
86 fi
87 else
88 root=UUID=$UUID
89 fi
90 everbose "Root device is: $root"
91fi
92
93if [ -z "${timeout##*[!0-9]*}" ]; then
94 if [ -n "$warn_only" ]; then
95 ewarn "timeout ($timeout) must be an integer; flooring."
96 timeout=$(echo $timeout | cut -f1 -d.)
97 else
98 eerror "timeout ($timeout) must be an integer."
99 exit 1
100 fi
101fi
102rtimeout=$(( $timeout * 10 ))
103syslinux_menu=menu.c32
104menu_hidden=
105
106# vesa menu has been requested?
107if [ "$vesa_menu" = "1" ]; then
108 syslinux_menu=vesamenu.c32
109fi
110
111umask 0022
112rm -f $conf.new
113echo "# Generated by update-extlinux $version" > $conf.new
114if [ -n "$serial_port" ]; then
115 echo "SERIAL $serial_port ${serial_baud:-115200}" >> $conf.new
116fi
117echo "DEFAULT $syslinux_menu" >> $conf.new
118echo "PROMPT 0" >> $conf.new
119echo "MENU TITLE Alpine/$(uname -s) Boot Menu" >> $conf.new
120if [ "$hidden" = "1" ]; then
121 echo "MENU HIDDEN" >> $conf.new
122fi
123echo "MENU AUTOBOOT Alpine will be booted automatically in # seconds." >> $conf.new
124echo "TIMEOUT $rtimeout" >> $conf.new
125
126lst=0
127if [ -f "/boot/xen.gz" ]; then
128 for kernel in $(find /boot -name "vmlinuz-*" -type f); do
129 tag=$(basename $kernel | cut -b9-)
130 everbose "Found Xen hypervisor: /boot/xen.gz, kernel: $kernel"
131
132 if [ -f "/boot/initramfs-$tag" ]; then
133 everbose "Found initramfs: /boot/initramfs-$tag"
134 initramfs="initramfs-$tag"
135 else
136 initramfs=
137 fi
138 initramfs_stage="${initramfs:+---} $initramfs"
139
140 if [ -f "/boot/amd-ucode.img" ]; then
141 everbose "Found microcode for AMD CPUs: /boot/amd-ucode.img"
142 ucode_image_amd="amd-ucode.img"
143 case "$xen_opts" in
144 *ucode=scan* ) ;;
145 * ) xen_opts="$xen_opts ucode=scan" ;;
146 esac
147 fi
148 if [ -f "/boot/intel-ucode.img" ]; then
149 everbose "Found microcode for Intel CPUs: /boot/intel-ucode.img"
150 ucode_image_intel="intel-ucode.img"
151 case "$xen_opts" in
152 *ucode=scan* ) ;;
153 * ) xen_opts="$xen_opts ucode=scan" ;;
154 esac
155 fi
156 ucode_image_stage="${ucode_image_amd:+---} $ucode_image_amd ${ucode_image_intel:+---} $ucode_image_intel"
157
158 label=xen-$(grep -w -l $tag /usr/share/kernel/*/kernel.release \
159 | cut -d/ -f5)
160 if [ "$label" = "xen-" ]; then
161 label=xen-$lst
162 fi
163
164 dom0_kernel_stage="--- $(basename $kernel) root=$root modules=${modules}${TYPE:+,$TYPE} $default_kernel_opts"
165
166 echo "LABEL $label" >> $conf.new
167 if [ "$label" = "$default" ]; then
168 echo " MENU DEFAULT" >> $conf.new
169 fi
170 echo " MENU LABEL Xen + Linux $tag" >> $conf.new
171 echo " COM32 mboot.c32" >> $conf.new
172 echo " APPEND xen.gz $xen_opts $dom0_kernel_stage $initramfs_stage $ucode_image_stage" >> $conf.new
173 echo "" >> $conf.new
174 lst=$(($lst + 1))
175 done
176fi
177
178for kernel in $(find /boot -name "vmlinuz*" -type f); do
179 case $kernel in
180 *vmlinuz) tag=vanilla;;
181 *vmlinuz-*) tag=$(basename $kernel | cut -b9-);;
182 *) continue;;
183 esac
184 everbose "Found kernel: $kernel"
185 label=$(grep -w -l $tag /usr/share/kernel/*/kernel.release | cut -d/ -f5)
186 if [ -z "$label" ]; then
187 if [ "$tag" = vanilla ]; then
188 label="vanilla"
189 else
190 label=$lst
191 fi
192 fi
193 echo "LABEL $label" >> $conf.new
194 if [ "$label" = "$default" ]; then
195 echo " MENU DEFAULT" >> $conf.new
196 fi
197 echo " MENU LABEL Linux $tag" >> $conf.new
198 echo " LINUX $(basename $kernel)" >> $conf.new
199 initrd=
200 if [ -f "/boot/initramfs-$tag" ]; then
201 everbose "Found initramfs: /boot/initramfs-$tag"
202 initrd="initramfs-$tag"
203 fi
204 if [ -f "/boot/amd-ucode.img" ]; then
205 everbose "Found microcode for AMD CPUs: /boot/amd-ucode.img"
206 initrd="amd-ucode.img${initrd:+,}${initrd}"
207 fi
208 if [ -f "/boot/intel-ucode.img" ]; then
209 everbose "Found microcode for Intel CPUs: /boot/intel-ucode.img"
210 initrd="intel-ucode.img${initrd:+,}${initrd}"
211 fi
212 echo " INITRD ${initrd}" >> $conf.new
213 echo " APPEND root=$root modules=${modules}${TYPE:+,$TYPE} $default_kernel_opts" >> $conf.new
214 echo "" >> $conf.new
215 lst=$(($lst + 1))
216done
217
218if [ -n "$password" ]; then
219 echo "NOESCAPE 1" >> $conf.new
220 echo "MENU MASTER PASSWD $password" >> $conf.new
221 echo "" >> $conf.new
222 chmod o-r $conf.new
223fi
224
225everbose "$lst entries found."
226
227for entry in /etc/update-extlinux.d/*; do
228 [ -f "$entry" ] && { cat $entry; echo ""; } >> $conf.new
229done
230
231echo "MENU SEPARATOR" >> $conf.new
232echo "" >> $conf.new
233
234if [ -f "/boot/hdt.c32" ]; then
235 everbose "Found Hardware Detection Tool: /boot/hdt.c32"
236 echo "LABEL hdt" >> $conf.new
237 echo " MENU LABEL Hardware info" >> $conf.new
238 if [ -n "$password" ]; then
239 echo " MENU PASSWD" >> $conf.new
240 fi
241 echo " COM32 hdt.c32" >> $conf.new
242 if [ -f "/boot/memtest" ]; then
243 everbose "Found memtest86+: /boot/memtest"
244 echo " APPEND memtest=memtest" >> $conf.new
245 fi
246 echo "" >> $conf.new
247elif [ -f "/boot/memtest" ]; then
248 everbose "Found memtest86+: /boot/memtest"
249 echo "LABEL memtest" >> $conf.new
250 echo " MENU LABEL Memtest86+" >> $conf.new
251 echo " KERNEL memtest" >> $conf.new
252 echo "" >> $conf.new
253fi
254
255for i in reboot poweroff; do
256 [ -f "/boot/$i.c32" ] || continue
257 everbose "Found $i"
258 # make first char capital
259 cap=$( echo $i | awk '{sub(".", substr(toupper($0),1,1), $0); print}' )
260 echo "LABEL $i" >> $conf.new
261 echo " MENU LABEL $cap" >> $conf.new
262 echo " COM32 $i.c32" >> $conf.new
263 echo "" >> $conf.new
264done
265
266if cmp -s $conf.new $conf; then
267 everbose "Configuration unchanged."
268 rm $conf.new
269fi
270
271if [ "$overwrite" != "1" ]; then
272 exit 0
273elif [ -f "$conf.new" ]; then
274 # keep a backup just in case
275 if [ -f "$conf" ]; then
276 mv $conf $conf.old
277 fi
278
279 mv $conf.new $conf
280fi
281
282everbose "Installing libutil.c32 libcom32.c32 mboot.c32 menu.c32 vesamenu.c32 to /boot."
283cp /usr/share/syslinux/libutil.c32 \
284 /usr/share/syslinux/libcom32.c32 \
285 /usr/share/syslinux/mboot.c32 \
286 /usr/share/syslinux/menu.c32 \
287 /usr/share/syslinux/vesamenu.c32 \
288 /boot
289
290case "$(stat -f -c '%T' /boot)" in
291ext*) extlinux --update /boot || [ -n "$warn_only" ];;
292esac
293