Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache HEYWHATSTHAT download if globe_history is persistent #178

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions rootfs/etc/s6-overlay/startup.d/06-range-outline
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -34,13 +34,27 @@ 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}"

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}") &>/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}"
else
echo "WARNING: Unable to download panorama. Outline will not be available."
exit 0
fi
fi
fi

exit 0