restore pm bash scripts

Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
Kiara Grouwstra 2025-10-22 14:00:34 +02:00
parent 0b3e545c58
commit 53dc08f5e9
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
2 changed files with 21 additions and 69 deletions

View file

@ -7,7 +7,7 @@ set -euC
## FIXME: There seems to be a problem with file upload where the task is ## 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 ## registered to `node051` no matter what node we are actually uploading to? For
## now, let us just use `node051` everywhere. ## now, let us just use `node051` everywhere.
node=node051 readonly node=node051
readonly tmpdir=/tmp/proxmox-provision-$RANDOM readonly tmpdir=/tmp/proxmox-provision-$RANDOM
mkdir $tmpdir mkdir $tmpdir
@ -69,7 +69,6 @@ while [ $# -gt 0 ]; do
--api-url|--api_url) readonly api_url="$1"; shift ;; --api-url|--api_url) readonly api_url="$1"; shift ;;
--username) readonly username="$1"; shift ;; --username) readonly username="$1"; shift ;;
--password) readonly password="$1"; shift ;; --password) readonly password="$1"; shift ;;
--node) readonly node="$1"; shift ;;
--debug) debug=true ;; --debug) debug=true ;;
@ -173,24 +172,11 @@ grab_vm_options () {
printf 'Grabing VM options for VM %s...\n' "$vm_name" printf 'Grabing VM options for VM %s...\n' "$vm_name"
options=$( options=$(
# nix --extra-experimental-features 'nix-command flakes' eval \ nix --extra-experimental-features 'nix-command flakes' eval \
# --impure --raw --expr " --impure --raw --expr "
# builtins.toJSON (builtins.getFlake (builtins.toString ./.)).vmOptions.$vm_name builtins.toJSON (builtins.getFlake (builtins.toString ./.)).vmOptions.$vm_name
# " \ " \
# --log-format raw --quiet --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"
}
'
) )
vm_id=$(echo "$options" | jq -r .vmId) vm_id=$(echo "$options" | jq -r .vmId)
@ -234,45 +220,18 @@ build_iso () {
nix_host_keys= nix_host_keys=
fi fi
# nix --extra-experimental-features 'nix-command flakes' build \ 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 \
--impure --expr " --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 \ --log-format raw --quiet \
--out-link "$tmpdir/installer-$vm_name" --out-link "$tmpdir/installer-$vm_name"
# ls "$tmpdir/installer-$vm_name"
# ls "$tmpdir/installer-$vm_name/image.raw"
# shellcheck disable=SC2181 # shellcheck disable=SC2181
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
die 'Something went wrong when building ISO for VM %s. 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" "$vm_name"
fi fi
# ln -sf "$(ls "$tmpdir/installer-$vm_name"/iso/nixos-*.iso)" "$tmpdir/installer-$vm_name.iso" 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"
printf 'done building ISO for VM %s.\n' "$vm_name" printf 'done building ISO for VM %s.\n' "$vm_name"
release_lock build release_lock build
@ -295,8 +253,8 @@ upload_iso () {
printf 'Uploading ISO for VM %s...\n' "$vm_name" printf 'Uploading ISO for VM %s...\n' "$vm_name"
proxmox_sync POST "$api_url/nodes/$node/storage/local/upload" \ proxmox_sync POST "$api_url/nodes/$node/storage/local/upload" \
"filename@$tmpdir/installer-$vm_name.raw" \ "filename@$tmpdir/installer-$vm_name.iso" \
content==raw content==iso
printf 'done uploading ISO for VM %s.\n' "$vm_name" printf 'done uploading ISO for VM %s.\n' "$vm_name"
release_lock upload release_lock upload
@ -308,7 +266,7 @@ upload_iso () {
remove_iso () { remove_iso () {
printf 'Removing ISO for VM %s...\n' "$vm_name" 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" printf 'done removing ISO for VM %s.\n' "$vm_name"
} }
@ -326,7 +284,7 @@ create_vm () {
pool==Fediversity \ pool==Fediversity \
description=="$description" \ description=="$description" \
\ \
ide2=="local:iso/installer-$vm_name.raw,media=cdrom" \ ide2=="local:iso/installer-$vm_name.iso,media=cdrom" \
ostype==l26 \ ostype==l26 \
\ \
bios==ovmf \ bios==ovmf \
@ -402,13 +360,8 @@ provision_vm () (
remove_iso remove_iso
) )
# FIXME make vm_names a thing from $vm_name to $configuration? for vm_name in $vm_names; do
# for vm_name in $vm_names; do provision_vm "$vm_name" &
# provision_vm "$vm_name" &
# done
for chunk in $vm_names; do
IFS=: read -r vm_name configuration <<< "$chunk"
provision_vm "$vm_name" "$configuration" &
done done
nb_errors=0 nb_errors=0

View file

@ -7,7 +7,7 @@ set -euC
## FIXME: There seems to be a problem with file upload where the task is ## 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 ## registered to `node051` no matter what node we are actually uploading to? For
## now, let us just use `node051` everywhere. ## now, let us just use `node051` everywhere.
node=node051 readonly node=node051
readonly tmpdir=/tmp/proxmox-remove-$RANDOM readonly tmpdir=/tmp/proxmox-remove-$RANDOM
mkdir $tmpdir mkdir $tmpdir
@ -59,7 +59,6 @@ while [ $# -gt 0 ]; do
--api-url|--api_url) readonly api_url="$1"; shift ;; --api-url|--api_url) readonly api_url="$1"; shift ;;
--username) readonly username=$1; shift ;; --username) readonly username=$1; shift ;;
--password) readonly password=$1; shift ;; --password) readonly password=$1; shift ;;
--node) readonly node="$1"; shift ;;
-h|-\?|--help) help; exit 0 ;; -h|-\?|--help) help; exit 0 ;;