provisioning-catalog/playbooks/bootstrap_initial/steps/verify_prerequisites.nu

43 lines
1.9 KiB
Text

#!/usr/bin/env nu
def main [
--workspace: string = ""
--hetzner-context: string = ""
--do-context: string = ""
--bootstrap-zot-url: string = ""
--ops-controller-key: string = ""
--keeper-key: string = ""
--initial-delegate-did: string = ""
--dry-run
]: nothing -> nothing {
if $dry_run {
print "[dry-run] would verify: hcloud auth, doctl auth, NATS tools, SOPS, Radicle, key files"
return
}
let tool_checks = [
{ label: "hcloud CLI", ok: ((do { ^hcloud version } | complete | get exit_code) == 0) },
{ label: "nickel CLI", ok: ((do { ^nickel --version } | complete | get exit_code) == 0) },
{ label: "sops CLI", ok: ((do { ^sops --version } | complete | get exit_code) == 0) },
{ label: "nats CLI", ok: ((do { ^nats --version } | complete | get exit_code) == 0) },
{ label: "rad CLI", ok: ((do { ^rad --version } | complete | get exit_code) == 0) },
{ label: "kubectl", ok: ((do { ^kubectl version --client } | complete | get exit_code) == 0) },
]
let missing_tools = $tool_checks | where { |c| not $c.ok }
for c in $missing_tools { print $"MISSING tool: ($c.label)" }
let missing_args = [
{ label: "ops-controller-key", ok: (($ops_controller_key | is-not-empty) and ($ops_controller_key | path exists)) },
{ label: "keeper-key", ok: (($keeper_key | is-not-empty) and ($keeper_key | path exists)) },
{ label: "initial-delegate-did", ok: ($initial_delegate_did | is-not-empty) },
{ label: "bootstrap-zot-url", ok: ($bootstrap_zot_url | is-not-empty) },
] | where { |a| not $a.ok }
for a in $missing_args { print $"MISSING param: ($a.label)" }
let total_missing = ($missing_tools | length) + ($missing_args | length)
if $total_missing > 0 {
error make { msg: $"($total_missing) prerequisite(s) not met. Fix before proceeding." }
}
print "All prerequisites satisfied"
}