| 1 | #!/bin/sh |
| 2 | |
| 3 | # find given append opt |
| 4 | get_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 |
| 17 | get_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 | |
| 37 | if ! [ -f /boot/extlinux.conf ]; then |
| 38 | exit 0 |
| 39 | fi |
| 40 | |
| 41 | # check if we already have a generated extlinux.conf |
| 42 | if grep -q '^# Generated by update-extlinux' /boot/extlinux.conf; then |
| 43 | exit 0 |
| 44 | fi |
| 45 | |
| 46 | # try fish out the kernel opts from extlinuix.conf's append line |
| 47 | root=$(get_append_opt 'root=' | head -n 1) |
| 48 | modules=$(get_append_opt 'modules=' | head -n 1) |
| 49 | opts=$(get_default_opts | head -n 1) |
| 50 | |
| 51 | # populate update-extlinux.conf with the info we know |
| 52 | if [ -n "$root" ]; then |
| 53 | sed -i -e "/^root=/s|.*|$root|g" /etc/update-extlinux.conf |
| 54 | fi |
| 55 | if [ -n "$modules" ]; then |
| 56 | sed -i -e "/^modules=/s|.*|$modules|g" /etc/update-extlinux.conf |
| 57 | fi |
| 58 | if [ -n "$opts" ]; then |
| 59 | sed -i -e "/^default_kernel_opts=/s|.*|default_kernel_opts=\"$opts\"|g" /etc/update-extlinux.conf |
| 60 | fi |
| 61 | |