From da7d85d81a596c3f6668def35a252e5d9c06777b Mon Sep 17 00:00:00 2001 From: Cem Keylan Date: Thu, 13 Aug 2020 11:36:52 +0300 Subject: rc.lib: simplify kernel command line parsing function Instead of specifying each variable, you can now set anything from the kernel command line. --- rc.boot | 10 ++++++---- rc.lib | 17 ++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/rc.boot b/rc.boot index ec0ddc5..84740a5 100755 --- a/rc.boot +++ b/rc.boot @@ -35,7 +35,7 @@ out "Parsing kernel commandline..."; { parse_cmdline } -[ "$dmesg_level" ] && { +[ "${dmesg_level:=$loglevel}" ] && { out "Setting dmesg level..." dmesg -n$dmesg_level } @@ -48,13 +48,15 @@ out "Remounting rootfs as read-only..."; { mount -o remount,ro / || shell } -[ "$FASTBOOT" = 1 ] || { +# shellcheck disable=2154 +[ "$fastboot" = 1 ] || { out "Checking filesystems..." - fsck "-ATat${FORCEFSCK}" noopts=_netdev 2>&1 | log + fsck "-ATat${forcefsck:+-f}" noopts=_netdev 2>&1 | log [ $? -gt 1 ] && shell } -[ "$RO" = "1" ] || { +# shellcheck disable=2154 +[ "$ro" = "1" ] || { out "Mounting rootfs read-write..." mount -o remount,rw / || shell } diff --git a/rc.lib b/rc.lib index b096ec7..94cc7b0 100644 --- a/rc.lib +++ b/rc.lib @@ -109,15 +109,14 @@ parse_cmdline() { # We want to read words instead of lines here. # shellcheck disable=2013 - for arg in $(cat /proc/cmdline); do - case "$arg" in - ro) RO=1 ;; - forcefsck) FORCEFSCK="-f" ;; - fastboot) FASTBOOT=1 ;; - loglevel=?) dmesg_level=${arg#loglevel=} ;; - devd=*) devd=${arg#devd=} ;; - esac - done + while read -r cmdline; do + for arg in $cmdline; do + case "$arg" in + *=*) export "$arg" ;; + *) export "$arg=1" ;; + esac + done + done < /proc/cmdline } random() { -- cgit v1.2.3