RustForge

rustforge

RustForge: the read-only, cgit-style git web host serving this site

rustforge / scripts / deploy.sh
1273 bytes ยท raw
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
#!/usr/bin/env bash
# Build forge here and install it on the server (never builds on the server).
#   scripts/deploy.sh                # binary + unit; keeps the server's config
#   scripts/deploy.sh --config       # also overwrite /etc/forge/forge.toml
set -euo pipefail
cd "$(dirname "$0")/.."

SSH_HOST="${FORGE_SSH_HOST:-rust@88.99.212.146}"
SSH_PORT="${FORGE_SSH_PORT:-2222}"
SSH=(ssh -o BatchMode=yes -p "$SSH_PORT" "$SSH_HOST")
SCP=(scp -q -o BatchMode=yes -P "$SSH_PORT")

cargo build --release
"${SCP[@]}" target/release/forge deploy/forge.service deploy/forge.toml.example README.md "$SSH_HOST:/tmp/"
"${SSH[@]}" "set -e
  sudo install -d -m 755 /opt/forge/bin
  sudo install -m 755 /tmp/forge /opt/forge/bin/forge
  sudo install -m 644 /tmp/README.md /opt/forge/README.md
  sudo install -m 644 /tmp/forge.service /etc/systemd/system/forge.service
  sudo install -d -m 755 /etc/forge
  if [ '${1:-}' = '--config' ] || [ ! -f /etc/forge/forge.toml ]; then
    sudo install -m 640 -o root -g forge /tmp/forge.toml.example /etc/forge/forge.toml
  fi
  rm -f /tmp/forge /tmp/forge.service /tmp/forge.toml.example /tmp/README.md
  sudo systemctl daemon-reload
  sudo systemctl enable --quiet forge
  sudo systemctl restart forge
  sleep 1
  systemctl is-active forge"