From 646031a73517303f99ca754e08c9c35b14aae041 Mon Sep 17 00:00:00 2001 From: Blackwhitebear8 Date: Tue, 10 Dec 2024 13:22:43 +0100 Subject: [PATCH] Update create.sh --- create.sh | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/create.sh b/create.sh index 946f45a..ed52b77 100755 --- a/create.sh +++ b/create.sh @@ -34,7 +34,7 @@ BRIDGE="vmbr0" MEMORY="4096" CORES="4" STORAGE="btrfs" # Opslaglocatie -OSKEUZE="2" # Naam en versie van het besturingssysteem, bijv. "Debian 12" +OSKEUZE="5" # Naam en versie van het besturingssysteem, bijv. "Debian 12" TEMPLATE="n" # Of de VM als template moet worden ingesteld (j/n) SSH_KEY_TEXT="" @@ -129,10 +129,13 @@ case $OSKEUZE in case $SSH_KEYS_PATH in '') # leeg - virt-customize -a /tmp/"$IMAGE_NAME" \ - --run-command 'sed -i "s/^#PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/sshd_config' \ - --run-command 'sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config' \ - --run-command 'systemctl restart sshd' + virt-customize --run-command ' + CONFIG_FILE="/etc/cloud/cloud.cfg" + if ! grep -q "ssh_pwauth" "$CONFIG_FILE"; then + echo "ssh_pwauth: true" | sudo tee -a "$CONFIG_FILE" > /dev/null + else + sudo sed -i "s/^ssh_pwauth false/ssh_pwauth true/" "$CONFIG_FILE" + fi' -a /tmp/"$IMAGE_NAME" ;; /tmp/temporary_ssh_key.pub) # iets ;; @@ -147,10 +150,13 @@ case $OSKEUZE in case $SSH_KEYS_PATH in '') # leeg - virt-customize -a /tmp/"$IMAGE_NAME" \ - --run-command 'sed -i "s/^#PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/sshd_config' \ - --run-command 'sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config' \ - --run-command 'systemctl restart sshd' + virt-customize --run-command ' + CONFIG_FILE="/etc/cloud/cloud.cfg" + if ! grep -q "ssh_pwauth" "$CONFIG_FILE"; then + echo "ssh_pwauth: true" | sudo tee -a "$CONFIG_FILE" > /dev/null + else + sudo sed -i "s/^ssh_pwauth false/ssh_pwauth true/" "$CONFIG_FILE" + fi' -a /tmp/"$IMAGE_NAME" ;; /tmp/temporary_ssh_key.pub) # iets ;; @@ -167,10 +173,13 @@ case $OSKEUZE in case $SSH_KEYS_PATH in '') # leeg - virt-customize -a /tmp/"$IMAGE_NAME" \ - --run-command 'sed -i "s/^#PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/sshd_config' \ - --run-command 'sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config' \ - --run-command 'systemctl restart sshd' + virt-customize --run-command ' + CONFIG_FILE="/etc/cloud/cloud.cfg" + if ! grep -q "ssh_pwauth" "$CONFIG_FILE"; then + echo "ssh_pwauth: true" | sudo tee -a "$CONFIG_FILE" > /dev/null + else + sudo sed -i "s/^ssh_pwauth false/ssh_pwauth true/" "$CONFIG_FILE" + fi' -a /tmp/"$IMAGE_NAME" ;; /tmp/temporary_ssh_key.pub) # iets ;; @@ -220,14 +229,6 @@ qm set $VMID --ciupgrade 1 qm set $VMID --onboot 1 [[ -n "$SSH_KEYS_PATH" && -f "$SSH_KEYS_PATH" ]] && qm set $VMID --sshkeys "$SSH_KEYS_PATH" -#case $SSH_KEYS_PATH in -# '') # leeg -# ;; -# /tmp/temporary_ssh_key.pub) # iets -# qm set $VMID --sshkeys /tmp/temporary_ssh_key.pub -# ;; -#esac - qm set $VMID --efidisk0 $STORAGE:0,format=raw,pre-enrolled-keys=1 # Stel de bootvolgorde en disk grootte in