summaryrefslogtreecommitdiffstats
path: root/core/modules/vmware-common/data/opt/openslx/vmchooser/plugins/vmware/includes/parse_vmx.inc
blob: e19d5a4ee75a69067643219f8026b594897e4d6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
######################################################################
# Include: Parsing the non-legacy delivered vmxfile ${TMPCONFIG} #
######################################################################
## Functions
parse_vmx() {
	# To avoid potential syntax problems from the vmx served by dmsd, sanitize
	# it before continuing with filling in the gaps
	local TMPTMPCONFIG="$(mktemp)"
	grep -E '^\s*(#|[^=]+=[^"]*"[^"]*"\s*$|[^=]+=[^"]+$|$)' "$TMPCONFIG" > "$TMPTMPCONFIG"
	if ! cmp -s "$TMPCONFIG" "$TMPTMPCONFIG"; then
		# file was corrupted, log it
		writelog "'$TMPCONFIG' had bad syntax and was pruned by the post-download sanitizer!"
		slxlog -s "virt-vmware-vmx-corrupt" "Downloaded .vmx for '$IMGUUID' has lines with invalid syntax!" "$TMPCONFIG"
		mv -f -- "$TMPTMPCONFIG" "$TMPCONFIG"
	else
		rm -f -- "$TMPTMPCONFIG"
	fi

	writelog "Parsing virtual machine description file for hwVersion..."
	local -i HW_VERSION=$(grep -i -m1 '^virtualHW.version *= *' "${TMPCONFIG}" | awk -F '=' '{print $2}' | sed -r 's/[^0-9]//g')
	if notempty HW_VERSION; then
		declare -g VM_HW_VERSION="${HW_VERSION}"
		return 0
	fi
	return 1
}

## MAIN ##
if notempty TMPCONFIG; then
	call_post_source parse_vmx
else
	writelog "Path to VMX file is not set or empty! Aborting..."
	EXIT_TYPE="internal" EXIT_REASON="Konnte Pfad zur VMX-Datei nicht finden!" cleanexit 1
fi