#!/usr/bin/env bash # Ship the browser build to gbc.sl0p.foo. # # Static files only - no service, no restart, nginx serves the directory. The # box does not build anything: the wasm is compiled here and rsynced. # # ./web/deploy.sh # build + ship # DRY=1 ./web/deploy.sh # show what would transfer # HOST=root@other ./web/deploy.sh # # The demo ROM is gbos (~/dev/gbos), which is a build artifact of that repo and # deliberately not vendored here - point GBOS_ROM at it if it lives elsewhere. set -euo pipefail HOST="${HOST:-root@sl0p.foo}" DEST="${DEST:-/opt/sl0p/gbc}" GBOS_ROM="${GBOS_ROM:-$HOME/dev/gbos/gbos.gb}" cd "$(dirname "$0")/.." echo "==> building wasm" make wasm stage="$(mktemp -d)" trap 'rm -rf "$stage"' EXIT for f in web/*.html web/*.js; do install -Dm644 "$f" "$stage/$(basename "$f")" done install -Dm644 web/sl0pboy.wasm "$stage/sl0pboy.wasm" if [ -f "$GBOS_ROM" ]; then install -Dm644 "$GBOS_ROM" "$stage/roms/gbos.gb" # Keep the (gitignored) dev copy in step, so `python3 -m http.server` in # web/ serves what was last shipped. A stale one here is invisible and # costs an hour: the page looks fine but the ROM predates the feature # you're testing. install -Dm644 "$GBOS_ROM" web/roms/gbos.gb echo "==> demo ROM: $GBOS_ROM ($(du -h "$GBOS_ROM" | cut -f1))" else # Not fatal: the page falls back to "drop in a ROM" when the fetch 404s. echo "!! no demo ROM at $GBOS_ROM - shipping without it" >&2 fi echo "==> ${HOST}:${DEST}" rsync -av --delete ${DRY:+--dry-run} -e ssh "$stage/" "${HOST}:${DEST}/" [ -n "${DRY:-}" ] && exit 0 # nginx (user http/www-data) only needs to read; keep it root-owned. ssh "$HOST" "chown -R root:root '$DEST' && chmod -R a+rX '$DEST'" echo "==> verify" for p in / /net.html /gbcore.js /gbhub.js /sl0pboy.wasm /roms/gbos.gb; do printf ' %-18s ' "$p" curl -s -o /dev/null -w '%{http_code} %{content_type} %{size_download}B\n' \ "https://gbc.sl0p.foo$p" done