From fa5b7b91d0fce44638c16f7829ade61545885886 Mon Sep 17 00:00:00 2001 From: kx1t Date: Wed, 14 Jun 2023 11:37:17 -0400 Subject: [PATCH] make config interpretation more robust --- rootfs/etc/services.d/mlat-client/run | 2 ++ rootfs/etc/services.d/mlathub/run | 5 +++++ rootfs/scripts/interpret_ultrafeeder_config | 23 +++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/rootfs/etc/services.d/mlat-client/run b/rootfs/etc/services.d/mlat-client/run index d5ffaaa..fcdb56d 100644 --- a/rootfs/etc/services.d/mlat-client/run +++ b/rootfs/etc/services.d/mlat-client/run @@ -69,6 +69,8 @@ fi # Strip any extraneous spaces: MLAT_CONFIG="${MLAT_CONFIG#"${MLAT_CONFIG%%[![:space:]]*}"}" # strip leading space MLAT_CONFIG="${MLAT_CONFIG//; /;}" +# remove any newlines: +MLAT_CONFIG="${MLAT_CONFIG//$'\n'/}" readarray -td ";" mlat_configs < <(printf '%s' "${MLAT_CONFIG}") diff --git a/rootfs/etc/services.d/mlathub/run b/rootfs/etc/services.d/mlathub/run index 6dab8ee..828edea 100644 --- a/rootfs/etc/services.d/mlathub/run +++ b/rootfs/etc/services.d/mlathub/run @@ -37,6 +37,11 @@ MLATHUB_CMD+=("--net-beast-reduce-out-port=${MLATHUB_BEAST_REDUCE_OUT_PORT:-3100 # We need to get the mlat results ports from the parameters: # parse MLAT_CONFIG string into mlat_configs array +# Strip any extraneous spaces: +MLAT_CONFIG="${MLAT_CONFIG#"${MLAT_CONFIG%%[![:space:]]*}"}" # strip leading space +MLAT_CONFIG="${MLAT_CONFIG//; /;}" +# remove any newlines: +MLAT_CONFIG="${MLAT_CONFIG//$'\n'/}" readarray -td ";" mlat_configs < <(printf '%s' "${MLAT_CONFIG// /}") # Now loop through the MLAT_CONFIG items and add a net-connector for each of them: mlat_result_sources=0 diff --git a/rootfs/scripts/interpret_ultrafeeder_config b/rootfs/scripts/interpret_ultrafeeder_config index f2026c6..e52c09f 100755 --- a/rootfs/scripts/interpret_ultrafeeder_config +++ b/rootfs/scripts/interpret_ultrafeeder_config @@ -56,6 +56,8 @@ # Do some prep work: # combine ULTRAFEEDER_CONFIG and ULTRAFEEDER_NET_CONNECTOR ULTRAFEEDER_CONFIG="${ULTRAFEEDER_CONFIG}${ULTRAFEEDER_CONFIG:+;}${ULTRAFEEDER_NET_CONNECTOR}" +# remove any newlines: +ULTRAFEEDER_CONFIG="${ULTRAFEEDER_CONFIG//$'\n'/}" # Strip any extraneous spaces: ULTRAFEEDER_CONFIG="${ULTRAFEEDER_CONFIG#"${ULTRAFEEDER_CONFIG%%[![:space:]]*}"}" # strip leading space ULTRAFEEDER_CONFIG="${ULTRAFEEDER_CONFIG//; /;}" @@ -120,8 +122,25 @@ do ;; *) - # unknown string; warn and skip - echo "[$(date)][${APPNAME}] Warning: skipping unknown ULTRAFEEDER_CONFIG config element \"${instance}\"" + # Check if there's anything in ${ULTRAFEEDER_NET_CONNECTOR} -- if not, it's a bad config element. If yes, add it as if it were ADSB + if [[ -z "${ULTRAFEEDER_NET_CONNECTOR}" ]]; then + echo "[$(date)][${APPNAME}] Warning: skipping unknown ULTRAFEEDER_CONFIG config element \"${instance}\"" + else + # parse arguments for main readsb + # build net-connector string into $readsb_str + # and add any extra arguments in as individual entries into READSB_CONF_ARR() + readsb_str="${param[0]},${param[1]},${param[2]}" + for ((i=3; i<${#param[*]}; i++)) + do + if [[ "${param[i]:0:5}" == "uuid=" ]]; then + readsb_str="${readsb_str},${param[i]}" + elif [[ -n "${param[i]}" ]]; then + READSB_CONF_ARR+=("${param[i]}") + fi + done + # Now add $readsb_str to the READSB_CONF_ARR() as --net-connector argument: + READSB_CONF_ARR+=("--net-connector=${readsb_str}") + fi esac done