#!/bin/sh # Install `spectra serve` on another machine as a systemd user service # (spec ยง8.6, spectra#25): build a release here, copy a stripped binary and # the unit over SSH, and enable it. The unit waits until a Spectra exists # there (`spectra init --owner KEYID`), and starts from boot when the # account has lingering on. # # scripts/install-server.sh [USER@]HOST set -eu [ $# -eq 1 ] || { echo "usage: $0 [USER@]HOST" >&2; exit 2; } target=$1 cd "$(dirname "$0")/.." SPECTRA_BUILD="$(oxy --plain describe 2>/dev/null || true)" CARGO_INCREMENTAL=0 cargo build --release -p spectra bin=${CARGO_TARGET_DIR:-target}/release/spectra tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT strip -o "$tmp/spectra" "$bin" ssh -o BatchMode=yes "$target" 'mkdir -p ~/.local/bin ~/.config/systemd/user' scp -q -o BatchMode=yes "$tmp/spectra" "$target:.local/bin/spectra.new" scp -q -o BatchMode=yes packaging/spectra.service "$target:.config/systemd/user/spectra.service" ssh -o BatchMode=yes "$target" ' set -e chmod 755 ~/.local/bin/spectra.new && mv ~/.local/bin/spectra.new ~/.local/bin/spectra systemctl --user daemon-reload systemctl --user enable spectra >/dev/null 2>&1 if systemctl --user is-active --quiet spectra; then systemctl --user restart spectra; fi echo "installed: $(~/.local/bin/spectra --version)" if [ -e ~/.local/share/spectra/spectra.db ]; then systemctl --user start spectra echo "service: $(systemctl --user is-active spectra)" else echo "service: enabled; waiting for a Spectra: spectra init --owner KEYID, then systemctl --user start spectra" fi echo "linger: $(loginctl show-user "$(id -un)" -p Linger --value) (yes means it runs from boot)" '