From a7878eb66900f123049fd22e8d23f1194de5585d Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Thu, 18 Apr 2024 21:11:07 +0200 Subject: [PATCH 1/4] cache HEYWHATSTHAT download if globe_history is persistent --- .../etc/s6-overlay/startup.d/06-range-outline | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/rootfs/etc/s6-overlay/startup.d/06-range-outline b/rootfs/etc/s6-overlay/startup.d/06-range-outline index 91deb4c..1e6e8d9 100755 --- a/rootfs/etc/s6-overlay/startup.d/06-range-outline +++ b/rootfs/etc/s6-overlay/startup.d/06-range-outline @@ -36,11 +36,25 @@ if [ -n "${HEYWHATSTHAT_PANORAMA_ID}" ]; then echo "[$(date)][06-range-outline] Getting HeyWhatsThat Range Outlines for these altitudes (in meters): ${HEYWHATSTHAT_ALTS}" - curl \ - --silent \ - --output /usr/local/share/tar1090/html-webroot/upintheair.json \ - "http://www.heywhatsthat.com/api/upintheair.json?id=${HEYWHATSTHAT_PANORAMA_ID}&refraction=0.25&alts=${HEYWHATSTHAT_ALTS:-12192}" || \ - echo "WARNING: Unable to download panorama. Outline will not be available."; exit 0 + HEY_URL="http://www.heywhatsthat.com/api/upintheair.json?id=${HEYWHATSTHAT_PANORAMA_ID}&refraction=0.25&alts=${HEYWHATSTHAT_ALTS:-12192}" + OFILE="${TAR1090_INSTALL_DIR}/html-webroot/upintheair.json" + + # in many configurations TAR1090_UPDATE_DIR will persist compose down / up + URL_FILE="${TAR1090_UPDATE_DIR}/upintheair.json.url" + PFILE="${TAR1090_UPDATE_DIR}/upintheair.json" + + if [[ -f "${PFILE}" ]] && diff -q "$URL_FILE" <(cat <<<"${HEY_URL}"); then + # url identical, use old file + cp -f "${PFILE}" "${OFILE}" + else + if curl --silent --show-error --output "${OFILE}" "${HEY_URL}"; then + cp -f "${OFILE}" "${PFILE}" + cat <<<"${HEY_URL}" >"${URL_FILE}" + else + echo "WARNING: Unable to download panorama. Outline will not be available." + exit 0 + fi + fi fi exit 0 From 081f45d35841a1b09f05b1dff919003e3aac15fd Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Thu, 18 Apr 2024 21:41:35 +0200 Subject: [PATCH 2/4] silence diff output --- rootfs/etc/s6-overlay/startup.d/06-range-outline | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootfs/etc/s6-overlay/startup.d/06-range-outline b/rootfs/etc/s6-overlay/startup.d/06-range-outline index 1e6e8d9..2c2b62f 100755 --- a/rootfs/etc/s6-overlay/startup.d/06-range-outline +++ b/rootfs/etc/s6-overlay/startup.d/06-range-outline @@ -43,7 +43,7 @@ if [ -n "${HEYWHATSTHAT_PANORAMA_ID}" ]; then URL_FILE="${TAR1090_UPDATE_DIR}/upintheair.json.url" PFILE="${TAR1090_UPDATE_DIR}/upintheair.json" - if [[ -f "${PFILE}" ]] && diff -q "$URL_FILE" <(cat <<<"${HEY_URL}"); then + if [[ -f "${PFILE}" ]] && diff -q "$URL_FILE" <(cat <<<"${HEY_URL}") &>/dev/null; then # url identical, use old file cp -f "${PFILE}" "${OFILE}" else From 414f866bc49c3c0d21ce348fbb5f01b0ca6f1fe5 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Thu, 18 Apr 2024 21:43:28 +0200 Subject: [PATCH 3/4] remove redundant log timestamp --- rootfs/etc/s6-overlay/startup.d/06-range-outline | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootfs/etc/s6-overlay/startup.d/06-range-outline b/rootfs/etc/s6-overlay/startup.d/06-range-outline index 2c2b62f..1c6f498 100755 --- a/rootfs/etc/s6-overlay/startup.d/06-range-outline +++ b/rootfs/etc/s6-overlay/startup.d/06-range-outline @@ -10,7 +10,7 @@ if [ -n "${HEYWHATSTHAT_PANORAMA_ID}" ]; then HEYWHATSTHAT_ALTS="${HEYWHATSTHAT_ALTS:-12192m}" if grep -e "[^0-9kmft,]" <<< "${HEYWHATSTHAT_ALTS}" >/dev/null 2>&1; then - echo "[$(date)][06-range-outline] FATAL: Illegal character in HEYWHATSTHAT_ALTS=${HEYWHATSTHAT_ALTS}" + echo "FATAL: Illegal character in HEYWHATSTHAT_ALTS=${HEYWHATSTHAT_ALTS}" exit 1 fi @@ -34,7 +34,7 @@ if [ -n "${HEYWHATSTHAT_PANORAMA_ID}" ]; then printf -v HEYWHATSTHAT_ALTS -- "%s," "${alts_array[@]}" HEYWHATSTHAT_ALTS="${HEYWHATSTHAT_ALTS:0:-1}" - echo "[$(date)][06-range-outline] Getting HeyWhatsThat Range Outlines for these altitudes (in meters): ${HEYWHATSTHAT_ALTS}" + echo "Getting HeyWhatsThat Range Outlines for these altitudes (in meters): ${HEYWHATSTHAT_ALTS}" HEY_URL="http://www.heywhatsthat.com/api/upintheair.json?id=${HEYWHATSTHAT_PANORAMA_ID}&refraction=0.25&alts=${HEYWHATSTHAT_ALTS:-12192}" OFILE="${TAR1090_INSTALL_DIR}/html-webroot/upintheair.json" From 23533bbaa6394a34cc2666c4c75026125fe9a940 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Thu, 18 Apr 2024 21:59:30 +0200 Subject: [PATCH 4/4] make clear when the cached version is used --- rootfs/etc/s6-overlay/startup.d/06-range-outline | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootfs/etc/s6-overlay/startup.d/06-range-outline b/rootfs/etc/s6-overlay/startup.d/06-range-outline index 1c6f498..a919a8b 100755 --- a/rootfs/etc/s6-overlay/startup.d/06-range-outline +++ b/rootfs/etc/s6-overlay/startup.d/06-range-outline @@ -34,8 +34,6 @@ if [ -n "${HEYWHATSTHAT_PANORAMA_ID}" ]; then printf -v HEYWHATSTHAT_ALTS -- "%s," "${alts_array[@]}" HEYWHATSTHAT_ALTS="${HEYWHATSTHAT_ALTS:0:-1}" - echo "Getting HeyWhatsThat Range Outlines for these altitudes (in meters): ${HEYWHATSTHAT_ALTS}" - HEY_URL="http://www.heywhatsthat.com/api/upintheair.json?id=${HEYWHATSTHAT_PANORAMA_ID}&refraction=0.25&alts=${HEYWHATSTHAT_ALTS:-12192}" OFILE="${TAR1090_INSTALL_DIR}/html-webroot/upintheair.json" @@ -45,8 +43,10 @@ if [ -n "${HEYWHATSTHAT_PANORAMA_ID}" ]; then if [[ -f "${PFILE}" ]] && diff -q "$URL_FILE" <(cat <<<"${HEY_URL}") &>/dev/null; then # url identical, use old file + echo "Using cached HeyWhatsThat Range Outlines for these altitudes (in meters): ${HEYWHATSTHAT_ALTS}" cp -f "${PFILE}" "${OFILE}" else + echo "Getting HeyWhatsThat Range Outlines for these altitudes (in meters): ${HEYWHATSTHAT_ALTS}" if curl --silent --show-error --output "${OFILE}" "${HEY_URL}"; then cp -f "${OFILE}" "${PFILE}" cat <<<"${HEY_URL}" >"${URL_FILE}"