Files
Legatus/install/install.sh
T
mnovak 5fcae1d152 [repo] Licence: CPAL-1.0 file headers instead of the MPL-2.0 notice
Each source file's three-line MPL-2.0 notice becomes an SPDX CPAL-1.0 header with the copyright
line; the Exhibit A notice itself is in LICENSE (CPAL 3.5). Shell scripts' SPDX ids follow.
Comments only: no code changes.
2026-11-23 00:19:33 +01:00

65 lines
2.6 KiB
Bash

#!/bin/sh
# SPDX-License-Identifier: CPAL-1.0
# Legatus installer, served by the Fabrica server at /legatus/install.sh:
# curl -fsSL https://<fabrica>/legatus/install.sh | sudo sh -s -- lgt1-<code>
# Downloads the Legatus binary for this machine from the same server, checks its SHA-256 against
# the SHA256SUMS beside it (and the minisign signature when minisign is installed), installs it,
# enrolls with the one-time code, and starts legatus.service.
set -eu
CODE=${1:-}
BASE=${LEGATUS_BASE:-} # Fabrica sets this in the script it serves, e.g. https://fabrica.example
KEY=${LEGATUS_RELEASE_KEY:-} # and the minisign key Legatus releases are signed with
die() { echo "legatus install: $*" >&2; exit 1; }
[ -n "$CODE" ] || die "usage: install.sh lgt1-<code>"
case "$CODE" in lgt1-*) ;; *) die "that is not an enrollment code" ;; esac
[ -n "$BASE" ] || die "this script must be served by Fabrica (LEGATUS_BASE is not set)"
[ "$(id -u)" = 0 ] || die "run it with sudo"
command -v systemctl >/dev/null || die "systemd is needed"
command -v sha256sum >/dev/null || die "sha256sum is needed"
case "$(uname -m)" in
x86_64|amd64) ARCH=x86_64 ;;
aarch64|arm64) ARCH=aarch64 ;;
*) die "this CPU ($(uname -m)) is not supported yet" ;;
esac
FILE="legatus-linux-$ARCH"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
curl -fsSL --proto '=https' --tlsv1.2 -o "$TMP/$FILE" "$BASE/legatus/download/$FILE"
curl -fsSL --proto '=https' --tlsv1.2 -o "$TMP/SHA256SUMS" "$BASE/legatus/download/SHA256SUMS"
if [ -n "$KEY" ] && command -v minisign >/dev/null; then
curl -fsSL --proto '=https' --tlsv1.2 -o "$TMP/SHA256SUMS.minisig" "$BASE/legatus/download/SHA256SUMS.minisig"
minisign -Vm "$TMP/SHA256SUMS" -P "$KEY" >/dev/null || die "SHA256SUMS is not signed by the Legatus release key"
fi
WANT=$(awk -v f="$FILE" '$2 == f || $2 == "*"f { print $1 }' "$TMP/SHA256SUMS")
[ -n "$WANT" ] || die "SHA256SUMS does not list $FILE"
GOT=$(sha256sum "$TMP/$FILE" | cut -d' ' -f1)
[ "$WANT" = "$GOT" ] || die "the download does not match SHA256SUMS"
install -m 755 "$TMP/$FILE" /usr/local/bin/legatus
install -d -m 700 /var/lib/legatus
/usr/local/bin/legatus enroll "$CODE"
cat > /etc/systemd/system/legatus.service <<'EOF'
[Unit]
Description=Legatus, the Fabrica Domi agent
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/local/bin/legatus run
Restart=always
RestartSec=5
StateDirectory=legatus
StateDirectoryMode=0700
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now legatus.service
echo "Legatus is running. It shows up in Fabrica under Targets."