From 53dc08f5e9949d58b701aa522093d6ed9f9f8b2d Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Wed, 22 Oct 2025 14:00:34 +0200 Subject: [PATCH] restore pm bash scripts Signed-off-by: Kiara Grouwstra --- infra/proxmox-provision.sh | 87 +++++++++----------------------------- infra/proxmox-remove.sh | 3 +- 2 files changed, 21 insertions(+), 69 deletions(-) diff --git a/infra/proxmox-provision.sh b/infra/proxmox-provision.sh index 1dd1654e..8fa3cd56 100755 --- a/infra/proxmox-provision.sh +++ b/infra/proxmox-provision.sh @@ -7,7 +7,7 @@ set -euC ## FIXME: There seems to be a problem with file upload where the task is ## registered to `node051` no matter what node we are actually uploading to? For ## now, let us just use `node051` everywhere. -node=node051 +readonly node=node051 readonly tmpdir=/tmp/proxmox-provision-$RANDOM mkdir $tmpdir @@ -69,7 +69,6 @@ while [ $# -gt 0 ]; do --api-url|--api_url) readonly api_url="$1"; shift ;; --username) readonly username="$1"; shift ;; --password) readonly password="$1"; shift ;; - --node) readonly node="$1"; shift ;; --debug) debug=true ;; @@ -173,24 +172,11 @@ grab_vm_options () { printf 'Grabing VM options for VM %s...\n' "$vm_name" options=$( - # nix --extra-experimental-features 'nix-command flakes' eval \ - # --impure --raw --expr " - # builtins.toJSON (builtins.getFlake (builtins.toString ./.)).vmOptions.$vm_name - # " \ - # --log-format raw --quiet - echo ' - { - "description":"", - "sockets":1, - "cores":1, - "memory":2048, - "diskSize":32, - "name":"test14", - "vmId":7014, - "hostPublicKey":"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTbxDzq3xFeLvrXs6tyTE08o3CekYZmqFeGmkcHmf21", - "unsafeHostPrivateKey":"-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUxOQAAACB028Q86t8RXi7617OrckxNPKNwnpGGZqhXhppHB5n9tQAAAIhfhYlCX4WJ\nQgAAAAtzc2gtZWQyNTUxOQAAACB028Q86t8RXi7617OrckxNPKNwnpGGZqhXhppHB5n9tQ\nAAAEAualLRodpovSzGAhza2OVvg5Yp8xv3A7xUNNbKsMTKSHTbxDzq3xFeLvrXs6tyTE08\no3CekYZmqFeGmkcHmf21AAAAAAECAwQF\n-----END OPENSSH PRIVATE KEY-----\n" - } - ' + nix --extra-experimental-features 'nix-command flakes' eval \ + --impure --raw --expr " + builtins.toJSON (builtins.getFlake (builtins.toString ./.)).vmOptions.$vm_name + " \ + --log-format raw --quiet ) vm_id=$(echo "$options" | jq -r .vmId) @@ -234,45 +220,18 @@ build_iso () { nix_host_keys= fi - # nix --extra-experimental-features 'nix-command flakes' build \ - # --impure --expr " - # let flake = builtins.getFlake (builtins.toString ./.); in - # import ./infra/makeInstallerIso.nix { - # nixosConfiguration = flake.nixosConfigurations.$vm_name; - # # FIXME pass nixpkgs from npins - # $nix_host_keys - # } - # " \ - # --log-format raw --quiet \ - # --out-link "$tmpdir/installer-$vm_name" - - # nix --extra-experimental-features 'nix-command' build \ - # --impure --expr " - # import ./infra/makeInstallerIso.nix { - # # nixosConfiguration = $configuration; - # nixosConfiguration = import $configuration; - # $nix_host_keys - # } - # " \ - # --log-format raw --quiet \ - # --out-link "$tmpdir/installer-$vm_name" - - # TODO after install: $nix_host_keys - # cp $tmpdir/${vm_name}_host_key /mnt/etc/ssh/ssh_host_ed25519_key - # chmod 600 /mnt/etc/ssh/ssh_host_ed25519_key - # cp $tmpdir/${vm_name}_host_key.pub /mnt/etc/ssh/ssh_host_ed25519_key.pub - # chmod 644 /mnt/etc/ssh/ssh_host_ed25519_key.pub - - nix --extra-experimental-features 'nix-command' build \ + nix --extra-experimental-features 'nix-command flakes' build \ --impure --expr " - (import $configuration).config.system.build.image + let flake = builtins.getFlake (builtins.toString ./.); in + import ./infra/makeInstallerIso.nix { + nixosConfiguration = flake.nixosConfigurations.$vm_name; + # FIXME pass nixpkgs from npins + $nix_host_keys + } " \ --log-format raw --quiet \ --out-link "$tmpdir/installer-$vm_name" - # ls "$tmpdir/installer-$vm_name" - # ls "$tmpdir/installer-$vm_name/image.raw" - # shellcheck disable=SC2181 if [ $? -ne 0 ]; then die 'Something went wrong when building ISO for VM %s. @@ -280,8 +239,7 @@ Check the Nix logs and fix things. Possibly there just is no NixOS configuration "$vm_name" fi - # ln -sf "$(ls "$tmpdir/installer-$vm_name"/iso/nixos-*.iso)" "$tmpdir/installer-$vm_name.iso" - ln -sf "$(ls "$tmpdir/installer-$vm_name"/image.raw)" "$tmpdir/installer-$vm_name.raw" + ln -sf "$(ls "$tmpdir/installer-$vm_name"/iso/nixos-*.iso)" "$tmpdir/installer-$vm_name.iso" printf 'done building ISO for VM %s.\n' "$vm_name" release_lock build @@ -295,8 +253,8 @@ upload_iso () { printf 'Uploading ISO for VM %s...\n' "$vm_name" proxmox_sync POST "$api_url/nodes/$node/storage/local/upload" \ - "filename@$tmpdir/installer-$vm_name.raw" \ - content==raw + "filename@$tmpdir/installer-$vm_name.iso" \ + content==iso printf 'done uploading ISO for VM %s.\n' "$vm_name" release_lock upload @@ -308,7 +266,7 @@ upload_iso () { remove_iso () { printf 'Removing ISO for VM %s...\n' "$vm_name" - proxmox_sync DELETE "$api_url/nodes/$node/storage/local/content/local:iso/installer-$vm_name.raw" + proxmox_sync DELETE "$api_url/nodes/$node/storage/local/content/local:iso/installer-$vm_name.iso" printf 'done removing ISO for VM %s.\n' "$vm_name" } @@ -326,7 +284,7 @@ create_vm () { pool==Fediversity \ description=="$description" \ \ - ide2=="local:iso/installer-$vm_name.raw,media=cdrom" \ + ide2=="local:iso/installer-$vm_name.iso,media=cdrom" \ ostype==l26 \ \ bios==ovmf \ @@ -402,13 +360,8 @@ provision_vm () ( remove_iso ) -# FIXME make vm_names a thing from $vm_name to $configuration? -# for vm_name in $vm_names; do -# provision_vm "$vm_name" & -# done -for chunk in $vm_names; do - IFS=: read -r vm_name configuration <<< "$chunk" - provision_vm "$vm_name" "$configuration" & +for vm_name in $vm_names; do + provision_vm "$vm_name" & done nb_errors=0 diff --git a/infra/proxmox-remove.sh b/infra/proxmox-remove.sh index 361f0e3d..1ab46938 100755 --- a/infra/proxmox-remove.sh +++ b/infra/proxmox-remove.sh @@ -7,7 +7,7 @@ set -euC ## FIXME: There seems to be a problem with file upload where the task is ## registered to `node051` no matter what node we are actually uploading to? For ## now, let us just use `node051` everywhere. -node=node051 +readonly node=node051 readonly tmpdir=/tmp/proxmox-remove-$RANDOM mkdir $tmpdir @@ -59,7 +59,6 @@ while [ $# -gt 0 ]; do --api-url|--api_url) readonly api_url="$1"; shift ;; --username) readonly username=$1; shift ;; --password) readonly password=$1; shift ;; - --node) readonly node="$1"; shift ;; -h|-\?|--help) help; exit 0 ;;