1
0
Fork 0
mirror of https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git synced 2024-11-24 23:00:11 +00:00
docker-adsb-ultrafeeder/rootfs/etc/s6-overlay/scripts/mlathub

138 lines
4.8 KiB
Text
Raw Normal View History

2023-08-31 02:59:09 +00:00
#!/command/with-contenv bash
2023-04-19 00:36:45 +00:00
# shellcheck shell=bash disable=SC1091,SC2015,SC2016
2023-03-21 19:56:02 +00:00
2023-04-19 00:36:45 +00:00
APPNAME="mlathub"
2023-04-08 21:07:11 +00:00
source /scripts/common
2023-04-19 00:36:45 +00:00
source /scripts/interpret_ultrafeeder_config
s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}")
2023-04-08 21:07:11 +00:00
if [[ -z "${MLAT_CONFIG}" ]] && [[ -z "$MLATHUB_NET_CONNECTOR" ]]; then
"${s6wrap[@]}" --args echo "No MLAT servers have been defined in MLAT_CONFIG and no external sources have been defined in MLATHUB_NET_CONNECTOR - no need to start MLATHUB"
2023-05-09 15:56:20 +00:00
exec sleep infinity
2023-03-21 19:56:02 +00:00
fi
2023-05-09 15:56:20 +00:00
if chk_enabled "${MLATHUB_DISABLE}"; then
"${s6wrap[@]}" --args echo "MLATHUB is disabled."
2023-05-09 15:56:20 +00:00
exec sleep infinity
2023-03-21 19:56:02 +00:00
fi
# Build the readsb command line based on options
MLATHUB_BIN="/usr/local/bin/readsb"
2023-03-22 21:50:49 +00:00
# set some basic options:
2023-03-21 19:56:02 +00:00
MLATHUB_CMD=("--net")
MLATHUB_CMD+=("--quiet")
MLATHUB_CMD+=("--net-only")
MLATHUB_CMD+=("--mlat")
MLATHUB_CMD+=("--forward-mlat")
2023-04-30 12:56:44 +00:00
MLATHUB_CMD+=("--forward-mlat-sbs")
2023-03-21 19:56:02 +00:00
MLATHUB_CMD+=("--net-connector=localhost,30004,beast_reduce_out")
2023-03-22 21:50:49 +00:00
# define some more ports:
MLATHUB_CMD+=("--net-sbs-port=${MLATHUB_SBS_OUT_PORT:-31003}")
2023-03-26 17:23:31 +00:00
MLATHUB_CMD+=("--net-bi-port=${MLATHUB_BEAST_IN_PORT:-31004}")
2023-03-22 21:50:49 +00:00
MLATHUB_CMD+=("--net-bo-port=${MLATHUB_BEAST_OUT_PORT:-31005}")
2023-03-30 20:41:09 +00:00
MLATHUB_CMD+=("--net-beast-reduce-out-port=${MLATHUB_BEAST_REDUCE_OUT_PORT:-31006}")
2023-03-21 19:56:02 +00:00
# We need to get the mlat results ports from the parameters:
# parse MLAT_CONFIG string into mlat_configs array
2023-06-14 15:37:17 +00:00
# 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'/}"
2023-03-21 19:56:02 +00:00
readarray -td ";" mlat_configs < <(printf '%s' "${MLAT_CONFIG// /}")
2023-03-22 21:50:49 +00:00
# Now loop through the MLAT_CONFIG items and add a net-connector for each of them:
2023-03-21 19:56:02 +00:00
mlat_result_sources=0
for instance in "${mlat_configs[@]}"
do
2023-03-22 15:01:03 +00:00
# shellcheck disable=SC2015
2023-03-21 19:56:02 +00:00
[[ -z "${instance}" ]] && continue || true
# put individual params into the $params array:
readarray -td "," params < <(printf '%s' "${instance}")
2023-04-14 12:21:17 +00:00
for ((i=2; i<${#params[*]}; i++))
do
if [[ -n "${params[i]}" ]] && [[ "${params[i]}" =~ ^[0-9]+$ ]]; then
# the parameter is a number and it is assumed that this is the beast_results port
MLATHUB_CMD+=("--net-connector=localhost,${params[i]},beast_in")
(( mlat_result_sources++ )) || true
break
fi
done
2023-03-21 19:56:02 +00:00
done
2023-04-14 12:21:17 +00:00
2023-04-08 23:18:45 +00:00
if (( mlat_result_sources == 0 ))
2023-03-21 19:56:02 +00:00
then
"${s6wrap[@]}" --args echo "No MLAT servers have been defined in MLAT_CONFIG - no need to start MLATHUB"
2023-05-09 15:56:20 +00:00
exec sleep infinity
2023-03-21 19:56:02 +00:00
fi
# Add any additional net_connectors:
if [[ -n "$MLATHUB_NET_CONNECTOR" ]]; then
2023-04-19 00:36:45 +00:00
# Strip any extraneous spaces:
MLATHUB_NET_CONNECTOR="${MLATHUB_NET_CONNECTOR#"${MLATHUB_NET_CONNECTOR%%[![:space:]]*}"}" # strip leading spaces
MLATHUB_NET_CONNECTOR="${MLATHUB_NET_CONNECTOR//; /;}" # strip space after semicolon
2023-03-21 19:56:02 +00:00
IFS=';' read -r -a MLATHUB_NET_CONNECTOR_ARRAY <<< "$MLATHUB_NET_CONNECTOR"
for NET_CONNECTOR_ELEMENT in "${MLATHUB_NET_CONNECTOR_ARRAY[@]}"
do
2023-04-19 00:36:45 +00:00
MLATHUB_CMD+=("--net-connector=${NET_CONNECTOR_ELEMENT}")
2023-03-21 19:56:02 +00:00
done
fi
2023-04-19 00:36:45 +00:00
# Handle ULTRAFEEDER_CONFIG / ULTRAFEEDER_NET_CONNECTOR elements relevant to readsb:
[[ "${#MLATHUB_CONF_ARR[@]}" -gt 0 ]] && MLATHUB_CMD+=("${MLATHUB_CONF_ARR[@]}") || true
2023-04-08 21:07:11 +00:00
if chk_enabled "${READSB_DEBUG}"; then
2023-03-21 19:56:02 +00:00
MLATHUB_CMD+=("--debug=$READSB_DEBUG")
fi
if [ -n "${LAT}" ]; then
MLATHUB_CMD+=(--lat "${LAT}")
elif [ -n "${READSB_LAT}" ]; then
MLATHUB_CMD+=(--lat "${READSB_LAT}")
fi
if [ -n "${LONG}" ]; then
MLATHUB_CMD+=(--lon "${LONG}")
elif [ -n "${READSB_LON}" ]; then
MLATHUB_CMD+=(--lon "${READSB_LON}")
fi
# Handle "--max-range=<dist>"
if [[ -n "$READSB_MAX_RANGE" ]]; then
MLATHUB_CMD+=("--max-range=$READSB_MAX_RANGE")
fi
# Handle "--net-connector-delay=<seconds>"
if [[ -n "$READSB_NET_CONNECTOR_DELAY" ]]; then
MLATHUB_CMD+=("--net-connector-delay=$READSB_NET_CONNECTOR_DELAY")
fi
# Handle "--net-heartbeat=<rate>"
2023-04-19 01:29:12 +00:00
MLATHUB_CMD+=("--net-heartbeat=${READSB_NET_HEARTBEAT:-35}")
2023-03-25 19:37:30 +00:00
if [[ ! -f /run/mlathub_up ]]
then
if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then
"${s6wrap[@]}" --args echo "Delaying MLAT hub start until container is established..."
fi
while [[ ! -f /run/mlathub_up ]]
do
sleep 2
done
fi
sleep 5 # sleep a bit so everything is well established
"${s6wrap[@]}" --args echo "Starting MLATHUB..."
2023-03-21 19:56:02 +00:00
2023-05-03 19:58:08 +00:00
# shellcheck disable=SC2086,SC2069
2023-03-27 15:39:27 +00:00
if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then
exec "${s6wrap[@]}" --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS
2023-03-27 15:39:27 +00:00
elif [[ "${LOGLEVEL,,}" == "error" ]]; then
exec "${s6wrap[@]}" --ignore-stdout --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS
2023-03-27 15:39:27 +00:00
elif [[ "${LOGLEVEL,,}" == "none" ]]; then
exec "${s6wrap[@]}" --ignore-stdtout --ignore-stderr --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS
2023-03-27 15:39:27 +00:00
fi