RustForge

rustforge

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

rustforge / scripts / deploy.sh
1385 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 RustForge 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/rustforge/rustforge.toml
set -euo pipefail
cd "$(dirname "$0")/.."

SSH_HOST="${RUSTFORGE_SSH_HOST:-rust@88.99.212.146}"
SSH_PORT="${RUSTFORGE_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/rustforge deploy/rustforge.service deploy/rustforge.toml.example README.md "$SSH_HOST:/tmp/"
"${SSH[@]}" "set -e
  sudo install -d -m 755 /opt/rustforge/bin
  sudo install -m 755 /tmp/rustforge /opt/rustforge/bin/rustforge
  sudo install -m 644 /tmp/README.md /opt/rustforge/README.md
  sudo install -m 644 /tmp/rustforge.service /etc/systemd/system/rustforge.service
  sudo install -d -m 755 /etc/rustforge
  if [ '${1:-}' = '--config' ] || [ ! -f /etc/rustforge/rustforge.toml ]; then
    sudo install -m 640 -o root -g rustforge /tmp/rustforge.toml.example /etc/rustforge/rustforge.toml
  fi
  rm -f /tmp/rustforge /tmp/rustforge.service /tmp/rustforge.toml.example /tmp/README.md
  sudo systemctl daemon-reload
  sudo systemctl enable --quiet rustforge
  sudo systemctl restart rustforge
  sleep 1
  systemctl is-active rustforge"