From 2c851759129f0a2bd7d07cf9d8e3ce387ca51ecb Mon Sep 17 00:00:00 2001 From: vandomej Date: Mon, 29 Sep 2025 22:51:08 -0700 Subject: [PATCH] Creating wrapper script --- .../vm-setup/create-control-plane-vms.sh | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/control-plane/vm-setup/create-control-plane-vms.sh b/control-plane/vm-setup/create-control-plane-vms.sh index 74ced36..fd5b04b 100755 --- a/control-plane/vm-setup/create-control-plane-vms.sh +++ b/control-plane/vm-setup/create-control-plane-vms.sh @@ -81,25 +81,42 @@ create_vm_script() { local script_path="$vm_path/start.sh" - cat > "$script_path" << EOF + cat > "$script_path" << 'EOF' #!/bin/bash -qemu-system-aarch64 \\ - -name "$vm_name" \\ - -machine virt,highmem=off \\ - -accel hvf \\ - -cpu host \\ - -smp "$CPUS" \\ - -m "${MEMORY}M" \\ - -drive file="$disk_path",if=virtio,format=qcow2 \\ - -cdrom "$iso_path" \\ - -netdev user,id=net0 \\ - -device virtio-net-pci,netdev=net0,mac=$mac_address \\ - -nographic \\ +VM_NAME="$1" +MAC_ADDRESS="$2" +ISO_PATH="$3" +DISK_PATH="$4" +CPUS="$5" +MEMORY="$6" + +qemu-system-aarch64 \ + -name "$VM_NAME" \ + -machine virt,highmem=off \ + -accel hvf \ + -cpu host \ + -smp "$CPUS" \ + -m "${MEMORY}M" \ + -drive file="$DISK_PATH",if=virtio,format=qcow2 \ + -cdrom "$ISO_PATH" \ + -netdev user,id=net0 \ + -device virtio-net-pci,netdev=net0,mac="$MAC_ADDRESS" \ + -nographic \ -serial mon:stdio EOF + # Make the script executable and create a wrapper that passes the parameters chmod +x "$script_path" - echo "$script_path" + + # Create a wrapper script that calls the main script with proper arguments + local wrapper_path="$vm_path/run.sh" + cat > "$wrapper_path" << EOF +#!/bin/bash +"$script_path" "$vm_name" "$mac_address" "$iso_path" "$disk_path" "$CPUS" "$MEMORY" +EOF + + chmod +x "$wrapper_path" + echo "$wrapper_path" } # Create systemd service file (optional) @@ -148,13 +165,13 @@ main() { create_service_file "$controlplane_path" "$CONTROLPLANE_NAME" "$controlplane_script" local manage_script="$VM_DIR/manage-vm.sh" - cat > "$manage_script" << 'EOF' + cat > "$manage_script" << EOF #!/bin/bash -VM_DIR="$(cd "$(dirname "$0")" && pwd)" +VM_DIR="\$(cd "\$(dirname "\$0")" && pwd)" start_vm() { echo "Starting Talos VM..." - "$VM_DIR/talos-controlplane/start.sh" & + "\$VM_DIR/talos-controlplane/run.sh" & } stop_vm() { @@ -162,7 +179,7 @@ stop_vm() { pkill -f "qemu-system-aarch64.*talos-controlplane" } -case "$1" in +case "\$1" in start) start_vm ;; @@ -173,7 +190,7 @@ case "$1" in pgrep -f "qemu-system-aarch64.*talos-controlplane" > /dev/null && echo "VM is running" || echo "VM is stopped" ;; *) - echo "Usage: $0 {start|stop|status}" + echo "Usage: \$0 {start|stop|status}" exit 1 ;; esac