diff options
-rwxr-xr-x | buildos | 24 | ||||
-rwxr-xr-x | init | 24 |
2 files changed, 42 insertions, 6 deletions
@@ -59,6 +59,11 @@ info "starting build os monitor..." # foo='foo fox' # bar="bar 'box'" # +# Or (as rewritten by GRUB): +# +# 'foo=foo fox' +# "bar=bar 'box'" +# # First we separete quoted variables and arguments with newlines (giving # priority to assignments). Then we replace whitespaces with newline on # lines that don't contain quites. Finally, we clean up by removing blank @@ -81,11 +86,24 @@ declare -A toolchains toolchains["default"]="" for v in "${cmdline[@]}"; do - var="$(sed -n -re 's/^buildos\.([^=]+)=.*$/\1/p' <<<"$v")" # Extract name. + + # Rewrite "x=y" as x="y" (as well as the single-quote variant). + # + v1="$(sed -n -re "s/^\"([^= ]+)=(.*)\"\$/\1=\"\2\"/p" <<<"$v")" + if [ -n "$v1" ]; then + v="$v1" + else + v1="$(sed -n -re "s/^'([^= ]+)=(.*)'\$/\1='\2'/p" <<<"$v")" + if [ -n "$v1" ]; then + v="$v1" + fi + fi + + var="$(sed -n -re 's/^buildos\.([^= ]+)=.*$/\1/p' <<<"$v")" # Extract name. if [ -n "$var" ]; then - val="$(sed -re 's/^[^=]+=(.*)$/\1/' <<<"$v")" # Extract value. - val="$(sed -re "s/^('(.*)'|\"(.*)\")$/\2\3/" <<<"$val")" # Strip quoted. + val="$(sed -re 's/^[^= ]+=(.*)$/\1/' <<<"$v")" # Extract value. + val="$(sed -re "s/^('(.*)'|\"(.*)\")\$/\2\3/" <<<"$val")" # Strip quoted. # Recognize some variables as arrays. # @@ -104,6 +104,11 @@ sensors-detect --auto # foo='foo fox' # bar="bar 'box'" # +# Or (as rewritten by GRUB): +# +# 'foo=foo fox' +# "bar=bar 'box'" +# # First we separete quoted variables and arguments with newlines (giving # priority to assignments). Then we replace whitespaces with newline on # lines that don't contain quotes. Finally, clean up by removing blank @@ -120,11 +125,24 @@ readarray -t cmdline < <(cat /proc/cmdline | \ # info "command line:" for v in "${cmdline[@]}"; do - var="$(sed -n -re 's/^buildos\.([^=]+)=.*$/\1/p' <<<"$v")" # Extract name. + + # Rewrite "x=y" as x="y" (as well as the single-quote variant). + # + v1="$(sed -n -re "s/^\"([^= ]+)=(.*)\"\$/\1=\"\2\"/p" <<<"$v")" + if [ -n "$v1" ]; then + v="$v1" + else + v1="$(sed -n -re "s/^'([^= ]+)=(.*)'\$/\1='\2'/p" <<<"$v")" + if [ -n "$v1" ]; then + v="$v1" + fi + fi + + var="$(sed -n -re 's/^buildos\.([^= ]+)=.*$/\1/p' <<<"$v")" # Extract name. if [ -n "$var" ]; then - val="$(sed -re 's/^[^=]+=(.*)$/\1/' <<<"$v")" # Extract value. - val="$(sed -re "s/^('(.*)'|\"(.*)\")$/\2\3/" <<<"$val")" # Strip quoted. + val="$(sed -re 's/^[^= ]+=(.*)$/\1/' <<<"$v")" # Extract value. + val="$(sed -re "s/^('(.*)'|\"(.*)\")\$/\2\3/" <<<"$val")" # Strip quoted. info " $var=$val" # If the variable contains a dot, then it is a toolchain variable and we |