From 60f1373b4e9e47c9ce3d537bd519be5f6bd165e0 Mon Sep 17 00:00:00 2001 From: tcude Date: Wed, 17 Jan 2024 20:58:47 -0600 Subject: [PATCH] switched to key-based auth for proxmox and added gitignore --- .gitignore | 2 ++ vmware_to_proxmox.sh | 15 ++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cda8e4a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.ova + diff --git a/vmware_to_proxmox.sh b/vmware_to_proxmox.sh index 71aa72a..2fa8111 100755 --- a/vmware_to_proxmox.sh +++ b/vmware_to_proxmox.sh @@ -25,8 +25,6 @@ read -sp "Enter the ESXi server password: " ESXI_PASSWORD echo PROXMOX_SERVER=$(get_input "Enter the Proxmox server hostname/IP") PROXMOX_USERNAME=$(get_input "Enter the Proxmox server username") -read -sp "Enter the Proxmox server password: " PROXMOX_PASSWORD -echo VM_NAME=$(get_input "Enter the name of the VM to migrate") # Export VM from VMware @@ -47,23 +45,22 @@ function export_vmware_vm() { # Transfer VM to Proxmox function transfer_vm() { echo "Transferring VM to Proxmox..." - echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "mkdir -p /var/vm-migration" - echo $PROXMOX_PASSWORD | scp $VM_NAME.ova $PROXMOX_USERNAME@$PROXMOX_SERVER:/var/vm-migration/ + scp $VM_NAME.ova $PROXMOX_USERNAME@$PROXMOX_SERVER:/var/vm-migration/ } # Convert VM to Proxmox format function convert_vm() { echo "Converting VM to Proxmox format..." - echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "tar -xvf /var/vm-migration/$VM_NAME.ova -C /var/vm-migration/" + ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "tar -xvf /var/vm-migration/$VM_NAME.ova -C /var/vm-migration/" local vmdk_file=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "find /var/vm-migration -name '*.vmdk'") - echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qemu-img convert -f vmdk -O qcow2 $vmdk_file /var/vm-migration/$VM_NAME.qcow2" + ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qemu-img convert -f vmdk -O qcow2 $vmdk_file /var/vm-migration/$VM_NAME.qcow2" } # Get the next VM ID function get_next_vm_id() { echo "Getting next VM ID..." # Get the list of VMs, sort by VM ID, get the last one, and increment by one - NEXT_VM_ID=$(echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "pvesh get /cluster/resources --type vm" | jq -r '.[].vmid' | sort -n | tail -1) + NEXT_VM_ID=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "pvesh get /cluster/resources --type vm" | jq -r '.[].vmid' | sort -n | tail -1) let "NEXT_VM_ID++" echo $NEXT_VM_ID } @@ -76,11 +73,11 @@ function create_proxmox_vm() { echo "Error: Invalid VM ID '$VM_ID'." exit 1 fi - echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm create $VM_ID --name $VM_NAME --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0" + ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm create $VM_ID --name $VM_NAME --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0" } # Main process export_vmware_vm transfer_vm convert_vm -create_proxmox_vm +create_proxmox_vm \ No newline at end of file