interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / spark / edge-certs.sh

30 lines · 1406 bytes Raw Blame History
1#!/bin/sh
2# spark/edge-certs.sh: copy the TLS certificates for www.aienos.com, aienos.com and interplane.io
3# from the hub Pi (where acme.sh renews them through Gandi DNS, independent of where :443 points)
4# into the Spark front door's /etc/nginx/certs, and reload nginx only when a file changed and
5# `nginx -t` passes. Runs from the spark user timer edge-certs.timer (needs passwordless sudo).
6# Host tools: OpenSSH, tar, sha256sum, install, nginx. Omega replacement: none planned for the
7# ACME client (encryption and certificate handling stay on vetted tools, per Drake's rule).
8set -eu
9HUB=${HUB:-hub}
10W=$(mktemp -d)
11trap 'rm -rf -- "${W:?}"' EXIT
12timeout 300 ssh -o BatchMode=yes -o ConnectTimeout=60 "$HUB" \
13 'sudo tar -C /etc/nginx/certs -cf - aienos.com www.aienos.com interplane.io' | tar -C "$W" -xf -
14changed=0
15for c in aienos.com www.aienos.com interplane.io; do
16 for f in fullchain.pem key.pem; do
17 [ -s "$W/$c/$f" ] || { echo "FAIL: $c/$f missing from hub copy"; exit 1; }
18 if ! sudo cmp -s "$W/$c/$f" "/etc/nginx/certs/$c/$f"; then
19 m=644; [ "$f" = key.pem ] && m=600
20 sudo install -d -m 700 "/etc/nginx/certs/$c"
21 sudo install -m "$m" -o root -g root "$W/$c/$f" "/etc/nginx/certs/$c/$f"
22 changed=1; echo "updated $c/$f"
23 fi
24 done
25done
26if [ "$changed" = 1 ]; then
27 sudo nginx -t && sudo systemctl reload nginx && echo "RELOADED"
28else
29 echo "UNCHANGED"
30fi