blob: 059665d9438d7087d975449ce9fbb31d302ac78e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/bin/bash
set -euo pipefail
# 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 cremonde for pestrel.com.
ARCHIVE_DIR=/var/lib/synoptic/archive
RAW_DIR=/var/lib/synoptic/archive/raw
LATEST=/srv/www/pestrel/synopticLatest.png
require_cmd() {
local cmd="$1"
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Required command not found: ${cmd}" >&2
exit 127
fi
}
require_cmd curl
require_cmd magick
require_cmd gs
# 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
echo "${nowDate}${fileTime}"
}
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
if [ "$curlExit" -eq 78 ]; then
echo "No file at remote site: ${latestChart} (curl exit ${curlExit})" >&2
fi
exit "$curlExit"
fi
magick -density 300 "${latestChart}" -resize 1920x1080 "${dateTime}.png"
mv "${latestChart}" "${RAW_DIR}/"
cp "${dateTime}.png" "${ARCHIVE_DIR}/"
mv "${dateTime}.png" "${LATEST}"
chmod 644 "${LATEST}"
|