#!/usr/bin/env nu # Verify all prerequisites for Hetzner + NixOS deployment def check_command [cmd: string, name: string] { let result = (which $cmd 2>&1) if ($result | is-empty) { print $"❌ ($name) - NOT INSTALLED" print $" Install with: brew install $cmd" return {name: $name, installed: false, version: ""} } else { let version = (try { ^$cmd --version | lines | first } catch { "unknown" }) print $"✅ ($name) - OK" return {name: $name, installed: true, version: $version} } } def check_env_var [var: string] { let value = (try { $env | get $var } catch { "" }) if ($value | is-empty) { print $"❌ ($var) - NOT SET" return {name: $var, set: false} } else { print $"✅ ($var) - SET" return {name: $var, set: true} } } def check_file [path: string, name: string] { if ($path | path exists) { print $"✅ ($name) - EXISTS" return {name: $name, exists: true} } else { print $"❌ ($name) - MISSING" return {name: $name, exists: false} } } def main [] { print "╔════════════════════════════════════════════════════════╗" print "║ LibreCloud Hetzner + NixOS - Prerequisites Check ║" print "╚════════════════════════════════════════════════════════╝" print "" # Check tools print "📦 Required Tools:" mut tools_ok = true let tools = [ {cmd: "nushell", name: "Nushell 0.110+"}, {cmd: "nickel", name: "Nickel"}, {cmd: "nix", name: "Nix"}, {cmd: "nixos-anywhere", name: "nixos-anywhere"}, {cmd: "hcloud", name: "Hetzner Cloud CLI"}, {cmd: "jq", name: "jq (JSON processor)"}, {cmd: "curl", name: "curl"}, {cmd: "ssh", name: "OpenSSH"}, ] for tool in $tools { let result = (check_command $tool.cmd $tool.name) if not $result.installed { $tools_ok = false } } print "" # Check environment variables print "🔐 Hetzner Configuration:" let hcloud_token_set = (check_env_var "HCLOUD_TOKEN") if not $hcloud_token_set.set { print " ⚠️ To set: export HCLOUD_TOKEN='your-token-here'" print " Get token: https://console.hetzner.cloud/tokens" $tools_ok = false } print "" # Check SSH key in Hetzner print "🔑 SSH Key in Hetzner:" if $hcloud_token_set.set { let ssh_key_exists = (try { ^hcloud ssh-key list --output json | from json | where name == "provisioning-key" | length } catch { 0 }) if $ssh_key_exists > 0 { print "✅ provisioning-key - EXISTS in Hetzner" } else { print "❌ provisioning-key - NOT FOUND in Hetzner" print " Create with:" print " hcloud ssh-key create --name provisioning-key --public-key-from-file ~/.ssh/id_rsa.pub" $tools_ok = false } } else { print "⏭️ Skipping (HCLOUD_TOKEN not set)" } print "" # Check local SSH key print "🔑 Local SSH Key:" let ssh_key_path = $"($env.HOME)/.ssh/id_rsa.pub" if ($ssh_key_path | path exists) { print "✅ SSH public key - EXISTS" } else { print "❌ SSH public key - NOT FOUND at ($ssh_key_path)" print " Generate with: ssh-keygen -t rsa -b 4096" $tools_ok = false } print "" # Check project files print "📁 Project Files:" let project_files = [ {path: "provisioning/scripts/deploy-librecloud-hetzner.nu", name: "Deploy script"}, {path: "provisioning/scripts/generate-flakes.nu", name: "Flake generator"}, {path: "workspaces/librecloud_hetzner/infra/main/servers.ncl", name: "Server config"}, ] for file in $project_files { let result = (check_file $file.path $file.name) if not $result.exists { $tools_ok = false } } print "" # Summary print "╔════════════════════════════════════════════════════════╗" if $tools_ok { print "║ ✅ ALL PREREQUISITES MET - Ready to Deploy! ║" print "╚════════════════════════════════════════════════════════╝" print "" print "Next steps:" print "1. Generate flakes:" print " nu provisioning/scripts/deploy-librecloud-hetzner.nu --generate-only" print "" print "2. Dry-run deployment:" print " nu provisioning/scripts/deploy-librecloud-hetzner.nu --dry-run" print "" print "3. Deploy to Hetzner (30-40 minutes):" print " nu provisioning/scripts/deploy-librecloud-hetzner.nu" } else { print "║ ❌ MISSING PREREQUISITES - See above for details ║" print "╚════════════════════════════════════════════════════════╝" } } main