deploy/install.sh

9df917e73a67d15adecc3f45976690f6fcd4e47a
gitbay/deploy/install.sh history · blame · raw

26 lines · 1063 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"$(dirname "$0")/copy.sh" "$host" "$port" "$bin" /usr/local/bin/gitbayd.new
12ssh -p "$port" "root@$host" '
13  set -eu
14  chmod 755 /usr/local/bin/gitbayd.new
15  mv /usr/local/bin/gitbayd.new /usr/local/bin/gitbayd
16  /usr/local/bin/gitbayd --config /etc/gitbay/config.toml check-config --no-host-checks
17  # The key that seals secrets in the database. Created on the first
18  # install, never replaced here; gitbayd refuses to start without it.
19  if [ ! -e /etc/gitbay/secret.key ]; then
20    /usr/local/bin/gitbayd --config /etc/gitbay/config.toml admin secrets init
21    chown gitbay:gitbay /etc/gitbay/secret.key
22  fi
23  systemctl restart gitbayd
24  sleep 1
25  systemctl --no-pager --lines=5 status gitbayd
26'