bringup (1901B)
1 #!/bin/sh 2 # One-time server setup on Debian. Run after first `push` lands tooling in ~/repos/. 3 # Assumes Caddy is already installed and running (we piggyback via an import line). 4 # Usage: ~/repos/bin/bringup 5 set -eu 6 7 REPOS=$HOME/repos 8 9 sudo apt-get update 10 sudo apt-get install -y git rsync build-essential libgit2-dev curl md2html 11 12 # Build stagit from source (not in Debian repos). Pinned commit is content-verified 13 # by git's object hashing even though upstream only serves git://. 14 STAGIT_COMMIT=4d3348560faf732f9304a05a269b4d33df930988 15 STAGIT_URL=git://git.codemadness.org/stagit 16 if ! command -v stagit >/dev/null; then 17 tmp=$(mktemp -d) 18 git clone "$STAGIT_URL" "$tmp/stagit" 19 git -C "$tmp/stagit" checkout --quiet "$STAGIT_COMMIT" 20 actual=$(git -C "$tmp/stagit" rev-parse HEAD) 21 [ "$actual" = "$STAGIT_COMMIT" ] || { echo "stagit SHA mismatch: $actual"; exit 1; } 22 make -C "$tmp/stagit" 23 sudo make -C "$tmp/stagit" install PREFIX=/usr/local 24 rm -rf "$tmp" 25 fi 26 27 # Caddy (runs as caddy user) needs to traverse into ~/repos 28 chmod 755 "$HOME" "$REPOS" 29 30 # Substitute placeholders into site config 31 TS_IP=$(tailscale ip -4 2>/dev/null | head -n1 || true) 32 if [ -z "$TS_IP" ]; then 33 echo "error: tailscale not up" >&2 34 exit 1 35 fi 36 . "$REPOS/config.env" 2>/dev/null || { echo "missing $REPOS/config.env (run push first)"; exit 1; } 37 sed -i "s|__TAILSCALE_IP__|$TS_IP|g; s|__GIT_HOSTNAME__|$GIT_HOSTNAME|g" "$REPOS/caddy/git.caddy" 38 39 # Hook into the main Caddyfile once (idempotent) 40 IMPORT_LINE="import $REPOS/caddy/*.caddy" 41 if ! sudo grep -qxF "$IMPORT_LINE" /etc/caddy/Caddyfile; then 42 echo "$IMPORT_LINE" | sudo tee -a /etc/caddy/Caddyfile >/dev/null 43 fi 44 sudo caddy validate --config /etc/caddy/Caddyfile 45 sudo systemctl reload caddy 46 47 # Initial build over anything already present 48 "$REPOS/bin/stagit-update" 49 50 echo "ok: server ready. next: ~/repos/bin/add-repo <name> [--public]"