deploy/install.sh

v1.6.0
gitbay/deploy/install.sh history · blame · raw

26 lines · 1055 bytes · executable

 1#!/bin/sh
 2# Push the gitbayd binary to a freshly cloud-inited host and start it.
 3# Usage: deploy/install.sh <host-or-ip> [ssh-port]
 4set -eu
 5host=${1:?usage: install.sh <host-or-ip> [ssh-port]}
 6port=${2:-2222}
 7bin=dist/gitbayd-linux-amd64
 8
 9[ -f "$bin" ] || { echo "build first: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $bin ./cmd/gitbayd" >&2; exit 1; }
10
11# rsync resumes a transfer the host's load stalled and compresses the
12# binary on the wire; scp -C is the fallback where the host has no rsync.
13if ssh -p "$port" "root@$host" 'command -v rsync >/dev/null'; then
14  rsync --partial --inplace -z -e "ssh -p $port" "$bin" "root@$host:/usr/local/bin/gitbayd.new"
15else
16  scp -C -P "$port" "$bin" "root@$host:/usr/local/bin/gitbayd.new"
17fi
18ssh -p "$port" "root@$host" '
19  set -eu
20  chmod 755 /usr/local/bin/gitbayd.new
21  mv /usr/local/bin/gitbayd.new /usr/local/bin/gitbayd
22  /usr/local/bin/gitbayd --config /etc/gitbay/config.toml check-config --no-host-checks
23  systemctl restart gitbayd
24  sleep 1
25  systemctl --no-pager --lines=5 status gitbayd
26'