From f19bdb759f4c9778744c35fe4fce743aeb3cb8c4 Mon Sep 17 00:00:00 2001 From: kx1t Date: Fri, 13 Oct 2023 08:09:13 -0400 Subject: [PATCH 1/8] initial commit --- .../dependencies.d/01-print-container-version | 0 .../dependencies.d/02-remove-prometheus-data | 0 .../dependencies.d/03-remove-mlathub-up | 0 .../adsbx-stats/dependencies.d/50-store-uuid | 0 .../dependencies.d/60-mlathub-prep | 0 rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/run | 2 + .../etc/s6-overlay/s6-rc.d/adsbx-stats/type | 1 + rootfs/etc/s6-overlay/scripts/adsbx-stats | 38 +++++++++++++++++++ 8 files changed, 41 insertions(+) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/01-print-container-version create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/02-remove-prometheus-data create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/03-remove-mlathub-up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/50-store-uuid create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/60-mlathub-prep create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/type create mode 100755 rootfs/etc/s6-overlay/scripts/adsbx-stats diff --git a/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/01-print-container-version b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/01-print-container-version new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/02-remove-prometheus-data b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/02-remove-prometheus-data new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/03-remove-mlathub-up b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/03-remove-mlathub-up new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/50-store-uuid b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/50-store-uuid new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/60-mlathub-prep b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/dependencies.d/60-mlathub-prep new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/run b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/run new file mode 100755 index 0000000..c146d12 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/adsbx-stats diff --git a/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/type b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/adsbx-stats/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/scripts/adsbx-stats b/rootfs/etc/s6-overlay/scripts/adsbx-stats new file mode 100755 index 0000000..c2a9af5 --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/adsbx-stats @@ -0,0 +1,38 @@ +#!/command/with-contenv bash +# shellcheck shell=bash disable=SC2015,SC2016,SC1091 + +APPNAME="readsb" + +source /scripts/common +s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}" --args) + +# First check if ADSBX is in the config string + +# 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//; /;}" +if ! grep -i adsbexchange.com <<< "$ULTRAFEEDER_CONFIG" >/dev/null 2>&1; then + "${s6wrap[@]}" echo "AdsbExchange not configured - no stats package needed" + exec sleep infinity +fi + +# Install the Stats package: + +if [[ ! -f /etc/default/adsbexchange-stats ]]; then + echo -e "UUID_FILE=/run/uuid\nJSON_PATHS=(\"/run/readsb\")" > /etc/default/adsbexchange-stats +fi + +if [[ ! -f /usr/local/bin/json-status ]]; then + if ! curl -sSL -o /usr/local/bin/json-status https://raw.githubusercontent.com/ADSBexchange/adsbexchange-stats/master/json-status; then + "${s6wrap[@]}" echo "ERROR: AdsbExchange configure, but cannot download stats package! AdsbExchange will be fed but stats will not be available" + exec sleep infinity + fi + chmod 755 /usr/local/bin/json-status +fi + +mkdir -p /run/adsbexchange-stats +"${s6wrap[@]}" /usr/local/bin/json-status \ No newline at end of file From 511d4191d0c1057003e8d767cce35bd0a1ad22cb Mon Sep 17 00:00:00 2001 From: kx1t Date: Fri, 13 Oct 2023 08:18:57 -0400 Subject: [PATCH 2/8] update 1 --- rootfs/etc/s6-overlay/scripts/adsbx-stats | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rootfs/etc/s6-overlay/scripts/adsbx-stats b/rootfs/etc/s6-overlay/scripts/adsbx-stats index c2a9af5..489899f 100755 --- a/rootfs/etc/s6-overlay/scripts/adsbx-stats +++ b/rootfs/etc/s6-overlay/scripts/adsbx-stats @@ -1,10 +1,8 @@ #!/command/with-contenv bash # shellcheck shell=bash disable=SC2015,SC2016,SC1091 -APPNAME="readsb" - source /scripts/common -s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}" --args) +s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) # First check if ADSBX is in the config string From 8e11964c40492286658f770dbbf8056c70203f92 Mon Sep 17 00:00:00 2001 From: kx1t Date: Fri, 13 Oct 2023 08:34:07 -0400 Subject: [PATCH 3/8] update --- rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/adsbx-stats | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/adsbx-stats diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/adsbx-stats b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/adsbx-stats new file mode 100755 index 0000000..e69de29 From 8af1ec1e332b5f5b6f27d7f1ddae0e1ae254baff Mon Sep 17 00:00:00 2001 From: kx1t Date: Fri, 13 Oct 2023 08:37:54 -0400 Subject: [PATCH 4/8] update --- rootfs/etc/s6-overlay/scripts/adsbx-stats | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/rootfs/etc/s6-overlay/scripts/adsbx-stats b/rootfs/etc/s6-overlay/scripts/adsbx-stats index 489899f..3378afc 100755 --- a/rootfs/etc/s6-overlay/scripts/adsbx-stats +++ b/rootfs/etc/s6-overlay/scripts/adsbx-stats @@ -15,7 +15,7 @@ ULTRAFEEDER_CONFIG="${ULTRAFEEDER_CONFIG#"${ULTRAFEEDER_CONFIG%%[![:space:]]*}"} ULTRAFEEDER_CONFIG="${ULTRAFEEDER_CONFIG//; /;}" if ! grep -i adsbexchange.com <<< "$ULTRAFEEDER_CONFIG" >/dev/null 2>&1; then "${s6wrap[@]}" echo "AdsbExchange not configured - no stats package needed" - exec sleep infinity + sleep infinity & wait $! fi # Install the Stats package: @@ -27,10 +27,26 @@ fi if [[ ! -f /usr/local/bin/json-status ]]; then if ! curl -sSL -o /usr/local/bin/json-status https://raw.githubusercontent.com/ADSBexchange/adsbexchange-stats/master/json-status; then "${s6wrap[@]}" echo "ERROR: AdsbExchange configure, but cannot download stats package! AdsbExchange will be fed but stats will not be available" - exec sleep infinity + sleep infinity & wait $! fi chmod 755 /usr/local/bin/json-status fi mkdir -p /run/adsbexchange-stats + +# wait until readsb is established... +if ! pgrep readsb >/dev/null; then + if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then + "${s6wrap[@]}" --args echo "Delaying start of the AdsbExchange Stats module until container is established..." + fi + while ! pgrep readsb >/dev/null + do + sleep 2 & wait $! + done + # wait 2 seconds after readsb process exists + sleep 2 & wait $! +fi + +"${s6wrap[@]}" --args echo "invoking: /usr/local/bin/json-status" + "${s6wrap[@]}" /usr/local/bin/json-status \ No newline at end of file From 31ae9e3a99c32c0329f87bd6ff738a4281c68be0 Mon Sep 17 00:00:00 2001 From: kx1t Date: Fri, 13 Oct 2023 08:40:38 -0400 Subject: [PATCH 5/8] fix logging --- rootfs/etc/s6-overlay/scripts/adsbx-stats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootfs/etc/s6-overlay/scripts/adsbx-stats b/rootfs/etc/s6-overlay/scripts/adsbx-stats index 3378afc..b96231b 100755 --- a/rootfs/etc/s6-overlay/scripts/adsbx-stats +++ b/rootfs/etc/s6-overlay/scripts/adsbx-stats @@ -37,7 +37,7 @@ mkdir -p /run/adsbexchange-stats # wait until readsb is established... if ! pgrep readsb >/dev/null; then if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - "${s6wrap[@]}" --args echo "Delaying start of the AdsbExchange Stats module until container is established..." + "${s6wrap[@]}" echo "Delaying start of the AdsbExchange Stats module until container is established..." fi while ! pgrep readsb >/dev/null do @@ -47,6 +47,6 @@ if ! pgrep readsb >/dev/null; then sleep 2 & wait $! fi -"${s6wrap[@]}" --args echo "invoking: /usr/local/bin/json-status" +"${s6wrap[@]}" echo "invoking: /usr/local/bin/json-status" "${s6wrap[@]}" /usr/local/bin/json-status \ No newline at end of file From 366893507a23d840394e362c227f23d079b6372f Mon Sep 17 00:00:00 2001 From: kx1t Date: Fri, 13 Oct 2023 09:19:36 -0400 Subject: [PATCH 6/8] add UUID --- rootfs/etc/s6-overlay/scripts/adsbx-stats | 31 +++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/rootfs/etc/s6-overlay/scripts/adsbx-stats b/rootfs/etc/s6-overlay/scripts/adsbx-stats index b96231b..ada2b61 100755 --- a/rootfs/etc/s6-overlay/scripts/adsbx-stats +++ b/rootfs/etc/s6-overlay/scripts/adsbx-stats @@ -1,29 +1,23 @@ #!/command/with-contenv bash -# shellcheck shell=bash disable=SC2015,SC2016,SC1091 +# shellcheck shell=bash disable=SC2015,SC2016,SC1091,SC2001 source /scripts/common +source /scripts/interpret_ultrafeeder_config s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) -# First check if ADSBX is in the config string - -# 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//; /;}" +# Check if ADSBExchange is configured if ! grep -i adsbexchange.com <<< "$ULTRAFEEDER_CONFIG" >/dev/null 2>&1; then "${s6wrap[@]}" echo "AdsbExchange not configured - no stats package needed" sleep infinity & wait $! fi -# Install the Stats package: +# prep work: +mkdir -p /run/adsbexchange-stats +# Install the Stats package: if [[ ! -f /etc/default/adsbexchange-stats ]]; then echo -e "UUID_FILE=/run/uuid\nJSON_PATHS=(\"/run/readsb\")" > /etc/default/adsbexchange-stats fi - if [[ ! -f /usr/local/bin/json-status ]]; then if ! curl -sSL -o /usr/local/bin/json-status https://raw.githubusercontent.com/ADSBexchange/adsbexchange-stats/master/json-status; then "${s6wrap[@]}" echo "ERROR: AdsbExchange configure, but cannot download stats package! AdsbExchange will be fed but stats will not be available" @@ -32,7 +26,18 @@ if [[ ! -f /usr/local/bin/json-status ]]; then chmod 755 /usr/local/bin/json-status fi -mkdir -p /run/adsbexchange-stats +# set the UUID: +if [[ ! -f /usr/local/share/adsbexchange/adsbx-uuid ]]; then + ADSBX_UUID="$(sed 's|.*adsbexchange.*uuid=\([a-f0-9-]\+\).*|\1|g' <<< "${READSB_CONF_ARR[@]}")" || true # get UUID from ULTRAFEEDER_CONFIG if it exists + ADSBX_UUID="${ADSBX_UUID:-${UUID}}" || true # ...else get it from the UUID param + ADSBX_UUID="${ADSBX_UUID:-$(cat /proc/sys/kernel/random/uuid 2>/dev/null)}" || true # ...else generate a random one + if [[ -n "$ADSBX_UUID" ]]; then + mkdir -p /usr/local/share/adsbexchange + echo "$ADSBX_UUID" > /usr/local/share/adsbexchange/adsbx-uuid + else + "${s6wrap[@]}" echo "WARNING: no UUID can be identified to be used with AdsbExchange; a random one will be generated every time the container is started." + fi +fi # wait until readsb is established... if ! pgrep readsb >/dev/null; then From 57ae1052364540525a987f9f79caee61b7f15e21 Mon Sep 17 00:00:00 2001 From: kx1t Date: Fri, 13 Oct 2023 09:33:31 -0400 Subject: [PATCH 7/8] minor stuff - intermediate --- rootfs/etc/s6-overlay/scripts/adsbx-stats | 1 + 1 file changed, 1 insertion(+) diff --git a/rootfs/etc/s6-overlay/scripts/adsbx-stats b/rootfs/etc/s6-overlay/scripts/adsbx-stats index ada2b61..0d64ff8 100755 --- a/rootfs/etc/s6-overlay/scripts/adsbx-stats +++ b/rootfs/etc/s6-overlay/scripts/adsbx-stats @@ -34,6 +34,7 @@ if [[ ! -f /usr/local/share/adsbexchange/adsbx-uuid ]]; then if [[ -n "$ADSBX_UUID" ]]; then mkdir -p /usr/local/share/adsbexchange echo "$ADSBX_UUID" > /usr/local/share/adsbexchange/adsbx-uuid + "${s6wrap[@]}" echo "Using UUID $ADSBX_UUID for AdsbExchange" else "${s6wrap[@]}" echo "WARNING: no UUID can be identified to be used with AdsbExchange; a random one will be generated every time the container is started." fi From 4a2df580dd3c31e1531da1ef1a9ff44143fc74cb Mon Sep 17 00:00:00 2001 From: kx1t Date: Fri, 13 Oct 2023 09:46:12 -0400 Subject: [PATCH 8/8] add Anywhere Map and Stats URL printing to logs --- rootfs/etc/s6-overlay/scripts/adsbx-stats | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rootfs/etc/s6-overlay/scripts/adsbx-stats b/rootfs/etc/s6-overlay/scripts/adsbx-stats index 0d64ff8..3ff355e 100755 --- a/rootfs/etc/s6-overlay/scripts/adsbx-stats +++ b/rootfs/etc/s6-overlay/scripts/adsbx-stats @@ -53,6 +53,13 @@ if ! pgrep readsb >/dev/null; then sleep 2 & wait $! fi -"${s6wrap[@]}" echo "invoking: /usr/local/bin/json-status" +# Let json-status start up, and then print the Anywhere Map and Anywhere Stats URLs to the container logs: +{ sleep 15 + AnywhereMap="$(curl -sSL https://www.adsbexchange.com/myip/ | grep "ADSBx Anywhere Map" | sed -n 's|.*\(https.*\)\" class.*|\1|p')" + AnywhereStats="$(curl -sSL https://www.adsbexchange.com/myip/ | grep "ADSBx Anywhere Stats" | sed -n 's|.*\(https.*\)\" class.*|\1|p')" + "${s6wrap[@]}" echo "Your AdsbExchange Anywhere Map URL is $AnywhereMap" + "${s6wrap[@]}" echo "Your AdsbExchange Anywhere Stats URL is $AnywhereStats" +} & +"${s6wrap[@]}" echo "invoking: /usr/local/bin/json-status" "${s6wrap[@]}" /usr/local/bin/json-status \ No newline at end of file