summaryrefslogtreecommitdiff
path: root/system/syslinux/syslinux.post-upgrade
blob: 90388668de93c7112d698a8b030462a6951eac23 (plain) (blame)
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
#!/bin/sh

# find given append opt
get_append_opt() {
	awk -v search="$1" '
		$1 == "append" || $1 == "APPEND" {
		        split($0, a);
		        for (i in a) {
		                if (index(a[i], search) == 1) {
	        	                print a[i];
				}	
			}
		}' /boot/extlinux.conf | sort | uniq
}

# print default kernel options
get_default_opts() {
	awk '
		$1 == "append" || $1 == "APPEND" {
			opts="";
			space="";
		        split($0, a);
		        for (i in a) {
		                if (i != 1 \
				    && (index(a[i], "root=") != 1) \
				    && (index(a[i], "initrd=") != 1) \
				    && (index(a[i], "modules=") != 1)) {
	        	                opts = opts space a[i];
					space = " ";
				}
			}
			print opts;
		}
		' /boot/extlinux.conf | sort | uniq
}

if ! [ -f /boot/extlinux.conf ]; then
	exit 0
fi

# check if we already have a generated extlinux.conf
if grep -q '^# Generated by update-extlinux' /boot/extlinux.conf; then
	exit 0
fi

# try fish out the kernel opts from extlinuix.conf's append line
root=$(get_append_opt 'root=' | head -n 1)
modules=$(get_append_opt 'modules=' | head -n 1)
opts=$(get_default_opts | head -n 1)

# populate update-extlinux.conf with the info we know
if [ -n "$root" ]; then
	sed -i -e "/^root=/s|.*|$root|g" /etc/update-extlinux.conf
fi
if [ -n "$modules" ]; then
	sed -i -e "/^modules=/s|.*|$modules|g" /etc/update-extlinux.conf
fi
if [ -n "$opts" ]; then
	sed -i -e "/^default_kernel_opts=/s|.*|default_kernel_opts=\"$opts\"|g" /etc/update-extlinux.conf
fi