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 /setup.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 'setup.sh')
| -rwxr-xr-x | setup.sh | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..14c2eec --- /dev/null +++ b/setup.sh @@ -0,0 +1,83 @@ +#!/bin/bash +set -euo pipefail + +# Run once on pestrel as root (or with sudo) to install the synoptic service. +# Usage: sudo ./setup.sh + +if [ "$(id -u)" -ne 0 ]; then + echo "Must run as root or with sudo." >&2 + exit 1 +fi + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +OWNER=st33v + +# --------------------------------------------------------------------------- +# Nginx conflict checks +# --------------------------------------------------------------------------- +echo "==> Checking for nginx conflicts..." + +CONFLICT=0 + +if grep -rl "server_name.*pestrel\.com" /etc/nginx/ 2>/dev/null; then + echo "WARNING: The above nginx config(s) already reference pestrel.com — check for duplicate server blocks." + CONFLICT=1 +fi + +if grep -rl "listen.*80.*default_server" /etc/nginx/ 2>/dev/null; then + echo "WARNING: The above nginx config(s) define a default_server on port 80 — may intercept traffic intended for this site." + CONFLICT=1 +fi + +if ! grep -q "include.*conf\.d" /etc/nginx/nginx.conf 2>/dev/null; then + echo "WARNING: /etc/nginx/nginx.conf does not appear to include conf.d/*.conf — you may need to add the following line manually:" + echo " include /etc/nginx/conf.d/*.conf;" + CONFLICT=1 +fi + +[ "$CONFLICT" -eq 0 ] && echo " No conflicts detected." + +# --------------------------------------------------------------------------- +# Directories +# --------------------------------------------------------------------------- +echo "==> Creating directories..." +install -d -o "$OWNER" -g "$OWNER" /opt/synoptic +install -d -o "$OWNER" -g "$OWNER" /var/lib/synoptic +install -d -o "$OWNER" -g "$OWNER" /var/lib/synoptic/archive +install -d -o "$OWNER" -g "$OWNER" /var/lib/synoptic/archive/raw +install -d -o "$OWNER" -g "$OWNER" /srv/www + +# --------------------------------------------------------------------------- +# Web content +# --------------------------------------------------------------------------- +echo "==> Writing index.html..." +install -o "$OWNER" -g "$OWNER" -m 644 "$SCRIPT_DIR/index.html" /srv/www/index.html + +# --------------------------------------------------------------------------- +# Systemd units +# --------------------------------------------------------------------------- +echo "==> Installing systemd unit files..." +for unit in synoptic.service synoptic.timer synoptic-retry.service synoptic-retry.timer; do + install -m 644 "$SCRIPT_DIR/systemd/${unit}" "/etc/systemd/system/${unit}" + echo " installed ${unit}" +done + +echo "==> Reloading systemd and enabling timer..." +systemctl daemon-reload +systemctl enable --now synoptic.timer + +# --------------------------------------------------------------------------- +# Nginx +# --------------------------------------------------------------------------- +echo "==> Installing nginx config..." +install -m 644 "$SCRIPT_DIR/nginx/pestrel.com.conf" /etc/nginx/conf.d/synoptic.conf + +echo "==> Testing nginx config..." +nginx -t + +echo "==> Reloading nginx..." +systemctl reload nginx + +# --------------------------------------------------------------------------- +echo "==> Done." +echo " Run 'systemctl list-timers synoptic.timer' to confirm next scheduled run." |
