[deploy] Anywhere: the Docker image and compose file (edge and control), the Linux installer and systemd units, the Windows Server installer (Caddy mode, three services), the preview client for Fabrica, and the Windows smoke script

This commit is contained in:
2026-11-17 20:42:04 +01:00
parent 09f6b12676
commit 49c05e2523
12 changed files with 988 additions and 0 deletions
+144
View File
@@ -0,0 +1,144 @@
#!/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/.
#
# Writes Ianitor's control.toml and its first secrets from environment variables, once.
# Shared by the Linux installer (deploy/linux/install.sh) and the Docker image's entrypoint.
# An existing control.toml is never touched; secrets are random files (0600), never values in
# the config, the image or a log.
#
# IANITOR_ADMIN_HOST the web UI's address, e.g. ianitor.example.org (required)
# IANITOR_TLS letsencrypt (default) or domi, for the admin host
# IANITOR_DOMI_ROOT the Domi root certificate (public) for tls = domi (docs/pki.md)
# IANITOR_PREVIEW_DOMAIN branch previews live under it, e.g. preview.example.org
# IANITOR_PREVIEW_UPSTREAMS comma list of what previews may point at (10.0.0.0/8,app.internal)
# IANITOR_PREVIEW_TLS letsencrypt or domi (default: IANITOR_TLS)
# IANITOR_ROUTES_REMOTE where the routes repository is pushed (https URL on Gitea, GitHub, GitLab)
# IANITOR_ROUTES_HOST gitea (default), github or gitlab: the push user name and the UI's label
# IANITOR_ROUTES_USER overrides the push user name
# IANITOR_ROOT state root (default /var/lib/ianitor)
# IANITOR_CONFIG where control.toml goes (default /etc/ianitor/control.toml)
# IANITOR_CREDENTIALS the credentials folder (default $IANITOR_ROOT/credentials)
# IANITOR_EDGE_SOCKET edge's admin socket (default /run/ianitor/admin.sock)
# IANITOR_WEB the built web UI (default /usr/share/ianitor/web)
# IANITOR_HTTP, IANITOR_HTTPS listen addresses (default 0.0.0.0:80, 0.0.0.0:443)
set -eu
ROOT="${IANITOR_ROOT:-/var/lib/ianitor}"
CONFIG="${IANITOR_CONFIG:-/etc/ianitor/control.toml}"
CREDS="${IANITOR_CREDENTIALS:-$ROOT/credentials}"
SOCKET="${IANITOR_EDGE_SOCKET:-/run/ianitor/admin.sock}"
WEB="${IANITOR_WEB:-/usr/share/ianitor/web}"
TLS="${IANITOR_TLS:-letsencrypt}"
die() { echo "ianitor setup: $*" >&2; exit 1; }
# Only plain values reach the TOML: no quotes, backslashes, dollars or newlines.
plain() {
case "$1" in
*[\"\\\'\`\$]*) die "$2 contains a character that is not allowed" ;;
esac
if [ "$(printf '%s' "$1" | wc -l)" -ne 0 ]; then die "$2 must be one line"; fi
}
for d in "$ROOT" "$ROOT/control" "$ROOT/edge" "$ROOT/caddy" "$ROOT/certs" "$ROOT/edge-state" \
"$ROOT/caddy-state" "$ROOT/logs" "$CREDS"; do
mkdir -p "$d"
done
chmod 0700 "$CREDS" "$ROOT/control"
# Secrets: made here once, random, readable by their owner only.
umask 077
[ -s "$CREDS/share-link-key" ] || head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n' > "$CREDS/share-link-key"
[ -s "$CREDS/pki-password" ] || head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n' > "$CREDS/pki-password"
umask 022
[ -f "$ROOT/edge/share-revocations.json" ] || echo '{"epoch":0,"deny":[]}' > "$ROOT/edge/share-revocations.json"
[ -f "$ROOT/engine" ] || echo pingora > "$ROOT/engine"
if [ -f "$CONFIG" ]; then
echo "ianitor setup: $CONFIG exists; leaving it as it is." >&2
exit 0
fi
[ -n "${IANITOR_ADMIN_HOST:-}" ] || die "IANITOR_ADMIN_HOST is required (the web UI's address, e.g. ianitor.example.org)"
plain "$IANITOR_ADMIN_HOST" IANITOR_ADMIN_HOST
case "$TLS" in letsencrypt|domi) ;; *) die "IANITOR_TLS must be letsencrypt or domi" ;; esac
PTLS="${IANITOR_PREVIEW_TLS:-$TLS}"
case "$PTLS" in letsencrypt|domi) ;; *) die "IANITOR_PREVIEW_TLS must be letsencrypt or domi" ;; esac
routes_remote=""
if [ -n "${IANITOR_ROUTES_REMOTE:-}" ]; then
plain "$IANITOR_ROUTES_REMOTE" IANITOR_ROUTES_REMOTE
case "${IANITOR_ROUTES_HOST:-gitea}" in
github) user=x-access-token; label=GitHub ;;
gitlab) user=oauth2; label=GitLab ;;
gitea) user=ianitor; label=Gitea ;;
*) die "IANITOR_ROUTES_HOST must be gitea, github or gitlab" ;;
esac
user="${IANITOR_ROUTES_USER:-$user}"
plain "$user" IANITOR_ROUTES_USER
routes_remote="remote = \"$IANITOR_ROUTES_REMOTE\"
remote_name = \"$label\"
push_username = \"$user\"
push_credential = \"routes-token\""
fi
pki=""
if [ "$TLS" = domi ] || [ "$PTLS" = domi ]; then
[ -n "${IANITOR_DOMI_ROOT:-}" ] || die "tls = domi needs IANITOR_DOMI_ROOT (the Domi root certificate; docs/pki.md)"
plain "$IANITOR_DOMI_ROOT" IANITOR_DOMI_ROOT
pki="[pki]
root_cert = \"$IANITOR_DOMI_ROOT\""
fi
previews=""
if [ -n "${IANITOR_PREVIEW_DOMAIN:-}" ]; then
plain "$IANITOR_PREVIEW_DOMAIN" IANITOR_PREVIEW_DOMAIN
plain "${IANITOR_PREVIEW_UPSTREAMS:-}" IANITOR_PREVIEW_UPSTREAMS
list=$(printf '%s\n' "${IANITOR_PREVIEW_UPSTREAMS:-}" | tr ',' '\n' | sed '/^ *$/d; s/^ *//; s/ *$//; s/.*/"&"/' | paste -sd, -)
previews="[previews]
domain = \"$IANITOR_PREVIEW_DOMAIN\"
tls = \"$PTLS\"
upstreams = [$list]"
fi
mkdir -p "$(dirname "$CONFIG")"
cat > "$CONFIG.new" <<EOF
# Written by Ianitor's setup on $(date -u +%Y-%m-%d). Edit freely; setup never rewrites it.
# Secrets are files in $CREDS, never values here.
listen = "127.0.0.1:7878"
state_dir = "$ROOT/control"
credentials_dir = "$CREDS"
[routes]
repo = "$ROOT/routes.git"
$routes_remote
[edge]
config = "$ROOT/edge/edge.json"
admin_socket = "$SOCKET"
share_revocations = "$ROOT/edge/share-revocations.json"
[caddy]
config = "$ROOT/caddy/caddy.json"
[compile]
http_listen = "${IANITOR_HTTP:-0.0.0.0:80}"
https_listen = "${IANITOR_HTTPS:-0.0.0.0:443}"
cert_dir = "$ROOT/certs"
state_dir = "$ROOT/edge-state"
access_log = "$ROOT/logs/access.log"
caddy_credentials_dir = "$CREDS"
[ui]
hostname = "$IANITOR_ADMIN_HOST"
static_dir = "$WEB"
admin_tls = "$TLS"
$pki
$previews
EOF
mv "$CONFIG.new" "$CONFIG"
echo "ianitor setup: wrote $CONFIG" >&2