From e4d3b266efd7392ad435e5f3a8d6be7f54da066c Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Thu, 14 May 2020 22:45:24 +0200 Subject: [PATCH] Some more Kobo startup script tweaks (#6147) * Simplify env siphoning some more * Nope, shellcheck, quoting this breaks it. (it preserves the LNs instead of abusing them as free field separators with word splitting). And, while this does break on env vars with spaces (since they'll be unquoted), that was already the case of the xargs approach. If we had read -d & printf %q, we could go with a pure shell approach, but we don't ;). * Document a working quoted variant. For science! --- platform/kobo/koreader.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index 70ef283fd..1badd3fad 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -100,8 +100,10 @@ if [ "${VIA_NICKEL}" = "true" ]; then # If we were spawned outside of Nickel, we'll need a few extra bits from its own env... if [ "${FROM_NICKEL}" = "false" ]; then # Siphon a few things from nickel's env (namely, stuff exported by rcS *after* on-animator.sh has been launched)... - eval "$(xargs -n 1 -0 <"/proc/$(pidof -s nickel)/environ" | grep -s -F -e DBUS_SESSION_BUS_ADDRESS -e NICKEL_HOME -e WIFI_MODULE -e LANG -e WIFI_MODULE_PATH -e INTERFACE)" - export DBUS_SESSION_BUS_ADDRESS NICKEL_HOME WIFI_MODULE LANG WIFI_MODULE_PATH INTERFACE + # shellcheck disable=SC2046 + export $(grep -s -E -e '^(DBUS_SESSION_BUS_ADDRESS|NICKEL_HOME|WIFI_MODULE|LANG|WIFI_MODULE_PATH|INTERFACE)=' "/proc/$(pidof -s nickel)/environ") + # NOTE: Quoted variant, w/ the busybox RS quirk (c.f., https://unix.stackexchange.com/a/125146): + #eval "$(awk -v 'RS="\0"' '/^(DBUS_SESSION_BUS_ADDRESS|NICKEL_HOME|WIFI_MODULE|LANG|WIFI_MODULE_PATH|INTERFACE)=/{gsub("\047", "\047\\\047\047"); print "export \047" $0 "\047"}' "/proc/$(pidof -s nickel)/environ")" fi # Flush disks, might help avoid trashing nickel's DB... @@ -120,8 +122,8 @@ fi # check whether PLATFORM & PRODUCT have a value assigned by rcS if [ -z "${PRODUCT}" ]; then - eval "$(xargs -n 1 -0 <"/proc/$(pidof -s udevd)/environ" | grep -s -F -e PRODUCT)" - export PRODUCT + # shellcheck disable=SC2046 + export $(grep -s -e '^PRODUCT=' "/proc/$(pidof -s udevd)/environ") fi if [ -z "${PRODUCT}" ]; then @@ -131,8 +133,8 @@ fi # PLATFORM is used in koreader for the path to the WiFi drivers (as well as when restarting nickel) if [ -z "${PLATFORM}" ]; then - eval "$(xargs -n 1 -0 <"/proc/$(pidof -s udevd)/environ" | grep -s -F -e PLATFORM)" - export PLATFORM + # shellcheck disable=SC2046 + export $(grep -s -e '^PLATFORM=' "/proc/$(pidof -s udevd)/environ") fi if [ -z "${PLATFORM}" ]; then