diff options
| author | St33v <github@f3rr3t.com> | 2026-03-15 15:48:10 +1100 |
|---|---|---|
| committer | St33v <github@f3rr3t.com> | 2026-03-15 15:48:10 +1100 |
| commit | 96a9cd525e7caf46704ba2240c1c86f6892e3aaf (patch) | |
| tree | 11f022a651adc766256e00d4dd8bf18f4ab46e35 /synopticChart.sh | |
| parent | 078d16785d7b027aead68f59d1c1b4dd18cd5267 (diff) | |
Add deployment config and strengthen synopticChart.sh
- Inline DeriveTime from func/deriveTimeString.sh; delete func/
- Add set -euo pipefail, quoting, and stderr for error messages
- Archive PDFs to /var/lib/synoptic/archive/raw/ after conversion
- Publish PNG to /srv/www/synopticLatest.png
- Add systemd units: synoptic.{service,timer}, synoptic-retry.{service,timer}
- Timer fires at 02:10, 08:10, 14:10, 20:10 UTC (2h after BOM publish slots)
- Add nginx site config for pestrel.com
- Add setup.sh (run once on VPS as root) and deploy.sh (run from cr4y)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'synopticChart.sh')
| -rwxr-xr-x | synopticChart.sh | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/synopticChart.sh b/synopticChart.sh index e7d3726..a515c90 100755 --- a/synopticChart.sh +++ b/synopticChart.sh @@ -1,37 +1,49 @@ #!/bin/bash -# SJP 28 Nov 2021 -# Get synoptic weather charts from BOM and make them into a movie -# See notes about BOM. they don't like scrapers but permit anon FTP -# for *personal use* -# This script will be called froma timer, once every 6 hours, which is -# how often new charts are published. -# -# The timer will take care of scheduing the call to the script -# todo: check what happens with daylight saving... +set -euo pipefail -source func/deriveTimeString.sh +# SJP 28 Nov 2021 — extended for deployment +# Download BOM synoptic chart (IDY00030) and publish as PNG. +# BOM permits anonymous FTP for personal use. +# Charts are valid at 00, 06, 12, 18 UTC; files appear ~2h later. +# Deployed to /opt/synoptic/synopticChart.sh on pestrel.com. -dateTime=$(DeriveTime) +ARCHIVE_DIR=/var/lib/synoptic/archive +RAW_DIR=/var/lib/synoptic/archive/raw +LATEST=/srv/www/synopticLatest.png + +# Return the datetime string for the most recently published chart slot. +# BOM chart slots: 0000, 0600, 1200, 1800 UTC. +DeriveTime() { + local nowDate nowTime fileTime + nowDate=$(date -u +%Y%m%d) + nowTime=$(date -u +%H%M) + + if [ "$nowTime" -ge 1800 ]; then fileTime=1800 + elif [ "$nowTime" -ge 1200 ]; then fileTime=1200 + elif [ "$nowTime" -ge 0600 ]; then fileTime=0600 + else fileTime=0000 + fi -latestChart=IDY00030.${dateTime}.pdf -#printf "latestChart filename: %s\n" ${latestChart} + echo "${nowDate}${fileTime}" +} -# -q no config file lookup -# -f fail early -# -s silent -curl -q -fs -o ${latestChart} ftp://ftp.bom.gov.au/anon/gen/fwo/${latestChart} -curlExit=$? +dateTime=$(DeriveTime) +latestChart="IDY00030.${dateTime}.pdf" +# -q no config file lookup -f fail on error -s silent +curlExit=0 +curl -q -fs -o "${latestChart}" "ftp://ftp.bom.gov.au/anon/gen/fwo/${latestChart}" \ + || curlExit=$? -if [ $curlExit -gt 0 ] ; then - # Did we find a file? (Maybe it has not been created yet). - if [ $curlExit -eq 78 ] ; then - echo "No file at remote site $curlExit" - # todo create a one-shot timer service +if [ "$curlExit" -gt 0 ]; then + if [ "$curlExit" -eq 78 ]; then + echo "No file at remote site: ${latestChart} (curl exit ${curlExit})" >&2 fi - exit $curlExit + exit "$curlExit" fi +magick -density 300 "${latestChart}" "${dateTime}.png" -magick -density 300 ${latestChart} ${dateTime}.png - +mv "${latestChart}" "${RAW_DIR}/" +cp "${dateTime}.png" "${ARCHIVE_DIR}/" +mv "${dateTime}.png" "${LATEST}" |
