projects/aports·blob master · refs

61 lines · 1.5 KiB

1#!/bin/sh
2
3# find given append opt
4get_append_opt() {
5 awk -v search="$1" '
6 $1 == "append" || $1 == "APPEND" {
7 split($0, a);
8 for (i in a) {
9 if (index(a[i], search) == 1) {
10 print a[i];
11 }
12 }
13 }' /boot/extlinux.conf | sort | uniq
14}
15
16# print default kernel options
17get_default_opts() {
18 awk '
19 $1 == "append" || $1 == "APPEND" {
20 opts="";
21 space="";
22 split($0, a);
23 for (i in a) {
24 if (i != 1 \
25 && (index(a[i], "root=") != 1) \
26 && (index(a[i], "initrd=") != 1) \
27 && (index(a[i], "modules=") != 1)) {
28 opts = opts space a[i];
29 space = " ";
30 }
31 }
32 print opts;
33 }
34 ' /boot/extlinux.conf | sort | uniq
35}
36
37if ! [ -f /boot/extlinux.conf ]; then
38 exit 0
39fi
40
41# check if we already have a generated extlinux.conf
42if grep -q '^# Generated by update-extlinux' /boot/extlinux.conf; then
43 exit 0
44fi
45
46# try fish out the kernel opts from extlinuix.conf's append line
47root=$(get_append_opt 'root=' | head -n 1)
48modules=$(get_append_opt 'modules=' | head -n 1)
49opts=$(get_default_opts | head -n 1)
50
51# populate update-extlinux.conf with the info we know
52if [ -n "$root" ]; then
53 sed -i -e "/^root=/s|.*|$root|g" /etc/update-extlinux.conf
54fi
55if [ -n "$modules" ]; then
56 sed -i -e "/^modules=/s|.*|$modules|g" /etc/update-extlinux.conf
57fi
58if [ -n "$opts" ]; then
59 sed -i -e "/^default_kernel_opts=/s|.*|default_kernel_opts=\"$opts\"|g" /etc/update-extlinux.conf
60fi
61