108 lines
3.8 KiB
Bash
Executable File
108 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# build-stack.sh — orchestrate the Ulicraft stack: offline prep then bring-up.
|
|
#
|
|
# Phases:
|
|
# preflight always — verify .env + required tools
|
|
# --prep ONLINE — render configs, build landing, mirror mods + air-gap,
|
|
# fetch launcher, pre-bake the server volume
|
|
# --up OFFLINE — docker compose up -d the full stack
|
|
# (no flag) preflight + print what each phase would do, then exit
|
|
#
|
|
# Cautious by design: halts on the first missing var, missing tool, or failed
|
|
# step. Each sub-script is itself responsible for its own integrity checks.
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.." # repo root
|
|
COMPOSE=(docker compose)
|
|
|
|
# ---- helpers ---------------------------------------------------------------
|
|
log() { printf '\n\033[1;32m==>\033[0m %s\n' "$*"; }
|
|
warn() { printf '\033[1;33m!!\033[0m %s\n' "$*" >&2; }
|
|
die() { printf '\033[1;31mxx\033[0m %s\n' "$*" >&2; exit 1; }
|
|
|
|
need_tool() { command -v "$1" >/dev/null 2>&1 || die "missing required tool: $1"; }
|
|
have_script() { [ -x "tooling/$1" ] || die "missing/not-executable: tooling/$1"; }
|
|
|
|
# ---- preflight -------------------------------------------------------------
|
|
preflight() {
|
|
log "preflight"
|
|
[ -f .env ] || die ".env not found (copy .env.example and fill it)"
|
|
# shellcheck disable=SC1091
|
|
set -a; . ./.env; set +a
|
|
: "${BASE_DOMAIN:?BASE_DOMAIN unset in .env}"
|
|
: "${HOST_LAN_IP:?HOST_LAN_IP unset in .env}"
|
|
: "${RCON_PASSWORD:?RCON_PASSWORD unset in .env}"
|
|
|
|
need_tool docker
|
|
${COMPOSE[@]} version >/dev/null 2>&1 || die "docker compose plugin not available"
|
|
need_tool envsubst
|
|
need_tool jq
|
|
need_tool curl
|
|
need_tool sha1sum
|
|
command -v pnpm >/dev/null 2>&1 || warn "pnpm not found — landing build will be skipped if absent"
|
|
|
|
echo " BASE_DOMAIN=${BASE_DOMAIN} HOST_LAN_IP=${HOST_LAN_IP}"
|
|
echo " preflight ok"
|
|
}
|
|
|
|
# ---- online prep -----------------------------------------------------------
|
|
prep() {
|
|
log "PHASE prep (requires internet)"
|
|
|
|
log "render configs"
|
|
have_script render-config.sh
|
|
tooling/render-config.sh
|
|
|
|
log "build landing page → www/"
|
|
if command -v pnpm >/dev/null 2>&1; then
|
|
( cd landing && pnpm install --frozen-lockfile && BASE_DOMAIN="${BASE_DOMAIN}" pnpm run build )
|
|
else
|
|
warn "pnpm absent — skipping landing build"
|
|
fi
|
|
|
|
log "mirror mod jars (offline pack)"
|
|
have_script mirror-mods.sh
|
|
tooling/mirror-mods.sh
|
|
|
|
log "mirror full air-gap upstream (meta/libraries/assets/client.jar)"
|
|
have_script mirror-airgap.sh
|
|
tooling/mirror-airgap.sh
|
|
|
|
log "fetch launcher releases"
|
|
have_script fetch-launcher.sh
|
|
tooling/fetch-launcher.sh
|
|
|
|
log "pre-bake server volume (TYPE=NEOFORGE install, one-shot, online)"
|
|
# Bring minecraft up once so itzg installs NeoForge + mods into the volume,
|
|
# then stop it. The party then runs offline against the baked volume.
|
|
"${COMPOSE[@]}" up -d minecraft
|
|
warn "watch logs until 'Done' then re-run with --up; or automate a readiness probe"
|
|
}
|
|
|
|
# ---- offline bring-up ------------------------------------------------------
|
|
up() {
|
|
log "PHASE up (offline-capable bring-up)"
|
|
have_script render-config.sh
|
|
tooling/render-config.sh # cheap; ensures configs match current .env
|
|
"${COMPOSE[@]}" up -d
|
|
log "stack up. apex: http://${BASE_DOMAIN} auth: http://auth.${BASE_DOMAIN}"
|
|
}
|
|
|
|
# ---- dispatch --------------------------------------------------------------
|
|
preflight
|
|
case "${1:-}" in
|
|
--prep) prep ;;
|
|
--up) up ;;
|
|
"") cat <<EOF
|
|
|
|
Nothing run. Choose a phase:
|
|
$0 --prep # ONLINE: render, build landing, mirror everything, pre-bake server
|
|
$0 --up # OFFLINE: docker compose up -d the full stack
|
|
|
|
Sub-scripts expected in tooling/: render-config.sh, mirror-mods.sh,
|
|
mirror-airgap.sh, fetch-launcher.sh (built in their own commits — see plan/12).
|
|
EOF
|
|
;;
|
|
*) die "unknown arg: $1 (use --prep or --up)" ;;
|
|
esac
|