From d21a3f0b3e2a2c5a2d8006b96c918314b57b0089 Mon Sep 17 00:00:00 2001 From: Steffen Ritter Date: Tue, 30 Jan 2024 14:35:18 +0100 Subject: [run-virt] Fix corrupted vmx with additional NICs Don't accidentally add an empty line to TMPCONFIG. Also make awk ignore empty lines when looking for duplicates so we don't end up with an ' = ' line which will crash vmplayer. Bonuspoint: sort the output for better readability --- .../openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/modules/vmware-common/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc b/core/modules/vmware-common/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc index f1d83fb6..6dd226de 100644 --- a/core/modules/vmware-common/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc +++ b/core/modules/vmware-common/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc @@ -40,9 +40,9 @@ setup_ethernet() { # Remove lines that could break things sed -i "/^${eth}\.connectionType/Id;/^${eth}\.present/Id" "${TMPCONFIG}" # Set up devType - devline= if ! grep -q -i "^${eth}\.virtualDev" "${TMPCONFIG}" && [ -n "$devtype" ]; then devline="${eth}.virtualDev = "'"'"${devtype}"'"' + echo "${devline}" >> "${TMPCONFIG}" fi cat >> "${TMPCONFIG}" <<-HEND ${eth}.connectionType = "custom" @@ -50,7 +50,6 @@ setup_ethernet() { ${eth}.vnet = "vmnet${vmnet}" ${eth}.addressType = "static" ${eth}.address = "${mac}" - ${devline} HEND done fi @@ -336,7 +335,7 @@ write_final_vmx() { finalize_hardware # Killing duplicate entries; always keep last value: - awk -F= '{ + awk -F= 'NF{ b = $0; gsub(/^[ \t]+|[ \t]+$/, "", $1); gsub(/^[ \t]*[^ \t]+[ \t]*=[ \t]*|[ \t]+$/, "", b); @@ -347,6 +346,8 @@ write_final_vmx() { }' "${TMPCONFIG}" > "${TMPCONFIG}.tmp" \ && mv -f "${TMPCONFIG}.tmp" "${TMPCONFIG}" + sort -o "${TMPCONFIG}" "${TMPCONFIG}" + # At last: Let's copy it to $VM_CONF_DIR/run-vmware.conf if cp -p "${TMPCONFIG}" "${VM_RUN_FILE}"; then writelog "Copied '${TMPCONFIG}' to '${VM_RUN_FILE}'" -- cgit v1.2.3-55-g7522