1
0
Fork 0
mirror of https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git synced 2024-11-27 16:20:10 +00:00
docker-adsb-ultrafeeder/rootfs/etc/s6-overlay/scripts/adsbx-stats

72 lines
3.2 KiB
Text
Raw Normal View History

2023-10-13 12:09:13 +00:00
#!/command/with-contenv bash
2023-10-13 13:19:36 +00:00
# shellcheck shell=bash disable=SC2015,SC2016,SC1091,SC2001
2023-10-13 12:09:13 +00:00
source /scripts/common
2023-10-13 13:19:36 +00:00
source /scripts/interpret_ultrafeeder_config
2023-10-13 12:18:57 +00:00
s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)
2023-10-13 12:09:13 +00:00
2023-10-13 13:19:36 +00:00
# Check if ADSBExchange is configured
2023-10-13 12:09:13 +00:00
if ! grep -i adsbexchange.com <<< "$ULTRAFEEDER_CONFIG" >/dev/null 2>&1; then
"${s6wrap[@]}" echo "AdsbExchange not configured - no stats package needed"
2023-10-13 12:37:54 +00:00
sleep infinity & wait $!
2023-10-13 12:09:13 +00:00
fi
2023-10-13 20:23:16 +00:00
# Check if ADSBExchange stats are disabled
if chk_disabled "$ADSBX_STATS" ; then
"${s6wrap[@]}" echo "AdsbExchange stats disabled"
sleep infinity & wait $!
fi
2023-10-13 13:19:36 +00:00
# prep work:
mkdir -p /run/adsbexchange-stats
2023-10-13 12:09:13 +00:00
2023-10-13 13:19:36 +00:00
# Install the Stats package:
2023-10-13 12:09:13 +00:00
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/sdr-enthusiasts/docker-adsb-ultrafeeder/main/downloads/adsbexchange-json-status; then
"${s6wrap[@]}" echo "ERROR: AdsbExchange configured, but cannot download stats package! AdsbExchange will be fed but stats will not be available"
2023-10-13 12:37:54 +00:00
sleep infinity & wait $!
2023-10-13 12:09:13 +00:00
fi
chmod 755 /usr/local/bin/json-status
fi
2023-10-13 13:19:36 +00:00
# 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
2023-10-13 13:33:31 +00:00
"${s6wrap[@]}" echo "Using UUID $ADSBX_UUID for AdsbExchange"
2023-10-13 13:19:36 +00:00
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
2023-10-13 12:37:54 +00:00
# wait until readsb is established...
if ! pgrep readsb >/dev/null; then
if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then
2023-10-13 12:40:38 +00:00
"${s6wrap[@]}" echo "Delaying start of the AdsbExchange Stats module until container is established..."
2023-10-13 12:37:54 +00:00
fi
while ! pgrep readsb >/dev/null
do
sleep 2 & wait $!
done
# wait 2 seconds after readsb process exists
sleep 2 & wait $!
fi
# 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</a>" | sed -n 's|.*\(https.*\)\" class.*|\1|p')"
AnywhereStats="$(curl -sSL https://www.adsbexchange.com/myip/ | grep "ADSBx Anywhere Stats</a>" | 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"
} &
2023-10-13 12:37:54 +00:00
"${s6wrap[@]}" echo "invoking: /usr/local/bin/json-status"
"${s6wrap[@]}" /usr/local/bin/json-status