65 lines
1.5 KiB
Bash
Executable File
65 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
LEDGER="${HOMELAB_GOLDEN_LEDGER:-${REPO_ROOT}/infra/pimox/golden-image-ledger.yml}"
|
|
|
|
case "${1:-show}" in
|
|
show)
|
|
sed -n '1,220p' "$LEDGER"
|
|
;;
|
|
check)
|
|
if [ ! -s "$LEDGER" ]; then
|
|
echo "missing ledger: $LEDGER" >&2
|
|
exit 1
|
|
fi
|
|
python3 - "$LEDGER" <<'PY'
|
|
import sys
|
|
|
|
try:
|
|
import yaml
|
|
except ImportError:
|
|
print("yaml module unavailable; ledger file exists")
|
|
raise SystemExit(0)
|
|
|
|
path = sys.argv[1]
|
|
with open(path, encoding="utf-8") as handle:
|
|
doc = yaml.safe_load(handle) or {}
|
|
|
|
required = [
|
|
"template.vmid",
|
|
"template.name",
|
|
"os.distribution",
|
|
"os.release",
|
|
"os.architecture",
|
|
"kubernetes.kubelet",
|
|
"kubernetes.kubeadm",
|
|
"kubernetes.kubectl",
|
|
]
|
|
missing = []
|
|
for dotted in required:
|
|
value = doc
|
|
for part in dotted.split("."):
|
|
value = value.get(part) if isinstance(value, dict) else None
|
|
if value in (None, ""):
|
|
missing.append(dotted)
|
|
|
|
if missing:
|
|
print("missing required ledger fields:")
|
|
for item in missing:
|
|
print(f" {item}")
|
|
raise SystemExit(1)
|
|
|
|
print(f"ledger ok: {path}")
|
|
PY
|
|
;;
|
|
update-stamp)
|
|
echo "Manual edit is preferred so image URLs/checksums stay reviewable: $LEDGER" >&2
|
|
exit 1
|
|
;;
|
|
*)
|
|
echo "Usage: ./jeannie golden-ledger {show|check}" >&2
|
|
exit 1
|
|
;;
|
|
esac
|