82 lines
4.1 KiB
Bash
82 lines
4.1 KiB
Bash
#!/bin/sh
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
#
|
|
# Ianitor Domi on plain Linux with systemd (T4), in one line:
|
|
#
|
|
# curl -fsSL https://gitea.marek-novak.cz/mnovak/Ianitor/releases/download/vX.Y.Z/install.sh \
|
|
# | sudo IANITOR_ADMIN_HOST=ianitor.example.org sh
|
|
#
|
|
# It downloads the release tarball and SHA256SUMS of the same release, checks the sum, installs
|
|
# the binaries, the web UI and two systemd units (ianitor-control, ianitor-edge), writes
|
|
# /etc/ianitor/control.toml once (deploy/linux/setup.sh: every IANITOR_* variable), starts both,
|
|
# and prints the first admin's sign-in link. Running it again upgrades the binaries and keeps
|
|
# the config and the state. IANITOR_TARBALL=<file> installs a local tarball instead (no download).
|
|
set -eu
|
|
|
|
VERSION="${IANITOR_VERSION:-__VERSION__}"
|
|
BASE="${IANITOR_RELEASES:-https://gitea.marek-novak.cz/mnovak/Ianitor/releases/download}/v$VERSION"
|
|
ARCH="$(uname -m)"
|
|
NAME="ianitor-$VERSION-linux-$ARCH.tar.gz"
|
|
|
|
die() { echo "ianitor install: $*" >&2; exit 1; }
|
|
[ "$(id -u)" = 0 ] || die "run it as root (sudo)"
|
|
command -v systemctl >/dev/null || die "this installer needs systemd; use the Docker image otherwise (deploy/docker)"
|
|
command -v git >/dev/null || die "install git first (apt install git / dnf install git)"
|
|
[ "$ARCH" = x86_64 ] || die "only x86_64 builds are published so far"
|
|
|
|
work="$(mktemp -d)"
|
|
trap 'rm -rf "$work"' EXIT
|
|
if [ -n "${IANITOR_TARBALL:-}" ]; then
|
|
cp "$IANITOR_TARBALL" "$work/$NAME"
|
|
else
|
|
command -v curl >/dev/null || die "install curl first"
|
|
curl -fsSLo "$work/$NAME" "$BASE/$NAME"
|
|
curl -fsSLo "$work/SHA256SUMS" "$BASE/SHA256SUMS"
|
|
(cd "$work" && grep " $NAME\$" SHA256SUMS | sha256sum -c -) || die "the download does not match SHA256SUMS"
|
|
fi
|
|
tar -xzf "$work/$NAME" -C "$work"
|
|
src="$work/ianitor-$VERSION"
|
|
[ -x "$src/bin/ianitor-control" ] || die "the tarball has no bin/ianitor-control"
|
|
|
|
getent group ianitor >/dev/null || groupadd --system ianitor
|
|
id ianitor >/dev/null 2>&1 || useradd --system --gid ianitor --home-dir /var/lib/ianitor --shell /usr/sbin/nologin ianitor
|
|
id ianitor-edge >/dev/null 2>&1 || useradd --system --gid ianitor --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin ianitor-edge
|
|
|
|
install -m 0755 "$src/bin/ianitor-control" "$src/bin/ianitor-edge" /usr/local/bin/
|
|
install -d -m 0755 /usr/local/lib/ianitor /usr/share/ianitor
|
|
install -m 0755 "$src/lib/setup.sh" /usr/local/lib/ianitor/setup.sh
|
|
rm -rf /usr/share/ianitor/web && cp -r "$src/web" /usr/share/ianitor/web
|
|
install -m 0644 "$src/lib/ianitor-control.service" "$src/lib/ianitor-edge.service" /etc/systemd/system/
|
|
|
|
IANITOR_ROOT=/var/lib/ianitor IANITOR_CONFIG=/etc/ianitor/control.toml \
|
|
IANITOR_EDGE_SOCKET=/run/ianitor-edge/admin.sock sh /usr/local/lib/ianitor/setup.sh
|
|
|
|
# Who may read what (as the NixOS module's tmpfiles): control owns the state, edge reads its
|
|
# config and the certificates through the group and writes only its own state and logs.
|
|
chown -R ianitor:ianitor /var/lib/ianitor
|
|
chmod 0755 /var/lib/ianitor
|
|
chmod 0700 /var/lib/ianitor/control /var/lib/ianitor/credentials
|
|
chmod 0750 /var/lib/ianitor/edge /var/lib/ianitor/certs /var/lib/ianitor/caddy
|
|
chown -R ianitor-edge:ianitor /var/lib/ianitor/edge-state /var/lib/ianitor/logs
|
|
chmod 0700 /var/lib/ianitor/edge-state
|
|
chmod 0770 /var/lib/ianitor/logs
|
|
chown root:ianitor /etc/ianitor /etc/ianitor/control.toml
|
|
chmod 0750 /etc/ianitor
|
|
chmod 0640 /etc/ianitor/control.toml
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable --now ianitor-control.service ianitor-edge.service
|
|
systemctl restart ianitor-control.service ianitor-edge.service
|
|
|
|
i=0
|
|
until curl -s -o /dev/null http://127.0.0.1:7878/api/v1/health 2>/dev/null; do
|
|
i=$((i + 1)); [ $i -le 30 ] || die "control did not start; see journalctl -u ianitor-control"
|
|
sleep 1
|
|
done
|
|
echo
|
|
echo "Ianitor $VERSION is running. Open this link to sign in as the first admin:"
|
|
runuser -u ianitor -- /usr/local/bin/ianitor-control team setup-link --config /etc/ianitor/control.toml 2>/dev/null \
|
|
|| echo "(the team already has an admin; they invite you from Settings → Team)"
|