[linux] Installer (one copied line) and the container test of the Linux target with real systemd
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: MPL-2.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."
|
||||
Reference in New Issue
Block a user