1
0
Fork 0
mirror of https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git synced 2024-11-25 15:20:10 +00:00
docker-adsb-ultrafeeder/rootfs/etc/s6-overlay/scripts/readsb
2023-10-26 15:26:37 -04:00

330 lines
9.4 KiB
Text
Executable file

#!/command/with-contenv bash
# shellcheck shell=bash disable=SC2015,SC2016,SC1091
APPNAME="readsb"
source /scripts/common
source /scripts/interpret_ultrafeeder_config
s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}")
mkdir -p /run/readsb
# Build the readsb command line based on options
READSB_BIN="/usr/local/bin/readsb"
READSB_CMD=("--net")
READSB_CMD+=("--quiet")
if chk_enabled "${READSB_NET_ONLY}"; then
READSB_CMD+=("--net-only")
fi
if [ -n "${LAT}" ]; then
READSB_CMD+=(--lat "${LAT}")
elif [ -n "${READSB_LAT}" ]; then
READSB_CMD+=(--lat "${READSB_LAT}")
fi
if [ -n "${LONG}" ]; then
READSB_CMD+=(--lon "${LONG}")
elif [ -n "${READSB_LON}" ]; then
READSB_CMD+=(--lon "${READSB_LON}")
fi
if [ -n "${MLATHOST}" ]; then
READSB_CMD+=("--net-connector=${MLATHOST},${MLATPORT},beast_in")
fi
if [ -n "${BEASTHOST}" ]; then
READSB_CMD+=("--net-connector=${BEASTHOST},${BEASTPORT},beast_in")
fi
if [ -n "${UUID}" ]; then
READSB_CMD+=("--uuid-file=/run/uuid")
fi
READSB_CMD+=("--write-json=/run/readsb")
READSB_CMD+=("--write-state=/var/globe_history")
READSB_CMD+=("--json-trace-interval=15")
READSB_CMD+=("--json-reliable=1")
READSB_CMD+=("--net-ri-port=30001")
READSB_CMD+=("--net-ro-port=30002")
READSB_CMD+=("--net-sbs-port=30003")
READSB_CMD+=("--net-bi-port=30004,30104")
READSB_CMD+=("--net-bo-port=30005")
READSB_CMD+=("--net-beast-reduce-out-port=30006")
READSB_CMD+=("--net-json-port=30047")
READSB_CMD+=(--net-api-port=30152)
READSB_CMD+=(--net-sbs-in-port=32006)
if chk_enabled "${READSB_ENABLE_HEATMAP:-true}"; then
READSB_CMD+=("--heatmap-dir=/var/globe_history")
READSB_CMD+=("--heatmap=${READSB_HEATMAP_INTERVAL:-15}")
fi
if ! chk_enabled "$READSB_NET_SBS_DISABLE_REDUCE"; then
READSB_CMD+=("--net-sbs-reduce")
fi
if chk_enabled "${READSB_FORWARD_MLAT}"; then
"${s6wrap[@]}" --args echo "WARNING -- READSB_FORWARD_MLAT has been set! Do not feed the output of this container to any aggregators!"
READSB_CMD+=("--forward-mlat")
fi
if chk_enabled "${READSB_FORWARD_MLAT_SBS}"; then
"${s6wrap[@]}" --args echo "WARNING -- READSB_FORWARD_MLAT_SBS has been set! Do not feed the SBS (BaseStation) output of this container to any aggregators!"
READSB_CMD+=("--forward-mlat-sbs")
fi
if [[ -n "$READSB_RX_LOCATION_ACCURACY" ]]; then
READSB_CMD+=("--json-location-accuracy=$READSB_RX_LOCATION_ACCURACY")
fi
if [[ -n "$READSB_JSON_INTERVAL" ]]; then
READSB_CMD+=("--write-json-every=$READSB_JSON_INTERVAL")
fi
if [ -n "${READSB_DEBUG}" ]; then
READSB_CMD+=("--debug=$READSB_DEBUG")
fi
# Handle --write-state-only-on-exit
if chk_enabled "${READSB_WRITE_STATE_ONLY_ON_EXIT}"; then
READSB_CMD+=("--write-state-only-on-exit")
fi
# Handle "--max-range=<dist>"
if [[ -n "$READSB_MAX_RANGE" ]]; then
READSB_CMD+=("--max-range=$READSB_MAX_RANGE")
fi
# Handle "--mlat"
# shellcheck disable=SC2153
if chk_enabled "$READSB_MLAT"; then
READSB_CMD+=("--mlat")
fi
# Handle "--modeac"
if chk_enabled "$READSB_MODEAC"; then
READSB_CMD+=("--modeac")
fi
# Handle "--stats-every=<sec>"
if [[ -n "$READSB_STATS_EVERY" ]]; then
READSB_CMD+=("--stats-every=$READSB_STATS_EVERY")
fi
# Handle "--stats-range"
if chk_enabled "$READSB_STATS_RANGE"; then
READSB_CMD+=("--stats-range")
fi
if [[ -n "$READSB_RANGE_OUTLINE_HOURS" ]]; then
READSB_CMD+=("--range-outline-hours=$READSB_RANGE_OUTLINE_HOURS")
fi
##### NETWORK OPTIONS #####
#
READSB_CMD+=("--net-api-port=${READSB_NET_API_PORT:-30152}")
# Handle "--net-beast-reduce-interval=<seconds>"
# Default it to 1.0 second if no value is provided
READSB_CMD+=("--net-beast-reduce-interval=${READSB_NET_BEAST_REDUCE_INTERVAL:-1.0}")
# Handle "--net-beast-reduce-out-port=<ports>"
if [[ -n "$READSB_NET_BEAST_REDUCE_OUT_PORT" ]]; then
READSB_CMD+=("--net-beast-reduce-out-port=$READSB_NET_BEAST_REDUCE_OUT_PORT")
fi
if chk_enabled "$READSB_NET_SBS_REDUCE"; then
READSB_CMD+=("--net-sbs-reduce")
fi
if [[ -n "$READSB_NET_BEAST_REDUCE_FILTER_DIST" ]]; then
READSB_CMD+=("--net-beast-reduce-filter-dist=$READSB_NET_BEAST_REDUCE_FILTER_DIST")
fi
if [[ -n "$READSB_JSON_TRACE_INTERVAL" ]]; then
READSB_CMD+=("--json-trace-interval=$READSB_JSON_TRACE_INTERVAL")
fi
if [[ -n "$READSB_NET_BEAST_REDUCE_FILTER_ALT" ]]; then
READSB_CMD+=("--net-beast-reduce-filter-alt=$READSB_NET_BEAST_REDUCE_FILTER_ALT")
fi
# Handle "--net-bi-port=<ports>"
if [[ -n "$READSB_NET_BEAST_INPUT_PORT" ]]; then
READSB_CMD+=("--net-bi-port=$READSB_NET_BEAST_INPUT_PORT")
fi
# Handle "--net-bo-port=<ports>"
if [[ -n "$READSB_NET_BEAST_OUTPUT_PORT" ]]; then
READSB_CMD+=("--net-bo-port=$READSB_NET_BEAST_OUTPUT_PORT")
fi
# Handle "--net-buffer=<n>"
if [[ -n "$READSB_NET_BUFFER" ]]; then
READSB_CMD+=("--net-buffer=$READSB_NET_BUFFER")
fi
# Handle "--net-connector=<ip,port,protocol>"
if [[ -n "$READSB_NET_CONNECTOR" ]]; then
# Strip any extraneous spaces:
READSB_NET_CONNECTOR="${READSB_NET_CONNECTOR#"${READSB_NET_CONNECTOR%%[![:space:]]*}"}" # strip leading space
READSB_NET_CONNECTOR="${READSB_NET_CONNECTOR//; /;}"
IFS=';' read -r -a READSB_NET_CONNECTOR_ARRAY <<< "$READSB_NET_CONNECTOR"
for NET_CONNECTOR_ELEMENT in "${READSB_NET_CONNECTOR_ARRAY[@]}"
do
READSB_CMD+=("--net-connector=${NET_CONNECTOR_ELEMENT// /}")
done
fi
# Handle ULTRAFEEDER_CONFIG / ULTRAFEEDER_NET_CONNECTOR elements relevant to readsb:
[[ "${#READSB_CONF_ARR[@]}" -gt 0 ]] && READSB_CMD+=("${READSB_CONF_ARR[@]}") || true
# Handle "--net-connector-delay=<seconds>"
if [[ -n "$READSB_NET_CONNECTOR_DELAY" ]]; then
READSB_CMD+=("--net-connector-delay=$READSB_NET_CONNECTOR_DELAY")
fi
# Handle "--net-heartbeat=<rate>"
READSB_CMD+=("--net-heartbeat=${READSB_NET_HEARTBEAT:-35}")
# Handle "--net-ri-port=<ports>"
if [[ -n "$READSB_NET_RAW_INPUT_PORT" ]]; then
READSB_CMD+=("--net-ri-port=$READSB_NET_RAW_INPUT_PORT")
fi
# Handle "--net-ro-interval=<rate>"
if [[ -n "$READSB_NET_RAW_OUTPUT_INTERVAL" ]]; then
READSB_CMD+=("--net-ro-interval=$READSB_NET_RAW_OUTPUT_INTERVAL")
fi
# Handle "--net-ri-port=<ports>"
if [[ -n "$READSB_NET_RAW_OUTPUT_PORT" ]]; then
READSB_CMD+=("--net-ro-port=$READSB_NET_RAW_OUTPUT_PORT")
fi
# Handle "--net-ro-size=<size>"
if [[ -n "$READSB_NET_RAW_OUTPUT_SIZE" ]]; then
READSB_CMD+=("--net-ro-size=$READSB_NET_RAW_OUTPUT_SIZE")
fi
# Handle "--net-sbs-in-port=<ports>"
if [[ -n "$READSB_NET_SBS_INPUT_PORT" ]]; then
READSB_CMD+=("--net-sbs-in-port=$READSB_NET_SBS_INPUT_PORT")
fi
# Handle "--net-sbs-port=<ports>"
if [[ -n "$READSB_NET_SBS_OUTPUT_PORT" ]]; then
READSB_CMD+=("--net-sbs-port=$READSB_NET_SBS_OUTPUT_PORT")
fi
# Handle "--net-verbatim"
if chk_enabled "$REASSB_NET_VERBATIM"; then
READSB_CMD+=("--net-verbatim")
fi
# Handle "--net-vrs-port=<ports>"
if [[ -n "$READSB_NET_VRS_PORT" ]]; then
READSB_CMD+=("--net-vrs-port=$READSB_NET_VRS_PORT")
fi
# make sure the db file exists, and if it does, use it
if [[ -e $TAR1090_INSTALL_DIR/aircraft.csv.gz ]]; then
if [[ "$TAR1090_ENABLE_AC_DB" == "true" ]]; then
READSB_CMD+=("--db-file=$TAR1090_INSTALL_DIR/aircraft.csv.gz")
fi
fi
# Handle "--device-type"
if [[ -n "$READSB_DEVICE_TYPE" ]]; then
READSB_CMD+=("--device-type=$READSB_DEVICE_TYPE")
fi
# Handle "--gain"
if [[ -n "$READSB_GAIN" ]]; then
if [[ "${READSB_GAIN,,}" == "autogain" ]] && [[ -f /var/globe_history/autogain/gain ]]; then
read -r gain < /var/globe_history/autogain/gain
else
[[ "${READSB_GAIN,,}" == "autogain" ]] && gain="${READSB_AUTOGAIN_INITIAL_GAIN:-49.6}" || gain="${READSB_GAIN}"
fi
READSB_CMD+=("--gain=$gain")
fi
##### RTL-SDR OPTIONS #####
# Handle "--device=<index|serial>"
if [[ -n "$READSB_RTLSDR_DEVICE" ]]; then
READSB_CMD+=("--device=$READSB_RTLSDR_DEVICE")
fi
# Handle "--enable-agc"
if [[ -n "$READSB_RTLSDR_ENABLE_AGC" ]]; then
READSB_CMD+=("--enable-agc")
fi
# Handle "--ppm=<correction>"
if [[ -n "$READSB_RTLSDR_PPM" ]]; then
READSB_CMD+=("--ppm=$READSB_RTLSDR_PPM")
fi
##### MODE-S BEAST OPTIONS #####
# Handle "--beast-crc-off"
if chk_enabled "$READSB_BEAST_CRC_OFF"; then
READSB_CMD+=("--beast-crc-off")
fi
# Handle "--beast-df045-on"
if chk_enabled "$READSB_BEAST_DF045_ON"; then
READSB_CMD+=("--beast-df045-on")
fi
# Handle "--beast-df1117-on"
if chk_enabled "$READSB_BEAST_DF1117_ON"; then
READSB_CMD+=("--beast-df1117-on")
fi
# Handle "--beast-fec-off"
if chk_enabled "$READSB_BEAST_FEC_OFF"; then
READSB_CMD+=("--beast-fec-off")
fi
# Handle "--beast-mlat-off"
if chk_enabled "$READSB_BEAST_MLAT_OFF"; then
READSB_CMD+=("--beast-mlat-off")
fi
# Handle "--beast-modeac"
if chk_enabled "$READSB_BEAST_MODEAC"; then
READSB_CMD+=("--beast-modeac")
fi
# Handle "--beast-serial=<path>"
if [[ -n "$READSB_BEAST_SERIAL" ]]; then
READSB_CMD+=("--beast-serial=$READSB_BEAST_SERIAL")
fi
if [[ -n "$READSB_BEAST_BAUDRATE" ]]; then
READSB_CMD+=("--beast-baudrate=$READSB_BEAST_BAUDRATE")
fi
#####################
# Handle --write-prom=<filepath>
if chk_enabled "$PROMETHEUS_ENABLE"; then
READSB_CMD+=("--write-prom=/run/readsb-prometheus.prom")
fi
LOGLEVEL="${LOGLEVEL:-verbose}"
# shellcheck disable=SC2086,SC2069
if [[ "${LOGLEVEL,,}" == "verbose" ]]; then
exec "${s6wrap[@]}" --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS
elif [[ "${LOGLEVEL,,}" == "error" ]]; then
exec "${s6wrap[@]}" --ignore-stdout --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS
elif [[ "${LOGLEVEL,,}" == "none" ]]; then
exec "${s6wrap[@]}" --ignore-stdout --ignore-stderr --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS
fi