Files
railiance-cluster/tools/seed_node.sh
Bernd Worsch 75d11583e4
Some checks failed
railiance-tests / smoke (push) Has been cancelled
feat(tools): directed panspermia inspired colonization scripts
2025-09-13 00:11:18 +02:00

137 lines
4.2 KiB
Bash

#!/usr/bin/env bash
# tools/seed_node.sh
# Railiance Seed — kick off biogenesis on a blank (or nearly blank) host.
#
# Responsibilities:
# - Ensure minimal prerequisites (curl, git, jq)
# - Discover metadata (panspermia.json or env vars)
# - Clone or update the parent repo (default: railiance-bootstrap)
# - Run furnishing (idempotent) to align housekeeping
# - (Optional) handoff to further bootstrap steps
#
# Usage examples:
# ./tools/seed_node.sh
# REPO_URL=https://git.example.com/org/railiance-bootstrap.git ./tools/seed_node.sh
# ./tools/seed_node.sh --repo-dir /srv/railiance --branch main
#
# Notes:
# - No secrets are written or echoed by this script.
# - Git authentication relies on your environment (SSH keys or credential helper).
set -euo pipefail
# --------- defaults & flags ----------
REPO_DIR="${REPO_DIR:-railiance-bootstrap}"
BRANCH="${BRANCH:-main}"
META_PATH="${META_PATH:-}" # optional explicit path to panspermia.json
QUIET=false
while [[ $# -gt 0 ]]; do
case "$1" in
--repo-dir) REPO_DIR="${2:?}"; shift 2 ;;
--branch) BRANCH="${2:?}"; shift 2 ;;
--meta) META_PATH="${2:?}"; shift 2 ;;
-q|--quiet) QUIET=true; shift ;;
-h|--help)
sed -n '1,120p' "$0" | sed -n '1,/^set -euo pipefail/p'
exit 0 ;;
*) echo "Unknown arg: $1" >&2; exit 2 ;;
esac
done
log() { $QUIET || echo "$@"; }
need() {
command -v "$1" >/dev/null 2>&1 && return 0
log "[*] Installing $1 ..."
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update -y && sudo apt-get install -y "$1"
elif command -v dnf >/dev/null 2>&1; then
sudo dnf install -y "$1"
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y "$1"
else
echo "ERROR: package manager not found to install $1" >&2
exit 1
fi
}
# prerequisites
need curl
need git
command -v jq >/dev/null 2>&1 || need jq
# --------- discover metadata ----------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEFAULT_META="${SCRIPT_DIR}/../panspermia.json"
REPO_URL="${REPO_URL:-}"
if [[ -z "${REPO_URL}" ]]; then
# read metadata file (explicit > default > none)
SRC_META=""
if [[ -n "${META_PATH}" && -f "${META_PATH}" ]]; then
SRC_META="${META_PATH}"
elif [[ -f "${DEFAULT_META}" ]]; then
SRC_META="${DEFAULT_META}"
fi
if [[ -n "${SRC_META}" ]]; then
log "[=] Using metadata: ${SRC_META}"
REPO_URL="$(jq -r '.parent_body.repo_url // empty' "${SRC_META}")"
BRANCH_FROM_META="$(jq -r '.parent_body.branch // empty' "${SRC_META}")" || true
if [[ -n "${BRANCH_FROM_META}" ]]; then BRANCH="${BRANCH_FROM_META}"; fi
fi
fi
if [[ -z "${REPO_URL}" ]]; then
echo "ERROR: No REPO_URL provided and no panspermia metadata found." >&2
echo "Provide one of:" >&2
echo " - env REPO_URL=https://git.example.com/org/railiance-bootstrap.git" >&2
echo " - or a panspermia.json with .parent_body.repo_url" >&2
exit 1
fi
log "[*] Target repo: ${REPO_URL} (branch: ${BRANCH})"
log "[*] Local dir : ${REPO_DIR}"
# --------- clone or update ----------
if [[ -d "${REPO_DIR}/.git" ]]; then
log "[=] Repo dir exists. Fetching updates ..."
(
cd "${REPO_DIR}"
git remote -v
git fetch --all --tags
git checkout "${BRANCH}"
git pull --ff-only origin "${BRANCH}" || true
)
else
log "[+] Cloning repository ..."
git clone --branch "${BRANCH}" "${REPO_URL}" "${REPO_DIR}"
fi
# --------- furnishing ----------
if [[ -x "${REPO_DIR}/tools/furnish_railiance_repo.sh" ]]; then
log "[*] Running furnishing script (idempotent) ..."
bash "${REPO_DIR}/tools/furnish_railiance_repo.sh"
else
log "[!] Furnishing script not found at ${REPO_DIR}/tools/furnish_railiance_repo.sh — skipping."
fi
# --------- placeholder for next steps ----------
cat <<'NEXT'
[✓] Seed completed.
Next steps (manual, for now):
1) Review the repo at $REPO_DIR
2) Configure host inventory and credentials (kept local, never committed)
3) Run the initial bootstrap playbook (e.g., ansible/bootstrap.yml)
4) Prepare GitOps operator (ArgoCD/Flux) pointing to this repo
Hints:
- To use SSH instead of HTTPS, set REPO_URL=git@your-gitea:org/railiance-bootstrap.git
- If using HTTPS, set up 'git config --global credential.helper cache|store'
- For air-gapped: copy a Spore bundle, extract, then run this seed script
NEXT