summaryrefslogtreecommitdiff
path: root/scripts/deploy
blob: 5f730cc66809be1d163a364991368f3532e4ac10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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}"

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 "==> 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"
cp "${REPO_DIR}/scripts/"* "${SITE_DIR}/scripts/"
chown -R www-data:www-data "${SITE_DIR}/scripts"
chmod +x "${SITE_DIR}/scripts/"*

echo "==> Fixing permissions..."
chown www-data:www-data "${BIN_DIR}/claudomator"
chmod +x "${BIN_DIR}/claudomator"

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!"