#!/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 master 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/ chown www-data:www-data "${BIN_DIR}/claudomator" chmod +x "${BIN_DIR}/claudomator" if [ -f "${BIN_DIR}/claude" ]; then echo "==> Fixing Claude permissions..." chown www-data:www-data "${BIN_DIR}/claude" chmod +x "${BIN_DIR}/claude" fi echo "==> Copying scripts..." mkdir -p "${SITE_DIR}/scripts" find "${REPO_DIR}/scripts" -maxdepth 1 -type f -exec cp -p {} "${SITE_DIR}/scripts/" \; chown -R www-data:www-data "${SITE_DIR}/scripts" find "${SITE_DIR}/scripts" -maxdepth 1 -type f -exec chmod +x {} + echo "==> Installing to /usr/local/bin..." cp "${BIN_DIR}/claudomator" /usr/local/bin/claudomator chmod +x /usr/local/bin/claudomator echo "==> Restarting service..." sudo systemctl restart "${SERVICE}" sudo systemctl status "${SERVICE}" --no-pager -l echo "==> Done!"