diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2018-07-25 23:33:15 +0800 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2018-07-26 01:16:31 +0800 |
commit | f273172beb41326c8dc81e5b734e3ee00b0930b5 (patch) | |
tree | 3f06cfcf2c077dc6887e99facde318c10a146df8 | |
parent | f39625afd6ba6c1aa2027286dc3ef1c933da14e0 (diff) |
scripts/functions: Fix parsing of device name from ip parameter
Parameter expansion is not useful for parsing delimited lists of
arbitrary length. Instead, set IFS=:, disable wildcard expansion, and
use "set". Use a separate function, as this makes it easy to change
$IFS temporarily.
Also do the parsing earlier, so we can avoid a redundant invocation of
ipconfig.
This was mentioned in #721088, but it's not the main bug reported.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | scripts/functions | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/scripts/functions b/scripts/functions index 0b7ca10..997269c 100644 --- a/scripts/functions +++ b/scripts/functions @@ -180,6 +180,20 @@ get_fstype () return ${RET} } +_handle_device_vs_ip() +{ + # If the ip= parameter is present and is a colon-separated list + # that specifies a device, use that in preference to any device + # name we already have. + local IFS=: + set -f + set -- ${IP} + set +f + if [ -n "$6" ]; then + DEVICE="$6" + fi +} + configure_networking() { if [ -n "${BOOTIF}" ]; then @@ -218,6 +232,8 @@ configure_networking() done fi + _handle_device_vs_ip + # networking already configured thus bail out [ -n "${DEVICE}" ] && [ -e /run/net-"${DEVICE}".conf ] && return 0 @@ -249,18 +265,6 @@ configure_networking() ;; *) ipconfig -t ${ROUNDTTT} -d $IP - - # grab device entry from ip option - NEW_DEVICE=${IP#*:*:*:*:*:*} - if [ "${NEW_DEVICE}" != "${IP}" ]; then - NEW_DEVICE=${NEW_DEVICE%%:*} - else - # wrong parse, possibly only a partial string - NEW_DEVICE= - fi - if [ -n "${NEW_DEVICE}" ]; then - DEVICE="${NEW_DEVICE}" - fi ;; esac done |