OXYGENHUB
# 813b6330f3ad spectra / scripts / install-server.sh
1.6 KiB · Bourne Again Shell (bash) · executable · last changed Run the daemon on Earth: make install-server, a unit that waits for a Spectra (#25) 1 day ago source blame history raw
1
#!/bin/sh
2
# Install `spectra serve` on another machine as a systemd user service
3
# (spec §8.6, spectra#25): build a release here, copy a stripped binary and
4
# the unit over SSH, and enable it. The unit waits until a Spectra exists
5
# there (`spectra init --owner KEYID`), and starts from boot when the
6
# account has lingering on.
7
#
8
#   scripts/install-server.sh [USER@]HOST
9
set -eu
10
[ $# -eq 1 ] || { echo "usage: $0 [USER@]HOST" >&2; exit 2; }
11
target=$1
12
cd "$(dirname "$0")/.."
13
SPECTRA_BUILD="$(oxy --plain describe 2>/dev/null || true)" CARGO_INCREMENTAL=0 cargo build --release -p spectra
14
bin=${CARGO_TARGET_DIR:-target}/release/spectra
15
tmp=$(mktemp -d)
16
trap 'rm -rf "$tmp"' EXIT
17
strip -o "$tmp/spectra" "$bin"
18
ssh -o BatchMode=yes "$target" 'mkdir -p ~/.local/bin ~/.config/systemd/user'
19
scp -q -o BatchMode=yes "$tmp/spectra" "$target:.local/bin/spectra.new"
20
scp -q -o BatchMode=yes packaging/spectra.service "$target:.config/systemd/user/spectra.service"
21
ssh -o BatchMode=yes "$target" '
22
set -e
23
chmod 755 ~/.local/bin/spectra.new && mv ~/.local/bin/spectra.new ~/.local/bin/spectra
24
systemctl --user daemon-reload
25
systemctl --user enable spectra >/dev/null 2>&1
26
if systemctl --user is-active --quiet spectra; then systemctl --user restart spectra; fi
27
echo "installed: $(~/.local/bin/spectra --version)"
28
if [ -e ~/.local/share/spectra/spectra.db ]; then
29
  systemctl --user start spectra
30
  echo "service: $(systemctl --user is-active spectra)"
31
else
32
  echo "service: enabled; waiting for a Spectra: spectra init --owner KEYID, then systemctl --user start spectra"
33
fi
34
echo "linger: $(loginctl show-user "$(id -un)" -p Linger --value) (yes means it runs from boot)"
35
'