#!/bin/bash # deploy — Build and deploy claudomator to /site/doot.terst.org # Usage: ./scripts/deploy [--dirty] # Example: sudo ./scripts/deploy set -euo pipefail DIRTY=false for arg in "$@"; do if [ "$arg" == "--dirty" ]; then DIRTY=true fi done FQDN="doot.terst.org" SITE_DIR="/site/${FQDN}" BIN_DIR="${SITE_DIR}/bin" SERVICE="claudomator@${FQDN}.service" REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" cd "${REPO_DIR}" echo "==> Pulling latest from bare repo..." git pull --ff-only local main STASHED=false if [ "$DIRTY" = false ] && [ -n "$(git status --porcelain)" ]; then echo "==> Stashing uncommitted changes..." git stash push -u -m "Auto-stash before deploy" STASHED=true trap 'if [ "$STASHED" = true ]; then echo "==> Popping stash..."; git stash pop; fi' EXIT fi echo "==> Verifying (build + tests)..." "${REPO_DIR}/scripts/verify" echo "==> Building claudomator..." export GOCACHE="${SITE_DIR}/cache/go-build" export GOPATH="${SITE_DIR}/cache/gopath" mkdir -p "${GOCACHE}" "${GOPATH}" go build -o "${BIN_DIR}/claudomator" ./cmd/claudomator/ echo "==> Copying scripts..." mkdir -p "${SITE_DIR}/scripts" find "${REPO_DIR}/scripts" -maxdepth 1 -type f -exec cp -p {} "${SITE_DIR}/scripts/" \; echo "==> Installing to /usr/local/bin..." cp "${BIN_DIR}/claudomator" /usr/local/bin/claudomator echo "==> Fixing permissions..." "${REPO_DIR}/scripts/fix-permissions" echo "==> Syncing credentials..." "${REPO_DIR}/scripts/sync-credentials" echo "==> Restarting service..." sudo systemctl restart "${SERVICE}" sudo systemctl status "${SERVICE}" --no-pager -l echo "==> Done!"