diff options
Diffstat (limited to 'core/modules/vmware12/data/opt/openslx/vmchooser/plugins')
8 files changed, 783 insertions, 0 deletions
diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/create_vmhome_preferences_file.inc b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/create_vmhome_preferences_file.inc new file mode 100644 index 00000000..b4197051 --- /dev/null +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/create_vmhome_preferences_file.inc @@ -0,0 +1,81 @@ +#!/bin/bash +########################################### +# Include: Create VMware preferences file # +########################################### +## Functions ## +create_vmhome_preferences_file() { + cat > "${VM_HOME}/preferences" <<-HEREEND + .encoding = "UTF-8" + # This configuration file was generated on $(date) + # by $0 for VMWare version $vmware_version + + # updates + webUpdate.enabled = "FALSE" + webUpdate.lastCheck.status = "done_updates" + webUpdate.checkPeriod = "never" + pref.downloadPermission = "DENY" + pref.vmplayer.downloadPermission = "DENY" + pref.vmplayer.webUpdateOnStartup = "FALSE" + pref.lastUpdateCheckSec = "$(date +%s)" + # hints + pref.tip.startup = "FALSE" + hints.hideAll = "TRUE" + hint.vmui.showAllUSBDevs = "FALSE" + hint.usb.disconnectHostdriver = "FALSE" + hint.vmui.reset = "FALSE" + hint.vmui.poweroff = "FALSE" + hint.upgrade.legacyVM = "FALSE" + hint.tools.toolsReminder = "FALSE" + hint.nfsmounted.persistent = "FALSE" + hint.loader.debug.beta = "FALSE" + hint.leaveFullScreen = "FALSE" + hint.guestos.xp = "FALSE" + hint.buslogic.needDriver = "FALSE" + + # configs + prefvmx.defaultVMPath = "${VM_HOME}" + prefvmx.mru.config = "$VM_RUN_FILE:" + + # hot keys + pref.hotkey.control = "true" + pref.hotkey.alt = "true" + pref.hotkey.shift = "true" + pref.hotkey.gui = "true" + + # fullscreen/mouse/keyboard + pref.fullscreen.toolbarPixels = "0" + pref.vmplayer.fullscreen.autohide = "TRUE" + pref.vmplayer.fullscreen.nobar = 1 + pref.grabOnMouseClick = "TRUE" + pref.grabOnKeyPress = "TRUE" + pref.motionGrab = "TRUE" + pref.motionUngrab = "TRUE" + pref.hideCursorOnUngrab = "TRUE" + pref.autoFit = "TRUE" + pref.autoFitFullScreen = "fitGuestToHost" + pref.autoFitGuestToWindow = "TRUE" + pref.vmplayer.exit.vmAction = "poweroff" + pref.vmplayer.confirmOnExit = "TRUE" + pref.backgroundOnClose = "FALSE" + pref.trayicon.enabled = "FALSE" + pref.keyboardAndMouse.vmHotKey.enabled = "FALSE" + pref.keyboardAndMouse.vmHotKey.count = "0" + + # shared folders + pref.enableAllSharedFolders = "TRUE" + + # eula + pref.vmplayer.firstRunDismissedVersion = "$vmware_version" + pref.eula.count = "2" + pref.eula0.product = "VMware Player" + pref.eula0.build = "$vmware_build" + pref.eula1.product = "VMware Workstation" + pref.eula1.build = "$vmware_build" + HEREEND + if [ -n "$SLX_EXAM" ]; then + echo 'pref.hotkey.rightControl = "true"' >> "${VM_HOME}/preferences" + fi + writelog "Vmware preferences file created in $VM_HOME." +} + +call_post_source create_vmhome_preferences_file diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/determine_hardware_limitations.inc b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/determine_hardware_limitations.inc new file mode 100644 index 00000000..c288ed09 --- /dev/null +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/determine_hardware_limitations.inc @@ -0,0 +1,197 @@ +#!/bin/bash +########################################################################## +# Include: Determine limitations caused by hardware version and guest os # +########################################################################## +## Functions +set_vm_hardware_limits() { + # Sanity checks + if isempty VM_OS_TYPE; then + writelog "VM_OS_TYPE is empty! This should have been parsed from the VM metadata." + EXIT_TYPE="user" EXIT_REASON="Konnte Gastbetriebsystems der gewählten virtuellen Maschine nicht ermitteln!" cleanexit 1 + fi + + declare -g MAXMEM="9999999" + declare -g MAXCORES="4" + declare -g SHARED_FOLDERS="TRUE" + declare -g SOUND_DEV="es1371" + + # define hardware configuration depending on the guest OS used + # this needs to be fixed and is the base for the creation of new VMs + case "$VM_OS_TYPE" in + win31*|windows31*) + VM_OS_TYPE="win31" + SHARED_FOLDERS="FALSE" + SOUND_DEV="sb16" + MAXMEM="32" + MAXCORES="1" + ;; + winnt*|windowsnt*) + VM_OS_TYPE="winnt" + SHARED_FOLDERS="FALSE" + SOUND_DEV="sb16" + MAXMEM="1000" + MAXCORES="2" + ;; + win95*|windows95*) + VM_OS_TYPE="win95" + SHARED_FOLDERS="FALSE" + MAXMEM="96" + MAXCORES="1" + ;; + win98*|windows98*) + VM_OS_TYPE="win98" + MAXMEM="256" + MAXCORES="1" + ;; + winme*|windowsme*) + VM_OS_TYPE="winme" + MAXMEM="384" + MAXCORES="1" + ;; + win2000|windows2000|win2000pro*) + VM_OS_TYPE="win2000pro" + MAXMEM="4000" + MAXCORES="2" + ;; + win2000srv*|windows2000srv*|win2000serv*|windows2000serv*) + VM_OS_TYPE="win2000serv" + SHARED_FOLDERS="FALSE" + MAXMEM="4000" + MAXCORES="4" + ;; + win2000adv*|windows2000adv*|win2000dat*|windows2000dat*) + VM_OS_TYPE="win2000advserv" + SHARED_FOLDERS="FALSE" + MAXMEM="8000" + MAXCORES="8" + ;; + winnet*64|win*2003*64|windowsnet*64) + VM_OS_TYPE="winnetstandard-64" + MAXMEM="8000" + MAXCORES="8" + ;; + winnet*|win*2003*|windowsnet*) + VM_OS_TYPE="winnetstandard" + MAXMEM="4000" + MAXCORES="8" + ;; + winxphome*|windowsxphome*) + VM_OS_TYPE="winxphome" + MAXMEM="4000" + MAXCORES="2" + ;; + winxp*64|windowsxp*64) + VM_OS_TYPE="winxppro-64" + MAXMEM="8000" + MAXCORES="8" + ;; + winxp*|windowsxp*) + VM_OS_TYPE="winxppro" + MAXMEM="4000" + MAXCORES="4" + ;; + winvista-64) + VM_OS_TYPE="winvista-64" + MAXMEM="16000" + MAXCORES="4" + ;; + windows7-64) + VM_OS_TYPE="windows7-64" + MAXMEM="32000" + MAXCORES="8" + ;; + windows8-64) + VM_OS_TYPE="windows8-64" + MAXMEM="32000" + MAXCORES="8" + ;; + windows9-64) + VM_OS_TYPE="windows9-64" + MAXMEM="64000" + MAXCORES="8" + ;; + winvista) + VM_OS_TYPE="winvista" + MAXMEM="8000" + MAXCORES="2" + ;; + windows7) + VM_OS_TYPE="windows7" + MAXMEM="8000" + MAXCORES="4" + ;; + windows8) + VM_OS_TYPE="windows8" + MAXMEM="8000" + MAXCORES="4" + ;; + windows9) + VM_OS_TYPE="windows9" + MAXMEM="8000" + MAXCORES="4" + ;; + win*64) + MAXMEM="16000" + MAXCORES="4" + ;; + win*) + MAXMEM="8000" + MAXCORES="1" + ;; + dos|msdos*|ms-dos*) + VM_OS_TYPE="dos" + SHARED_FOLDERS="FALSE" + MAXMEM="128" + MAXCORES="1" + ;; + macos*64) + VM_OS_TYPE="freebsd-64" + MAXMEM="4000" + MAXCORES="2" + ;; + macos*) + VM_OS_TYPE="freebsd" + MAXMEM="4000" + MAXCORES="1" + ;; + beos*) + VM_OS_TYPE="other" + SHARED_FOLDERS="FALSE" + ;; + # Unknown guestOS setting in .xml - this encompasses linux too, + # as there is a multitude of different distributions. Perhaps further + # action will be needed if this leads to problems with exotic OSs. + *64) + VM_OS_TYPE="other-64" + # SHARED_FOLDERS="FALSE" + MAXMEM="123456" + MAXCORES="4" + ;; + *) + VM_OS_TYPE="other" + # SHARED_FOLDERS="FALSE" + MAXMEM="8000" + MAXCORES="1" + ;; + esac + + declare -rg HOST_CORE_COUNT="$CPU_CORES" + [ "$CPU_CORES" -gt "$MAXCORES" ] && CPU_CORES="$MAXCORES" + + # It currently makes no sense to set the virtual number of cores + # to a different value than the virtual number of cores per virtual CPU. + declare -rg VM_CORES_PER_SOCKET="$CPU_CORES" + + if [ "x$SHARED_FOLDERS" != "xFALSE" ] && [ "$SHARE_REMAP_MODE" -gt 1 ]; then + declare -rg HGFS_DISABLED="FALSE" + else + declare -rg HGFS_DISABLED="TRUE" + fi + + [ "${VM_MEM}" -ge "${MAXMEM}" ] && VM_MEM="${MAXMEM}" + [ "${VM_HW_VERSION}" -lt "7" -a "${VM_MEM}" -gt "3500" ] && VM_MEM="3500" + return 0 +} + +## MAIN ## +call_post_source set_vm_hardware_limits diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/init_core.inc b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/init_core.inc new file mode 100644 index 00000000..d7ad77c6 --- /dev/null +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/init_core.inc @@ -0,0 +1,55 @@ +#!/bin/bash +####################################################################### +# Include: Declaration of core functions and variables of this plugin # +####################################################################### +# This core include just runs commands directly + +## Sanity checks for systemd-vmware_env +# /dev/vmmon should exist, missing vmnet's does not make vmplayer crash +if [ ! -c /dev/vmmon ]; then + # would cause vmplayer to crash, so abort + EXIT_TYPE="internal" EXIT_REASON="VMWare wurde nicht richtig initialisiert!" cleanexit 1 +fi + +# For now define helpers here, maybe use a dedicated include later on +vmw_cap_hw_version() { + [ -z "$1" ] && writelog "cap_hw_version called without parameter!" && return 1 + [ "$1" -lt "$maxhardwareversion" ] && maxhardwareversion="$1" +} + +# Temporary disk space for logs, etc... +declare -rg VM_REDO_DIR="/tmp/virt/vmware/${USER}.$$" + +# Dir for configs and vmem file +declare -rg VM_CONF_DIR="/tmp/virt/vmware/${USER}.$$" + +# The VMX file of the starting VM +declare -rg VM_RUN_FILE="${VM_CONF_DIR}/run-vmware.conf" + +# Users vmware config folder +[ -z "$UID" ] && UID=$(id -u) +[ -z "${HOME}" ] && declare -rg HOME=$(getent passwd "$UID" | awk -F ':' '{print $6}') +[ -z "${HOME}" ] && slxlog "run-virt-vmware-home" "Could not get home directory of user $(whoami) ($UID)" +declare -rg VM_HOME="${HOME}/.vmware" + +# mltk generates a vmware config file with several version infos for vmware/player, read it +$(safesource "${VMWARE_PLUGIN_DIR}/vmware.conf") + +# VMware start options +# "-X": start in fullscreen +declare -rg VM_START_OPTIONS="-X" + +# create vmware directories +mkdir -p "$VM_REDO_DIR" >/dev/null 2>&1 +mkdir -p "$VM_CONF_DIR" >/dev/null 2>&1 +mkdir -p "$VM_HOME/dndlogs" >/dev/null 2>&1 +touch "$VM_HOME/dndlogs/dndlog.conf" >/dev/null 2>&1 + +# link to VM_RUN_FILE if VM_CONF_DIR != VM_REDO_DIR +[ "$VM_CONF_DIR" != "$VM_REDO_DIR" ] && ln -s "$VM_RUN_FILE" "$VM_REDO_DIR/run-vmware.conf" >/dev/null 2>&1 + +# own nvram. We need it for floppy drive b, default nvram has just drive a +if ! cp "${VMWARE_PLUGIN_DIR}/nvram" "$VM_CONF_DIR/nvram"; then + slxlog "virt-vmware-nvram" "Could not copy nvram from '${VMWARE_PLUGIN_DIR}/nvram' '$VM_CONF_DIR/nvram'" +fi + diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/log_config_summary.inc b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/log_config_summary.inc new file mode 100644 index 00000000..0c20cbcc --- /dev/null +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/log_config_summary.inc @@ -0,0 +1,60 @@ +#!/bin/bash +################################################## +# Include: Print vm config summary into log file # +################################################## + +log_config_summary() { + # write all results to logfile + # log disksetup + writelog "Directories:" + writelog "\tConfig dir:\t\t${VM_CONF_DIR}" + writelog "\tConfig file:\t\t${VM_RUN_FILE}" + writelog "\tRedo dir:\t\t${VM_REDO_DIR}" + writelog "\tVM home:\t\t${VM_HOME}" + writelog "\tDrag n' drop log:\t${VM_HOME}/dndlogs" + writelog "\t/tmp info:\t\t$(grep "/tmp " /proc/mounts) $(df -h | grep " /tmp$" | awk '{print $2}')" + + # hw setup + writelog "Hardware:" + writelog "\tvCPUs:\t\t\t${CPU_CORES}" + writelog "\tVM RAM:\t\t\t${VM_MEM} MB" + writelog "\tMAC:\t\t\t${VM_MAC_ADDR}" + if [ -n "${network_card}" ]; then + writelog "\tNet Adaptor:\t\t${network_card}" + fi + + writelog "\tCD-ROM 1:\t\t${CDROM0}" + writelog "\tCD-ROM 2:\t\t${CDROM1}" + writelog "\tFloppy A:\t\t${FLOPPY0}" + # echo nur wenn HOST_MEM_REMAINING gesetzt + if isset HOST_MEM_REMAINING; then + writelog "\tRemaining host RAM:\t${HOST_MEM_REMAINING} MB" + fi + + # image + writelog "Disk image:" + writelog "\tDisk file:\t\t${VM_DISKFILE_RO}" + if isset VM_DISKFILE_RW; then + writelog "\tDisk mode:\t\twritable" + writelog "\tRW-Layer:\t\t${VM_DISKFILE_RW}" + else + writelog "\tDisk mode:\t\tread-only" + fi + writelog "\tHardware version:\t${VM_HW_VERSION}" + writelog "\tGuest OS:\t\t${VM_OS_TYPE}" + + # misc + writelog "Misc:" + writelog "\tDisplayname:\t\t${VM_DISPLAYNAME}" + if [ "${cap3d}" = "TRUE" -a "${enable3d}" = "TRUE" ]; then + writelog "\t3D Graphics:\tenabled" + fi + if [ "${HGFS_DISABLED}" = "FALSE" ]; then + writelog "\tShared folders:\t\tdisabled" + else + writelog "\tShared folders:\t\tenabled." + fi + # empty line at end + writelog "" +} +call_post_source log_config_summary diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/parse_vmx.inc b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/parse_vmx.inc new file mode 100644 index 00000000..47330bb0 --- /dev/null +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/parse_vmx.inc @@ -0,0 +1,32 @@ +###################################################################### +# 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 ! diff -q "$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 a corrupted format!" "$TMPCONFIG" + fi + mv -f -- "$TMPTMPCONFIG" "$TMPCONFIG" + + writelog "Parsing virtual machine description file..." + 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 diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc new file mode 100644 index 00000000..a7d3d837 --- /dev/null +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc @@ -0,0 +1,297 @@ +#!/bin/bash +################################################ +# Include: Create final VMX configuration file # +################################################ + + +# check for vmdk file marker %VM_DISK_PATH% and put vmdk path in it's place: also VM_DISK_MODE +# and VM_DISK_REDOLOGDIR. +replace_placeholders() { + if [ -n "$VM_DISKFILE_RW" ]; then + sed -i 's#%VM_DISK_PATH%#'"$VM_DISKFILE_RW"'#g' "${TMPCONFIG}" + sed -i 's#%VM_DISK_MODE%#'"independent-persistent"'#g' "${TMPCONFIG}" + else + sed -i 's#%VM_DISK_PATH%#'"$VM_DISKFILE_RO"'#g' "${TMPCONFIG}" + sed -i 's#%VM_DISK_MODE%#'"independent-nonpersistent"'#g' "${TMPCONFIG}" + fi + sed -i 's#%VM_DISK_REDOLOGDIR%#'"$VM_REDO_DIR"'#g' "${TMPCONFIG}" +} + +# Ethernet: All we do is entering a generated MAC, as we do not want to interfere +# in the possible case no networking is wanted. +setup_ethernet() { + echo 'ethernet0.addressType = "static"' >> "${TMPCONFIG}" + echo 'ethernet0.address = "'"${VM_MAC_ADDR}"'"' >> "${TMPCONFIG}" + if [ -n "$OTHER_NICS" ]; then + local devtype mac cnt eth + # Copy type of eth0, in case the others don't specify a type in the vmx, we'll use the same + # so we know the drivers are there + devtype=$(< "${TMPCONFIG}" grep -m1 -i '^ethernet0\.virtualDev' | sed -r 's/^[^=]+//;s/^(\s|=|")*//;s/(\s|")+$//') # TODO: Make a helper like "getVmxOption" + cnt=0 + for mac in $OTHER_NICS; do + vmnet=$(( cnt + 10 )) + cnt=$(( cnt + 1 )) + eth="ethernet${cnt}" + # Check device exists + if ! [ -c "/dev/vmnet${vmnet}" ]; then + slxlog "vmware-bridge-setup" "Cannot bridge NIC into VM: /dev/vmnet${vmnet} does not exist" + continue + fi + # 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}"'"' + fi + cat >> "${TMPCONFIG}" <<-HEND + ${eth}.connectionType = "custom" + ${eth}.present = "TRUE" + ${eth}.vnet = "vmnet${vmnet}" + ${eth}.addressType = "static" + ${eth}.address = "${mac}" + ${devline} + HEND + done + fi +} + +# DVD, CDROM +setup_optical_drives() { + # XXX: For now it's safe to assume ide channel 1 is free, as we support only one HDD. + # If it's IDE, it's on channel 0 + cat >> "${TMPCONFIG}" <<-HEREEND + ide1:0.present = "$CDROM0" + ide1:0.autodetect = "TRUE" + ide1:0.fileName = "auto detect" + ide1:0.deviceType = "cdrom-raw" + ide1:1.present = "$CDROM1" + ide1:1.autodetect = "TRUE" + ide1:1.fileName = "auto detect" + ide1:1.deviceType = "cdrom-raw" + HEREEND +} + +setup_floppies() { + local SLX_FLOPPY + if isset SLX_FLOPPY_IMG; then + SLX_FLOPPY="TRUE" + else + SLX_FLOPPY="FALSE" + fi + + # Floppies: + cat >> "${TMPCONFIG}" <<-HEREEND + floppy0.present = "TRUE" + floppy0.startConnected = "$FLOPPY0" + floppy0.autodetect = "TRUE" + floppy0.fileName = "auto detect" + floppy1.present = "$SLX_FLOPPY" + floppy1.startConnected = "TRUE" + floppy1.fileType = "file" + floppy1.fileName = "$SLX_FLOPPY_IMG" + HEREEND +} + +setup_serial() { + # Serial port + if [ -n "$SERIAL0" ]; then + cat >> "${TMPCONFIG}" <<-HEREEND + serial0.present = "TRUE" + serial0.startConnected = "TRUE" + serial0.fileType = "device" + serial0.fileName = "$SERIAL0" + serial0.tryNoRxLoss = "FALSE" + serial0.autodetect = "FALSE" + HEREEND + fi + + # Parallel port + if [ -n "$PARALLEL0" ]; then + cat >> "${TMPCONFIG}" <<-HEREEND + parallel0.present = "TRUE" + parallel0.startConnected = "TRUE" + parallel0.fileType = "device" + parallel0.fileName = "$PARALLEL0" + parallel0.bidirectional = "TRUE" + parallel0.autodetect = "FALSE" + HEREEND + fi +} + +# CPU and RAM +setup_vcpu_ram() { + #writelog "numvcpus = ${CPU_CORES} - maxvcpus=${HOST_CORE_COUNT}" + cat >> "${TMPCONFIG}" <<-HEREEND + numvcpus = "$CPU_CORES" + cpuid.coresPerSocket = "$VM_CORES_PER_SOCKET" + maxvcpus = "$HOST_CORE_COUNT" + memsize = "${VM_MEM}" + MemAllowAutoScaleDown = "FALSE" + MemTrimRate = "-1" + HEREEND +} + +setup_usb() { + # USB fallback: Only write usb config if there's none + if ! grep -q -i "^usb\.present" "${TMPCONFIG}"; then + # Nothing found, go ahead + if [ -n "$SLX_EXAM" ]; then # TODO better handling of exam mode... + # Exam mode: Default to no USB + sed -i '/^usb\./Id' "${TMPCONFIG}" + echo 'usb.present = "FALSE"' >> "${TMPCONFIG}" + else + echo 'usb.present = "TRUE"' >> "${TMPCONFIG}" + fi + fi + sed -i '/^usb\.generic\.autoconnect/Id' "${TMPCONFIG}" + echo 'usb.generic.autoconnect = "TRUE"' >> "${TMPCONFIG}" + + # USB 3.0 support changes quality and has different side effects + # with every minor release of vmware. Always force 2.0 for now. + # TODO: Get it fixed by vmware? + sed -i '/^ehci\.present/Id;/^usb_xhci\.present/Id' "${TMPCONFIG}" + echo 'ehci.present = "TRUE"' >> "${TMPCONFIG}" + + # See if there are any USB devices connected that we want to pass through immediately + get_usb_devices 'usb.autoConnect.deviceXXXXX = "0x%VENDOR%:0x%PRODUCT%"' \ + | sed -r 's/0x0+/0x/g' \ + | awk '{sub(/XXXXX/,NR-1)}1' \ + >> "${TMPCONFIG}" +} + +setup_shared_folders() { + if ! notempty SHARED_FOLDERS HOME_SHARE_PATH HOME_SHARE_NAME COMMON_SHARE_PATH COMMON_SHARE_NAME; then + writelog "Missing information to setup shared folders." + return 1 + fi + + cat >> "${TMPCONFIG}" <<-HEREEND + sharedFolder.option = "alwaysEnabled" + sharedFolder0.present = "$SHARED_FOLDERS" + sharedFolder0.enabled = "$SHARED_FOLDERS" + sharedFolder0.expiration = "never" + sharedFolder0.guestName = "$HOME_SHARE_NAME" + sharedFolder0.hostPath = "$HOME_SHARE_PATH" + sharedFolder0.readAccess = "TRUE" + sharedFolder0.writeAccess = "TRUE" + sharedFolder1.present = "$SHARED_FOLDERS" + sharedFolder1.enabled = "$SHARED_FOLDERS" + sharedFolder1.expiration = "never" + sharedFolder1.guestName = "$COMMON_SHARE_NAME" + sharedFolder1.hostPath = "$COMMON_SHARE_PATH" + sharedFolder1.readAccess = "TRUE" + sharedFolder1.writeAccess = "FALSE" + sharedFolder.maxNum = "2" + hgfs.mapRootShare = "TRUE" + hgfs.linkRootShare = "TRUE" + HEREEND +} + +setup_isolation() { + # Settings for isolation tools (drag & drop, copy & paste, etc...) + cat >> "${TMPCONFIG}" <<-HEREEND + isolation.tools.hgfs.disable = "$HGFS_DISABLED" + isolation.tools.dnd.disable = "FALSE" + isolation.tools.copy.enable = "TRUE" + isolation.tools.paste.enabled = "TRUE" + HEREEND +} + +# Serial, parallel: Empty, nothing is being currently set. TODO later. + +setup_graphics() { + # Graphics, GPU: 3D will be enabled (even if vmware doesn't support the chip) if we whitelisted it. + if isset SLX_VMWARE_3D; then + writelog "FORCE3D set - overriding 3D in vmx file." + echo 'mks.gl.allowBlacklistedDrivers = "TRUE"' >> "${TMPCONFIG}" + # We override... play safe and cap the hwVersion to 10, since some i915 chips goofed up with 12 + # Investigate if we might have to do this in other cases where we don't override + if grep -qi '^mks.enable3d.*true' "${TMPCONFIG}"; then + vmw_cap_hw_version "10" + fi + else + writelog "FORCE3D not set - 3D will only work if GPU/driver is whitelisted by vmware." + fi + + # Disable DPI scaling information passing via vmware tools + sed -i '/^gui.applyHostDisplayScaling/Id' "${TMPCONFIG}" + echo 'gui.applyHostDisplayScalingToGuest = "FALSE"' >> "${TMPCONFIG}" + + # Additinal exam mode settings + if [ -n "$SLX_EXAM" ]; then + echo 'gui.restricted = "true"' >> "${TMPCONFIG}" + fi + + # Hack resolution if we know the desired one is not in the default list of vmx_svga + # For now, only do it on the odd ones, as we don't know if this has any side effects + # This seems unnecessary on Win7 but is required on WinXP - need more research for other OSs + case "$RESOLUTION" in + 1600x900|2560x1440|2880x1800|3200x1800) + X=${RESOLUTION%x*} + Y=${RESOLUTION#*x} + BYTES=$(( ( ( X * Y * 4 + 65535 ) / 65536 ) * 65536 )) + [ "$BYTES" -lt 16777216 ] && BYTES=16777216 + cat >> "${TMPCONFIG}" <<-EOF + svga.autodetect = "FALSE" + svga.vramSize = $BYTES + svga.maxWidth = $X + svga.maxHeight = $Y + EOF + ;; + esac + + # Killing duplicate lines (output much nicer than sort -u): + awk '!a[$0]++' "${TMPCONFIG}" > "${TMPCONFIG}.tmp" && mv -f "${TMPCONFIG}.tmp" "${TMPCONFIG}" +} + +finalize_hardware() { + # Apply $maxhardwareversion to final VMX + if notempty VM_HW_VERSION && [ "$VM_HW_VERSION" -gt "$maxhardwareversion" ]; then + writelog "Hardware version capped to $maxhardwareversion (was $VM_HW_VERSION)" + sed -i 's/^virtualHW\.version.*$/virtualHW.version = "'$maxhardwareversion'"/I' "${TMPCONFIG}" + VM_HW_VERSION="$maxhardwareversion" + fi + + # Enable nested virtualization if not specified in remote vmx + if [ -e "/run/hwinfo" ] && ! grep -qi '^vhv\.enable' "${TMPCONFIG}" \ + && grep -qE '^flags\s*:.*\b(ept|npt)\b' "/proc/cpuinfo" \ + && [ "$VM_HW_VERSION" -ge "9" ]; then + . "/run/hwinfo" + [ "${HW_KVM}" = "ENABLED" ] && echo 'vhv.enable = "TRUE"' >> "${TMPCONFIG}" + fi + + # Disable space check warnings + sed -i '/^mainMem.freeSpaceCheck/Id' "${TMPCONFIG}" + echo 'mainMem.freeSpaceCheck = "FALSE"' >> "${TMPCONFIG}" + + # TODO: Need a way to check if supported by hardware before enabling! + #grep -qi '^vpmc\.enable' "${TMPCONFIG}" || echo 'vpmc.enable = "TRUE"' >> "${TMPCONFIG}" +} + + +## MAIN ## +write_final_vmx() { + replace_placeholders + setup_ethernet + setup_optical_drives + setup_floppies + setup_serial + setup_vcpu_ram + setup_usb + [ "x$HGFS_DISABLED" = "xFALSE" ] && setup_shared_folders + setup_isolation + setup_graphics + finalize_hardware + + # 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}'" + else + writelog "Could not copy TMPDIR/IMGUUID -${TMPCONFIG}- to VM_RUN_FILE ${VM_RUN_FILE}!" + # cleanexit 1 # that seems not needed! + fi +} +call_post_source write_final_vmx + + diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/nvram b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/nvram Binary files differnew file mode 100644 index 00000000..88074390 --- /dev/null +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/nvram diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/run-virt.include b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/run-virt.include new file mode 100644 index 00000000..a552038b --- /dev/null +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/run-virt.include @@ -0,0 +1,61 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) 2009..2017 - RZ Uni Freiburg +# Copyright (c) 2009..2017 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# run-virt.include +# - component for vmware/player of the vmchooser plugin vmchooser-run_virt +################################################################################ + +# BASH_SOURCE[0] contains the file being sourced, namely this one +declare -rg VMWARE_PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")" +declare -rg VMWARE_INCLUDE_DIR="${VMWARE_PLUGIN_DIR}/includes" + +# TODO make this part of the metadata coming from the server +# Define which features the VMware plugin supports +declare -rg PLUGIN_FEATURES="firewall printer usb slxfloppy sound netshares" + +run_plugin() { + # declaration of default functions and variables for vmware + $(safesource --exit "${VMWARE_INCLUDE_DIR}/init_core.inc") + + # get information from downloaded vmx + $(safesource "${VMWARE_INCLUDE_DIR}/parse_vmx.inc") + + # determine limitations wrt RAM and CPU count of VM + $(safesource "${VMWARE_INCLUDE_DIR}/determine_hardware_limitations.inc") + + # create preferences file ${HOME}/.vmware/preferences + $(safesource "${VMWARE_INCLUDE_DIR}/create_vmhome_preferences_file.inc") + + # parse the given vmx file + $(safesource "${VMWARE_INCLUDE_DIR}/write_final_vmx.inc") + + # print summary - needs writelog() from vmchooser-run_virt + $(safesource "${VMWARE_INCLUDE_DIR}/log_config_summary.inc") + + # For debugging + cp "$VM_RUN_FILE" "/tmp/vmware-last-config" + + # HACK: make the mouse disappear + ( + local WINDOWS="$(xdotool search --sync --name '.*VMware.*Player.*')" + isempty WINDOWS && writelog "Could not find any vmplayer windows." + for WINDOW in $WINDOWS; do + xdotool set_desktop_for_window $WINDOW 0 || writelog "Could not move vmplayer to desktop 0" + xdotool windowactivate --sync $WINDOW || writelog "Could not activate vmplayer window" + xdotool key --delay 2000 --clearmodifiers ctrl+g || writelog "Could not send ctrl+g to vmplayer window" + done + ) & + + # HACK: using the modified version of the wrapper script + declare -rg VIRTCMD="/opt/openslx/bin/vmplayer" + declare -rg VIRTCMDOPTS="${VM_START_OPTIONS} ${VM_RUN_FILE}" +} |