diff options
author | Jonathan Bauer | 2017-01-25 18:32:35 +0100 |
---|---|---|
committer | Jonathan Bauer | 2017-01-25 18:32:35 +0100 |
commit | eea5898961a40fc50f01356f90c42904a73a3f74 (patch) | |
tree | 52c19d11efc2d7d904ac89e36ff271de305cfc5a /core/modules | |
parent | [pam] Include cifs.upcall for DFS support (diff) | |
download | mltk-eea5898961a40fc50f01356f90c42904a73a3f74.tar.gz mltk-eea5898961a40fc50f01356f90c42904a73a3f74.tar.xz mltk-eea5898961a40fc50f01356f90c42904a73a3f74.zip |
major run-virt restructure, only vmware plugin tested!
Diffstat (limited to 'core/modules')
77 files changed, 1924 insertions, 3098 deletions
diff --git a/core/modules/printergui/data/opt/openslx/vmchooser/run-virt.d/setup_printer_lpd.inc b/core/modules/printergui/data/opt/openslx/vmchooser/run-virt.d/setup_printer_lpd.inc new file mode 100644 index 00000000..d4c7df07 --- /dev/null +++ b/core/modules/printergui/data/opt/openslx/vmchooser/run-virt.d/setup_printer_lpd.inc @@ -0,0 +1,72 @@ +##################################### +# Include: Setup printer daemon LPD # +##################################### +## Functions ## +setup_virtual_printer() { + # TODO: QUEUE should prolly not be hardcoded .... + local QUEUE="STANDARD" # This has to match the queue you configured in your VM + local SPOOLDIR + + ### Disabled: 100megs is not enough, some jobs are HUGE, try to use temp which should be on disk + ## Try using user's tmpfs home first, as it gets wiped on logout + #if [ -n "${HOME}" ] && [ -w "${HOME}" ]; then + # SPOOLDIR="${HOME}/.spool" + # mkdir -p "${SPOOLDIR}/${QUEUE}" + #fi + # If failed, try to fall back to /tmp + + if [ -z "${SPOOLDIR}" ] || [ ! -w "${SPOOLDIR}/${QUEUE}" ]; then + SPOOLDIR="${TMPDIR}/printergui-${RANDOM}" + rm -rf -- "${SPOOLDIR}" + if ! mkdir -p "${SPOOLDIR}/${QUEUE}"; then + slxlog "virt-spooldir" "Could not create spool directory ($SPOOLDIR) for $USER - printing will not work!" + notify_user "Drucksystem" "Das Drucksystem konnte nicht initialisiert werden. Druckfunktion nicht verfügbar." + fi + chmod 0700 "${SPOOLDIR}/${QUEUE}" + fi + + # Start the lpdaemon listening on the given port + # TODO: externalize with something like runvirt.d (other parts might benefit from that too) + tcpsvd -E 192.168.101.1 5515 \ + lpd "$SPOOLDIR" \ + ash -c "/opt/openslx/scripts/run-virt_print '${USER}' \"${SPOOLDIR}/${QUEUE}/\$DATAFILE\"" & + + # PID to kill the process + declare -rg PID_LPD="$!" + add_cleanup "stop_virtual_printer" + { + sleep 2 + # Check if tcpsvd is running. Do this a little delayed so we do not check + # immediately after trying to spawn it, as this could result in + # success even if it's not really working. + + if ! kill -0 "$PID_LPD"; then + slxlog "virt-lpd" "Could not start tcpsvd/lpd for virtual machine session" + notify_user "Drucksystem" "Das Drucksystem konnte nicht initialisiert werden. Druckfunktion nicht verfügbar." + fi + } & +} + +# cleanup helper to stop lpd +stop_virtual_printer() { + isset PID_LPD && kill "${PID_LPD}" +} + +## MAIN ## +# Sanity checks +unset FAIL +if ! check_dep tcpsvd lpd; then + writelog "One of 'tcpsvd' or 'lpd' could not be found in PATH: $PATH" + FAIL=y +fi +if [ ! -f "/opt/openslx/scripts/run-virt_print" ]; then + writelog "File not found: /opt/openslx/scripts/run-virt_print" + FAIL=y +fi +if isset FAIL; then + unset FAIL + notify_user "Drucksystem" "Das Drucksystem konnte nicht initialisiert werden. Druckfunktion nicht verfügbar." +else + reg_feature_handler "printer" "setup_virtual_printer" +fi + diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/README b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/README new file mode 100644 index 00000000..549d0037 --- /dev/null +++ b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/README @@ -0,0 +1 @@ +Not tested since refactoring! (January 2017) diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/qemukvm/run-virt.include b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include index 81bf9218..e2a60f9c 100644 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/qemukvm/run-virt.include +++ b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include @@ -30,6 +30,8 @@ setup_if () ################################################################################ ### Declaration of default variables ################################################################################ +# Define which features the VMware plugin supports +declare -rg PLUGIN_FEATURES="TODO" VMCHOOSERQK="/opt/openslx/vmchooser/${self}" # create TMPDIR for all users @@ -52,12 +54,12 @@ else fi # set the emulator/virtualization options for various operating systems -sound="es1370" +SOUND_DEV="es1370" case "${VM_OS_TYPE}" in beos*) VIRTCMDOPTS="qemu-system-i386 -machine accel=tcg" - sound="sb16" - if [ "${totalmem}" -ge "1000" ]; then + SOUND_DEV="sb16" + if [ "${HOST_MEM_TOTAL}" -ge "1000" ]; then forcemem=512 else forcemem=256 @@ -65,7 +67,7 @@ case "${VM_OS_TYPE}" in ;; win3*|win*3*|Win*3*) VIRTCMDOPTS="qemu-system-i386 -machine accel=tcg" - sound="sb16" + SOUND_DEV="sb16" forcemem=32 ;; win95*|Win*95) @@ -78,12 +80,12 @@ case "${VM_OS_TYPE}" in ;; winme*|windowsme*) VIRTCMDOPTS="qemu-system-i386 -machine accel=tcg" - sound="ac97" + SOUND_DEV="ac97" forcemem=384 ;; winxp*64|windowsxp*64) VIRTCMDOPTS="qemu-system-x86_64 -machine accel=kvm" - sound="ac97" + SOUND_DEV="ac97" ;; esac @@ -110,14 +112,14 @@ if [ -n "${forcemem}" ]; then mem="${forcemem}" else permem=30 - if [ "${totalmem}" -ge "1600" ]; then + if [ "${HOST_MEM_TOTAL}" -ge "1600" ]; then permem=40 fi # # check if /tmp is on harddisk # if grep -qe "/dev/.* /tmp " /proc/mounts ; then # permem=60 # id44="1" -# #if [ "${totalmem}" -ge "2500" ]; then +# #if [ "${HOST_MEM_TOTAL}" -ge "2500" ]; then # #permem=40 # #rmdir ${snapshotdir} # #snapshotdirold=${snapshotdir} @@ -126,27 +128,29 @@ else # #ln -sf ${snapshotdir} ${snapshotdirold} # #fi # fi - mem=$(expr ${totalmem} / 100 \* ${permem}) + mem=$(expr ${HOST_MEM_TOTAL} / 100 \* ${permem}) if [ "${id44}" = "1" ]; then - memhost=$(expr ${totalmem} - ${mem}) + HOST_MEM_REMAINING=$(expr ${HOST_MEM_TOTAL} - ${VM_MEM}) else - memhost=$(expr ${totalmem} - ${mem} - ${mem}) + HOST_MEM_REMAINING=$(expr ${HOST_MEM_TOTAL} - ${VM_MEM} - ${VM_MEM}) fi # static first permem=50 - mem=$(expr ${totalmem} / 100 \* ${permem}) - if [ "${mem}" -lt "256" ] || [ "${memhost}" -lt "256" ]; then - writelog "Memory out of range: ${mem} MB (guest) / ${memhost} MB (host)!" + mem=$(expr ${HOST_MEM_TOTAL} / 100 \* ${permem}) + if [ "${VM_MEM}" -lt "256" ] || [ "${HOST_MEM_REMAINING}" -lt "256" ]; then + writelog "Memory out of range: ${VM_MEM} MB (guest) / ${HOST_MEM_REMAINING} MB (host)!" writelog "Min. 256 MB for host and guest!" exit 1 fi fi -VIRTCMDOPTS="${VIRTCMDOPTS} -m ${mem}" +VIRTCMDOPTS="${VIRTCMDOPTS} -m ${VM_MEM}" # network adaptor alternatives: rtl8139, pcnet, e1000 network_card=${network_card:=pcnet} -VIRTCMDOPTS="${VIRTCMDOPTS} -net nic,macaddr=${macaddr},model=${network_card}" +# TODO handle new way of generating MAC addr with prefix/suffix +# KVM MAC prefix should be 52:54:00 +VIRTCMDOPTS="${VIRTCMDOPTS} -net nic,macaddr=${VM_MAC_ADDR},model=${network_card}" # define network kind and configure the interfaces case "${network_kind}" in @@ -190,6 +194,7 @@ else boot="c" fi +# TODO externalize! # external GUI port vncport="590${VM_ID}" @@ -199,29 +204,29 @@ ide="TRUE" hddrv="ide" # special feature for real and virtual floppy disks -[ -n "${floppy_0}" ] && VIRTCMDOPTS="${VIRTCMDOPTS} -fda ${floppy_0}" -VIRTCMDOPTS="${VIRTCMDOPTS} -fdb /opt/openslx/vmchooser/data/loopimg/fd.img" +[ -n "${floppy_0}" ] && VIRTCMDOPTS="${VIRTCMDOPTS} -fda ${FLOPPY_0}" +VIRTCMDOPTS="${VIRTCMDOPTS} -fdb ${SLX_FLOPPY_IMG}" # add optical drive if available -[ -n "${cdrom_0}" ] && VIRTCMDOPTS="${VIRTCMDOPTS} -cdrom ${cdrom_0}" +[ -n "${CDROM_0}" ] && VIRTCMDOPTS="${VIRTCMDOPTS} -cdrom ${CDROM_0}" # audio -VIRTCMDOPTS="${VIRTCMDOPTS} -soundhw ${sound}" +VIRTCMDOPTS="${VIRTCMDOPTS} -soundhw ${SOUND_DEV}" # serial [ "x${serial}" == "xttyS0" ] && VIRTCMDOPTS="${VIRTCMDOPTS} -serial /dev/ttyS0" writelog "Virtual Hardware:" -writelog "\tGuest RAM:\t\t${mem} MB" -# echo nur wenn memhost gesetzt -[ -n "${memhost}" ] && writelog "\tHost RAM:\t\t${memhost} MB" -writelog "\tMAC address:\t\t$macaddr" +writelog "\tGuest RAM:\t\t${VM_MEM} MB" +# echo nur wenn HOST_MEM_REMAINING gesetzt +[ -n "${HOST_MEM_REMAINING}" ] && writelog "\tHost RAM:\t\t${HOST_MEM_REMAINING} MB" +writelog "\tMAC address:\t\t${VM_MAC_ADDR}" writelog "\tNetwork card:\t\t${network_card}" writelog "\tNetwork kind:\t\t${network_kind}" -writelog "\tCD-ROM1:\t${cdrom0}" +writelog "\tCD-ROM1:\t${CDROM_0}" #writelog "\tCD-ROM2:\t${cdrom1}" -writelog "\tFloppy_A:\t${floppy_0}" -writelog "\tFloppy_B:\t/opt/openslx/vmchooser/data/loopimg/fd.img" +writelog "\tFloppy_A:\t${FLOPPY_0}" +writelog "\tFloppy_B:\t${SLX_FLOPPY_IMG}" #writelog "\tShared Folders 'home':\t/home/${USER}" ################################################################################ diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/check_lpd.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/check_lpd.inc deleted file mode 100644 index 8286bbaa..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/check_lpd.inc +++ /dev/null @@ -1,11 +0,0 @@ -############################################ -# Include: Checking whether lpd is running # -############################################ - -# Check if tcpsvd is running. Do this down here so we do not check -# immediately after trying to spawn it, as this could result in -# success even if it's not really working. - -if ! kill -0 "$PID_LPD"; then - slxlog "virt-lpd" "Could not start tcpsvd/lpd for virtual machine session" -fi diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/check_runvirt_needed_files.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/check_runvirt_needed_files.inc deleted file mode 100644 index fbb0bc70..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/check_runvirt_needed_files.inc +++ /dev/null @@ -1,53 +0,0 @@ -################################################################# -# Include: Check for important files used by vmchooser_run-virt # -################################################################# - -# WARNING: This is perhaps vestigial! - -filecheck() { - filecheck=$(LANG=us ls -lh ${diskfile} 2>&1) - writelog "Filecheck:\n${filecheck}\n" - noimage=$(echo ${filecheck} | grep -i "no such file or directory" | wc -l) - rightsfile=${diskfile} - - # check if link - if [ -L "${diskfile}" ]; then - # take link target - rightsfile=$(ls -lh ${diskfile} 2>&1 | awk -F '-> *' '{print $2}') - rightsfile=${vmdir}/${rightsfile} - filecheck=$(LANG=us ls -lh ${rightsfile} 2>&1) - fi - - # does file exist - if [ "${noimage}" -ge "1" ]; then - writelog "Virtual Machine Image Problem:\c " - writelog "\tThe image you've specified doesn't exist." - writelog "Filecheck says:\c " - writelog "\t\t${diskfile}:\n\t\t\tNo such file or directory" - writelog "Hint:\c " - writelog "\t\t\tCompare spelling of the image with your options.\n" - exit 1 - fi - # readable by calling user - if ! [ -r "${diskfile}" >/dev/null 2>&1 \ - -o -r "${diskfile}" >/dev/null 2>&1 ]; then - writelog "Vmware Image Problem:\c " - writelog "\tThe image you've specified has wrong rights." - writelog "Filecheck says:\t\t$(echo ${filecheck} \ - | awk '{print $1" "$3" "$4}') ${rightsfile}" - writelog "Hint:\t\t\tChange rights with: chmod a+r ${rightsfile}\n" - exit 1 - fi - - # writable (for persistent-mode)? - if ! [ -w "${diskfile}" >/dev/null 2>&1 \ - -o -w "${diskfile}" >/dev/null 2>&1 ] \ - && [ "${np}" = "independent-persistent" ]; then - writelog "Vmware Image Problem:\c " - writelog "\tThe image you have specified has wrong rights." - writelog "Filecheck says:\t\t$(echo ${filecheck} \ - | awk '{print $1" "$3" "$4}') ${rightsfile}" - writelog "Hint:\t\t\tUse nonpersistent-mode or change rights to rw\n" - exit 1 - fi -} diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/check_runvirt_xml_sanity_legacy.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/check_runvirt_xml_sanity_legacy.inc deleted file mode 100644 index d331e1af..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/check_runvirt_xml_sanity_legacy.inc +++ /dev/null @@ -1,23 +0,0 @@ -####################################################### -# Include: check xml file for sanity (legacy, old way # -####################################################### - -# test if the xml file is valid -if ! [ -r "${xmlfile}" ]; then - writelog "${xmlfile} not a readable XML file!" - slxlog "virt-nonreadable-xml" "XML file not readable: $xmlfile" - exit 1 -fi - -# test if XML file -if ! grep -q '<?xml' "${xmlfile}"; then - writelog "Submitted configuration file ${xmlfile} seems to have wrong XML format" - slxlog "virt-invalid-xml" "Malformed XML file: $xmlfile" "$xmlfile" - exit 1 -fi - -# check for running in graphical environment otherwise no much use here -if [ -z "$DISPLAY" ]; then - echo -e "\n\tStart only within a graphical desktop!\n" - exit 1 -fi diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/detect_legacy.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/detect_legacy.inc deleted file mode 100644 index 11a21832..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/detect_legacy.inc +++ /dev/null @@ -1,33 +0,0 @@ -######################################################## -# Include: Detect, whether runvirt runs in legacy mode # -######################################################## - -# Legacy mode: As runvirt has been before. -# New mode: uuid in xml _and_ vmx given via http. - -writelog "Detecting current/legacy mode ..." - -# First, let's try to extract an imguuid from xmlfile: -IMGUUID=$(grep -io '<uuid param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') - -writelog "IMGUUID extracted: $IMGUUID" - -if [ ! -n "$IMGUUID" ]; then # Keine uuid: Abbruch, Legacy - writelog "Could not extract an uuid param from ${xmlfile}. Triggering legacy mode." - LEGACY=: # No uuid; legacy. -else - # Now getting template file: - if wget -O "$TMPDIR/$IMGUUID" "${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}" 1>&2 2>/dev/null; then - writelog "wget ${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID} successful." - writelog "Triggering current (non-legacy) mode." - LEGACY= # both strings set: no legacy. - if [ ! -s "$TMPDIR/$IMGUUID" ]; then - LEGACY= # no legacy: server sent 0 byte file. - writelog "Server sent zero byte virtual machine description file. Retriggering legacy mode." - fi - else - writelog "wget ${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}. Triggering legacy mode." - LEGACY=: - fi -fi - diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_dir_legacy.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_dir_legacy.inc deleted file mode 100644 index c3c6f7b3..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_dir_legacy.inc +++ /dev/null @@ -1,50 +0,0 @@ -######################################################### -# Include: Get xml file and directory (legacy, old way) # -######################################################### - -## Added for persistent support. -diskmode='nonpersistent' -if [[ "$(grep --extended-regexp \ - '< *short_description *param=".+ --persistent--"' "$1")" ]]; then - diskmode='persistent' - imageFilePath="$(grep -io '<image_path param=.*"' "$1" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }')" - [ -z "$imageFilePath" ] && imageFilePath="$(grep -io '<image_name param=.*"' "$1" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }')" - originalXMLFilePath="$(grep -io '<original_xml_file_path param=.*"' "$1" \ - | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }')" - originalImageFileName="$(grep -io '<image_name param=.*"' \ - "$originalXMLFilePath" | sed -e "s/&.*;/; /g" | awk -F '"' \ - '{ print $2 }')" - originalVMDKFilePath="$(dirname \ - "$originalXMLFilePath")/${originalImageFileName}" - # Added to workaround path prefix coming from temporary generated xml file - # by vmchooser. - if [[ "$(grep --extended-regexp '^/tmp/tmp\.[^\/]+/' <<< \ - "$imageFilePath")" ]]; then - imageFilePath=$(sed -r 's/^\/?tmp\/[^\/]+\///g' \ - <<< "$imageFilePath") - sed -ir \ - "s/(<image_name param=\")[^\"]*(\")/\\1$(sed -e \ - 's/\\/\\\\/g' -e 's/\//\\\//g' -e \ - 's/&/\\\&/g' <<< "$imageFilePath")\\2/g" "$1" - fi - # Create linked clone if not exists. - if [ ! -f "$imageFilePath" ]; then - mkdir -p "$(dirname "$imageFilePath")" && \ - bash "$(dirname "$0")/vmchooser-clc" "$originalXMLFilePath" \ - "$imageFilePath" --debug --verbose &>"${LOGFILE}" - fi -fi - -# absolute or relative path? -xmlfile=$1 -if ls "${xmlfile}" 2>/dev/null | grep '/' >/dev/null 2>&1; then - xmlpath=$(dirname "${xmlfile}") - xmlfile=$(basename "${xmlfile}") -else - xmlpath=${vmchooser_xmlpath} -fi -# full path -xmlfile="${xmlpath}/${xmlfile%.xml}.xml" - -DO_PROFILE="$(grep -c -E -i '<\s*profile\s*param="?(true|yes)"?' "$xmlfile")" - diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_variables.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_variables.inc deleted file mode 100644 index b7ed648c..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_variables.inc +++ /dev/null @@ -1,103 +0,0 @@ -########################################### -# Include: Set hardware related variables # -########################################### - -writelog "Starting configuration..." -writelog "\tLogfile:\t\t${LOGFILE}" -writelog "\t/tmp info:\t\t$(df -h | grep " /tmp$" | awk '{print $2}') \c" -writelog "$(grep "/tmp " /proc/mounts | awk '{print $1" "$2" "$3" "$4}')" -writelog "\tVM XML dir:\t\t$(dirname "${xmlfile}")" -writelog "\tXML file:\t\t${xmlfile}" -writelog "Enable 3D:\t\t${enable3d}" -writelog "VM config:" - -# # Name of the virt image -imgname=$(grep -io '<image_path param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') -imgrelpath=$(grep -io '<image_name param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') -# [ -z "$imgname" ] && imgname="${imgrelpath}" -imgrelpath=${imgrelpath#/mnt/vmstore/} - -writelog "Virtual image file name: $imgname" - -# Imagename w/ full path -if echo "${imgname}" | grep -q '^/'; then - imgpath="$(dirname "${imgname}")" - imgname="$(basename "${imgname}")" - vmpath="${imgpath}/${imgname}" - # If old vmchooser binary stuff - # We do not need folder name as it is already included by vmchooser -elif echo "${xmlfile}" | grep -q '^/tmp/'; then - vmpath="$imgname" - imgname="$(basename "${imgname}")" - ## Added for persistent support. -else - # Else use same path as xml - imgpath="${xmlpath}" - vmpath="${imgpath}/${imgname}" -fi - -# If ${vm_name} not defined use ${xmlfile} -vm_name="${vm_name:-${xmlfile%.xml}}" - -# Define vm_shortname since vm_name can be very long -vm_shortname="$(basename "${xmlfile%.xml}" | sed -e "s, ,-,g")" - -# vm_name = displayname, define for old scripts -displayname="${vm_name}" - -# image is for the following virtual machine -xmlvirt=$(grep -o 'virtualmachine param=.*"' "${xmlfile}" \ - | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') - -# choose the proper virtualization/emulator plugin -[ "x${xmlvirt}" != "x" -a "x${xmlvirt}" != "xqemukvm" -a "x${xmlvirt}" != "xvirtualbox" -a "x${xmlvirt}" != "xvmware" ] && xmlvirt="emufe" - -# Extracting OS type (vmostype) from xml file. We don't care here whether vmostype is empty, as then -# it will yield the default entries later on. -vmostype=$(grep -io '<os param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') - -# make a guess from the filename extension if ${xmlvirt} is empty -# (not set within the XML file) -# TODO: implement possibility to submit own configuration files -if [ -z "${xmlvirt}" ] && [ -n "${additional_config}" ]; then - writelog "No virtual machine parameter defined in ${xmlfile}" - writelog "Trying to guess VM...\c" - case "$(cat ${additional_config} | tr \"[A-Z]\" \"[a-z]\")" in - *config.version*|*virtualhw.version*|*independent-nonpersistent*|*vmdk*) - xmlvirt="vmware" - ;; - *innotek*|*virtualbox*) - xmlvirt="virtualbox" - ;; - *qemu*|*kvm*) - xmlvirt="qemukvm" - ;; - *) - xmlvirt="none" - ;; - esac - elif [ -z "${xmlvirt}" ]; then - case "$(echo ${imgname##*.} | tr \"[A-Z]\" \"[a-z]\")" in - vmdk) - xmlvirt="vmware" - ;; - vbox|vdi) - xmlvirt="virtualbox" - ;; - qcow*) - xmlvirt="qemukvm" - ;; - *) - xmlvirt="emufe" - ;; - esac - writelog "result:\t${xmlvirt}" -fi - -# Set redirects to 0, see vmgrid if you want to define some -redirects=0 - -writelog "\tVirtualization:\t\t$xmlvirt" -writelog "\tVM name:\t\t$vm_name" -writelog "\tVM short name:\t\t$vm_shortname" -writelog "\tVM OS:\t\t$vmostype" diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_variables_legacy.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_variables_legacy.inc deleted file mode 100644 index 3fdc06d2..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/get_xml_file_variables_legacy.inc +++ /dev/null @@ -1,120 +0,0 @@ -########################################### -# Include: Set hardware related variables # -########################################### - -writelog "Starting configuration..." -writelog "\tLogfile:\t\t${LOGFILE}" -writelog "\t/tmp info:\t\t$(df -h | grep " /tmp$" | awk '{print $2}') \c" -writelog "$(grep "/tmp " /proc/mounts | awk '{print $1" "$2" "$3" "$4}')" -writelog "\tVM XML dir:\t\t$(dirname "${xmlfile}")" -writelog "\tXML file:\t\t${xmlfile}" -writelog "Enable 3D:\t\t${enable3d}" -writelog "VM config:" - -# Name of the virt image -imgname=$(grep -io '<image_path param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') -imgrelpath=$(grep -io '<image_name param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') -[ -z "$imgname" ] && imgname="${imgrelpath}" -imgrelpath=${imgrelpath#/mnt/vmstore/} - -## Added for persistent support. -if [[ "$userBranchFilePath" ]]; then - imgname="$userBranchFilePath" -fi - -# Imagename w/ full path -if echo "${imgname}" | grep -q '^/'; then - imgpath="$(dirname "${imgname}")" - imgname="$(basename "${imgname}")" - vmpath="${imgpath}/${imgname}" - # If old vmchooser binary stuff - # We do not need folder name as it is already included by vmchooser -elif echo "${xmlfile}" | grep -q '^/tmp/'; then - vmpath="$imgname" - imgname="$(basename "${imgname}")" - ## Added for persistent support. -elif [[ "$userBranchFilePath" ]]; then - vmpath="$userBranchFilePath" -else - # Else use same path as xml - imgpath="${xmlpath}" - vmpath="${imgpath}/${imgname}" -fi - -# Name of the virt machine, sed because of Windows formatting -vm_name=$(grep -o 'short_description param=.*"' "${xmlfile}" \ - | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') - -# If ${vm_name} not defined use ${xmlfile} -vm_name="${vm_name:-${xmlfile%.xml}}" - -# Define vm_shortname since vm_name can be very long -vm_shortname="$(basename "${xmlfile%.xml}" | sed -e "s, ,-,g")" - -# vm_name = displayname, define for old scripts -displayname="${vm_name}" - -# image is for the following virtual machine -xmlvirt=$(grep -o 'virtualmachine param=.*"' "${xmlfile}" \ - | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') - -# choose the proper virtualization/emulator plugin -[ "x${xmlvirt}" != "x" -a "x${xmlvirt}" != "xqemukvm" -a "x${xmlvirt}" != "xvirtualbox" -a "x${xmlvirt}" != "xvmware" ] && xmlvirt="emufe" - -# make a guess from the filename extension if ${xmlvirt} is empty -# (not set within the XML file) -# TODO: implement possibility to submit own configuration files -if [ -z "${xmlvirt}" ] && [ -n "${additional_config}" ]; then - writelog "No virtual machine parameter defined in ${xmlfile}" - writelog "Trying to guess VM...\c" - case "$(cat ${additional_config} | tr \"[A-Z]\" \"[a-z]\")" in - *config.version*|*virtualhw.version*|*independent-nonpersistent*|*vmdk*) - xmlvirt="vmware" - ;; - *innotek*|*virtualbox*) - xmlvirt="virtualbox" - ;; - *qemu*|*kvm*) - xmlvirt="qemukvm" - ;; - *) - xmlvirt="none" - ;; - esac - elif [ -z "${xmlvirt}" ]; then - case "$(echo ${imgname##*.} | tr \"[A-Z]\" \"[a-z]\")" in - vmdk) - xmlvirt="vmware" - ;; - vbox|vdi) - xmlvirt="virtualbox" - ;; - qcow*) - xmlvirt="qemukvm" - ;; - *) - xmlvirt="emufe" - ;; - esac - writelog "result:\t${xmlvirt}" -fi - -# Definition of the client system -vmostype=$(grep -io '<os param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }' | tr "[A-Z]" "[a-z]") - -# Definition of the networking the client system is connected to -network_kind=$(grep -io '<network param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }' | tr "[A-Z]" "[a-z]") -network_card=$(grep -io '<netcard param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }'| tr "[A-Z]" "[a-z]") -override_hddtype=$(grep -io '<hddtype param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }'| tr "[A-Z]" "[a-z]") - -# Set redirects to 0, see vmgrid if you want to define some -redirects=0 - -# Serial/parallel ports defined (e.g. "ttyS0" or "autodetect") -serial=$(grep -io '<serialport param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }') -parallel=$(grep -io '<parport param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }') - -writelog "\tVirtualization:\t\t$xmlvirt" -writelog "\tVM name:\t\t$vm_name" -writelog "\tVM short name:\t\t$vm_shortname" - diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/print_runvirt_console_logo.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/print_runvirt_console_logo.inc deleted file mode 100644 index 649cf956..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/print_runvirt_console_logo.inc +++ /dev/null @@ -1,12 +0,0 @@ -####################################### -# Include: Print Logo for console use # -####################################### - -cat <<EOL - __ __ - .----.--.--.-----.___.--.--.|__|.----.| |_ - | _| | | |___| | || || _|| _| - |__| |_____|__|__| \___/ |__||__| |____| - OpenSLX virtual machine environment preparation script ... - -EOL diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables.inc deleted file mode 100644 index 400c1bf4..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables.inc +++ /dev/null @@ -1,88 +0,0 @@ -########################################### -# Include: Set hardware related variables # -########################################### - -# take last two digits of current pid... -VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2) - -# Make sure cpu_cores is not empty -cpu_cores=${cpu_cores:-"1"} - -# Amount of memory for the VM. Be generous if diff is written to HDD -if mount | grep -q '^/dev/sd.*on.*/tmp'; then - reserve=20 - min=768 - max=1536 -else - reserve=65 - min=768 - max=8192 -fi - -# Calculate absulute amount of RAM that should stay available to the host -reserve="$[ ( $totalmem * $reserve ) / 100 ]" -# Respect some upper and lower bounds for the host amount -[ "$reserve" -lt "$min" ] && reserve="$min" -[ "$reserve" -gt "$max" ] && reserve="$max" - -# Get a result which can be divided by 4 -mem="$[ ( ( $totalmem - $reserve ) / 4 ) * 4 ]" -if [ -n "$mainvirtmem" ]; then - forcemem="$[ "$mainvirtmem" / 4 * 4 ]" - mem="$forcemem" -fi -hostmem="$[ $totalmem - $mem ]" - -# TODO: We should only generate the suffix here (last 3 octets) as the first 3 are -# dependant on the virtualizer/emulator. Check if any run-virt.include still relies on -# $macguestpart/$macaddr. If so, fix it to use its specific first 3 bytes -# and append $macaddrssuffix -macguestpart="00:50:56:${VM_ID}" -machostpart=$(echo "${hostmacaddr}" | awk -F ":" '{print $(NF-1)":"$NF}') -macaddr=$(echo "${macguestpart}:${machostpart}" | tr "[a-z]" "[A-Z]") -macaddrsuffix=$(echo "${VM_ID}:${machostpart}" | tr "[a-z]" "[A-Z]") - -if ! echo "$macaddrsuffix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then - slxlog "virt-mac" "Could not properly generate mac address suffix (got $macaddrsuffix)" -fi - -# Virtual fd/cd/dvd and drive devices, floppy b: for configuration -# if $floppy_0 from virtualization.conf set then fdtest="TRUE" -fdtest=${floppy_0:+"TRUE"} -# if $fdtest not set floppy0="FALSE", else "TRUE" -floppy0=${fdtest:-"FALSE"} -floppy1="TRUE" -floppy1name="$VMCHOOSER_DIR/data/loopimg/fd.img" -# if $cdrom_0 from virtualization.conf set then cdtest="TRUE" -cdtest=${cdrom_0:+"TRUE"} -# if $cdtest not set cdrom0="FALSE", else "TRUE" -cdrom0=${cdtest:-"FALSE"} -# if $cdrom_1 from virtualization.conf set then cdtest="TRUE" -cdtest=${cdrom_1:+"TRUE"} -# if $cdtest not set cdrom1="FALSE", else "TRUE" -cdrom1=${cdtest:-"FALSE"} -# IDE is expected default, test for the virtual disk image type should -# be done while creating the runscripts ... -# TODO enable SCSI support instead of just disabling it. -ide="TRUE" -scsi="FALSE" -hddrv="ide" -audio="true" -remotedesktopport="590${VM_ID}" - -# Enable 3D -enable3d=$(grep -i -o "<enable3d param=.*" "${xmlfile}" | awk -F '"' '{print $2}' | rv_clean_string) - -# Add rw share for home dir -homesharepath="${HOME}/PERSISTENT" -homesharename="home" - -# Add common share -commonsharepath="${HOME}/SHARE" -commonsharename="share" - -# Set hostname: using original hostname and adding string -hostname="virt-$(hostname)" - -writelog "\tVM Hostname:\t\t$hostname" - diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables_legacy.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables_legacy.inc deleted file mode 100644 index 0da5e2be..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables_legacy.inc +++ /dev/null @@ -1,89 +0,0 @@ -########################################### -# Include: Set hardware related variables # -########################################### - -# take last two digits of current pid... -VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2) - -# Make sure cpu_cores is not empty -cpu_cores=${cpu_cores:-"1"} - -# Amount of memory for the VM. Be generous if diff is written to HDD -if mount | grep -q '^/dev/sd.*on.*/tmp'; then - reserve=20 - min=768 - max=1536 -else - reserve=65 - min=768 - max=8192 -fi - -# Calculate absulute amount of RAM that should stay available to the host -reserve="$[ ( $totalmem * $reserve ) / 100 ]" -# Respect some upper and lower bounds for the host amount -[ "$reserve" -lt "$min" ] && reserve="$min" -[ "$reserve" -gt "$max" ] && reserve="$max" - -# Get a result which can be divided by 4 -mem="$[ ( ( $totalmem - $reserve ) / 4 ) * 4 ]" -if [ -n "$mainvirtmem" ]; then - forcemem="$[ "$mainvirtmem" / 4 * 4 ]" - mem="$forcemem" -fi -hostmem="$[ $totalmem - $mem ]" - -# TODO: We should only generate the suffix here (last 3 octets) as the first 3 are -# dependant on the virtualizer/emulator. Check if any run-virt.include still relies on -# $macguestpart/$macaddr. If so, fix it to use its specific first 3 bytes -# and append $macaddrssuffix -macguestpart="00:50:56:${VM_ID}" -machostpart=$(echo "${hostmacaddr}" | awk -F ":" '{print $(NF-1)":"$NF}') -macaddr=$(echo "${macguestpart}:${machostpart}" | tr "[a-z]" "[A-Z]") -macaddrsuffix=$(echo "${VM_ID}:${machostpart}" | tr "[a-z]" "[A-Z]") - -if ! echo "$macaddrsuffix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then - slxlog "virt-mac" "Could not properly generate mac address suffix (got $macaddrsuffix)" -fi - -# Virtual fd/cd/dvd and drive devices, floppy b: for configuration -# if $floppy_0 from virtualization.conf set then fdtest="TRUE" -fdtest=${floppy_0:+"TRUE"} -# if $fdtest not set floppy0="FALSE", else "TRUE" -floppy0=${fdtest:-"FALSE"} -floppy1="TRUE" -floppy1name="$VMCHOOSER_DIR/data/loopimg/fd.img" -# if $cdrom_0 from virtualization.conf set then cdtest="TRUE" -cdtest=${cdrom_0:+"TRUE"} -# if $cdtest not set cdrom0="FALSE", else "TRUE" -cdrom0=${cdtest:-"FALSE"} -# if $cdrom_1 from virtualization.conf set then cdtest="TRUE" -cdtest=${cdrom_1:+"TRUE"} -# if $cdtest not set cdrom1="FALSE", else "TRUE" -cdrom1=${cdtest:-"FALSE"} -# IDE is expected default, test for the virtual disk image type should -# be done while creating the runscripts ... -# TODO enable SCSI support instead of just disabling it. -ide="TRUE" -scsi="FALSE" -hddrv="ide" -audio="true" -remotedesktopport="590${VM_ID}" - - -# Enable 3D -enable3d=$(grep -i -o "<enable3d param=.*" "${xmlfile}" | awk -F '"' '{print $2}' | rv_clean_string) - -# Add rw share for home dir -homesharepath="${HOME}/PERSISTENT" -homesharename="home" - -# Add common share -commonsharepath="${HOME}/SHARE" -commonsharename="share" - -# Set hostname: using original hostname and adding string -hostname="virt-$(hostname)" - -writelog "\tVM Hostname:\t\t$hostname" - diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_variables.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_variables.inc deleted file mode 100644 index 5215eb2d..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_variables.inc +++ /dev/null @@ -1,21 +0,0 @@ -###################################################### -# Include: Declaration of run-virt default variables # -###################################################### - -VMCHOOSER_DIR="/opt/openslx/vmchooser" -VMCHOOSER_CONF_DIR="$VMCHOOSER_DIR/config" -LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" -USER="$(whoami)" -TMPDIR="/tmp/virt/${USER}/$$" - -readonly VMCHOOSER_DIR VMCHOOSER_CONF_DIR LOGFILE TMPDIR USER - -# include general configuration from vmchooser -[ -f "$VMCHOOSER_CONF_DIR/vmchooser.conf" ] && . "$VMCHOOSER_CONF_DIR/vmchooser.conf" -# load general virtualization information -[ -f "$VMCHOOSER_CONF_DIR/virtualization.conf" ] && . "$VMCHOOSER_CONF_DIR/virtualization.conf" -# Load general openslx config -[ -f "/opt/openslx/config" ] && . "/opt/openslx/config" -# Create temp dir -mkdir -p "$TMPDIR" # TODO error out if failed - diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc deleted file mode 100644 index dd408b22..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc +++ /dev/null @@ -1,71 +0,0 @@ -########################################################### -# Include: Setup dnbd for image access, nfs/cifs fallback # -########################################################### - -writelog "Now in setup_image_access.inc ..." - -# Try to use dnbd3 to access the image -unset vm_diskfile -unset vm_revision -unset dnbd3_fuse_mount_point -unset dnbd3_tmplog -if ! which dnbd3-fuse; then - writelog "Can't use dnbd3 as dnbd3-fuse binary is not in PATH" -elif [ -z "$SLX_DNBD3_SERVERS" ] || [ "x$SLX_VM_DNBD3" != "xyes" ]; then - writelog "Can't use dnbd3 as no servers are given in config, or SLX_VM_DNBD3 is not set to yes" -else - # Mount path for images mounted with dnbd3-fuse - dnbd3_fuse_mount_point="$TMPDIR/dnbd3fuse.mnt" - mkdir -p "${dnbd3_fuse_mount_point}" - # start dnbd3-fuse in subshell - dnbd3_tmplog="$TMPDIR/dnbd3fuse.log" - dnbd3_exitflag="$TMPDIR/dnbd3exit$RANDOM" - rm -f -- "$dnbd3_exitflag" - ( - dnbd3-fuse -f -o allow_other,max_readahead=262144 -h "$SLX_DNBD3_SERVERS" -i "${imgrelpath}" "${dnbd3_fuse_mount_point}" > "$dnbd3_tmplog" 2>&1 - RET=$? - touch "$dnbd3_exitflag" - if [ "$RET" != "0" ]; then - writelog "dnbd3-fuse stopped working (Exit code $RET)" - slxlog "virt-dnbd3-fuse" "dnbd3-fuse stopped/refused serving '${imgrelpath}' from '${SLX_DNBD3_SERVERS}' with error code: $RET" "${dnbd3_tmplog}" - fi - sleep 2 - rm -f -- "$dnbd3_tmplog" "$dnbd3_exitflag" - ) & - # give it a bit of time - usleep 250000 - # check if we have the image - for TIMEOUT in 0.5 1 1 OUT; do - if [ -r "${dnbd3_fuse_mount_point}/img" ]; then - vm_revision="$(grep -m 1 "^Revision:" "${dnbd3_fuse_mount_point}/status" | cut -d" " -f2)" - vm_diskfile="${dnbd3_fuse_mount_point}/img" - writelog "DNBD3: $imgrelpath on $vm_diskfile with rid $vm_revision" - vmpath="$vm_diskfile" - break - fi - [ "$TIMEOUT" = "OUT" -o -e "$dnbd3_exitflag" ] && break - sleep "$TIMEOUT" - done - - if [ -z "$vm_diskfile" ]; then - slxlog "virt-dnbd3" "No dnbd3 server for ${imgrelpath} found, trying NFS/CIFS..." "$dnbd3_tmplog" - writelog "No working dnbd3 server found :-(" - fi -fi - -# $vm_diskfile will be empty if dnbd3 is not used or failed. Let's try to fall back to NFS/CIFS via file system -if [ -z "$vm_diskfile" ]; then - new_vmpath=$(ls "${vmpath}.r"* | grep -E -o '\.r[0-9]+$' | grep -o -E '[0-9]+' | sort -n | tail -n 1) - [ -n "$new_vmpath" ] && vmpath="${vmpath}.r${new_vmpath}" - vm_diskfile="$vmpath" -fi - -# Check if virtual machine container file exists -if ! [ -e "${vmpath}" ]; then - slxlog "virt-image-missing" "VM image $vmpath not found!" - writelog "Virtual machine image ${vmpath} not found!" - cleanexit 1 -fi - -writelog "Virtual machine disk file: $vm_diskfile" - diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc deleted file mode 100644 index ee0b2c70..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc +++ /dev/null @@ -1,33 +0,0 @@ -##################################### -# Include: Setup printer daemon LPD # -##################################### - -QUEUE="STANDARD" # This has to match the queue you configured in your VM -SPOOLDIR= - -### Disabled: 100megs is not enough, some jobs are HUGE, try to use temp which should be on disk -## Try using user's tmpfs home first, as it gets wiped on logout -#if [ -n "${HOME}" ] && [ -w "${HOME}" ]; then -# SPOOLDIR="${HOME}/.spool" -# mkdir -p "${SPOOLDIR}/${QUEUE}" -#fi -# If failed, try to fall back to /tmp - -if [ -z "${SPOOLDIR}" ] || [ ! -w "${SPOOLDIR}/${QUEUE}" ]; then - SPOOLDIR="${TMPDIR}/printergui-${RANDOM}" - rm -rf -- "${SPOOLDIR}" - if ! mkdir -p "${SPOOLDIR}/${QUEUE}"; then - slxlog "virt-spooldir" "Could not create spool directory ($SPOOLDIR) for $USER - printing will not work!" - # TODO: Warn user - fi - chmod 0700 "${SPOOLDIR}/${QUEUE}" -fi - -# Start the lpdaemon listening on the given port -# TODO: externalize with something like runvirt.d (other parts might benefit from that too) -tcpsvd -E 192.168.101.1 5515 \ - lpd "$SPOOLDIR" \ - ash -c "/opt/openslx/scripts/run-virt_print '${USER}' \"${SPOOLDIR}/${QUEUE}/\$DATAFILE\"" & - -# PID to kill the process -PID_LPD="$!" diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_sound.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_sound.inc deleted file mode 100644 index 201c0ff5..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_sound.inc +++ /dev/null @@ -1,64 +0,0 @@ -######################## -# Include: Setup sound # -######################## -# 8086:1e20: Sound card in bwPX4 - -writelog "Starting sound setup ..." - -if lspci -n | grep -E -i '8086:1e20( |$)'; then - VOL="100%" # bwPC 4: Speaker too quiet :-( -else - VOL="85%" -fi - -if true; then - # detecting which card is to be used - writelog "Detecting which sound card to use ..." - PROC="/proc/asound/cards" - if [ ! -r "$PROC" ]; then - writelog "'${PROC}' not found or not readable." - SOUND_CARD_INDEX=0 - SOUND_CARD_COUNT=1 - else - # Try to filter HDMI cards first - SOUND_CARD_INDEX=$(grep -v -i 'HDMI' "${PROC}" | grep -E -o '^[[:space:]]{0,2}[0-9]+[[:space:]]+' | head -n 1) - # If empty, try again with all - [ -z "${SOUND_CARD_INDEX}" ] && SOUND_CARD_INDEX=$(cat "${PROC}" | grep -E -o '^[[:space:]]{0,2}[0-9]+[[:space:]]+' | head -n 1) - if [ -z "${SOUND_CARD_INDEX}" ]; then - writelog "No sound card found." - SOUND_CARD_INDEX=0 - fi - SOUND_CARD_COUNT=$(grep -E '^[[:space:]]{0,2}[0-9]+[[:space:]]+' "${PROC}" | wc -l) - fi - - SOUND_CARD_INDEX="$(grep -E -o '[0-9]+' <<<$SOUND_CARD_INDEX)" - writelog "Detected sound card index is: $SOUND_CARD_INDEX" - writelog "Sound card count: $SOUND_CARD_COUNT" - - # Adjust sound volume (playback)... Random mixer names we have encountered during testing - writelog "Setting up volume..." - amixer -q -c "$SOUND_CARD_INDEX" sset 'Master' "$VOL" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'PCM' "$VOL" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'CD' "$VOL" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Headphone' "$VOL" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Front' "$VOL" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Speaker' "$VOL" unmute - # Recording. It seems that (most) devices need the volume set to 0, so you - # don't hear your own mic input, but should be unmuted. Also on some cards, - # you need to set the cap option on the mic you want to use, while other cards - # will just ignore that option. - # Plus, most cards have a Capture mixer, which needs to be set to cap too, and - # have its volume turned up. (There'll probably be some cards that need yet - # another setup, but this works for now on 4 tested cards) - amixer -q -c "$SOUND_CARD_INDEX" sset 'Rear Mic Boost' "50%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Rear Mic' "0%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Front Mic Boost' "50%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Front Mic' "0%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Mic Boost' "50%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Mic' "0%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Capture' "100%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Input Source' 'Front Mic' # Let's hope nobody uses rear mic... - # fix random static noise when starting vmplayer when module snd_pcsp (not pcspkr) is loaded - amixer -q -c pcsp sset Master "0%" mute - writelog "Done setting up volume." -fi >> "${LOGFILE}" 2>&1 diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_virtual_floppy.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_virtual_floppy.inc deleted file mode 100644 index 4b8e10aa..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_virtual_floppy.inc +++ /dev/null @@ -1,21 +0,0 @@ -############################################## -# Include: Setup virtual floppy for drive b: # -############################################## - -# Copy guest configuration (with added information) config.xml to be accessed -# via virtual floppy -cp "$xmlfile" "$VMCHOOSER_DIR/fd-loop/config.xml" - -# Add another file with resolution information -xrandr | grep -o -E 'connected\s*(primary)?\s*[0-9]+x[0-9]+\+0\+0' | grep -o -E '[0-9]+x[0-9]+' | head -n 1 > "$VMCHOOSER_DIR/fd-loop/hostres.txt" - -# Add our magic openslx binary that sets the correct guest resolution -cp "$VMCHOOSER_DIR/data/openslx.exe" "$VMCHOOSER_DIR/fd-loop/" -cp "$VMCHOOSER_DIR/data/SHARELWS.BAT" "$VMCHOOSER_DIR/fd-loop/" -rm "$VMCHOOSER_DIR/fd-loop/SHARELW.CFG" - -for SHARE in $(grep -o -E '^SLX_SHARE_.*_PATH' /opt/openslx/config); do - eval "echo -n \$${SHARE} | /opt/openslx/bin/tr '/' '\' " >> "$VMCHOOSER_DIR/fd-loop/SHARELW.CFG" - #eval echo -n " \$${SHARE%PATH}AUTH_PASS /user:\$${SHARE%PATH}AUTH_USER" >> "$VMCHOOSER_DIR/fd-loop/SHARELW.CFG" - echo -e '\r\n' >> "$VMCHOOSER_DIR/fd-loop/SHARELW.CFG" -done diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_vm_hypervisor.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_vm_hypervisor.inc deleted file mode 100644 index b7bb8f01..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/setup_vm_hypervisor.inc +++ /dev/null @@ -1,19 +0,0 @@ -########################################################################## -# Include: Setup virtual machine hypervisor via vm-specific include file # -########################################################################## - -# Get all virtual machine specific stuff from the respective include file -if [ ! -e "$VMCHOOSER_DIR/$xmlvirt/run-virt.include" ] ; then - # TODO: Tell user - slxlog "virt-plugin-missing" "Could not find run-virt.include for $xmlvirt ($VMCHOOSER_DIR/$xmlvirt/run-virt.include)" - writelog "Failed because of missing ${xmlvirt} plugin." - cleanexit 1 -fi - - self="${xmlvirt}" - -# Now including the hypervisor specific include file: -if ! source "$VMCHOOSER_DIR/$xmlvirt/run-virt.include"; then - slxlog "virt-plugin-error" "run-virt.include for $xmlvirt could not be sourced (contains syntax errors?)" "$xmlvirt" - writelog "Erroneous run-virt.include for $xmlvirt" -fi diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/start_pvs.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/start_pvs.inc deleted file mode 100644 index 90cd237b..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/start_pvs.inc +++ /dev/null @@ -1,11 +0,0 @@ -####################################################### -# Include: Starting PVS (Pool Video switch) if wanted # -####################################################### - -# if [ -e /etc/xdg/autostart/pvsgui.desktop ]; then -# /usr/local/bin/pvsgui -p 2 -b >/dev/null 2>&1 & -# fi - -if [[ "$DO_PROFILE" -ge "1" ]]; then - wget "http://132.230.8.113/profile/do.php?action=start" & -fi diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/start_windowmanager.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/start_windowmanager.inc deleted file mode 100644 index 940f4ff3..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/start_windowmanager.inc +++ /dev/null @@ -1,20 +0,0 @@ -#################################################### -# Include: Start windowmanager for easier handling # -#################################################### - -# Some problems may arise with windows opening in background when -# using eg. vmware without a window manager. - -for dm in openbox kwin xfwm4 metacity blackbox twm fvwm2 ; do - if which $dm >/dev/null 2>&1 ; then - if [ "$dm" = "fvwm2" ] ; then - echo "EdgeScroll 0 0" > ${redodir}/fvwm - writelog "Starting fvwm2." - fvwm2 -f ${redodir}/fvwm >/dev/null 2>&1 & - else - writelog "Starting ${dm}." - $dm >/dev/null 2>&1 & - fi - break - fi -done diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/usb_detector.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/usb_detector.inc deleted file mode 100644 index 9769c81d..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/usb_detector.inc +++ /dev/null @@ -1,77 +0,0 @@ -# Helper function that will scan /dev/bus/usb for devices matching specific classes -# and then output the corresponding device ids. This can be used for selective -# handover of devices to a virtual machine - -declare -rg PASSTHROUGH_USB_DEVICES="2 0:5 0:6 0:7 0:14 0:16 0:17" - -# $1: expression to fill with device information. -# valid placeholders are: -# %VENDOR% - device vendor id -# %PRODUCT% - device product id -# $2-n: device classes to include in output -get_usb_devices_int() { - [ -z "$TMPDIR" ] && TMPDIR="/tmp" - local EXP=$1 - shift - if [ -z "$EXP" ]; then - writelog --quiet "No ouput expression template passed to get_usb_devices" - cleanexit 1 - fi - if [ $# -eq 0 ]; then - writelog --quiet "No device classes given to get_usb_devices" - cleanexit 1 - fi - local MATCH=';' - while [ $# -gt 0 ]; do - MATCH+="$1;" - [[ "$1" != *:* ]] && MATCH+="0:$1;" - shift - done - local dev= - local key value trailing - trailing= - local tmp="${TMPDIR}/lsusb.$$.$RANDOM" - for dev in /dev/bus/usb/*/*; do - if ! lsusb -D "$dev" > "$tmp" 2>/dev/null; then - writelog --quiet "Cannot lsusb $dev" - continue - fi - local DC= - local OK= - local VENDOR= - local PRODUCT= - while read -r key value trailing || [ -n "$key" ]; do - if [[ "$key" == "idVendor" ]]; then - [[ "$value" == 0x* ]] && VENDOR="${value:2}" - elif [[ "$key" == "idProduct" ]]; then - [[ "$value" == 0x* ]] && PRODUCT="${value:2}" - elif [ -z "$DC" ]; then - # No bDeviceClass seen yet - if [[ "$key" == "bDeviceClass" ]]; then - DC="$value" - [[ "$MATCH" == *";${DC};"* ]] && OK=yo - fi - else - # #DeviceClass is generic, look at sub class - if [[ "$key" == "bInterfaceClass" ]]; then - [[ "$MATCH" == *";${DC}:${value};"* ]] && OK=yo - fi - fi - if [ -n "$OK" -a -n "$VENDOR" -a -n "$PRODUCT" ]; then - echo "$EXP" | sed "s/%VENDOR%/${VENDOR}/g;s/%PRODUCT%/${PRODUCT}/g" - break - fi - done < "$tmp" - done - rm -f -- "$tmp" -} - -get_usb_devices() { - if which lsusb 2>/dev/null >&2 && lsusb --help 2>&1 | grep -q -- '-D' 2>/dev/null; then - [ $# -eq 1 ] && set -- "$1" $PASSTHROUGH_USB_DEVICES # no quotes here! - get_usb_devices_int "$@" | sort -u - else - writelog --quiet "Cannot scan usb bus: lsusb not found or doesn't support -D" - fi -} - diff --git a/core/modules/run-virt/data/opt/openslx/scripts/includes/vmchooser_runvirt_functions.inc b/core/modules/run-virt/data/opt/openslx/scripts/includes/vmchooser_runvirt_functions.inc deleted file mode 100644 index 1f09b3d2..00000000 --- a/core/modules/run-virt/data/opt/openslx/scripts/includes/vmchooser_runvirt_functions.inc +++ /dev/null @@ -1,48 +0,0 @@ -####################################################### -# Include: Set functions needed by vmchooser-run_virt # -####################################################### - -# function to write to stdout and logfile -writelog() { - local DATE=$(date +%Y-%m-%d-%H-%M-%S) - # write to stdout? - if [ "x$1" = "x--quiet" ]; then - shift - else - echo -e "$DATE: $@" - fi - # log into file - echo -e "$DATE: $@" >> "${LOGFILE}" -} - -# Clean exit will be called at the end of vmchooser-run_virt -cleanexit() { - sleep 1 - # Ummount dnbd3-fuse - if [ -n "$dnbd3_fuse_mount_point" ] && [ -e "$dnbd3_fuse_mount_point/img" ]; then - for timeout in 1 1 1 FAIL; do - fusermount -u "$dnbd3_fuse_mount_point" && break - writelog "dnbd3 still busy...." - [ "$timeout" = "FAIL" ] && break - sleep "$timeout" - done - fi - # Kill LPD - [ -n "${PID_LPD}" ] && kill "${PID_LPD}" - - # If we're not in debug mode, remove all temporary files - if [ -n "${TMPDIR}" -a -z "$SLX_DEBUG" ]; then - rm -rf -- "${TMPDIR}" - fi - - [ $# -gt 0 ] && exit "$1" - exit 129 # No exit code was given :/ -} - -rv_clean_string() { - if [ "$#" -ge 1 ]; then - echo "$@" | tr '[A-Z]' '[a-z]' | tr -d -c '[a-z0-9\-]' - else - tr '[A-Z]' '[a-z]' | tr -d -c '[a-z0-9\-]' - fi -} diff --git a/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env b/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env index a86b2d0b..f53983ec 100755 --- a/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env +++ b/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env @@ -1,7 +1,7 @@ #!/bin/ash # ----------------------------------------------------------------------------- -# Copyright (c) 2007..2013 - RZ Uni FR -# Copyright (c) 2007..2013 - OpenSLX GmbH +# Copyright (c) 2007..2016 - RZ Uni FR +# Copyright (c) 2007..2016 - OpenSLX GmbH # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING @@ -14,6 +14,8 @@ # systemd-vmchooser_env # - This is the preparation script for the configuration of the virtuali- # zation tools used later on. +# - This creates '$VMCHOOSER_CONF_DIR/virtualization.conf' that is later +# evaluated by the runvirt script. ################################################################################ ################################################################################ @@ -22,16 +24,22 @@ export PATH=$PATH:/opt/openslx/bin:/opt/openslx/sbin -# source config file with vars (e.g. ipaddr, macaddr, hostname) +# source config file with vars (e.g. ipaddr, macaddr, HOSTNAME) . /opt/openslx/config # from plugins/vmchooser/XX_vmchooser.sh VMCHOOSER_DIR="/opt/openslx/vmchooser" -VMCHOOSER_CONF_DIR="$VMCHOOSER_DIR/config" -DHCP_NAT_CONF="/opt/openslx/vmchooser/config/udhcpd-nat1.conf" +VMCHOOSER_CONF_DIR="${VMCHOOSER_DIR}/config" +VMCHOOSER_VIRT_CONF="${VMCHOOSER_CONF_DIR}/virtualization.conf" +DHCP_NAT_CONF="${VMCHOOSER_CONF_DIR}/udhcpd-nat1.conf" # setup more scratch space for virtual machines, if configured -mkdir -p /tmp/virt /var/log/samba /run/samba +for DIR in /tmp/virt /var/log/samba /run/samba; do + if ! mkdir -p "$DIR"; then + echo "Could not create '$DIR'!" + exit 1 + fi +done chmod a+rwxt /tmp/virt @@ -53,80 +61,76 @@ chmod a+rwxt /tmp/virt #EOF ################################################################################ -### Determine hardware configuration +### Determine host's hardware configuration ################################################################################ # estimate free mem -mem_free=$(grep -i "^memfree:" /proc/meminfo | awk '{print $2}') -mem_cached=$(grep -i "^cached:" /proc/meminfo | awk '{print $2}') -mem_swapcached=$(grep -i "^swapcached:" /proc/meminfo | awk '{print $2}') -[ -z "$mem_free" ] && mem_free="2048000" -[ -z "$mem_cached" ] && mem_cached="0" -[ -z "$mem_swapcached" ] && mem_swapcached="0" -totalmem="$(expr $(expr $mem_free + $mem_cached + $mem_swapcached) / 1024)" -echo "totalmem=${totalmem}" > "${VMCHOOSER_CONF_DIR}/virtualization.conf" +MEM_FREE=$(grep -i "^memfree:" /proc/meminfo | awk '{print $2}') +MEM_CACHED=$(grep -i "^cached:" /proc/meminfo | awk '{print $2}') +MEM_SWAPCACHED=$(grep -i "^swapcached:" /proc/meminfo | awk '{print $2}') +[ -z "$MEM_FREE" ] && MEM_FREE="2048000" +[ -z "$MEM_CACHED" ] && MEM_CACHED="0" +[ -z "$MEM_SWAPCACHED" ] && MEM_SWAPCACHED="0" +MEM_TOTAL="$(expr $(expr $MEM_FREE + $MEM_CACHED + $MEM_SWAPCACHED) / 1024)" +echo "HOST_MEM_TOTAL=${MEM_TOTAL}" > "${VMCHOOSER_VIRT_CONF}" # determine number of cpu cores CPU_CORES=$(grep '^processor.*:' /proc/cpuinfo | wc -l) if [ "${CPU_CORES}" -gt "1" 2>/dev/null ]; then - echo "cpu_cores=${CPU_CORES}" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" + echo "CPU_CORES=${CPU_CORES}" >> "${VMCHOOSER_VIRT_CONF}" else - echo 'cpu_cores=1' >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" + echo 'CPU_CORES=1' >> "${VMCHOOSER_VIRT_CONF}" fi # general machine architecture (32/64bit) -echo "host_arch=$(uname -m)" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" +echo "HOST_ARCH=$(uname -m)" >> "${VMCHOOSER_VIRT_CONF}" # check for VT enabled CPU if grep -q '^flags.*\<vmx\>' "/proc/cpuinfo"; then - echo "vtflag=1" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" - echo 'kvm_module="kvm_intel"' >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" + echo "VTFLAG=1" >> "${VMCHOOSER_VIRT_CONF}" + echo 'KVM_MODULE="kvm_intel"' >> "${VMCHOOSER_VIRT_CONF}" elif grep -q '^flags.*\<svm\>' "/proc/cpuinfo"; then - echo "vtflag=1" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" - echo 'kvm_module="kvm_amd"' >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" + echo "VTFLAG=1" >> "${VMCHOOSER_VIRT_CONF}" + echo 'KVM_MODULE="kvm_amd"' >> "${VMCHOOSER_VIRT_CONF}" else - echo "vtflag=0" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" + echo "VTFLAG=0" >> "${VMCHOOSER_VIRT_CONF}" fi # write mac if [ -n "$SLX_PXE_MAC" ]; then - hostmacaddr="${SLX_PXE_MAC}" + HOSTMACADDR="${SLX_PXE_MAC}" else ## Fallback: - hostmacaddr="$(ip a | grep ether | grep -o -E -i '([0-9a-f]{2}:){5}[0-9a-f]{2}' | head -n 1)" + HOSTMACADDR="$(ip a | grep ether | grep -o -E -i '([0-9a-f]{2}:){5}[0-9a-f]{2}' | head -n 1)" fi -echo "hostmacaddr='$hostmacaddr'" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" +echo "HOSTMACADDR='$HOSTMACADDR'" >> "${VMCHOOSER_VIRT_CONF}" # TODO: We should only generate the suffix here (last 3 octets) as the first 3 are # dependant on the virtualizer/emulator. Check if any run-virt.include still relies on -# $macguestpart/$macaddr. If so, fix it to use its specific first 3 bytes -# and append $macaddrssuffix -macaddrprefix='00:50:56' -macaddrsuffix="$(echo "$hostmacaddr" | awk -F ":" '{print "%VMID%:" $(NF-1) ":" $NF}' | tr '[a-z]' '[A-Z]')" -echo "macaddrprefix='$macaddrprefix'" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" -echo "macaddrsuffix='$macaddrsuffix'" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" +# $macguestpart/$macaddr (now VM_MAC_ADDR). If so, fix it to use its specific first 3 bytes +# and append $MACADDRSUFFIX. For now, keep MACADDRPREFIX as vmware's defaults and overwrite +# it if needed. +MACADDRPREFIX='00:50:56' +MACADDRSUFFIX="$(echo "$HOSTMACADDR" | awk -F ":" '{print "%VMID%:" $(NF-1) ":" $NF}' | tr '[a-z]' '[A-Z]')" +echo "MACADDRPREFIX='$MACADDRPREFIX'" >> "${VMCHOOSER_VIRT_CONF}" +echo "MACADDRSUFFIX='$MACADDRSUFFIX'" >> "${VMCHOOSER_VIRT_CONF}" # read in ip address -echo "hostip=${SLX_PXE_CLIENT_IP}" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" +echo "HOSTIP=${SLX_PXE_CLIENT_IP}" >> "${VMCHOOSER_VIRT_CONF}" # hostname -echo "hostname=\"$(hostname -s)\"" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" +echo "HOSTNAME=\"$(hostname -s)\"" >> "${VMCHOOSER_VIRT_CONF}" # get further hw information and check for traces of available optical and floppy drives j=0 -for cdrom in $(dmesg|grep -i "Attached scsi CD-ROM sr" | sed "s,.*Attached scsi CD-ROM ,,"); do - echo "cdrom_$j=/dev/${cdrom}" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" +for CDROM in $(dmesg|grep -i "Attached scsi CD-ROM sr" | sed "s,.*Attached scsi CD-ROM ,,"); do + echo "CDROM_$j=/dev/${CDROM}" >> "${VMCHOOSER_VIRT_CONF}" j=$(expr $j + 1) done j=0 -for floppy in $(dmesg|grep -i "Floppy drive"|sed "s,.*(s): ,,;s, is .*,,"); do - echo "floppy_$j=/dev/${floppy}" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" +for FLOPPY in $(dmesg|grep -i "Floppy drive"|sed "s,.*(s): ,,;s, is .*,,"); do + echo "FLOPPY_$j=/dev/${FLOPPY}" >> "${VMCHOOSER_VIRT_CONF}" j=$(expr $j + 1) done -# Serial ports -echo "serial_ports='$(dmesg | grep -Eo 'ttyS[0-9]+' | sed 's,^,/dev/,' | tr '\n' ' ')'" >> "${VMCHOOSER_CONF_DIR}/virtualization.conf" -# Parallel ports -modprobe parport_pc - ################################################################################ ### Setup VM networking ################################################################################ @@ -175,7 +179,7 @@ done sed -i "s#%DNSSERVER%#${SLX_DNS}#;s#%DOMAIN%#${SLX_NET_DOMAIN}#;s#%SEARCH%#${SLX_NET_SEARCH}#" "${DHCP_NAT_CONF}" # Make sure the primary vm running (we most likely never run more than one at a time anyways) always gets the same ip -echo "static_lease $(echo "$macaddrprefix:$macaddrsuffix" | sed 's/%VMID%/01/') 192.168.101.20" >> "${DHCP_NAT_CONF}" +echo "static_lease $(echo "$MACADDRPREFIX:$MACADDRSUFFIX" | sed 's/%VMID%/01/') 192.168.101.20" >> "${DHCP_NAT_CONF}" mkdir -p /var/lib/udhcpd udhcpd -S "${DHCP_NAT_CONF}" diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/plugins/README b/core/modules/run-virt/data/opt/openslx/vmchooser/plugins/README new file mode 100644 index 00000000..d353f6b0 --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/plugins/README @@ -0,0 +1 @@ +This folder contains the virtualisation plugins for run-virt. diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc index 974a5626..818896fc 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc @@ -1,32 +1,46 @@ ######################################################## # Include: Detect, whether runvirt runs in legacy mode # ######################################################## - +## Functions ## # Legacy mode: As runvirt has been before. # New mode: uuid in xml _and_ vmx given via http. +download_metadata() { + # Sanity checks + if ! check_dep wget; then + writelog "Could not find 'wget' in PATH: $PATH" + EXIT_TYPE="internal" EXIT_REASON="Fehlendes Dienstprogramm 'wget'!" cleanexit 1 + fi -writelog "Detecting current/legacy mode ..." + if ! isset SLX_VMCHOOSER_BASE_URL; then + writelog "SLX_VMCHOOSER_BASE_URL is not set! Was /opt/openslx/config sourced?" + EXIT_TYPE="internal" EXIT_REASON="Keine URL zur Schnittstelle des bwLehrpool-Satelliten gefunden!" cleanexit 1 + fi -declare -rg TMPCONFIG="$TMPDIR/vmconfig.tmp" + writelog "Detecting current/legacy mode..." + declare -rg TMPCONFIG="$TMPDIR/vmconfig.tmp" -# Assume legacy mode by default, only trigger "current" mode if everything else below worked -LEGACY=yes -if [ -z "$IMGUUID" ]; then # Keine uuid: Abbruch, Legacy - writelog "Could not extract a uuid param from ${xmlfile}. Triggering legacy mode." -else - # Now getting template file: - if ! wget -T 6 -O "$TMPCONFIG" "${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}" 2>/dev/null >&2; then - writelog "wget ${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}. Triggering legacy mode." - else - writelog "wget ${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID} successful." - if [ ! -s "$TMPCONFIG" ]; then - writelog "Server sent zero byte virtual machine description file. Triggering legacy mode." + if wget -T 6 -O "$TMPCONFIG" "${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}" 2>/dev/null >&2; then + writelog "Downloaded VM description from '${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}' successfully." + if [ -s "$TMPCONFIG" ]; then + # Downloaded a non-zero VM description file, all good + return 0 else - writelog "Triggering current (non-legacy) mode." - LEGACY= # everything worked - clear legacy mode variable (so we use the "current" mode) + writelog "Server sent zero byte virtual machine description file. Triggering legacy mode." fi fi -fi -readonly LEGACY + # Seems we are in legacy mode, which is no longer supported. Warn user and exit + EXIT_TYPE="user" EXIT_REASON=" +Die gewählte VM ist eine 'Legacy VM', für die unvollständige +Metadaten auf dem bwLehrpool-Server hinterlegt sind. Diese +werden nicht mehr unterstützt. Um diese VM weiterhin nutzen +zu können, muss sie mittels der bwLehrpool-Suite heruntergeladen, +einmal gebootet, und wieder hochgeladen werden. +(Bei der Gelegenheit könnten z.B. auch gleich anfallende Updates +eingespielt werden.) +" cleanexit 1 +} + +## Main ## +call_post_source download_metadata diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc index fdacc69c..a6543c76 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc @@ -1,63 +1,69 @@ ############################################ # Include: Get needed values from XML file # ############################################ - -writelog "Parsing XML..." - -declare -rg VMSTORE_PATH=/mnt/vmstore - -get_xml () { - xmlextract "//settings/eintrag/${1}/@param" "${xmlfile}" +## Functions ## +parse_xml() { + # Sanity checks + if ! check_dep get_xml; then + writelog "Could not find 'get_xml'" + EXIT_TYPE="internal" EXIT_REASON="Keine XML-Unterstützung!" cleanexit 1 + fi + + writelog "Parsing XML..." + declare -rg VMSTORE_PATH=/mnt/vmstore + declare -rg IMGUUID=$(get_xml "uuid") + if isempty IMGUUID; then + writelog "Error parsing XML: No value for 'uuid'." + EXIT_TYPE="user" EXIT_REASON="Konnte keine ID für das ausgewählte Image ermitteln!" cleanexit 1 + fi + + # Relative / Absolute path to image + declare -rg SRC_IMG_RELATIVE=$(get_xml "image_name") + declare -g SRC_IMG_ABSOLUTE=$(get_xml "image_path") + + if isempty SRC_IMG_ABSOLUTE SRC_IMG_RELATIVE; then + writelog "Error parsing XML: Neither relative nor absolute path for image found!" + EXIT_TYPE="user" EXIT_REASON="Konnte kein Pfad zur ausgewählten virtuellen Maschine ermitteln!" cleanexit 1 + fi + + if isempty SRC_IMG_ABSOLUTE && [ "${SRC_IMG_ABSOLUTE:0:1}" != "/" ]; then + writelog "Error parsing XML: Parsed value for absolute path doesn't start with '/': '$SRC_IMG_ABSOLUTE'" + EXIT_TYPE="user" EXIT_REASON="Ungültiger asboluter Pfad zur virtuellen Maschine!" cleanexit 1 + fi + + notempty SRC_IMG_ABSOLUTE || SRC_IMG_ABSOLUTE="${VMSTORE_PATH}/${SRC_IMG_RELATIVE}" + readonly SRC_IMG_ABSOLUTE + + declare -rg IMG_BASENAME=$(basename "$SRC_IMG_ABSOLUTE") + + VM_DISPLAYNAME=$(get_xml "short_description") + notempty VM_DISPLAYNAME || VM_DISPLAYNAME="${IMG_BASENAME}" + readonly VM_DISPLAYNAME + + # Define VM_CLEANNAME since VM_DISPLAYNAME can be long and contain weird characters + declare -rg VM_CLEANNAME=$(echo "${VM_DISPLAYNAME:0:32}" | sed -r 's/[^0-9a-zA-Z_-\.]+/_/g') + + # image is for the following virtual machine + declare -rg PLUGIN_ID=$(get_xml "virtualmachine") + if isempty PLUGIN_ID; then + writelog "Error parsing XML: No value for 'virtualmachine'." + EXIT_TYPE="user" EXIT_REASON="Konnte kein Virtualisierer für das ausgewählte Image ermitteln." cleanexit 1 + fi + + # Extracting OS type (VM_OS_TYPE) from xml file. We don't care here whether VM_OS_TYPE is empty, as then + # it will yield the default entries later on. + declare -g VM_OS_TYPE=$(get_xml "os") + + # Print summary to log + writelog "\tVirtualization plugin: $PLUGIN_ID" + writelog "\tVM filename: $IMG_BASENAME" + writelog "\tVM UUID: $IMGUUID" + writelog "\tVM name: $VM_DISPLAYNAME" + writelog "\tVM short name: $VM_CLEANNAME" + writelog "\tVM OS: $VM_OS_TYPE" + writelog "Done parsing XML." + return 0 } -IMGUUID=$(get_xml "uuid") - -# # Name of the virt image -SRC_IMG_ABSOLUTE=$(get_xml "image_path") -SRC_IMG_RELATIVE=$(get_xml "image_name") - -if [ -z "${SRC_IMG_ABSOLUTE}${SRC_IMG_RELATIVE}" ]; then - writelog "Neither relative nor absolute path for image found in xml" - cleanexit 1 -fi - -if [ -n "$SRC_IMG_ABSOLUTE" ] && [ "${SRC_IMG_ABSOLUTE:0:1}" != "/" ]; then - writelog "Error parsing XML for absolute image path: given value doesn't start with '/': '$SRC_IMG_ABSOLUTE'" - cleanexit 1 -fi - -if [ -z "$SRC_IMG_ABSOLUTE" ]; then - SRC_IMG_ABSOLUTE="${VMSTORE_PATH}/${SRC_IMG_RELATIVE}" -fi - -IMG_BASENAME=$(basename "$SRC_IMG_ABSOLUTE") -writelog "Virtual image file name: $IMG_BASENAME" - -VM_DISPLAYNAME=$(get_xml "short_description") -[ -z "$VM_DISPLAYNAME" ] && VM_DISPLAYNAME="${IMG_BASENAME}" - -# Define VM_NAME_CLEAN since VM_DISPLAYNAME can be long and contain weird characters -VM_NAME_CLEAN=$(echo "${VM_DISPLAYNAME:0:32}" | sed -r 's/[^0-9a-zA-Z_-\.]+/_/g') - -# image is for the following virtual machine -PLUGIN_ID=$(grep -o 'virtualmachine param=.*"' "${xmlfile}" \ - | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') - -# Extracting OS type (VM_OS_TYPE) from xml file. We don't care here whether VM_OS_TYPE is empty, as then -# it will yield the default entries later on. -VM_OS_TYPE=$(get_xml "os") - -readonly IMGUUID -readonly SRC_IMG_ABSOLUTE SRC_IMG_RELATIVE -readonly IMG_BASENAME -readonly VM_DISPLAYNAME VM_NAME_CLEAN -readonly PLUGIN_ID -readonly VM_OS_TYPE - -writelog "VM UUID: $IMGUUID" -writelog "Virtualization plugin: $PLUGIN_ID" -writelog "VM name: $VM_DISPLAYNAME" -writelog "VM short name: $VM_NAME_CLEAN" -writelog "VM OS: $VM_OS_TYPE" -writelog "Done parsing XML." - +## MAIN ## +call_post_source parse_xml diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc new file mode 100644 index 00000000..8e83811c --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc @@ -0,0 +1,18 @@ +################################################ +# Include: Sets core variables and directories # +################################################ +# Global variables needed for the core functionality +declare -rg VMCHOOSER_DIR="/opt/openslx/vmchooser" +declare -rg VMCHOOSER_CONF_DIR="$VMCHOOSER_DIR/config" +declare -rg USER="$(whoami)" +declare -rg LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" +declare -rg TMPDIR="/tmp/virt/${USER}/$$" + +# Create temporary directory for current invocation +if check_dep mkdir && ! mkdir -p "$TMPDIR"; then + writelog "Could not create temporary directory '$TMPDIR' for session" + EXIT_TYPE="internal" EXIT_REASON="Konnte kein Arbeitsverzeichnis für die VM-Sitzung anlegen." cleanexit 1 +fi + +# Get a unique VM_ID for the current invocation +get_vm_id diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/load_configs.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/load_configs.inc new file mode 100644 index 00000000..bd205816 --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/load_configs.inc @@ -0,0 +1,19 @@ +################################################### +# Include: Declaration of run-virt core variables # +################################################### +## Functions ## +load_configs() { + writelog "Loading configs..." + + # Include general configuration from vmchooser + $(safesource --exit "$VMCHOOSER_CONF_DIR/vmchooser.conf") + + # Load general virtualization information + $(safesource --exit "$VMCHOOSER_CONF_DIR/virtualization.conf") + + # Load general openslx config + $(safesource --exit "/opt/openslx/config") +} + +## MAIN ## +call_post_source load_configs diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc index 508c9efe..5fb14806 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc @@ -1,113 +1,124 @@ ########################################### # Include: Set hardware related variables # ########################################### +# New way of handling MAC address prefixes to support +# nested and concurrent run-virt invocations. +# Using a list of predefined MAC prefixes to use for VMs, +# check if the host's MAC address prefix is in that list. +# If not, use the first prefix in the list. If it is +# use the next prefix in the list. If the host's prefix +# is the last in the list, use the first one again. +# This way we support up to 10 nested/concurrent VMs. +# Use: 00:FF:00 for firtual machines ;) +declare -gA MAC_PREFIXES +for i in {0..9}; do + # make an associate array, it will make our life easier later + MAC_PREFIXES["00:FF:0$i"]="$i" +done -get_vm_id() { - local script=${BASH_SOURCE[-1]} - [ -z "$script" ] && script="$0" - if [ -n "$script" ]; then - script=$(readlink -f "$script") - if [ -n "$script" ] && [ -s "$script" ]; then - #bingo - VM_ID=$(ps ax | grep -F "$script" | grep -v 'grep' | grep -o -- "${script}.*\$" | sort -u | wc -l) - if [ "$VM_ID" -gt 0 ]; then - [ "${#VM_ID}" -eq 1 ] && VM_ID="0${VM_ID}" - [ "${#VM_ID}" -gt 2 ] && VM_ID="${VM_ID:0:2}" - [ "${#VM_ID}" -eq 2 ] && return - fi - fi - fi - # fallback: take last two digits of current pid... - VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2) - [ "${#VM_ID}" -eq 1 ] && VM_ID="0${VM_ID}" -} - -get_vm_id - -# Make sure cpu_cores is not empty -cpu_cores=${cpu_cores:-"1"} - -# Amount of memory for the VM. Be generous if diff is written to HDD -if mount | grep -q '^/dev/sd.*on.*/tmp'; then - reserve=20 - min=768 - max=1800 -else - reserve=65 - min=768 - max=8192 -fi -# Calculate absulute amount of RAM that should stay available to the host -reserve="$(( ( totalmem * reserve ) / 100 ))" -# Respect some upper and lower bounds for the host amount -[ "$reserve" -lt "$min" ] && reserve="$min" -[ "$reserve" -gt "$max" ] && reserve="$max" +## Functions ## +# Sets the VM's hostname to the original hostname prefixed with a fixed string and its ID +set_virt_hostname() { + declare -rg HOSTNAME="virt${VM_ID}-$(hostname)" + writelog "\tVM Hostname:\t\t$HOSTNAME" +} +set_virt_cpu() { + # Make sure CPU_CORES is not empty + declare -g CPU_CORES=${CPU_CORES:-"1"} +} +# Derives the amount of memory allocated to the VM from the +# host's total memory (previously determined by systemd-run_virt_env) +set_virt_memory() { + # Make sure we have a VM_ID and HOST_MEM_TOTAL (read from virtualization.conf) + if isempty HOST_MEM_TOTAL; then + writelog "HOST_MEM_TOTAL is empty! Was '$VMCHOOSER_CONF_DIR/virtualization.conf' sourced?" + EXIT_TYPE="internal" EXIT_REASON="Konnte die Größe des Arbeitsspeichers nicht ermitteln!" cleanexit 1 + fi -# Get a result which can be divided by 4 -mem="$(( ( ( totalmem - reserve ) / 4 ) * 4 ))" -if [ -n "$mainvirtmem" ]; then - forcemem="$(( mainvirtmem / 4 * 4 ))" - mem="$forcemem" -fi -hostmem="$(( totalmem - mem ))" + # Amount of memory for the VM. Be generous if diff is written to HDD + local min=768 + local reserve max + if mount | grep -q '^/dev/sd.*on.*/tmp'; then + reserve=20 + max=1800 + else + reserve=65 + max=8192 + fi -# Fill in VMID -macaddrsuffix=$(echo "$macaddrsuffix" | sed "s/%VMID%/${VM_ID}/") + # Calculate absulute amount of RAM that should stay available to the host + local reserve="$(( ( HOST_MEM_TOTAL * reserve ) / 100 ))" + # Respect some upper and lower bounds for the host amount + [ "$reserve" -lt "$min" ] && reserve="$min" + [ "$reserve" -gt "$max" ] && reserve="$max" + + # Get a result which can be divided by 4 + declare -g VM_MEM="$(( ( ( HOST_MEM_TOTAL - reserve ) / 4 ) * 4 ))" + declare -g HOST_MEM_REMAINING="$(( HOST_MEM_TOTAL - VM_MEM ))" + # NOTE: removed old code that evaluated 'mainvirtmem' + # as it did nothing and we don't know what the idea was... +} -if ! echo "$macaddrprefix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then - slxlog "virt-mac" "Could not properly generate mac address prefix (got $macaddrprefix)" -fi -if ! echo "$macaddrsuffix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then - slxlog "virt-mac" "Could not properly generate mac address suffix (got $macaddrsuffix)" -fi -macaddr="$macaddrprefix:$macaddrsuffix" +# New way to generate MAC addresses: +# MAC_PREFIXES is a statically declared list of prefixes which +# can be used for VMs. To support nested VMs, we just look for +# the MAC prefix of the host and if it is present in the list, +# we just take the next one in the list. Currently support up to 10. +# If none are found, we just take the first prefix. +# Suffix template is taken from /opt/openslx/vmchooser/config/virtualization.conf +# and will have the VMID inserted as first byte. +set_virt_mac() { + # First, determine prefix of the host's MAC address + isset HOSTMACADDR || writelog "Host's MAC address was not defined in ${VMCHOOSER_CONF_DIR}/virtualizer.conf" + local HOST_MAC_PREFIX=$(echo "$HOSTMACADDR" | tr '[a-z]' '[A-Z]' | grep -o -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}') + unset MACADDRPREFIX + if notempty HOST_MAC_PREFIX && notempty MAC_PREFIXES[${HOST_MAC_PREFIX}]; then + # the host's prefix was in our list, so use the next one in the list + local -i HOST_MAC_PREFIX_INDEX="${MAC_PREFIXES[${HOST_MAC_PREFIX}]}" # this will be at least 0 + # increment if its between 0 and 8 + if [[ $HOST_MAC_PREFIX_INDEX =~ ^[0-8]$ ]]; then + declare -g MACADDRPREFIX="${HOST_MAC_PREFIX%?}$(( ++HOST_MAC_PREFIX_INDEX ))" + fi + fi + # host's mac prefix could not be determined (practically this should never happen) + # or the prefix is not in our mac address list or we reached the end of the list. + # Either way, use first mac prefix in the list + notempty MACADDRPREFIX || declare -g MACADDRPREFIX="$(echo ${!MAC_PREFIXES[@]} | awk '{print $1}')" + + # Fill in VM_ID + local MACADDRSUFFIX=${MACADDRSUFFIX//%VMID%/"${VM_ID}"} + + if ! echo "$MACADDRPREFIX" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then + slxlog "virt-mac" "Could not properly generate mac address prefix (got $MACADDRPREFIX)" + fi + if ! echo "$MACADDRSUFFIX" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then + slxlog "virt-mac" "Could not properly generate mac address suffix (got $MACADDRSUFFIX)" + fi + declare -g VM_MAC_ADDR="$MACADDRPREFIX:$MACADDRSUFFIX" +} # Virtual fd/cd/dvd and drive devices, floppy b: for configuration -# if $floppy_0 from virtualization.conf set then fdtest="TRUE" -fdtest=${floppy_0:+"TRUE"} -# if $fdtest not set floppy0="FALSE", else "TRUE" -floppy0=${fdtest:-"FALSE"} -# if $cdrom_0 from virtualization.conf set then cdtest="TRUE" -cdtest=${cdrom_0:+"TRUE"} -# if $cdtest not set cdrom0="FALSE", else "TRUE" -cdrom0=${cdtest:-"FALSE"} -# if $cdrom_1 from virtualization.conf set then cdtest="TRUE" -cdtest=${cdrom_1:+"TRUE"} -# if $cdtest not set cdrom1="FALSE", else "TRUE" -cdrom1=${cdtest:-"FALSE"} - -# Dynamically detect serial ports here instead of at boot time -# (virtualization.conf), since USB serial ports get quite common -# and might not be plugged in at boot time yet -serial_0= -#for port in $(awk '{ if ($1 ~ /^[0-9]+:/ && $2 != "uart:unknown") print "/dev/ttyS" sub(/:\$/, "", $1) }' /proc/tty/driver/serial); do -for port in $serial_ports /dev/ttyUSB*; do - [ -c "$port" ] || continue - serial_0="$port" - break -done - -parallel_0= -for port in /dev/parport*; do - [ -c "$port" ] || continue - parallel_0="$port" - break -done - -# RDP/VNC port (59001 - 59099) -remotedesktopport="590${VM_ID}" - -# Add rw share for home dir -homesharepath="${HOME}/PERSISTENT" -homesharename="home" - -# Add common share -commonsharepath="${HOME}/SHARE" -commonsharename="share" - -# Set hostname: using original hostname and adding string -hostname="virt-$(hostname)" +# NOTE: This uses bash's variable expansion magic to set +# CDROM/FLOPPY variables evaluated later by the virtualizers... +# If the variables in virtualization.conf is set, "TRUE" is assigned, +# "FALSE" otherwise. +check_optical_drives() { + local TESTVAR=${FLOPPY_0:+"TRUE"} + declare -rg FLOPPY0=${TESTVAR:-"FALSE"} + + TESTVAR=${CDROM_0:+"TRUE"} + declare -rg CDROM0=${TESTVAR:-"FALSE"} + + TESTVAR=${CDROM_1:+"TRUE"} + declare -rg CDROM1=${TESTVAR:-"FALSE"} +} -writelog "\tVM Hostname:\t\t$hostname" +## MAIN ## +call_post_source \ + set_virt_cpu \ + set_virt_memory \ + set_virt_mac \ + set_virt_hostname \ + check_optical_drives diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_variables.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_variables.inc deleted file mode 100644 index cd9a573a..00000000 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_variables.inc +++ /dev/null @@ -1,26 +0,0 @@ -###################################################### -# Include: Declaration of run-virt default variables # -###################################################### - -VMCHOOSER_DIR="/opt/openslx/vmchooser" -VMCHOOSER_CONF_DIR="$VMCHOOSER_DIR/config" -USER="$(whoami)" -LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" -TMPDIR="/tmp/virt/${USER}/$$" - -readonly VMCHOOSER_DIR VMCHOOSER_CONF_DIR LOGFILE TMPDIR USER - -# include general configuration from vmchooser -[ -f "$VMCHOOSER_CONF_DIR/vmchooser.conf" ] && . "$VMCHOOSER_CONF_DIR/vmchooser.conf" -# load general virtualization information -[ -f "$VMCHOOSER_CONF_DIR/virtualization.conf" ] && . "$VMCHOOSER_CONF_DIR/virtualization.conf" -# Load general openslx config -[ -f "/opt/openslx/config" ] && . "/opt/openslx/config" -# Create temp dir -if ! mkdir -p "$TMPDIR"; then - slxlog "virt-tmpdir" "Could not create temporary directory '$TMPDIR' for session" - error_user "Konnte kein temporäres Arbeitsverzeichnis für die VM-Sitzung anlegen. Ein Computer-Neustart könnte das Problem lösen." - cleanexit 1 - exit 1 -fi - diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_firewall.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_firewall.inc deleted file mode 100644 index f0820ed7..00000000 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_firewall.inc +++ /dev/null @@ -1,12 +0,0 @@ - -setup_firewall () { - local LOGF="${TMPDIR}/firewall.log" - local RET - [ "$DISPLAY" = ":0" ] || return 0 # For now, to avoid conflicts, we only do this on display :0 - slxfwtool "$IMGUUID" > "$LOGF" 2>&1 - RET=$? - if [ "$RET" != "0" ]; then - slxlog "runvirt-firewall" "Error setting up firewall rules for lecture $IMGUUID (Exit code $RET)" "$LOGF" - fi - return 0 -} diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc index 4240d9ca..a41c1055 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc @@ -1,7 +1,6 @@ ########################################################### # Include: Setup dnbd for image access, nfs/cifs fallback # ########################################################### - # This will currently make sure that the variable # VM_DISKFILE_RO is set which will contain the # absolute path to the disk image to use for the vm @@ -14,85 +13,112 @@ # indicate to the virt plugin that it doesn't need to # handle creating a temporary CoW layer itself. -writelog "Setting up disk access for virtualizer/emulator ..." -# Try to use dnbd3 to access the image -unset VM_DISKFILE_RO -unset dnbd3_fuse_mount_point +# Helper to cleanup the image mounted with dnbd3-fuse +cleanup_dnbd3() { + if ! isset DNBD3_MOUNT_POINT; then + writelog "'DNBD3_MOUNT_POINT' is not set! Aborting DNBD3 cleanup." + return 1 + fi + # try to umount it now + for timeout in 1 1 1 FAIL; do + fusermount -u "${DNBD3_MOUNT_POINT}" && break + writelog "dnbd3 still busy...." + [ "$timeout" = "FAIL" ] && break + sleep "$timeout" + done +} setup_dnbd3 () { # Mount path for images mounted with dnbd3-fuse - dnbd3_fuse_mount_point="$TMPDIR/dnbd3fuse.mnt" - mkdir -p "${dnbd3_fuse_mount_point}" + declare -rg DNBD3_MOUNT_POINT="${TMPDIR}/dnbd3fuse.mnt" + mkdir -p "${DNBD3_MOUNT_POINT}" # start dnbd3-fuse in subshell - local dnbd3_tmplog="$TMPDIR/dnbd3fuse.log" - local dnbd3_exitflag="$TMPDIR/dnbd3exit$RANDOM" - local TIMEOUT vm_revision - rm -f -- "$dnbd3_exitflag" + local DNBD3_TMPLOG="${TMPDIR}/dnbd3fuse.log" + local DNBD3_EXITFLAG="${TMPDIR}/dnbd3exit$RANDOM" + local TIMEOUT VM_DISKFILE_REVISION + rm -f -- "${DNBD3_EXITFLAG}" ( - dnbd3-fuse -f -o allow_other,max_readahead=262144 -h "$SLX_DNBD3_SERVERS" -i "${SRC_IMG_RELATIVE}" "${dnbd3_fuse_mount_point}" > "$dnbd3_tmplog" 2>&1 + dnbd3-fuse -f -o allow_other,max_readahead=262144 -h "${SLX_DNBD3_SERVERS}" -i "${SRC_IMG_RELATIVE}" "${DNBD3_MOUNT_POINT}" > "${DNBD3_TMPLOG}" 2>&1 RET=$? - touch "$dnbd3_exitflag" + touch "${DNBD3_EXITFLAG}" if [ "$RET" != "0" ]; then writelog "dnbd3-fuse stopped working (Exit code $RET)" - slxlog "virt-dnbd3-fuse" "dnbd3-fuse stopped/refused serving '${SRC_IMG_RELATIVE}' from '${SLX_DNBD3_SERVERS}' with error code: $RET" "${dnbd3_tmplog}" + slxlog "virt-dnbd3-fuse" "dnbd3-fuse stopped/refused serving '${SRC_IMG_RELATIVE}' from '${SLX_DNBD3_SERVERS}' with error code: $RET" "${DNBD3_TMPLOG}" fi ) & # give it a bit of time usleep 250000 # check if we have the image for TIMEOUT in 0.5 1 1 OUT; do - if [ -r "${dnbd3_fuse_mount_point}/img" ]; then - vm_revision="$(grep -m 1 "^Revision:" "${dnbd3_fuse_mount_point}/status" | cut -d" " -f2)" - VM_DISKFILE_RO="${dnbd3_fuse_mount_point}/img" - writelog "DNBD3: $SRC_IMG_RELATIVE on $VM_DISKFILE_RO with rid $vm_revision" + if [ -r "${DNBD3_MOUNT_POINT}/img" ]; then + VM_DISKFILE_REVISION="$(grep -m 1 "^Revision:" "${DNBD3_MOUNT_POINT}/status" | cut -d" " -f2)" + VM_DISKFILE_RO="${DNBD3_MOUNT_POINT}/img" + writelog "DNBD3: ${SRC_IMG_RELATIVE} on ${VM_DISKFILE_RO} with rid ${VM_DISKFILE_REVISION}" + add_cleanup "cleanup_dnbd3" break fi - [ "$TIMEOUT" = "OUT" -o -e "$dnbd3_exitflag" ] && break + [ "$TIMEOUT" = "OUT" -o -e "$DNBD3_EXITFLAG" ] && break sleep "$TIMEOUT" done - if [ -z "$VM_DISKFILE_RO" ]; then - slxlog "virt-dnbd3" "No dnbd3 server for ${SRC_IMG_RELATIVE} found, trying NFS/CIFS..." "$dnbd3_tmplog" + if isempty VM_DISKFILE_RO; then + slxlog "virt-dnbd3" "No dnbd3 server for ${SRC_IMG_RELATIVE} found, trying NFS/CIFS..." "$DNBD3_TMPLOG" writelog "No working dnbd3 server found :-(" + else + readonly VM_DISKFILE_RO fi } -# See if we should setup dnbd3 image access at all -if ! which dnbd3-fuse; then - writelog "Can't use dnbd3 as dnbd3-fuse binary is not in PATH" -elif [ -z "$SRC_IMG_RELATIVE" ]; then - writelog "Can't use dnbd3 as SRC_IMG_RELATIVE is not set" -elif [ -z "$SLX_DNBD3_SERVERS" ] || [ "x$SLX_VM_DNBD3" != "xyes" ]; then - writelog "Can't use dnbd3 as no servers are given in config, or SLX_VM_DNBD3 is not set to yes" -else - setup_dnbd3 -fi - -# VM_DISKFILE_RO will be empty if dnbd3 is not used or failed to connect. -# Let's try to fall back to NFS/CIFS via file system -if [ -z "$VM_DISKFILE_RO" ]; then +setup_fallback() { # Maybe we're reading a dnbd3 directory with RIDs encoded into the filename - use latest one - rid_suffix=$(ls -1 "${SRC_IMG_ABSOLUTE}.r"* | grep -E -o '\.r[0-9]+$' | grep -o -E '[0-9]+$' | sort -n | tail -n 1) - if [ -n "$rid_suffix" ]; then + unset VM_DISKFILE_REVISION + local VM_DISKFILE_REVISION=$(ls -1 "${SRC_IMG_ABSOLUTE}.r"* | grep -E -o '\.r[0-9]+$' | grep -o -E '[0-9]+$' | sort -n | tail -n 1) + if notempty VM_DISKFILE_REVISION; then # found - VM_DISKFILE_RO="${SRC_IMG_ABSOLUTE}.r${rid_suffix}" - elif [ -e "$SRC_IMG_ABSOLUTE" ]; then + VM_DISKFILE_RO="${SRC_IMG_ABSOLUTE}.r${VM_DISKFILE_REVISION}" + elif [ -e "${SRC_IMG_ABSOLUTE}" ]; then # try name we got from xml in the first place - VM_DISKFILE_RO="$SRC_IMG_ABSOLUTE" + VM_DISKFILE_RO="${SRC_IMG_ABSOLUTE}" fi -fi - -# Check if virtual machine container file exists -if [ -z "$VM_DISKFILE_RO" ] || ! [ -e "${VM_DISKFILE_RO}" ]; then - slxlog "virt-image-missing" "VM image $VM_DISKFILE_RO not found!" - writelog "Virtual machine image ${VM_DISKFILE_RO} not found!" - error_user "Das Image für die gewählte Virtuelle Maschine konnte nicht gefunden werden. -Versuchen Sie zunächst, den Computer komplett neu zu starten. Sollte das Problem bestehen bleiben, wenden Sie sich bitte an den Support." - cleanexit 1 -fi + readonly VM_DISKFILE_RO +} -readonly VM_DISKFILE_RO -writelog "Disk file to use: $VM_DISKFILE_RO" +## MAIN PART / Sanity checks ## +setup_image_access() { + writelog "Setting up virtual hard disk access for virtualizer/emulator ..." + + unset VM_DISKFILE_RO + declare -g VM_DISKFILE_RO + + # See if we should setup dnbd3 image access at all + if ! check_dep dnbd3-fuse fusermount; then + writelog "\tCan't use dnbd3 as dnbd3-fuse/fusermount binaries are not in PATH" + elif ! isset SRC_IMG_RELATIVE; then + writelog "\tCan't use dnbd3 as SRC_IMG_RELATIVE is not set" + elif ! isset SLX_DNBD3_SERVERS || [ "x${SLX_VM_DNBD3}}" != "xyes" ]; then + writelog "\tCan't use dnbd3 as no servers are given in config, or SLX_VM_DNBD3 is not set to yes" + else + # register setup_dnbd3 as start hook after sourcing this include + writelog "Trying image access via DNBD3..." + setup_dnbd3 + fi + + # VM_DISKFILE_RO will be empty if dnbd3 is not used or failed to connect. + if isempty VM_DISKFILE_RO; then + # try to fallback to access the image via NFS/CIFS filesystem + writelog "Trying fallback image access via NFS/CIFS..." + setup_fallback + fi + + # Check if we finally found a valid, readable container + if isempty VM_DISKFILE_RO || [ ! -r "${VM_DISKFILE_RO}" ]; then + writelog "Virtual machine image ${VM_DISKFILE_RO} not found!" + EXIT_TYPE="user" EXIT_REASON="Konnte virtuelle Festplatte des gewählten Image nicht finden!" cleanexit 1 + fi + + writelog "\tVM disk file:\t\t${VM_DISKFILE_RO}" +} +call_post_source setup_image_access diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_printer_lpd.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_printer_lpd.inc deleted file mode 100644 index 2fb9310a..00000000 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_printer_lpd.inc +++ /dev/null @@ -1,46 +0,0 @@ -##################################### -# Include: Setup printer daemon LPD # -##################################### - -QUEUE="STANDARD" # This has to match the queue you configured in your VM -SPOOLDIR= - -### Disabled: 100megs is not enough, some jobs are HUGE, try to use temp which should be on disk -## Try using user's tmpfs home first, as it gets wiped on logout -#if [ -n "${HOME}" ] && [ -w "${HOME}" ]; then -# SPOOLDIR="${HOME}/.spool" -# mkdir -p "${SPOOLDIR}/${QUEUE}" -#fi -# If failed, try to fall back to /tmp - -if [ -z "${SPOOLDIR}" ] || [ ! -w "${SPOOLDIR}/${QUEUE}" ]; then - SPOOLDIR="${TMPDIR}/printergui-${RANDOM}" - rm -rf -- "${SPOOLDIR}" - if ! mkdir -p "${SPOOLDIR}/${QUEUE}"; then - slxlog "virt-spooldir" "Could not create spool directory ($SPOOLDIR) for $USER - printing will not work!" - # TODO: Warn user - fi - chmod 0700 "${SPOOLDIR}/${QUEUE}" -fi - -# Start the lpdaemon listening on the given port -# TODO: externalize with something like runvirt.d (other parts might benefit from that too) -tcpsvd -E 192.168.101.1 5515 \ - lpd "$SPOOLDIR" \ - ash -c "/opt/openslx/scripts/run-virt_print '${USER}' \"${SPOOLDIR}/${QUEUE}/\$DATAFILE\"" & - -# PID to kill the process -PID_LPD="$!" - -{ - sleep 2 - # Check if tcpsvd is running. Do this a little delayed so we do not check - # immediately after trying to spawn it, as this could result in - # success even if it's not really working. - - if ! kill -0 "$PID_LPD"; then - slxlog "virt-lpd" "Could not start tcpsvd/lpd for virtual machine session" - notify_user "Durcksystem" "Das Drucksystem konnte nicht initialisiert werden. Druckfunktion nicht verfügbar." - fi -} & - diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_sound.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_sound.inc deleted file mode 100644 index c6cece3d..00000000 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_sound.inc +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash -# ^-- Add shebang even though it's sourced so vim highlights bash specific features properly -######################## -# Include: Setup sound # -######################## - -writelog "Starting sound setup ..." - -unset VOL -if [ -r "/run/hwinfo" ] && source "/run/hwinfo"; then - # On startup, the volume of Master, PCM, Speaker, etc. will be set to 100% - # Some hardware with builtin speakers might be a bit too loud then, so you can - # define an exception table here. Array key is "Manufacturer//Model" - declare -A VOLUME_EXCEPTIONS - VOLUME_EXCEPTIONS["Hewlett-Packard//HP Compaq 8200 Elite CMT PC"]="85%" # This is bwPC3 - # Read - VOL=${VOLUME_EXCEPTIONS["${HW_MANUF}//${HW_MODEL}"]} -fi - -# Default to maximum volume -if [ -z "$VOL" ]; then - VOL="100%" -fi - -if true; then - # detecting which card is to be used - writelog --quiet "Detecting which sound card to use ..." - PROC="/proc/asound/cards" - if [ ! -r "$PROC" ]; then - writelog --quiet "'${PROC}' not found or not readable." - SOUND_CARD_INDEX=0 - SOUND_CARD_COUNT=1 - else - # Try to filter HDMI cards first - SOUND_CARD_INDEX=$(grep -v -i 'HDMI' "${PROC}" | grep -E -o '^[[:space:]]{0,2}[0-9]+[[:space:]]+' | head -n 1) - # If empty, try again with all - [ -z "${SOUND_CARD_INDEX}" ] && SOUND_CARD_INDEX=$(cat "${PROC}" | grep -E -o '^[[:space:]]{0,2}[0-9]+[[:space:]]+' | head -n 1) - if [ -z "${SOUND_CARD_INDEX}" ]; then - writelog --quiet "No sound card found." - SOUND_CARD_INDEX=0 - fi - SOUND_CARD_COUNT=$(grep -E '^[[:space:]]{0,2}[0-9]+[[:space:]]+' "${PROC}" | wc -l) - fi - - SOUND_CARD_INDEX="$(grep -E -o '[0-9]+' <<<$SOUND_CARD_INDEX)" - writelog --quiet "Detected sound card index is: $SOUND_CARD_INDEX" - writelog --quiet "Sound card count: $SOUND_CARD_COUNT" - - # Adjust sound volume (playback)... Random mixer names we have encountered during testing - writelog --quiet "Setting up volume..." - ( - amixer -q -c "$SOUND_CARD_INDEX" sset 'Master' "$VOL" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'PCM' "100%" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'CD' "100%" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Headphone' "100%" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Front' "100%" unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Speaker' "100%" unmute - # Recording. It seems that (most) devices need the volume set to 0, so you - # don't hear your own mic input, but should be unmuted. Also on some cards, - # you need to set the cap option on the mic you want to use, while other cards - # will just ignore that option. - # Plus, most cards have a Capture mixer, which needs to be set to cap too, and - # have its volume turned up. (There'll probably be some cards that need yet - # another setup, but this works for now on 4 tested cards) - amixer -q -c "$SOUND_CARD_INDEX" sset 'Rear Mic Boost' "50%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Rear Mic' "0%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Front Mic Boost' "50%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Front Mic' "0%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Mic Boost' "50%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Mic' "0%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Capture' "100%" cap unmute - amixer -q -c "$SOUND_CARD_INDEX" sset 'Input Source' 'Mic' - amixer -q -c "$SOUND_CARD_INDEX" sset 'Input Source' 'Front Mic' # Let's hope nobody uses rear mic... - # fix random static noise when starting vmplayer when module snd_pcsp (not pcspkr) is loaded - amixer -q -c pcsp sset Master "0%" mute 2>/dev/null >&2 - ) 2>&1 | grep -v 'amixer: Unable to find' - writelog --quiet "Done setting up volume." -fi >> "${LOGFILE}" 2>&1 # Don't pipe here since it would spawn a subshell so all variable modifications would be lost - diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_virtual_floppy.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_virtual_floppy.inc deleted file mode 100644 index d9ae052c..00000000 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_virtual_floppy.inc +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash -############################################## -# Include: Setup virtual floppy for drive b: # -############################################## - -declare -rg FLOPPYIMG="${TMPDIR}/floppy.img" -declare -rg TMPHOME="${HOME}" -declare -rg RUNSCRIPT="${TMPDIR}/runscript.tmp" - -wget -T 6 -O "${RUNSCRIPT}" "${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}/runscript" > /dev/null & -WGET=$! - -dd "if=/dev/zero" "of=${FLOPPYIMG}" count=1440 bs=1024 -chmod 0600 "${FLOPPYIMG}" -mkfs.fat "${FLOPPYIMG}" || mkfs.vfat "${FLOPPYIMG}" || mkdosfs "${FLOPPYIMG}" - -# Create file with resolution information etc. -. "/opt/openslx/inc/shares" -if [ -z "$SHARE_REMAP_MODE" ]; then - SHARE_REMAP_MODE_INI="0" - SHARE_REMAP_MODE="3" -else - SHARE_REMAP_MODE_INI="$SHARE_REMAP_MODE" -fi -[ -z "$SHARE_CREATE_MISSING_REMAP" ] && SHARE_CREATE_MISSING_REMAP="1" -declare -rg RESOLUTION=$(xrandr | grep -o -E 'connected\s*(primary)?\s*[0-9]+x[0-9]+\+0\+0' \ - | grep -o -E -m1 '[0-9]+x[0-9]+') - -# Legacy: HOSTRES.TXT -cat > "${TMPDIR}/HOSTRES.TXT" <<-HIER -${RESOLUTION} -HIER - -# Create file for network shares to mount -declare -rg SHARES="${TMPDIR}/shares.dat" -touch "${SHARES}" -chmod 0600 "${SHARES}" -if ! pwdaemon --query "${TMPHOME}/.pwsocket" > "${SHARES}"; then - slxlog "virt-pwdaemon" "Could not start pwdaemon" -else - sed -i 's/^/192.168.101.1\t/' "${SHARES}" # TODO: Depending on nettype (in case we have != nat some day) - if [ "${SHARE_REMAP_MODE}" = 1 -o "${SHARE_REMAP_MODE}" = 2 ] && [ -e "${TMPHOME}/.home" ]; then - NETHOME=$(cat "${TMPHOME}/.home") - [ -z "$SHARE_HOME_DRIVE" ] && SHARE_HOME_DRIVE="H:" - # Tab between items, so spaces can be used! - echo "${NETHOME} ${SHARE_HOME_DRIVE} Home-Verzeichnis" >> "${SHARES}" - fi - for VAR in ${!SHARE_LINE_*}; do - echo "${!VAR}" >> "${SHARES}" - done -fi - -wait "$WGET" - -# Check downloaded runscript, handle extension marker -EXT= -if [ -s "$RUNSCRIPT" ]; then - EXT=$(head -n 1 "$RUNSCRIPT" | grep -o -i '^EXT=.*$' | cut -d '=' -f 2-) - [ -n "$EXT" ] && [ "x${EXT:0:1}" != "x." ] && EXT=".$EXT" -fi - -# Write info file -UNAME= -[ -s "${HOME}/.account" ] && UNAME=$(cat "${HOME}/.account") -[ -z "${UNAME}" ] && UNAME=$(whoami) -cat > "${TMPDIR}/openslx.ini" <<-HIER -[openslx] -username=${UNAME} -resolution=${RESOLUTION} -createMissingRemap=${SHARE_CREATE_MISSING_REMAP} -remapMode=${SHARE_REMAP_MODE_INI} -homeDrive=${SHARE_HOME_DRIVE} -scriptExt=${EXT} - -[remap] -documents=${SHARE_DOCUMENTS} -downloads=${SHARE_DOWNLOADS} -desktop=${SHARE_DESKTOP} -media=${SHARE_MEDIA} -other=${SHARE_OTHER} -HIER - -# Copy all them there filez into floppy image -mcopy -i "${FLOPPYIMG}" "${TMPDIR}/openslx.ini" "${TMPDIR}/HOSTRES.TXT" "${SHARES}" "::/" -mcopy -i "${FLOPPYIMG}" "$VMCHOOSER_DIR/data/openslx.exe" "::/" -# Copy guest configuration (with added information) config.xml to be accessed -# via virtual floppy -mcopy -i "${FLOPPYIMG}" "$xmlfile" "::/config.xml" - -# Copying linux directory: -mcopy -s -i "${FLOPPYIMG}" "$VMCHOOSER_DIR/data/linux" "::/" - -# User supplied runscript -if [ -n "$EXT" ]; then - sed -i '1d' "${RUNSCRIPT}" - mcopy -i "${FLOPPYIMG}" "${RUNSCRIPT}" "::/runscript${EXT}" -fi - -rm -f -- "${SHARES}" "${TMPDIR}/openslx.ini" "${TMPDIR}/HOSTRES.TXT" -unset SHARES VAR NETHOME UNAME - diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_vm_hypervisor.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_vm_hypervisor.inc index 7709a85d..80b7dbb9 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_vm_hypervisor.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_vm_hypervisor.inc @@ -1,34 +1,18 @@ ########################################################################## # Include: Setup virtual machine hypervisor via vm-specific include file # ########################################################################## - -# Get all virtual machine specific stuff from the respective include file -if [ ! -e "$VMCHOOSER_DIR/$PLUGIN_ID/run-virt.include" ] ; then - slxlog "virt-plugin-missing" "Could not find run-virt.include for $PLUGIN_ID ($VMCHOOSER_DIR/$PLUGIN_ID/run-virt.include)" - writelog "Failed because of missing ${PLUGIN_ID} plugin." - error_user "Konnte den Virtualisierer '$PLUGIN_ID' nicht finden. Starten der Virtuellen Maschine fehlgeschlagen. - Starten Sie den Computer neu und wenden Sie sich an den Support, wenn das Problem weiterhin besteht." - cleanexit 1 -fi - -self="${PLUGIN_ID}" - -if ! bash -n "$VMCHOOSER_DIR/$PLUGIN_ID/run-virt.include"; then - slxlog "virt-plugin-syntax" "run-virt.include for $PLUGIN_ID contains syntax errors (bash -n run-virt.include failed)" - writelog "Erroneous run-virt.include for $PLUGIN_ID (syntax check)" - error_user "Das Start-Script für den Virtualisierer '$PLUGIN_ID' ist fehlerhaft. - Starten Sie den Computer neu und wenden Sie sich an den Support, wenn das Problem weiterhin besteht." - cleanexit 1 -fi - -setup_vm_commandline () { - # Now including the hypervisor specific include file: - if ! source "$VMCHOOSER_DIR/$PLUGIN_ID/run-virt.include"; then - slxlog "virt-plugin-error" "run-virt.include for $PLUGIN_ID could not be sourced properly." - writelog "Erroneous run-virt.include for ${PLUGIN_ID}? Source returned != 0" - error_user "Das Start-Script für den Virtualisierer '$PLUGIN_ID' hat einen fehlercode zurückgegeben. - Starten Sie den Computer neu, falls es beim Ausführen der VM zu Problemen kommt - und wenden Sie sich an den Support, wenn das Problem weiterhin besteht." +## Functions ## +setup_vm_commandline() { + # Sanity checks + if ! isset PLUGIN_ID; then + writelog "Sanity check failed: PLUGIN_ID is not set." + EXIT_TYPE="internal" EXIT_REASON="Konnte kein Virtualisierer für das gewählte Image ermitteln!" cleanexit 1 + fi + if ! $(safesource "$VMCHOOSER_DIR/plugins/$PLUGIN_ID/run-virt.include"); then + # safesource logs errors on its own + EXIT_TYPE="internal" EXIT_REASON="Konnte Virtualisierungsplugin '$PLUGIN_ID' nicht initialisieren!" cleanexit 1 fi } +## Main ## +call_post_source setup_vm_commandline diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/start_windowmanager.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/start_windowmanager.inc index da43f341..37d88ab4 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/start_windowmanager.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/start_windowmanager.inc @@ -1,27 +1,42 @@ #################################################### # Include: Start windowmanager for easier handling # #################################################### - +## Functions ## # Some problems may arise with windows opening in background when # using eg. vmware without a window manager. - -FOUND_WM= -for dm in openbox kwin xfwm4 metacity blackbox twm fvwm2 ; do - if which $dm >/dev/null 2>&1 ; then - if [ "$dm" = "fvwm2" ] ; then - echo "EdgeScroll 0 0" > ${redodir}/fvwm - writelog "Starting fvwm2." - fvwm2 -f ${redodir}/fvwm >/dev/null 2>&1 & - else - writelog "Starting ${dm}." - $dm >/dev/null 2>&1 & +start_wm() { + # Sanity checks + unset RUNVIRT_DM + for DM in openbox kwin xfwm4 metacity blackbox twm fvwm2 ; do + if type "${DM}" >/dev/null 2>&1 ; then + declare -rg RUNVIRT_DM="${DM}" + break fi - FOUND_WM=1 - break + done + if ! isset RUNVIRT_DM; then + # not fatal, so do not exit but report via slxlog + slxlog "runvirt-wm" "Could not find any window manager to use!" + notify_user "Konnte keinen Window Manager finden. (Das ist schlecht!)" + return 1 + fi + + # start RUNVIRT_DM determined above + writelog "Starting ${RUNVIRT_DM}." + if [ "${RUNVIRT_DM}" = "fvwm2" ]; then + # fvwm2 is not even in the minilinux, so this might be obsolete... + echo "EdgeScroll 0 0" > ${TMPDIR}/fvwm + fvwm2 -f ${TMPDIR}/fvwm >/dev/null 2>&1 & + else + ${RUNVIRT_DM} >/dev/null 2>&1 & + fi + local RUNVIRT_DM_PID="$$" + if ! kill -0 ${RUNVIRT_DM_PID} ; then + # not fatal, just warn user + notify_user "$RUNVIRT_VM stoppte unerwartet." + return 1 fi -done + return 0 +} -if [ -z "$FOUND_WM" ]; then - slxlog "virt-windowmanager" "Could not find any window manager to use!" - notify_user "Konnte keinen Window Manager finden. (Das ist schlecht!)" -fi +## MAIN ## +call_post_source start_wm diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc index ca475da0..d09f6a75 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc @@ -1,8 +1,32 @@ ####################################################### # Include: Set functions needed by vmchooser-run_virt # ####################################################### +## Assigns an ID to the currently starting VM to support +# multiple instances running simultaneously. +# Note that VM_ID will always have two digits. +get_vm_id() { + local script=${BASH_SOURCE[-1]} + [ -z "$script" ] && script="$0" + if [ -n "$script" ]; then + script=$(readlink -f "$script") + if [ -n "$script" ] && [ -s "$script" ]; then + #bingo + declare -g VM_ID=$(ps ax | grep -F "$script" | grep -v 'grep' | grep -o -- "${script}.*\$" | sort -u | wc -l) + if [ "$VM_ID" -gt 0 ]; then + [ "${#VM_ID}" -eq 1 ] && VM_ID="0${VM_ID}" + [ "${#VM_ID}" -gt 2 ] && VM_ID="${VM_ID:0:2}" + [ "${#VM_ID}" -eq 2 ] && readonly VM_ID && return + fi + fi + fi + # fallback: take last two digits of current pid... + VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2) + [ "${#VM_ID}" -eq 1 ] && VM_ID="0${VM_ID}" + readonly VM_ID +} -# function to write to stdout and logfile +################# LOGGING FUNCTIONS ################## +# Helper function to write to stdout and logfile writelog() { local DATE=$(date +%Y-%m-%d-%H-%M-%S) # write to stdout? @@ -12,9 +36,11 @@ writelog() { echo -e "$DATE: $@" fi # log into file - echo -e "$DATE: $@" >> "${LOGFILE}" + echo -e "$DATE: ${SLX_DEBUG:+(${FUNCNAME[1]}) }$@" >> "${LOGFILE}" } +# Helper function to notify the user. +# This directly returns and do not wait for a user confirmation. notify_user() { local TOPIC="$1" shift @@ -22,6 +48,8 @@ notify_user() { writelog "Notify: **${TOPIC}**: $*" } +# Helper to display an error message box to the user. +# Only returns when the user dismisses the message. error_user() { local TOPIC="$1" shift @@ -37,47 +65,246 @@ $*" BODY="$TOPIC" fi # Zenity should yield the nicest result - zenity --error --title "$TITLE" --text "$BODY" && return + # TODO the title is only set as the window name, + # which cannot be seen without a window manager + zenity --error --title "$TITLE" --text "$BODY" + local RET=$? + [ $RET -le 1 ] && return # QnD abuse printergui for error message as it's blocking /opt/openslx/cups/printergui --error "$MSG" && return # printergui might not exist, try fallback here - # unfortunately, i can only think of notify+sleep right now + # unfortunately, I can only think of notify+sleep right now notify-send -u critical "$TITLE" "$BODY" sleep 10 } -# Clean exit will be called at the end of vmchooser-run_virt +################## CLEANUP FUNCTIONS ################## +# Registers functions to be called when cleanexit is called. +# Only accepts functions that were not previously registered. +# This kinda detects when a cleanup function was overriden, +# or at least that something is fishy. +declare -ag CLEANUP_TASKS +add_cleanup() { + [ $# -lt 1 ] && writelog "'${FUNCNAME[0]}' needs at least one argument! $# given." && return + # check if the given function name is already used + while [ $# -ne 0 ]; do + if array_contains CLEANUP_TASKS "$1"; then + writelog "Cleanup function '$1' already registered! Are there multiple definitions of this function?" + writelog "This might suggest that a previously defined cleanup function was overriden!" + return 1 + fi + CLEANUP_TASKS+=("$1") + shift + done + return 0 +} +# This function will be called at the end of vmchooser-run_virt +# or upon critical errors during the runtime. +# It will call the cleanup functions registered through 'add_cleanup' +# and clean TMPDIR if appropriate. Further, it will evaluate and +# process the EXIT_{TYPE,REASON} variables that hold information +# on why we are about to exit. +# +# EXIT_TYPE should be either: +# - 'internal' for critical internal errors, this will +# automatically send the logfile via slxlog. +# - 'user' for errors related to the user's choice +# Others could be thought of like 'external' for failures +# with remote services (e.g. slx apis, external image repo, ...) +# +# EXIT_REASON should contain a user-friendly message to print to the user. cleanexit() { + writelog "Cleanexit '$1' triggered by '${BASH_SOURCE[1]}:${FUNCNAME[1]}'" sleep 1 - # Ummount dnbd3-fuse - if [ -n "$dnbd3_fuse_mount_point" ] && [ -e "$dnbd3_fuse_mount_point/img" ]; then - for timeout in 1 1 1 FAIL; do - fusermount -u "$dnbd3_fuse_mount_point" && break - writelog "dnbd3 still busy...." - [ "$timeout" = "FAIL" ] && break - sleep "$timeout" - done - fi - # Kill LPD - [ -n "${PID_LPD}" ] && kill "${PID_LPD}" + while isset CLEANUP_TASKS; do + local TASK=${CLEANUP_TASKS[-1]} + unset -v CLEANUP_TASKS[-1] + if ! is_function $TASK; then + writelog "Registered cleanup function '$TASK' is not a function. This should not be..." + continue + fi + if ! ${TASK}; then + writelog "Failed to run cleanup function '$TASK'! Exit code: $RET" + fi + done # If we're not in debug mode, remove all temporary files - if [ -n "${TMPDIR}" -a -z "$SLX_DEBUG" ]; then + if notempty SLX_DEBUG && isset TMPDIR; then rm -rf -- "${TMPDIR}" fi - [ $# -gt 0 ] && exit "$1" - exit 129 # No exit code was given :/ -} + # Now see if we need to do the catch all error stuff + # no exit code given, return 129 + [ $# -eq 0 ] && exit 129 + # if 0 given, exit 0 + [ "x$1" = "x0" ] && exit 0 -rv_clean_string() { - if [ "$#" -ge 1 ]; then - echo "$@" | tr '[A-Z]' '[a-z]' | tr -d -c '[a-z0-9\-]' + # given exit code is set and not 0, handle the error now + # now evaluate the EXIT_{TYPE,REASON} variables and generate error title/text + local ERR_TITLE ERR_TEXT ERR_FOOTER + # default error footer + ERR_FOOTER="Versuchen Sie den Computer neuzustarten und falls das Problem bestehen bleibt, kontaktieren Sie den Support." + if notempty EXIT_TYPE; then + case "${EXIT_TYPE}" in + user) + ERR_TITLE="Auswahlfehler" + ERR_FOOTER="Beim Start Ihrer Veranstaltung sind Fehler aufgetretten. Versuchen Sie es mit einer anderen Veranstaltung." + ;; + internal) + ERR_TITLE="Interner Fehler" + ;; + *) + ERR_TITLE="Unbekannter Fehler" + writelog "Unknown EXIT_TYPE: '${EXIT_TYPE}'." + ;; + esac + fi + if notempty EXIT_REASON; then + ERR_TEXT="${EXIT_REASON}" else - tr '[A-Z]' '[a-z]' | tr -d -c '[a-z0-9\-]' + # this should never happen if EXIT_REASON is properly + # used when calling cleanexit ! + ERR_TEXT="Unbekannter Fehler" + fi + + # first send the logfile (in case the user does not close the error before using magic keys e.g.) + # for any other error types besides 'user'. + [ "x${EXIT_TYPE}" != "xuser" ] && \ + slxlog "runvirt-exit-${EXIT_TYPE}" "Critical error happened in '${BASH_SOURCE[1]}:${FUNCNAME[1]}', see logs." "${LOGFILE}" + + # finally display the error + error_user "${ERR_TITLE}" " +${ERR_TEXT} + +${ERR_FOOTER} +" + writelog "All done. Exiting." + exit "$1" +} + +################# SOURCING FUNCTIONS ################# +# Wrapped 'source' that first checks for existence and +# syntax before actually sourcing the given file. +# The option '--exit' triggers cleanexit upon syntax errors. +# Without it, it returns 0 when tests passed, 1 otherwise. +# Usage: +# safesource [--exit] <files> +safesource() { + declare -i EXIT_ON_FAILURE=0 + [ "x$1" = "x--exit" ] && EXIT_ON_FAILURE=1 && shift + while [ $# -gt 0 ]; do + # sanitze filename just to be sure as it is part of the eval coming later + # alphanumeric and - _ . should be enough for common file naming scheme + if [[ ! "$1" =~ ^[a-zA-Z0-9./_-]+$ ]]; then + writelog "'$1' is a weird filename to source! Ignoring." + return 1 + fi + local FILE="$1" + shift + bash -n "${FILE}" + local -i RET=$? + if [ $RET -ne 0 ]; then + case $RET in + 1) writelog --quiet "Bad file to source: ${FILE}" ;; + 2) writelog --quiet "Bad syntax: ${FILE}" ;; + 126) writelog --quiet "Could not access: ${FILE}" ;; + 127) writelog --quiet "File not found: ${FILE}" ;; + *) writelog --quiet "Syntax check (bash -n) returned unknown error code '${RET}' for: ${FILE}" ;; + esac + if [ $EXIT_ON_FAILURE -eq 1 ]; then + echo "eval EXIT_REASON=\"internal:source:${FILE}\" cleanexit 1 ;" + else + echo "eval writelog \"Could not safesource '${FILE}'.\" ;" + fi + return 1 + fi + echo "eval source ${FILE} ;" + echo "run_post_source ${FILE} ;" + + done + return 0 +} + +# Registers functions to be called after sourcing an include. +# Includes should only define functions and register them +# to be called after successfully sourcing. +declare -Ag RUN_POST_SOURCE +call_post_source() { + while [ $# -gt 0 ]; do + if ! is_function "$1"; then + writelog "Tried to register a non-function: '$1'" + continue + fi + if notempty BASH_SOURCE[1]; then + RUN_POST_SOURCE[${BASH_SOURCE[1]}]+="$1 " + shift + else + writelog "Could not determine the sourced file calling ${FUNCNAME[0]}" + fi + done +} +# Helper called after sourcing the file via safesource. It just calls the +# functions in the same order they were registered. +run_post_source() { + [ $# -ne 1 ] && writelog "'${FUNCNAME[0]}' expects one argument only! $# given." && return 1 + for TASK in ${RUN_POST_SOURCE["${1}"]}; do + # sanity checks + if ! is_function $TASK; then + writelog "\tRegistered function '$TASK' is not a function!" + return 1 # TODO maybe even cleanexit here as this seems very bad... + fi + # remove from stack before running it + RUN_POST_SOURCE["${1}"]="${RUN_POST_SOURCE[${1//${TASK}\ /\ }]}" + ${TASK} + local -i RET=$? + if [ $RET -ne 0 ]; then + writelog "\tFailed to run post source '${TASK}' (Exit code: $RET)" + return $RET + fi + done + return 0 +} + +################# FEATURE FUNCTIONS ################## +# Helper to register feature handlers, read run-virt.d/README +declare -Ag FEATURE_HANDLERS +reg_feature_handler() { + if [ $# -ne 2 ]; then + writelog "'${FUNCNAME[0]}' expects 2 arguments! $# given." + return 1 + fi + if notempty FEATURE_HANDLERS["$1"]; then + writelog "'${BASH_SOURCE[1]}' tried to overwrite feat handler '$1'! Ignoring." + # maybe allow overwritting? + return 1 fi + if ! is_function "$2"; then + writelog "'${BASH_SOURCE[1]}' tried to register a non-function as feat handler!" + writelog "\t'$2' is a '$(type -t $2 2>&1)'." + return 1 + fi + # all good, save it + FEATURE_HANDLERS["$1"]="$2" + return 0 } + +################### XML FUNCTIONS #################### +# Extract given xpath from given xml file +# e.g.: xmlextract '//node/nestednode/@attribute' "$file" +# @param +# @return Plain text, UTF-8 +xmlextract() { + xmlstarlet sel -T -E utf-8 -t -v "$1" "$2" +} + +# Wrapper for convenience +get_xml () { + xmlextract "//settings/eintrag/${1}/@param" "${XML_FILE}" +} + + +################## HELPER FUNCTIONS ################## # Check if the given variables are set (empty or not) isset() { while [ $# -gt 0 ]; do @@ -96,12 +323,111 @@ notempty() { return 0 } -## -# Extract given xpath from given xml file -# e.g.: xmlextract '//node/nestednode/@attribute' "$file" -# @param -# @return Plain text, UTF-8 -xmlextract() { - xmlstarlet sel -T -E utf-8 -t -v "$1" "$2" +# Convenience function +isempty() { + ! notempty $@ +} + +# Helper to test if given arguments are declared as functions +is_function() { + while [ $# -gt 0 ]; do + local TYPE="$(type -t "$1" 2>/dev/null)" + if [ "x${TYPE}" != "xfunction" ]; then + writelog "'$1' not a function but a '${TYPE}'." + return 1 + fi + shift + done + return 0 } +# Helper to test if given arguments are declared as arrays +is_array() { + + # -ne 1 ] && writelog "is_array: Expects 1 argument! $# given." && return 1 + while [ $# -gt 0 ]; do + local ARRAY_DEF="$(declare -p ${1} 2>/dev/null)" + if [[ ! "${ARRAY_DEF}" =~ "declare -a" ]] && [[ ! "${ARRAY_DEF}" =~ "declare -A" ]]; then + return 1 + fi + shift + done + return 0 +} + +# Helper to test is the given array contains given value +# Usage: +# array_contains ARRAY_TO_TEST <values...> +array_contains() { + if [ $# -lt 2 ]; then + writelog "${FUNCNAME[0]}: Expects at least 2 arguments, $# given." + return 1 + fi + # is $1 even defined? + local ARRAY_DEF="$(declare -p $1 2>/dev/null)" + if isempty ARRAY_DEF; then + writelog "${FUNCNAME[0]}: '$1' not defined!" + return 1 + fi + local ARRAY_NAME="$1" + shift + + # sanity check on $ARRAY_DEF being either indexed or associative array + if ! is_array "${ARRAY_NAME}"; then + writelog "${FUNCNAME[0]}: '${ARRAY_NAME}' not an array! Declared as:\t${ARRAY_DEF}" + return 1 + fi + + # now test if array contains the given values in $2+ + while [ $# -gt 0 ]; do + # check if ARRAY_DEF contains '"<value>"' + if [[ ! "${ARRAY_DEF}" =~ '="'${1}'"'[^\]]+ ]]; then + writelog "${FUNCNAME[0]}: '${1}' not in '${ARRAY_NAME}'" + return 1 + fi + shift + done + return 0 +} + +# Helper to check if the given arguments are valid command names. +# This uses 'type -t' thus supports notably binaries, functions +# and aliases (might need these one day). +# By default, only 0 is returned if all arguments are found. +# Use '--oneof' to return 0 if any one of the arguments are found. +check_dep() { + [ $# -lt 1 ] && return 1 + unset ONEOF + if [ "x$1" = "x--oneof" ]; then + local ONEOF="1" + shift + fi + while [ $# -gt 0 ]; do + if ! type -t "$1" >/dev/null 2>&1 ; then + writelog "Dependency check failed! Could not find '$1'." + isset ONEOF || return 1 + else + isset ONEOF && return 0 + fi + shift + done + isset ONEOF && return 1 || return 0 +} + + + +# TODO: This is only used once in the whole script: +# to cleanup the os string stored in the xml +# Since the rework of this script, the os strings come from +# the satellite server which already gives us a sanitized string +# thus this function might not be needed anymore, as calling it on +# new gen os strings effectively does nothing. +# Removes any non-alphanumerical and non-hyphen chars +# from the given parameters. +clean_string() { + if [ "$#" -ge 1 ]; then + echo "$@" | tr '[A-Z]' '[a-z]' | tr -d -c '[a-z0-9\-]' + else + tr '[A-Z]' '[a-z]' | tr -d -c '[a-z0-9\-]' + fi +} diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/README b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/README new file mode 100644 index 00000000..73e1ec78 --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/README @@ -0,0 +1,21 @@ +## NOTES ## +Only independent things in here please! We don't want to start with inter-feature dependencies... +Simple ordering could be done via numerical prefixes... + +## USAGE ## +* Try to use some easy keywords and functions! e.g. sound -> setup_sound +* Basic include file should look like: + # example.inc + handle_example() { echo "Handling example..."; } + reg_feature_handler "example" "handle_example" +* Do not try to reg a function which was already registered, this won't work + (Maybe one day we want to support overwritting handlers, but not at the moment.) +* Only *.inc files are included by the mechanism! + +## MLTK INTEGRATION ## +FEATURE -> MLTK MODULE: +sound -> amixer +print -> printergui +firewall -> slxfwtool (TODO own fw mltk module) +netshares -> TODO network share mltk module +slxfloppy -> TODO externalize the floppy creation stuff from the run-virt mltk module diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_firewall.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_firewall.inc new file mode 100644 index 00000000..ac2c2e95 --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_firewall.inc @@ -0,0 +1,26 @@ +############################################ +# Feature: Setup firewall rules for the VM # +############################################ +## Functions +setup_firewall () { + local LOGF="${TMPDIR}/firewall.log" + local RET + [ "$DISPLAY" = ":0" ] || return 0 # For now, to avoid conflicts, we only do this on display :0 + slxfwtool "$IMGUUID" > "$LOGF" 2>&1 + RET=$? + if [ "$RET" != "0" ]; then + slxlog "virt-firewall" "Error setting up firewall rules for lecture $IMGUUID (Exit code $RET)" "$LOGF" + return 1 + fi + return 0 +} + +## MAIN ## +# Sanity checks +if check_dep slxfwtool; then + reg_feature_handler "firewall" "setup_firewall" +else + writelog "Could not find 'slxfwtool' in PATH: $PATH. Netrules firewall will not work!" + error_user "Fehler" "Keine Unterstützung von veranstaltungspezifische Firewall-Regeln!" + # TODO handle +fi diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_network_shares.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_network_shares.inc new file mode 100644 index 00000000..ed47f120 --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_network_shares.inc @@ -0,0 +1,16 @@ +# TODO this currently is not used. +# This should be continued when we have a clear idea +# how we will embed network shares in VMs +set_network_shares() { + + # Add rw share for home dir + homesharepath="${HOME}/PERSISTENT" + homesharename="home" + + # Add common share + commonsharepath="${HOME}/SHARE" + commonsharename="share" +} + +reg_feature_handler "netshares" "set_network_shares" + diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_sound.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_sound.inc new file mode 100644 index 00000000..3afaccd5 --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_sound.inc @@ -0,0 +1,92 @@ +#!/bin/bash +# ^-- Add shebang even though it's sourced so vim highlights bash specific features properly +######################## +# Include: Setup sound # +######################## +## Functions ## +setup_sound() { + unset VOL + if $(safesource "/run/hwinfo") ; then + # On startup, the volume of Master, PCM, Speaker, etc. will be set to 100% + # Some hardware with builtin speakers might be a bit too loud then, so you can + # define an exception table here. Array key is "Manufacturer//Model" + declare -A VOLUME_EXCEPTIONS + VOLUME_EXCEPTIONS["Hewlett-Packard//HP Compaq 8200 Elite CMT PC"]="85%" # This is bwPC3 + # Read + local VOL=${VOLUME_EXCEPTIONS["${HW_MANUF}//${HW_MODEL}"]} + fi + + # Default to maximum volume + notempty VOL || VOL="100%" + + # detecting which card is to be used + writelog --quiet "Detecting which sound card to use ..." + local PROC="/proc/asound/cards" + if [ ! -r "$PROC" ]; then + writelog --quiet "'${PROC}' not found or not readable." + local SOUND_CARD_INDEX=0 + local SOUND_CARD_COUNT=1 + else + # Try to filter HDMI cards first + SOUND_CARD_INDEX=$(grep -v -i 'HDMI' "${PROC}" | grep -E -m1 -o '^[[:space:]]{0,2}[0-9]+[[:space:]]+') + # If empty, try again with all + notempty SOUND_CARD_INDEX || SOUND_CARD_INDEX=$(grep -E -m1 -o '^[[:space:]]{0,2}[0-9]+[[:space:]]+' "${PROC}") + if isempty SOUND_CARD_INDEX; then + writelog --quiet "\tNo sound card found." + SOUND_CARD_INDEX=0 + fi + SOUND_CARD_COUNT=$(grep -E '^[[:space:]]{0,2}[0-9]+[[:space:]]+' "${PROC}" | wc -l) + fi + + SOUND_CARD_INDEX="$(grep -E -o '[0-9]+' <<<$SOUND_CARD_INDEX)" + writelog --quiet "\tDetected sound card index is: $SOUND_CARD_INDEX" + writelog --quiet "\tSound card count: $SOUND_CARD_COUNT" + + # Adjust sound volume (playback)... Random mixer names we have encountered during testing + # TODO instead of trying to set volume blindly, why not use 'amixer scontrols' to find + # which mixer control exists and set these only? + + writelog --quiet "Setting up volume to '$VOL' via amixer..." + amixer -q -c "$SOUND_CARD_INDEX" -s <<-EOF + sset 'Master' "$VOL" unmute + sset 'PCM' "100%" unmute + sset 'CD' "100%" unmute + sset 'Headphone' "100%" unmute + sset 'Front' "100%" unmute + sset 'Speaker' "100%" unmute + # Recording. It seems that (most) devices need the volume set to 0, so you + # don't hear your own mic input, but should be unmuted. Also on some cards, + # you need to set the cap option on the mic you want to use, while other cards + # will just ignore that option. + # Plus, most cards have a Capture mixer, which needs to be set to cap too, and + # have its volume turned up. (There'll probably be some cards that need yet + # another setup, but this works for now on 4 tested cards) + sset 'Master' "$VOL" unmute + sset 'PCM' "100%" unmute + sset 'CD' "100%" unmute + sset 'Headphone' "100%" unmute + sset 'Front' "100%" unmute + sset 'Speaker' "100%" unmute + sset 'Rear Mic Boost' "50%" cap unmute + sset 'Rear Mic' "0%" cap unmute + sset 'Front Mic Boost' "50%" cap unmute + sset 'Front Mic' "0%" cap unmute + sset 'Mic Boost' "50%" cap unmute + sset 'Mic' "0%" cap unmute + sset 'Capture' "100%" cap unmute + sset 'Input Source' 'Mic' + sset 'Input Source' 'Front Mic' # Let's hope nobody uses rear mic... + EOF + # fix random static noise when starting vmplayer when module snd_pcsp (not pcspkr) is loaded + lsmod | grep -q snd_pcsp && amixer -q -c pcsp sset Master "0%" mute + writelog --quiet "Done setting up volume." +} + +## MAIN ## +# Sanity checks +if ! check_dep amixer; then + writelog "'amixer' not available, sound will not work!" + error_user "Fehler" "Konnte Sound nicht initialisieren! Virtuelle Maschine wird kein Sound haben!" +else + reg_feature_handler "sound" "setup_sound" +fi diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_virtual_floppy.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_virtual_floppy.inc new file mode 100644 index 00000000..cd705333 --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_virtual_floppy.inc @@ -0,0 +1,131 @@ +############################################## +# Include: Setup virtual floppy for drive b: # +############################################## +## Functions ## +download_runscript() { + declare -g RUNSCRIPT="${TMPDIR}/runscript.tmp" + if ! wget -T 6 -O "${RUNSCRIPT}" "${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}/runscript" 2> /dev/null >&2; then + writelog "Downloading runscript from '${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}/runscript' failed." + fi + if [ -s "${RUNSCRIPT}" ]; then + # there is stuff in it, make it readonly + readonly RUNSCRIPT + else + # zero bytes, log and ignore + writelog "Downloaded runscript from '${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}/runscript' has zero bytes." + unset RUNSCRIPT + fi +} +setup_virtual_floppy() { + declare -rg SLX_FLOPPY_IMG="${TMPDIR}/floppy.img" + declare -rg TMPHOME="${HOME}" + + # create floppy disk file + filesystem + dd "if=/dev/zero" "of=${SLX_FLOPPY_IMG}" count=1440 bs=1024 + chmod 0600 "${SLX_FLOPPY_IMG}" + mkfs.fat "${SLX_FLOPPY_IMG}" || mkfs.vfat "${SLX_FLOPPY_IMG}" || mkdosfs "${SLX_FLOPPY_IMG}" + + # Create file with resolution information etc. + $(safesource "/opt/openslx/inc/shares") + + if notempty SHARE_REMAP_MODE; then + local SHARE_REMAP_MODE_INI="$SHARE_REMAP_MODE" + else + local SHARE_REMAP_MODE_INI="0" + local SHARE_REMAP_MODE="3" + fi + notempty SHARE_CREATE_MISSING_REMAP || local SHARE_CREATE_MISSING_REMAP="1" + + # Legacy: openslx.exe expects HOSTRES.TXT + local RESOLUTION=$(xrandr | grep -o -E 'connected\s*(primary)?\s*[0-9]+x[0-9]+\+0\+0' \ + | grep -o -E -m1 '[0-9]+x[0-9]+') + # TODO fallback if this fails? this is currently never checked... + cat > "${TMPDIR}/HOSTRES.TXT" <<-EOF + ${RESOLUTION} + EOF + + # Create file for network shares to mount + declare -g SHARES="${TMPDIR}/shares.dat" + touch "${SHARES}" + chmod 0600 "${SHARES}" + if ! pwdaemon --query "${TMPHOME}/.pwsocket" > "${SHARES}"; then + slxlog "virt-pwdaemon" "Could not start pwdaemon" + else + sed -i 's/^/192.168.101.1\t/' "${SHARES}" # TODO: Depending on nettype (in case we have != nat some day) + if [ "${SHARE_REMAP_MODE}" = 1 -o "${SHARE_REMAP_MODE}" = 2 ] && [ -e "${TMPHOME}/.home" ]; then + NETHOME=$(cat "${TMPHOME}/.home") + notempty SHARE_HOME_DRIVE || local SHARE_HOME_DRIVE="H:" + # Tab between items, so spaces can be used! + echo "${NETHOME} ${SHARE_HOME_DRIVE} Home-Verzeichnis" >> "${SHARES}" + fi + for VAR in ${!SHARE_LINE_*}; do + echo "${!VAR}" >> "${SHARES}" + done + fi + + # Check downloaded runscript, handle extension marker + if download_runscript; then + local EXT= + if [ -s "$RUNSCRIPT" ]; then + EXT=$(head -n 1 "$RUNSCRIPT" | grep -o -i '^EXT=.*$' | cut -d '=' -f 2-) + [ -n "$EXT" ] && [ "x${EXT:0:1}" != "x." ] && EXT=".$EXT" + fi + fi + + # Write info file + local UNAME= + [ -s "${HOME}/.account" ] && UNAME=$(cat "${HOME}/.account") + notempty UNAME || UNAME=$(whoami) + cat > "${TMPDIR}/openslx.ini" <<-EOF + [openslx] + username=${UNAME} + resolution=${RESOLUTION} + createMissingRemap=${SHARE_CREATE_MISSING_REMAP} + remapMode=${SHARE_REMAP_MODE_INI} + homeDrive=${SHARE_HOME_DRIVE} + scriptExt=${EXT} + + [remap] + documents=${SHARE_DOCUMENTS} + downloads=${SHARE_DOWNLOADS} + desktop=${SHARE_DESKTOP} + media=${SHARE_MEDIA} + other=${SHARE_OTHER} + EOF + + # Copy all them there filez into floppy image + mcopy -i "${SLX_FLOPPY_IMG}" "${TMPDIR}/openslx.ini" "${TMPDIR}/HOSTRES.TXT" "${SHARES}" "::/" + mcopy -i "${SLX_FLOPPY_IMG}" "$VMCHOOSER_DIR/data/openslx.exe" "::/" + # Copy guest configuration (with added information) config.xml to be accessed + # via virtual floppy + mcopy -i "${SLX_FLOPPY_IMG}" "$XML_FILE" "::/config.xml" + + # Copying linux directory: + mcopy -s -i "${SLX_FLOPPY_IMG}" "$VMCHOOSER_DIR/data/linux" "::/" + + # User supplied runscript + if [ -n "$EXT" ]; then + sed -i '1d' "${RUNSCRIPT}" + mcopy -i "${SLX_FLOPPY_IMG}" "${RUNSCRIPT}" "::/runscript${EXT}" + fi + + rm -f -- "${SHARES}" "${TMPDIR}/openslx.ini" "${TMPDIR}/HOSTRES.TXT" +} + +## MAIN ## +# Sanity checks # +# Check if we have any filesystem tool +if ! check_dep --oneof mkfs.fat mkfs.vfat mkdosfs; then + # no tools found in minilinux, this means no floppy/openslx.exe will be supported + slxlog "virt-fstool-missing" "Could not find any of 'mkfs.fat', 'mkfs.vfat', 'mkdosfs'!" + writelog "Could not find any filesystem-related tools to create the floppy's filesystem with!" + error_user "Konnte kein virtuelles Floppy anlegen! Setzen der Auflösung oder Einhängen von Netzwerkfreigaben werden nicht funktionieren. Bitte kontaktieren Sie den Support." + # still continue as this is not really critical +fi + +# separate check for other deps +if ! check_dep dd chmod pwdaemon sed head grep cut whoami mcopy; then + writelog "Missing core tools to setup the virtual floppy!" +else + reg_feature_handler "slxfloppy" "setup_virtual_floppy" +fi diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/usb_detector.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/usb_detector.inc index a2d442e4..72fd6ad6 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/usb_detector.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/usb_detector.inc @@ -1,9 +1,13 @@ +################################################## +# Include: Detect and pass USB devices to the VM # +################################################## +# TODO USB devices +declare -rg PASSTHROUGH_USB_DEVICES="2 0:5 0:6 0:7 0:14 0:16 0:17 239" + # Helper function that will scan /dev/bus/usb for devices matching specific classes # and then output the corresponding device ids. This can be used for selective # handover of devices to a virtual machine - -declare -rg PASSTHROUGH_USB_DEVICES="2 0:5 0:6 0:7 0:14 0:16 0:17 239" - +# # $1: expression to fill with device information. # valid placeholders are: # %VENDOR% - device vendor id @@ -15,7 +19,7 @@ get_usb_devices_int() { shift if [ -z "$EXP" ]; then writelog --quiet "No ouput expression template passed to get_usb_devices" - cleanexit 1 + EXIT_TYPE="internal" EXIT_REASON="Fehler beim Erkennen der USB-Geräte." cleanexit 1 fi if [ $# -eq 0 ]; then writelog --quiet "No device classes given to get_usb_devices" @@ -75,3 +79,14 @@ get_usb_devices() { fi } +# kinda of a special case since we only define functions +# the handler will only check if the functions are properly defined +check_usb_detector() { + if ! is_function get_usb_devices get_usb_devices_int; then + # this should practically never happen + writelog "'get_usb_devices[_int]' functions are not defined!" + return 1 + fi + return 0 +} +reg_feature_handler "usb" "check_usb_detector" diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt index b945cca2..1bf9de3e 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt @@ -1,8 +1,8 @@ #!/bin/bash # Full bash required # ----------------------------------------------------------------------------- -# Copyright (c) 2007..2010 - RZ Uni FR -# Copyright (c) 2007..2013 - OpenSLX GmbH +# Copyright (c) 2007..2016 - RZ Uni FR +# Copyright (c) 2007..2016 - OpenSLX GmbH # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING @@ -19,84 +19,95 @@ # fied virtualization tool. ################################################################################ -declare -rg RUNVIRTINCLUDEDIR=/opt/openslx/vmchooser/run-virt-includes -declare -rg xmlfile="$1" - -# Functions needed by vmchooser-run_virt (writelog(), cleanexit(), rv_clean_string()) -if ! source "${RUNVIRTINCLUDEDIR}/vmchooser_runvirt_functions.inc"; then - slxlog "run-virt" "Could not source ${RUNVIRTINCLUDEDIR}/vmchooser_runvirt_functions.inc" - exit 1 +# HACK: workaround if $0 is a symlink, exec its symlink target instead +SELF=$(readlink -f "$0") +if [ -n "$SELF" ] && [ "$0" != "$SELF" ]; then + exec "$SELF" "$@" fi +declare -rg RUN_VIRT_INCLUDE_DIR="$(dirname $SELF)/run-virt-includes" -trap 'trap "" SIGINT SIGTERM; cleanexit' SIGINT SIGTERM - -# Define default dirs / get configs -source "${RUNVIRTINCLUDEDIR}/set_runvirt_variables.inc" - -# Read needed variables from XML file -source "${RUNVIRTINCLUDEDIR}/get_xml_file_variables.inc" - -# Download meta data from server (e.g. vmx for vmware) -source "${RUNVIRTINCLUDEDIR}/download_vm_metadata.inc" +# This script expects the path to the xml file describing the VM to be started +declare -rg XML_FILE="$1" -if ! isset IMGUUID TMPCONFIG TMPDIR USER; then - slxlog "run-virt" "Internal sanity check failed: One of IMGUUID TMPCONFIG TMPDIR USER is not set." - cleanexit 1 +# Functions needed by vmchooser-run_virt (writelog(), cleanexit(), safesource()) +if ! source "${RUN_VIRT_INCLUDE_DIR}/vmchooser_runvirt_functions.inc"; then + slxlog "run-virt" "Could not source ${RUN_VIRT_INCLUDE_DIR}/vmchooser_runvirt_functions.inc" + exit 1 fi -if [ "$LEGACY" ]; then - - # No longer supported - yay +trap 'trap "" SIGINT SIGTERM; cleanexit' SIGINT SIGTERM - error_user "Legacy Mode" " -Die gewählte VM ist eine 'Legacy VM', für die unvollständige -Metadaten auf dem bwLehrpool-Server hinterlegt sind. Diese -werden nicht mehr unterstützt. Um diese VM weiterhin nutzen -zu können, muss sie mittels der bwLehrpool-Suite heruntergeladen, -einmal gebootet, und wieder hochgeladen werden. -(Bei der Gelegenheit könnten z.B. auch gleich anfallende Updates -eingespielt werden.) -" - cleanexit 1 +# Starting sourcing the includes files. Note that the critical ones should use +# the '--exit' option of safesource to trigger cleanexit in case of a corrupted/bad +# include file. - # End legacy warning -fi +# Set core runvirt variables and directories +$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/init_core.inc") +writelog "#################### Initialization ####################" -# Proper meta data received - proceed normally +# Window manager required early for user feedback through popups (e.g. errors) etc. +$(safesource "${RUN_VIRT_INCLUDE_DIR}/start_windowmanager.inc") -# Helper that looks for virtualizer-specific include, show error to user if not found -source "${RUNVIRTINCLUDEDIR}/setup_vm_hypervisor.inc" -# For scanning for certain usb classes -source "${RUNVIRTINCLUDEDIR}/usb_detector.inc" +# Read vmchooser.conf, (generated) virtualization.conf and slx config files +$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/load_configs.inc") -# Firewall -source "${RUNVIRTINCLUDEDIR}/setup_firewall.inc" || writelog "Could not source setup_firewall" -setup_firewall || writelog "Could not run setup_firewall" +# Read needed variables from XML file +$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/get_xml_file_variables.inc") -# Sound setup -source "${RUNVIRTINCLUDEDIR}/setup_sound.inc" +# Download metadata from server (e.g. vmx for vmware) +$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/download_vm_metadata.inc") -# Declaration of hardware relatedt variables -source "${RUNVIRTINCLUDEDIR}/set_runvirt_hardware_variables.inc" +# Declaration of hardware related variables +$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/set_runvirt_hardware_variables.inc") -# Start printer daemon -source "${RUNVIRTINCLUDEDIR}/setup_printer_lpd.inc" +# Try to use dnbd3 to access the image, nfs/cifs fallback +$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/setup_image_access.inc") -# Setup virtual floppy b: for windows guests with config.xml, openslx.exe etc. -source "${RUNVIRTINCLUDEDIR}/setup_virtual_floppy.inc" -# Try to use dnbd3 to access the image, nfs/cifs fallback -source "${RUNVIRTINCLUDEDIR}/setup_image_access.inc" +# Mark the end of generic run-virt part +writelog "Done with generic run-virt. Now loading virtualizer specific includes." +writelog "#################### Plugin init: $PLUGIN_ID ####################" -# Window manager required for handling of popups etc. -source "${RUNVIRTINCLUDEDIR}/start_windowmanager.inc" +# NG: first include the hypervisor includes +$(safesource "${RUN_VIRT_INCLUDE_DIR}/setup_vm_hypervisor.inc") -# Source run-virt.include of virtualizer -setup_vm_commandline +# It must declare PLUGIN_FEATURES to set which features are needed. +# Features are those defined by run-virt.d include files. +# After sourcing the plugin, check that it defined both PLUGIN_FEATURES and +# the main function 'run_plugin' which will be called later by the main scripts. +if ! isset PLUGIN_FEATURES || ! is_function run_plugin; then + writelog "Bad plugin '$PLUGIN_ID': either it did not set PLUGIN_FEATURES or did not define 'run_plugin'." + EXIT_TYPE="internal" EXIT_REASON="Fehlerhaftes vmchooser plugin: '$PLUGIN_ID'." cleanexit 1 +fi +writelog "Requested features:\t\t${PLUGIN_FEATURES}" + +# Source the *.inc files in run-virt.d +for FILE in ${VMCHOOSER_DIR}/run-virt.d/*.inc; do + $(safesource "$FILE") +done + +# Now look which features were requested and call the handler if one is defined. +for FEAT in $PLUGIN_FEATURES; do + if notempty FEATURE_HANDLERS["${FEAT}"]; then + writelog "Initialising '${FEAT}'..." + if ! ${FEATURE_HANDLERS["$FEAT"]}; then + writelog "\tFailed to run '${FEATURE_HANDLERS["$FEAT"]}'." + error_user "Konnte Feature namens '$FEAT' nicht initialisieren! +Diese Funktion wird nicht verfügbar sein!" # not critical, do not exit! + fi + else + writelog "\tFeature '$FEAT' has no handler! This function will be unavailable." + notify_user "Feature '$FEAT' nicht unterstützt" + fi +done +# The features should now be initialized, call the main 'run_plugin' function of the hypervisor +writelog "#################### Plugin run: $PLUGIN_ID ####################" +writelog "Calling 'run_plugin' of '$PLUGIN_ID'..." +run_plugin || writelog "Failed to run 'run_plugin' of '$PLUGIN_ID'." # It should have set this variable if all went well -if [ -z "${VIRTCMD}" ]; then +if isempty VIRTCMD; then error_user "Fehler beim Starten der VM-Sitzung" " Das Start-Script für den Virtualisierer $PLUGIN_ID hat kein Kommando zum Starten der Sitzung definiert. Kann Sitzung nicht initialisieren." @@ -104,16 +115,11 @@ zum Starten der Sitzung definiert. Kann Sitzung nicht initialisieren." cleanexit 1 fi -writelog "VM command: eval ${VIRTCMD} ${VIRTCMDOPTS}" -# This will start the VM -eval ${VIRTCMD} ${VIRTCMDOPTS} +writelog "VM command: ${VIRTCMD} ${VIRTCMDOPTS}" +# This will start the VM (no eval needed!) +${VIRTCMD} ${VIRTCMDOPTS} -writelog "Virtualizer exited. Bye." - -# Postrun for commands after virtualization finishes -if [ -n "${POSTRUN}" ]; then - eval ${POSTRUN} >/dev/null 2>&1 -fi +writelog "Virtualizer exited with '$?'. Bye." cleanexit 0 diff --git a/core/modules/systemd/data/usr/lib/tmpfiles.d/etc.conf b/core/modules/systemd/data/usr/lib/tmpfiles.d/etc.conf deleted file mode 100644 index 943bfea3..00000000 --- a/core/modules/systemd/data/usr/lib/tmpfiles.d/etc.conf +++ /dev/null @@ -1,14 +0,0 @@ -# This file is part of systemd. -# -# systemd is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. - -# See tmpfiles.d(5) for details - -L /etc/os-release - - - - ../usr/lib/os-release -L /etc/localtime - - - - ../usr/share/zoneinfo/UTC -L+ /etc/mtab - - - - ../proc/self/mounts -L! /etc/resolv.conf - - - - ../run/systemd/resolve/resolv.conf - diff --git a/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/README b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/README new file mode 100644 index 00000000..549d0037 --- /dev/null +++ b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/README @@ -0,0 +1 @@ +Not tested since refactoring! (January 2017) diff --git a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/empty-diff.vdi.gz b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/empty-diff.vdi.gz Binary files differindex c6abbd57..c6abbd57 100644 --- a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/empty-diff.vdi.gz +++ b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/empty-diff.vdi.gz diff --git a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/machine.include b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/machine.include index 344ccc48..bd14cdb0 100644 --- a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/machine.include +++ b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/machine.include @@ -32,7 +32,7 @@ cat << EOF > "${machconfig}" </ExtraData> --> <Hardware version="2"> - <CPU count="${cpu_cores}" hotplug="false"> + <CPU count="${CPU_CORES}" hotplug="false"> <HardwareVirtEx enabled="${enablevt}"/> <HardwareVirtExNestedPaging enabled="${npaging}"/> <HardwareVirtExVPID enabled="true"/> @@ -42,7 +42,7 @@ cat << EOF > "${machconfig}" <HardwareVirtExLargePages enabled="false"/> <HardwareVirtForce enabled="false"/> </CPU> - <Memory RAMSize="${mem}" PageFusion="false"/> + <Memory RAMSize="${VM_MEM}" PageFusion="false"/> <HID Pointing="USBTablet" Keyboard="PS2Keyboard"/> <HPET enabled="false"/> <Chipset type="ICH9"/> @@ -76,10 +76,10 @@ cat << EOF > "${machconfig}" </DeviceFilters> </USB> <Network> - <Adapter slot="0" enabled="true" MACAddress="${macaddr}" cable="true" speed="0" type="${vb_network_card}"> + <Adapter slot="0" enabled="true" MACAddress="${VM_MAC_ADDR}" cable="true" speed="0" type="${vb_network_card}"> <${network_kind}/> </Adapter> - <Adapter slot="1" enabled="false" MACAddress="${vdemacaddr}" cable="true" speed="0" type="${vb_network_card}"> + <Adapter slot="1" enabled="false" MACAddress="${VM_VDE_MAC_ADDR}" cable="true" speed="0" type="${vb_network_card}"> <GenericInterface driver="VDE"> <Properties name="network" value="/tmp/vde-switch"/> </GenericInterface> @@ -180,7 +180,7 @@ cat << EOF > "${machconfig}" <Image uuid="${imageuuid}"/> </AttachedDevice> <!-- PLEASE DO NOT REMOVE THIS COMMENT (HD)!!! --> <AttachedDevice passthrough="false" type="DVD" port="0" device="1"> - <HostDrive src="${cdrom_0}"/> + <HostDrive src="${CDROM_0}"/> <!-- <Image uuid="{849a61c7-ad64-4594-b0c8-fbe17dc3d2a6}"/> --> </AttachedDevice> <!-- PLEASE DO NOT REMOVE THIS COMMENT (CD)!!! --> </StorageController> diff --git a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/run-virt.include b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/run-virt.include index 59dd712d..8bec8446 100755 --- a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/run-virt.include +++ b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/run-virt.include @@ -1,6 +1,6 @@ # ----------------------------------------------------------------------------- -# Copyright (c) 2009..2011 - RZ Uni Freiburg -# Copyright (c) 2009..2013 - OpenSLX GmbH +# Copyright (c) 2009..2016 - RZ Uni Freiburg +# Copyright (c) 2009..2016 - OpenSLX GmbH # # This program/file is free software distributed under the GPL version 2. # See http://openslx.org/COPYING @@ -20,7 +20,7 @@ ### declaration of default variables ################################################################################ -if ! isset VM_NAME_CLEAN IMG_BASENAME SRC_IMG_ABSOLUTE VM_OS_TYPE; then +if ! isset VM_CLEANNAME IMG_BASENAME SRC_IMG_ABSOLUTE VM_OS_TYPE; then env=$(mktemp) env > "$env" slxlog -d "virt-vbox-init" "A required variable is not set." "$env" @@ -30,17 +30,20 @@ gesetzt. Kann die VM nicht starten." cleanexit 1 fi -declare -rg VMCHOOSERVBOX="/opt/openslx/vmchooser/${self}" +# Define which features the VMware plugin supports +declare -rg PLUGIN_FEATURES="TODO" + +declare -rg VMCHOOSERVBOX="/opt/openslx/vmchooser/${PLUGIN_ID}" declare -rg VBOX_ROOT="${TMPDIR}/vbox" # dir for configs declare -rg VBOX_MACHINES_DIR="${VBOX_ROOT}/Machines" -declare -rg VBOX_SNAPSHOT_DIR="${VBOX_MACHINES_DIR}/${VM_NAME_CLEAN}/Snapshots" +declare -rg VBOX_SNAPSHOT_DIR="${VBOX_MACHINES_DIR}/${VM_CLEANNAME}/Snapshots" declare -rg VBOX_HDD_DIR="${VBOX_ROOT}/HardDisks" declare -rg VBOX_HDD_LINK="${VBOX_HDD_DIR}/${IMG_BASENAME}" export VBOX_USER_HOME="${VBOX_ROOT}" # instead of $HOME/.VirtualBox -# use VM_NAME_CLEAN for dir and config names since VM_DISPLAYNAME can be very long -VBOX_MACHINE_CONFIG="${VBOX_MACHINES_DIR}/${VM_NAME_CLEAN}/${VM_NAME_CLEAN}.xml" +# use VM_CLEANNAME for dir and config names since VM_DISPLAYNAME can be very long +VBOX_MACHINE_CONFIG="${VBOX_MACHINES_DIR}/${VM_CLEANNAME}/${VM_CLEANNAME}.xml" mkdir -p "${VBOX_HDD_DIR}" "${VBOX_SNAPSHOT_DIR}" 2>/dev/null enable2d="true" # default setting for accelerated 2D grapics (OS dependent) vram="128" # set default graphics ram @@ -62,43 +65,43 @@ fi # Setting some default variables -shfolders="TRUE" +SHARED_FOLDERS="TRUE" enablevt="true" # set some base configuration depending on the guest operating system case "${VM_OS_TYPE}" in Windows31) - mem="32" + VM_MEM="32" vram="16" - cpu_cores=1 + CPU_CORES=1 enablevt="false" - shfolders="FALSE" + SHARED_FOLDERS="FALSE" ;; WindowsNT) - mem="4096" + VM_MEM="4096" vram="16" - cpu_cores=4 + CPU_CORES=4 enablevt="false" - shfolders="FALSE" + SHARED_FOLDERS="FALSE" ;; Windows95) - mem="128" + VM_MEM="128" vram="32" - cpu_cores=1 + CPU_CORES=1 enablevt="false" - shfolders="FALSE" + SHARED_FOLDERS="FALSE" ;; Windows98) - mem="256" + VM_MEM="256" vram="64" - cpu_cores=1 - shfolders="FALSE" + CPU_CORES=1 + SHARED_FOLDERS="FALSE" ;; WindowsMe) - mem="256" + VM_MEM="256" vram="64" - cpu_cores=1 - shfolders="FALSE" + CPU_CORES=1 + SHARED_FOLDERS="FALSE" ;; WindowsXP) ;; @@ -109,8 +112,8 @@ case "${VM_OS_TYPE}" in Windows8) ;; OS2eCS) - mem="256" - cpu_cores=1 + VM_MEM="256" + CPU_CORES=1 enable2d="false" ;; MacOS) @@ -126,7 +129,7 @@ esac if [ "$HW_KVM" != "ENABLED" ]; then enablevt="false" - cpu_cores=1 # check for VT, if not available only 1 cpu supported + CPU_CORES=1 # check for VT, if not available only 1 cpu supported fi writelog "Directories:" @@ -140,10 +143,10 @@ writelog "\tMachine config:\t\t$VBOX_MACHINE_CONFIG" # remove ':' from MAC addr for vbox and generate a VDE (virtual device ethernet) # MAC addr from the first one (put in prefix 00DE) -macaddr=$(echo ${macaddr} | sed 's/://g') -vdemacaddr=$(echo ${macaddr} | sed 's/^..../00DE/g') +VM_MAC_ADDR=$(echo ${VM_MAC_ADDR} | sed 's/://g') +VM_VDE_MAC_ADDR=$(echo ${VM_MAC_ADDR} | sed 's/^..../00DE/g') -machineuuid="00000000-0000-0000-0000-${macaddr}" # machine UUID, MAC addr part of it +machineuuid="00000000-0000-0000-0000-${VM_MAC_ADDR}" # machine UUID, MAC addr part of it machineuuid=$(echo ${machineuuid} | tr "[A-Z]" "[a-z]") # cosmetical, since UUID in lower case # get UUID of VBox image @@ -194,19 +197,19 @@ writelog "\tVMostype:\t\t$VM_OS_TYPE" writelog "\tMachine UUID:\t\t$machineuuid" writelog "\tDisk UUID:\t\t$diskuuid" writelog "Virtual Hardware:" -writelog "\tCPU cores:\t\t${cpu_cores}\c" +writelog "\tCPU cores:\t\t${CPU_CORES}\c" writelog "" [ "$HW_KVM" = "ENABLED" ] && writelog " (VT enabled CPU)" -writelog "\tGuest RAM:\t\t${mem} MB" -# echo nur wenn hostmem gesetzt -[ -n "${hostmem}" ] && writelog "\tHost RAM:\t\t${hostmem} MB" -writelog "\tMAC address:\t\t$macaddr" +writelog "\tGuest RAM:\t\t${VM_MEM} MB" +# echo nur wenn HOST_MEM_REMAINING gesetzt +[ -n "${HOST_MEM_REMAINING}" ] && writelog "\tHost RAM:\t\t${HOST_MEM_REMAINING} MB" +writelog "\tMAC address:\t\t$VM_MAC_ADDR" writelog "\tNetwork card:\t\t${vb_network_card}" writelog "\tNetwork kind:\t\t${network_kind}" writelog "\tBooting from:\t\t${boot}\c" writelog "" -writelog "\tCD-ROM1:\t\t${cdrom0}" -#writelog "\tCD-ROM2:\t\t${cdrom1}" +writelog "\tCD-ROM1:\t\t${CDROM0}" +#writelog "\tCD-ROM2:\t\t${CDROM1}" writelog "\tFloppy_A:\t\t${floppy0}" writelog "\tFloppy_B:\t\t${floppy1}" # defined in run-virt.sh and run-vmgrid.sh @@ -219,7 +222,7 @@ writelog "\tShared Folders '${sharename}':\t${sharepath}" # create Virtualbox.xml # Shares given? -if [ "x$shfolders" != "xFALSE" ]; then +if [ "x$SHARED_FOLDERS" != "xFALSE" ]; then sharelist="<SharedFolders> <SharedFolder name=\"${homesharename}\" hostPath=\"${homesharepath}\" writable=\"true\"/> <SharedFolder name=\"${commonsharename}\" hostPath=\"${commonsharepath}\" writable=\"true\"/> @@ -241,7 +244,7 @@ fi source "${VMCHOOSERVBOX}/machine.include" # create machine.xml # remove CD-ROM if not available -if [ "${cdrom0}" != "TRUE" ]; then +if [ "${CDROM0}" != "TRUE" ]; then sed -i "/HostDrive/d" "${VBOX_MACHINE_CONFIG}" sed -i '/AttachedDevice.*type="DVD"/d' "${VBOX_MACHINE_CONFIG}" sed -i "/<!-- PLEASE DO NOT REMOVE THIS COMMENT (CD)!!! -->/d" "${VBOX_MACHINE_CONFIG}" diff --git a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/rwimg.vdi.gz b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/rwimg.vdi.gz Binary files differindex e2133d6d..e2133d6d 100644 --- a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/rwimg.vdi.gz +++ b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/rwimg.vdi.gz diff --git a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/virtualbox.conf b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/virtualbox.conf index 8a7a58e4..8a7a58e4 100644 --- a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/virtualbox.conf +++ b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/virtualbox.conf diff --git a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/virtualbox.include b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/virtualbox.include index 70a036a8..b4bb38e3 100644 --- a/core/modules/vbox/data/opt/openslx/vmchooser/virtualbox/virtualbox.include +++ b/core/modules/vbox/data/opt/openslx/vmchooser/plugins/virtualbox/virtualbox.include @@ -27,7 +27,7 @@ cat << EOF > "${VBOX_ROOT}/VirtualBox.xml" <ExtraDataItem name="GUI/TrayIcon/Enabled" value="false"/> </ExtraData> <MachineRegistry> - <MachineEntry uuid="{${machineuuid}}" src="Machines/${VM_NAME_CLEAN}/${VM_NAME_CLEAN}.xml"/> + <MachineEntry uuid="{${machineuuid}}" src="Machines/${VM_CLEANNAME}/${VM_CLEANNAME}.xml"/> </MachineRegistry> <MediaRegistry> <HardDisks> diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmhome_preferences_file.inc b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/create_vmhome_preferences_file.inc index d50402f3..ed76490b 100644 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmhome_preferences_file.inc +++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/create_vmhome_preferences_file.inc @@ -1,8 +1,13 @@ +########################################### +# Include: Create VMware preferences file # +########################################### +## Functions ## create_vmhome_preferences_file() { - cat > "$vmhome/preferences" <<-HEREEND + cat > "${VM_HOME}/preferences" <<-HEREEND .encoding = "UTF-8" - # This configuration file was generated by $0 - + # This configuration file was generated on $(date) + # by $0 for VMWare version $vmware_version + # updates webUpdate.enabled = "FALSE" webUpdate.lastCheck.status = "done_updates" @@ -27,8 +32,8 @@ create_vmhome_preferences_file() { hint.buslogic.needDriver = "FALSE" # configs - prefvmx.defaultVMPath = "$vmhome" - prefvmx.mru.config = "$conffile:" + prefvmx.defaultVMPath = "${VM_HOME}" + prefvmx.mru.config = "$VM_RUN_FILE:" # hot keys pref.hotkey.control = "true" @@ -65,8 +70,9 @@ create_vmhome_preferences_file() { pref.eula1.build = "$vmware_build" HEREEND if [ -n "$SLX_EXAM" ]; then - echo 'pref.hotkey.rightControl = "true"' >> "$vmhome/preferences" + echo 'pref.hotkey.rightControl = "true"' >> "${VM_HOME}/preferences" fi - writelog "Vmware preferences file created in $vmhome." - true + writelog "Vmware preferences file created in $VM_HOME." } + +call_post_source create_vmhome_preferences_file diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/determine_hardware_limitations.inc b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/determine_hardware_limitations.inc new file mode 100644 index 00000000..f5fdf669 --- /dev/null +++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/determine_hardware_limitations.inc @@ -0,0 +1,196 @@ +########################################################################## +# 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" != 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/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/init_core.inc b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/init_core.inc new file mode 100644 index 00000000..63318589 --- /dev/null +++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/init_core.inc @@ -0,0 +1,44 @@ +####################################################################### +# Include: Declaration of core functions and variables of this plugin # +####################################################################### +# This core include just executes stuff! No post source calls! +# 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 "${HOME}" ] && declare -rg HOME=$(getent passwd "$(whoami)" | awk -F ':' '{print $6}') +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/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/log_config_summary.inc b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/log_config_summary.inc new file mode 100644 index 00000000..a33a8bc6 --- /dev/null +++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/log_config_summary.inc @@ -0,0 +1,59 @@ +################################################## +# 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/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/parse_vmx.inc b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/parse_vmx.inc new file mode 100644 index 00000000..daa77455 --- /dev/null +++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/parse_vmx.inc @@ -0,0 +1,22 @@ +###################################################################### +# Include: Parsing the non-legacy delivered vmxfile ${TMPCONFIG} # +###################################################################### +## Functions +parse_vmx() { + 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 -rg 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/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc new file mode 100644 index 00000000..5ab1d6e9 --- /dev/null +++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc @@ -0,0 +1,227 @@ +################################################ +# 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() { + sed -i 's#%VM_DISK_PATH%#'"$VM_DISKFILE_RO"'#g' "${TMPCONFIG}" + sed -i 's#%VM_DISK_MODE%#'"independent-nonpersistent"'#g' "${TMPCONFIG}" + 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}" +} + +# 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 = "$FLOPPY0" + floppy0.startConnected = "FALSE" + floppy0.autodetect = "TRUE" + floppy0.fileName = "auto detect" + floppy1.present = "$SLX_FLOPPY" + floppy1.startConnected = "TRUE" + floppy1.fileType = "file" + floppy1.fileName = "$SLX_FLOPPY_IMG" + HEREEND +} + +# 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() { + cat >> "${TMPCONFIG}" <<-HEREEND + sharedFolder.option = "alwaysEnabled" + sharedFolder0.present = "$SHARED_FOLDERS" + sharedFolder0.enabled = "$SHARED_FOLDERS" + sharedFolder0.expiration = "never" + sharedFolder0.guestName = "$homesharename" + sharedFolder0.hostPath = "$homesharepath" + sharedFolder0.readAccess = "TRUE" + sharedFolder0.writeAccess = "TRUE" + sharedFolder1.present = "$SHARED_FOLDERS" + sharedFolder1.enabled = "$SHARED_FOLDERS" + sharedFolder1.expiration = "never" + sharedFolder1.guestName = "$commonsharename" + sharedFolder1.hostPath = "$commonsharepath" + 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_vcpu_ram + setup_usb + [ "$HGFS_DISABLED" = "FALSE" ] && 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/vmware/data/opt/openslx/vmchooser/vmware/nvram b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/nvram Binary files differindex 85125f1e..85125f1e 100644 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/nvram +++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/nvram diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/run-virt.include b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/run-virt.include new file mode 100644 index 00000000..9d45becf --- /dev/null +++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/run-virt.include @@ -0,0 +1,50 @@ +# ----------------------------------------------------------------------------- +# 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" + +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: using the modified version of the wrapper script + declare -rg VIRTCMD="/opt/openslx/bin/vmplayer" + declare -rg VIRTCMDOPTS="${VM_START_OPTIONS} ${VM_RUN_FILE}" +} diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_static_directory_structure.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_static_directory_structure.inc deleted file mode 100644 index 96363de3..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_static_directory_structure.inc +++ /dev/null @@ -1,23 +0,0 @@ -############################### -# Include: Write config files # -############################### - -writelog "Redo directory: ${redodir}" -writelog "Config directory: ${confdir}" -writelog "Config file: ${conffile}" -writelog "vmhome/dndlogs: ${vmhome}/dndlogs" - -# create vmware directories -mkdir -p "$redodir" >/dev/null 2>&1 -mkdir -p "$confdir" >/dev/null 2>&1 -mkdir -p "$vmhome/dndlogs" >/dev/null 2>&1 -touch "$vmhome/dndlogs/dndlog.conf" >/dev/null 2>&1 - -# link to conffile if confdir != redodir -[ "$confdir" != "$redodir" ] && ln -s "$conffile" "$redodir/run-vmware.conf" >/dev/null 2>&1 - -# own nvram. We need it for floppy drive b, default nvram has just drive a -if ! cp "/opt/openslx/vmchooser/vmware/nvram" "$confdir/nvram"; then - slxlog "virt-vmware-nvram" "Could not copy nvram from '/opt/openslx/vmchooser/vmware/nvram' '$confdir/nvram'" -fi - diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file.inc deleted file mode 100644 index 5d33ce16..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file.inc +++ /dev/null @@ -1,186 +0,0 @@ -######################################## -# Include: Create vmware startup files # -######################################## - -writelog "Creating vmware configuration file: $conffile" - -MAXMEM="9999999" -MAXCORES="4" -shfolders="TRUE" -sound="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 "$vmostype" in - win31*|windows31*) - vmostype="win31" - shfolders="FALSE" - sound="sb16" - MAXMEM="32" - MAXCORES="1" - ;; - winnt*|windowsnt*) - vmostype="winnt" - shfolders="FALSE" - sound="sb16" - MAXMEM="1000" - MAXCORES="2" - ;; - win95*|windows95*) - vmostype="win95" - shfolders="FALSE" - MAXMEM="96" - MAXCORES="1" - ;; - win98*|windows98*) - vmostype="win98" - MAXMEM="256" - MAXCORES="1" - ;; - winme*|windowsme*) - vmostype="winme" - MAXMEM="384" - MAXCORES="1" - ;; - win2000|windows2000|win2000pro*) - vmostype="win2000pro" - MAXMEM="4000" - MAXCORES="2" - ;; - win2000srv*|windows2000srv*|win2000serv*|windows2000serv*) - vmostype="win2000serv" - shfolders="FALSE" - MAXMEM="4000" - MAXCORES="4" - ;; - win2000adv*|windows2000adv*|win2000dat*|windows2000dat*) - vmostype="win2000advserv" - shfolders="FALSE" - MAXMEM="8000" - MAXCORES="8" - ;; - winnet*64|win*2003*64|windowsnet*64) - vmostype="winnetstandard-64" - MAXMEM="8000" - ;; - winnet*|win*2003*|windowsnet*) - vmostype="winnetstandard" - MAXMEM="4000" - ;; - winxphome*|windowsxphome*) - vmostype="winxphome" - MAXMEM="4000" - MAXCORES="1" - ;; - winxp*64|windowsxp*64) - vmostype="winxppro-64" - MAXMEM="8000" - MAXCORES="2" - ;; - winxp*|windowsxp*) - vmostype="winxppro" - MAXMEM="4000" - MAXCORES="1" - ;; - winvista-64) - vmostype="winvista-64" - MAXMEM="16000" - MAXCORES="2" - ;; - windows7-64) - vmostype="windows7-64" - MAXMEM="32000" - MAXCORES="4" - ;; - windows8-64) - vmostype="windows8-64" - MAXMEM="32000" - MAXCORES="8" - ;; - windows9-64) - vmostype="windows9-64" - MAXMEM="64000" - MAXCORES="8" - ;; - winvista) - vmostype="winvista" - MAXMEM="8000" - MAXCORES="2" - ;; - windows7) - vmostype="windows7" - MAXMEM="8000" - MAXCORES="4" - ;; - windows8) - vmostype="windows8" - MAXMEM="8000" - MAXCORES="4" - ;; - windows9) - vmostype="windows9" - MAXMEM="8000" - MAXCORES="4" - ;; - win*64) - MAXMEM="16000" - MAXCORES="4" - ;; - win*) - MAXMEM="8000" - ;; - dos|msdos*|ms-dos*) - vmostype="dos" - shfolders="FALSE" - MAXMEM="128" - ;; - macos*64) - vmostype="freebsd-64" - MAXMEM="4000" - MAXCORES="2" - ;; - macos*) - vmostype="freebsd" - MAXMEM="4000" - MAXCORES="1" - ;; - beos*) - vmostype="other" - shfolders="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) - vmostype="other-64" - # shfolders="FALSE" - MAXMEM="123456" - MAXCORES="4" - ;; - *) - vmostype="other" - # shfolders="FALSE" - MAXMEM="8000" - MAXCORES="1" - ;; -esac - -real_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. -cores_per_socket="$cpu_cores" - -if [ "x$shfolders" != "xFALSE" ]; then - ENABLE_SHARE='sharedFolder.option = "alwaysEnabled"' -else - ENABLE_SHARE='' -fi - -[ "$mem" -ge "$MAXMEM" ] && mem="$MAXMEM" -[ "$hwver" -lt "7" -a "$mem" -gt "3500" ] && mem="3500" - -# set the appropriate permissions for the vmware config file -chmod u+rwx "${conffile}" >/dev/null 2>&1 - diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file_legacy.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file_legacy.inc deleted file mode 100644 index 1d6b2185..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/create_vmware_config_file_legacy.inc +++ /dev/null @@ -1,312 +0,0 @@ -######################################## -# Include: Create vmware startup files # -######################################## - -create_vmware_config_file_legacy() { - echo "# This configuration file was generated by $0" > "$conffile" - - MAXMEM="9999999" - MAXCORES="4" - shfolders="TRUE" - sound="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 "$vmostype" in - win31*|windows31*) - vmostype="win31" - shfolders="FALSE" - sound="sb16" - MAXMEM="32" - MAXCORES="1" - ;; - winnt*|windowsnt*) - vmostype="winnt" - shfolders="FALSE" - sound="sb16" - MAXMEM="1000" - MAXCORES="2" - ;; - win95*|windows95*) - vmostype="win95" - shfolders="FALSE" - MAXMEM="96" - MAXCORES="1" - ;; - win98*|windows98*) - vmostype="win98" - MAXMEM="256" - MAXCORES="1" - ;; - winme*|windowsme*) - vmostype="winme" - MAXMEM="384" - MAXCORES="1" - ;; - win2000|windows2000|win2000pro*) - vmostype="win2000pro" - MAXMEM="4000" - MAXCORES="2" - ;; - win2000srv*|windows2000srv*|win2000serv*|windows2000serv*) - vmostype="win2000serv" - shfolders="FALSE" - MAXMEM="4000" - MAXCORES="4" - ;; - win2000adv*|windows2000adv*|win2000dat*|windows2000dat*) - vmostype="win2000advserv" - shfolders="FALSE" - MAXMEM="8000" - MAXCORES="8" - ;; - winnet*64|win*2003*64|windowsnet*64) - vmostype="winnetstandard-64" - MAXMEM="8000" - ;; - winnet*|win*2003*|windowsnet*) - vmostype="winnetstandard" - MAXMEM="4000" - ;; - winxphome*|windowsxphome*) - vmostype="winxphome" - MAXMEM="4000" - MAXCORES="1" - ;; - winxp*64|windowsxp*64) - vmostype="winxppro-64" - MAXMEM="8000" - MAXCORES="2" - ;; - winxp*|windowsxp*) - vmostype="winxppro" - MAXMEM="4000" - MAXCORES="1" - ;; - winvista*64|windowsvista*64) - vmostype="winvista-64" - MAXMEM="16000" - MAXCORES="2" - ;; - winvista*|windowsvista*) - vmostype="winvista" - MAXMEM="8000" - MAXCORES="2" - ;; - win7*64|windows7*64) - vmostype="windows7-64" - MAXMEM="32000" - MAXCORES="4" - ;; - win7*|windows7*) - vmostype="windows7" - MAXMEM="8000" - MAXCORES="4" - ;; - win8*64|windows8*64) - vmostype="windows8-64" - MAXMEM="32000" - MAXCORES="4" - ;; - win8*|windows8*) - vmostype="windows8" - MAXMEM="8000" - MAXCORES="4" - ;; - win*64) - MAXMEM="16000" - MAXCORES="4" - ;; - win*) - MAXMEM="8000" - ;; - dos|msdos*|ms-dos*) - vmostype="dos" - shfolders="FALSE" - MAXMEM="128" - ;; - macos*64) - vmostype="freebsd-64" - MAXMEM="4000" - MAXCORES="2" - ;; - macos*) - vmostype="freebsd" - MAXMEM="4000" - MAXCORES="1" - ;; - beos*) - vmostype="other" - shfolders="FALSE" - ;; - # Unknown guestOS setting in .xml - use conservative defaults - *64) - vmostype="other-64" - shfolders="FALSE" - MAXMEM="123456" - MAXCORES="4" - ;; - *) - vmostype="other" - shfolders="FALSE" - MAXMEM="8000" - MAXCORES="1" - ;; - esac - real_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. - cores_per_socket="$cpu_cores" - - if [ "x$shfolders" != "xFALSE" ]; then - ENABLE_SHARE='sharedFolder.option = "alwaysEnabled"' - else - ENABLE_SHARE='' - fi - - [ "$mem" -ge "$MAXMEM" ] && mem="$MAXMEM" - [ "$hwver" -lt "7" -a "$mem" -gt "3500" ] && mem="3500" - - cap3d="WHAT IS THIS VAR USED FOR?" # helper var for loging output - - - cat >> "$conffile" <<-HEREEND - .encoding = "UTF-8" - config.version = "8" - - # general hardware (ehci, 3d accel) - ehci.present = "TRUE" - $FORCE3D - mks.enable3d = "$enable3d" - - monitor.virtual_mmu = "automatic" - monitor.virtual_exec = "automatic" - floppy1.clientDevice = "FALSE" - floppy1.readonly = "TRUE" - - # id - virtualHW.version = "$hwver" - displayName = "$displayname" - guestOS = "$vmostype" - - # CPU/MEM - numvcpus = "$cpu_cores" - cpuid.coresPerSocket = "$cores_per_socket" - maxvcpus = "$real_core_count" - memsize = "$mem" - MemAllowAutoScaleDown = "FALSE" - MemTrimRate = "-1" - - # ide-disks - ide0:0.present = "$ide" - ide0:0.fileName = "$vm_diskfile" - ## Edited for persistent mode. - ide0:0.mode = "independent-${diskmode}" - ## - 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" - - # scsi-disks - scsi0.present = "$scsi" - scsi0:0.present = "$scsi" - scsi0:0.fileName = "$vm_diskfile" - scsi0.virtualDev = "$hddrv" - ## Edited for persistent mode. - scsi0:0.mode = "independent-${diskmode}"$stateFileConfiguration - ## - - # floppies - floppy0.present = "$floppy0" - floppy0.startConnected = "FALSE" - floppy0.autodetect = "TRUE" - floppy0.fileName = "auto detect" - - # we need floppy b: for the client configuration - floppy1.present = "$floppy1" - floppy1.startConnected = "TRUE" - floppy1.fileType = "file" - floppy1.fileName = "$floppy1name" - - # nics - ethernet0.present = "TRUE" - ethernet0.addressType = "static" - $network_virtualDev - #ethernet0.connectionType = "hostonly" - ethernet0.connectionType = "custom" - ethernet0.vnet = "$hostdev" - ethernet0.address = "00:50:56:$macaddrsuffix" - ethernet0.wakeOnPcktRcv = "FALSE" - - # sound - sound.present = "TRUE" - $sound_fileName - sound.virtualdev = "$sound" - pciSound.enableVolumeControl = "FALSE" - sound.enableVolumeControl = "FALSE" - - # svga - svga.autodetect = "TRUE" - - # usb - usb.present = "TRUE" - usb.generic.autoconnect = "TRUE" - - # pci configuration - usb.pciSlotNumber = "16" - ethernet0.pciSlotNumber = "17" - sound.pciSlotNumber = "18" - ehci.pciSlotNumber = "19" - scsi0.pciSlotNumber = "20" - - $PCIE - - # shared folders - $ENABLE_SHARE - sharedFolder0.present = "$shfolders" - sharedFolder0.enabled = "$shfolders" - sharedFolder0.expiration = "never" - sharedFolder0.guestName = "$homesharename" - sharedFolder0.hostPath = "$homesharepath" - sharedFolder0.readAccess = "TRUE" - sharedFolder0.writeAccess = "TRUE" - sharedFolder1.present = "$shfolders" - sharedFolder1.enabled = "$shfolders" - sharedFolder1.expiration = "never" - sharedFolder1.guestName = "$commonsharename" - sharedFolder1.hostPath = "$commonsharepath" - sharedFolder1.readAccess = "TRUE" - sharedFolder1.writeAccess = "TRUE" - sharedFolder.maxNum = "2" - - # dirs/configs - tmpDirectory = "$redodir" - redoLogDir = "$redodir" - mainMem.useNamedFile = "TRUE" - snapshot.disabled = "TRUE" - tools.syncTime = "TRUE" - isolation.tools.hgfs.disable = "FALSE" - hgfs.mapRootShare = "TRUE" - isolation.tools.dnd.disable = "FALSE" - isolation.tools.copy.enable = "TRUE" - isolation.tools.paste.enabled = "TRUE" - - # serial port - serial0.present = "$serial" - $serialdev - - # parallel port - parallel0.present = "$parallel" - parallel0.bidirectional = "$paralbidi" - $paraldev - HEREEND - - # set the appropriate permissions for the vmware config file - chmod u+rwx "${conffile}" >/dev/null 2>&1 -} diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/determine_hardware_limitations.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/determine_hardware_limitations.inc deleted file mode 100644 index 11ea2e3a..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/determine_hardware_limitations.inc +++ /dev/null @@ -1,185 +0,0 @@ -######################################## -# Include: Determine hw limitations depending on hwver and guest os # -######################################## - -MAXMEM="9999999" -MAXCORES="4" -shfolders="TRUE" -sound="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" - shfolders="FALSE" - sound="sb16" - MAXMEM="32" - MAXCORES="1" - ;; - winnt*|windowsnt*) - VM_OS_TYPE="winnt" - shfolders="FALSE" - sound="sb16" - MAXMEM="1000" - MAXCORES="2" - ;; - win95*|windows95*) - VM_OS_TYPE="win95" - shfolders="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" - shfolders="FALSE" - MAXMEM="4000" - MAXCORES="4" - ;; - win2000adv*|windows2000adv*|win2000dat*|windows2000dat*) - VM_OS_TYPE="win2000advserv" - shfolders="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" - shfolders="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" - shfolders="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" - # shfolders="FALSE" - MAXMEM="123456" - MAXCORES="4" - ;; - *) - VM_OS_TYPE="other" - # shfolders="FALSE" - MAXMEM="8000" - MAXCORES="1" - ;; -esac - -real_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. -cores_per_socket="$cpu_cores" - -if [ "x$shfolders" != "xFALSE" ] && [ "$SHARE_REMAP_MODE" != 1 ]; then - HGFS_DISABLED="FALSE" -else - HGFS_DISABLED="TRUE" -fi - -[ "$mem" -ge "$MAXMEM" ] && mem="$MAXMEM" -[ "$HWVER" -lt "7" -a "$mem" -gt "3500" ] && mem="3500" - diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/log_config_summary.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/log_config_summary.inc deleted file mode 100644 index 41986b2a..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/log_config_summary.inc +++ /dev/null @@ -1,60 +0,0 @@ -################################################## -# Include: Print vm config summary into log file # -################################################## - -# log script information -writelog "# File created by $0 (VMware version ${vmware_version})\n# on $(date)\n" -## Edited for persistent mode. -writelog "Starting with ${diskmode} mode ...\n" -## - -# write all results to logfile -# log disksetup -writelog "Directories:" -writelog "\tConfdir:\t${confdir}" -writelog "\tConffile:\t${conffile}" -writelog "\tRedodir:\t${redodir}" -writelog "\tVMhome:\t\t${vmhome}" -writelog "\t/tmp info: $(grep "/tmp " /proc/mounts) $(df -h | grep " /tmp$" | awk '{print $2}')" -# hw setup -writelog "Hardware:" -writelog "\tMAC:\t\t$macaddr" -if [ -n "${network_card}" ]; then - writelog "\tNet Adaptor:\t${network_card}" -fi -writelog "\tMem:\t\t${mem} MB" - -# echo nur wenn hostmem gesetzt -[ -n "${hostmem}" ] && writelog "\tHostmem:\t${hostmem} MB" -writelog "\tCD-ROM1:\t${cdrom0}" -writelog "\tCD-ROM2:\t${cdrom1}" -writelog "\tFloppy_A:\t${floppy0}" -if [ "${serial}" = "TRUE" ]; then - writelog "\tSerial Port:\t${serialdev}" -fi -if [ "${parallel}" = "TRUE" ]; then - writelog "\tParallel Port:\t${paraldev}" -fi - -writelog "Shared folders:" -if [ "${HGFS_DISABLED}" = "FALSE" ]; then - writelog "\tNo shared folders enabled." -else - writelog "\Shared folders enabled." -fi - -# image -writelog "Diskimage:" -writelog "\tDiskfile:\t${VM_DISKFILE_RO}" -writelog "\tHWVersion:\t${HWVER}" -writelog "\tVMostype:\t${VM_OS_TYPE}" - -# misc -writelog "Misc:" -writelog "\tDisplayname:\t${VM_DISPLAYNAME}" -if [ "${cap3d}" = "TRUE" -a "${enable3d}" = "TRUE" ]; then - writelog "\t3D Graphics:\tenabled" -fi -# empty line at end -writelog "" - diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/logging.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/logging.inc deleted file mode 100644 index dc01434d..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/logging.inc +++ /dev/null @@ -1,64 +0,0 @@ -############################### -# Include: Logging and stdout # -############################### - -logging() { - # log script information - writelog "# File created by $0 (VMware version ${vmware_version})\n# on $(date)\n" - ## Edited for persistent mode. - writelog "Starting with ${diskmode} mode ...\n" - ## - - # write all results to logfile - # log disksetup - writelog "Directories:" - writelog "\tConfdir:\t${confdir}" - writelog "\tConffile:\t${conffile}" - writelog "\tRedodir:\t${redodir}" - writelog "\tVMhome:\t\t${vmhome}" - writelog "\t/tmp info: $(grep "/tmp " /proc/mounts) $(df -h | grep " /tmp$" | awk '{print $2}')" - # hw setup - writelog "Hardware:" - writelog "\tMAC:\t\t00:50:56:$macaddrsuffix" # TODO: Make var at top for this, it's hard coded twice - if [ -n "${network_card}" ]; then - writelog "\tNet Adaptor:\t${network_card}" - fi - writelog "\tMem:\t\t${mem} MB" - - # echo nur wenn hostmem gesetzt - [ -n "${hostmem}" ] && writelog "\tHostmem:\t${hostmem} MB" - writelog "\tMax. res.:\t${xres}x${yres}" - writelog "\tCD-ROM1:\t${cdrom0}" - writelog "\tCD-ROM2:\t${cdrom1}" - writelog "\tFloppy_A:\t${floppy0}" - if [ "${serial}" = "TRUE" ]; then - writelog "\tSerial Port:\t${serialdev}" - fi - if [ "${parallel}" = "TRUE" ]; then - writelog "\tParallel Port:\t${paraldev}" - fi - - writelog "Shared folders:" - if [ "${ENABLE_SHARE}" = '' ]; then - writelog "\tNo shared folders enabled." - else - writelog "\Shared folders enabled ($ENABLE_SHARE)" - fi - - # image - writelog "Diskimage:" - writelog "\tDiskfile:\t${diskfile}" - writelog "\tDisktype:\t${hddrv}" - writelog "\tHWVersion:\t${hwver}" - writelog "\tVMostype:\t${vmostype}" - - # misc - writelog "Misc:" - writelog "\tDisplayname:\t${displayname}" - if [ "${cap3d}" = "TRUE" -a "${enable3d}" = "TRUE" ]; then - writelog "\t3D Graphics:\tenabled" - fi - # empty line at end - writelog "" - -} diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/parse_vmx.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/parse_vmx.inc deleted file mode 100644 index dec80e1d..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/parse_vmx.inc +++ /dev/null @@ -1,8 +0,0 @@ -###################################################################### -# Include: Parsing the non-legacy delivered vmxfile ${TMPCONFIG} # -###################################################################### - -writelog "Parsing virtual machine description file..." - -HWVER=$(grep -i -m1 '^virtualHW.version *= *' "${TMPCONFIG}" | awk -F '=' '{print $2}' | sed -r 's/[^0-9]//g') - diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/set_hardware_legacy.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/set_hardware_legacy.inc deleted file mode 100644 index 22718839..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/set_hardware_legacy.inc +++ /dev/null @@ -1,152 +0,0 @@ -######################################### -# Include: Hardware checks and settings # -######################################### - -set_hardware_legacy() { - -# use different network card (default e1000, vlance, vmxnet) -if [ -n "${network_card}" ]; then - network_virtualDev="ethernet0.virtualDev = \"${network_card}\"" -else - network_virtualDev='ethernet0.virtualDev = "e1000"' -fi - -# use different network card (default e1000, vlance, vmxnet) -hostdev="/dev/vmnet1" -case "${network_kind}" in - bridge|bridged) - hostdev="/dev/vmnet0" - ;; - nat) - hostdev="/dev/vmnet1" - ;; - hostonly|host-only) - hostdev="/dev/vmnet2" - ;; -esac - -# set standard sound card, overwrite depending on OS (options sb16, es1371, hdaudio) -sound="es1371" - -# set sound card explicitly if there is more than one card in the host system -sound_fileName='sound.fileName = "-1" -sound.autodetect = "TRUE"' - -# check for 3D configuration setting -case "$enable3d" in - true|yes) - enable3d="TRUE" - ;; - *) - enable3d="FALSE" - ;; -esac - -# check for whitelisted HW-3D -FORCE3D="" -if [ -n "$SLX_VMWARE_3D" ]; then - FORCE3D='mks.gl.allowBlacklistedDrivers = "TRUE"' -fi - -# serial/parallel port defined (e.g. "ttyS0, lp0" or "autodetect") -case "$serial" in - tty*) - if [ -e "/dev/$serial" ]; then - serialdev="serial0.filename = \"/dev/${serial}\"" - serial="TRUE" - else - serialdev="# no serial port configured" - serial="FALSE" - fi - ;; - auto*) - serialdev="serial0.autodetect = \"TRUE\"" - serial="TRUE" - ;; - *) - serialdev="# no serial port configured" - serial="FALSE" - ;; -esac - -case "$parallel" in - lp*|parport*) - if [ -e "/dev/$parallel" ]; then - paraldev="parallel0.filename = \"/dev/${parallel}\"" - paralbidi="TRUE" - parallel="TRUE" - else - paraldev="# no parallel port configured" - paralbidi="FALSE" - parallel="FALSE" - fi - ;; - auto*) - paraldev="parallel0.autodetect = \"TRUE\"" - paralbidi="TRUE" - parallel="TRUE" - ;; - *) - paraldev="# no parallel port configured" - paralbidi="FALSE" - parallel="FALSE" - ;; -esac - -# check if ide/scsi and hwver of image -# read only the first 30 lines to be sure -imghead=$(head -n 30 "${diskfile}") - -## Added to handle persistent snapshots. -if [[ "$originalVMDKFilePath" ]]; then - echo "Select \"${originalVMDKFilePath}\" as information base for \"${diskfile}\"." - imghead=$(head -n 30 "$originalVMDKFilePath") && \ - - # Support suspend mode. - stateFilePath="$(readlink -f "$(dirname "$diskfile")/"*.vmss)" && \ - if [ -f "$stateFilePath" ]; then - echo "Found state file \"$stateFilePath\"." && \ - stateFileConfiguration=" - checkpoint.vmState = \"$stateFilePath\"" - fi - POSTRUN="stateFilePath=\"\$(readlink -f \"${confdir}/\"*.vmss)\" && memoryFilePath=\"\$(readlink -f \"${confdir}/\"*.vmem)\" && [ -f \"\$stateFilePath\" ] && echo \"Saving state and memory file \\\"\$stateFilePath\\\" and \\\"\$memoryFilePath\\\".\" && mv -f \"\$stateFilePath\" \"$(dirname "$diskfile")/\" && mv -f \"\$memoryFilePath\" \"$(dirname "$diskfile")/\"" -fi - -## -hwver=$(echo "${imghead}" | grep -m1 -ia "ddb.virtualHWVersion" | awk -F '"' '{print $2}') - - -if [ -z "$override_hddtype" ]; then - hddrv=$(echo "${imghead}" | grep -m1 -ia "ddb.adapterType" | awk -F '"' '{print $2}') -else - hddrv=$override_hddtype -fi - -PCIE= -case "${hddrv}" in - ide) - ide="TRUE" - scsi="FALSE" - ;; - lsisas*) - ide="FALSE" - scsi="TRUE" - PCIE='pciBridge4.present = "TRUE" - pciBridge4.virtualDev = "pcieRootPort" - pciBridge4.functions = "8"' - ;; - lsilogic|buslogic) - ide="FALSE" - scsi="TRUE" - ;; - scsi) - ide="FALSE" - scsi="TRUE" - hddrv="lsilogic" - ;; - *) - slxlog "virt-vmware-hdd" "vmware: Unknown HDD adapter type $hddrv" - ;; -esac - -} diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/set_vmware_include_variables.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/set_vmware_include_variables.inc deleted file mode 100644 index da820bc6..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/set_vmware_include_variables.inc +++ /dev/null @@ -1,25 +0,0 @@ -##################################################################### -# Include: Declaration of vmware run-virt-include default variables # -##################################################################### - -set_vmware_include_variables() { - # temporary disk space for logs, etc... - redodir="/tmp/virt/vmware/${USER}.$$" - - # dir for configs and vmem file - confdir="/tmp/virt/vmware/${USER}.$$" - - # configfile - conffile="${confdir}/run-vmware.conf" - - # users vmware config folder - [ -z "${HOME}" ] && HOME=$(getent passwd "$(whoami)" | awk -F ':' '{print $6}') - vmhome="${HOME}/.vmware" - - # get several version infos for vmware/player - source /opt/openslx/vmchooser/vmware/vmware.conf - - # VMware start options - # "-X": start in fullscreen - vmopt="-X" -} diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_config_files.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_config_files.inc deleted file mode 100644 index 555688bf..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_config_files.inc +++ /dev/null @@ -1,29 +0,0 @@ -############################### -# Include: Write config files # -############################### - -writelog "Redo directory: ${redodir}" -writelog "Config directory: ${confdir}" -writelog "Config file: ${conffile}" -writelog "vmhome/dndlogs: ${vmhome}/dndlogs" - -# create vmware directories -mkdir -p "$redodir" >/dev/null 2>&1 -mkdir -p "$confdir" >/dev/null 2>&1 -mkdir -p "$vmhome/dndlogs" >/dev/null 2>&1 -touch "$vmhome/dndlogs/dndlog.conf" >/dev/null 2>&1 - -# create preferences file ${vmhome}/preferences -source "${VMWAREINCLUDEDIR}/create_vmhome_preferences_file.inc" && create_vmhome_preferences_file - -# create VMware config file (conffile) -source "${VMWAREINCLUDEDIR}/create_vmware_config_file.inc" - -# link to conffile if confdir != redodir -[ "$confdir" != "$redodir" ] && ln -s "$conffile" "$redodir/run-vmware.conf" >/dev/null 2>&1 - -# own nvram. We need it for floppy drive b, default nvram has just drive a -if ! cp "/opt/openslx/vmchooser/vmware/nvram" "$confdir/nvram"; then - slxlog "virt-vmware-nvram" "Could not copy nvram from '/opt/openslx/vmchooser/vmware/nvram' '$confdir/nvram'" -fi - diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_config_files_legacy.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_config_files_legacy.inc deleted file mode 100644 index 52a341ba..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_config_files_legacy.inc +++ /dev/null @@ -1,29 +0,0 @@ -############################### -# Include: Write config files # -############################### - -write_config_files_legacy() { - # create vmware directories - mkdir -p "$redodir" >/dev/null 2>&1 - mkdir -p "$confdir" >/dev/null 2>&1 - mkdir -p "$vmhome/dndlogs" >/dev/null 2>&1 - touch "$vmhome/dndlogs/dndlog.conf" >/dev/null 2>&1 - - # create preferences file ${vmhome}/preferences - source "${VMWAREINCLUDEDIR}/create_vmhome_preferences_file.inc" && create_vmhome_preferences_file - - # create VMware config file (conffile) - source "${VMWAREINCLUDEDIR}/create_vmware_config_file_legacy.inc" && create_vmware_config_file_legacy - - # link to conffile if confdir != redodir - [ "$confdir" != "$redodir" ] && ln -s "$conffile" "$redodir/run-vmware.conf" >/dev/null 2>&1 - - # sync is needed to ensure that data is really written to virtual disk - # TODO: Move to general run-virt, right before exec of vm - sync - - # own nvram. We need it for floppy drive b, default nvram has just drive a - if ! cp "/opt/openslx/vmchooser/vmware/nvram" "$confdir/nvram"; then - slxlog "virt-vmware-nvram" "Could not copy nvram from '/opt/openslx/vmchooser/vmware/nvram' '$confdir/nvram'" - fi -} diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_final_vmx.inc b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_final_vmx.inc deleted file mode 100644 index f1395369..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/includes/write_final_vmx.inc +++ /dev/null @@ -1,211 +0,0 @@ - -# check for vmdk file marker %VM_DISK_PATH% and put vmdk path in it's place: also VM_DISK_MODE -# and VM_DISK_REDOLOGDIR. -sed -i 's#%VM_DISK_PATH%#'"$VM_DISKFILE_RO"'#g' "${TMPCONFIG}" -sed -i 's#%VM_DISK_MODE%#'"independent-nonpersistent"'#g' "${TMPCONFIG}" -sed -i 's#%VM_DISK_REDOLOGDIR%#'"$redodir"'#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. -writelog "Guest MAC: $macaddr" -echo 'ethernet0.addressType = "static"' >> "${TMPCONFIG}" -echo 'ethernet0.address = "'"${macaddr}"'"' >> "${TMPCONFIG}" - -# DVD, CDROM -# XXX: For now it's safe to assume ide channel 1 is free, as we support only one HDD, and 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 - -if [ -n "$FLOPPYIMG" ]; then - floppy1="TRUE" -else - floppy1="FALSE" -fi - -# Floppies: -cat >> "${TMPCONFIG}" <<-HEREEND -floppy0.present = "$floppy0" -floppy0.startConnected = "FALSE" -floppy0.autodetect = "TRUE" -floppy0.fileName = "auto detect" -floppy1.present = "$floppy1" -floppy1.startConnected = "TRUE" -floppy1.fileType = "file" -floppy1.fileName = "$FLOPPYIMG" -HEREEND - -writelog "numvcpus = ${cpu_cores} - maxvcpus=${real_core_count}" - -# RAM, CPUs -cat >> "${TMPCONFIG}" <<-HEREEND -numvcpus = "$cpu_cores" -cpuid.coresPerSocket = "$cores_per_socket" -maxvcpus = "$real_core_count" -memsize = "$mem" -MemAllowAutoScaleDown = "FALSE" -MemTrimRate = "-1" -HEREEND - -# 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 - # Exam mode: Default to no USB - sed -i '/^usb\./Id' "${TMPCONFIG}" - echo 'usb.present = "FALSE"' >> "${TMPCONFIG}" - else - cat >> "${TMPCONFIG}" <<-HEREEND - usb.present = "TRUE" - HEREEND - 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}" - -# shared folders -if [ "$HGFS_DISABLED" = "FALSE" ]; then - cat >> "${TMPCONFIG}" <<-HEREEND - sharedFolder.option = "alwaysEnabled" - sharedFolder0.present = "$shfolders" - sharedFolder0.enabled = "$shfolders" - sharedFolder0.expiration = "never" - sharedFolder0.guestName = "$homesharename" - sharedFolder0.hostPath = "$homesharepath" - sharedFolder0.readAccess = "TRUE" - sharedFolder0.writeAccess = "TRUE" - sharedFolder1.present = "$shfolders" - sharedFolder1.enabled = "$shfolders" - sharedFolder1.expiration = "never" - sharedFolder1.guestName = "$commonsharename" - sharedFolder1.hostPath = "$commonsharepath" - sharedFolder1.readAccess = "TRUE" - sharedFolder1.writeAccess = "FALSE" - sharedFolder.maxNum = "2" - hgfs.mapRootShare = "TRUE" - hgfs.linkRootShare = "TRUE" - HEREEND -fi - -# Isolation tools: settings -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 port -if [ -n "$serial_0" ]; then - cat >> "${TMPCONFIG}" <<-HEREEND - serial0.present = "TRUE" - serial0.startConnected = "TRUE" - serial0.fileType = "device" - serial0.fileName = "$serial_0" - serial0.tryNoRxLoss = "FALSE" - serial0.autodetect = "FALSE" - HEREEND -fi - -# Parallel port -if [ -n "$parallel_0" ]; then - cat >> "${TMPCONFIG}" <<-HEREEND - parallel0.present = "TRUE" - parallel0.startConnected = "TRUE" - parallel0.fileType = "device" - parallel0.fileName = "$parallel_0" - parallel0.bidirectional = "TRUE" - parallel0.autodetect = "FALSE" - HEREEND -fi - -# Graphics, GPU: 3D will be enabled (even if vmware doesn't support the chip) if we whitelisted it. -if [ -n "$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}" - -# Apply $maxhardwareversion to final VMX -if [ -n "$HWVER" ] && [ "$HWVER" -gt "$maxhardwareversion" ]; then - writelog "Hardware version capped to $maxhardwareversion (was $HWVER)" - sed -i 's/^virtualHW\.version.*$/virtualHW.version = "'$maxhardwareversion'"/I' "${TMPCONFIG}" - HWVER="$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" \ - && [ "$HWVER" -ge "9" ]; then - . "/run/hwinfo" - [ "${HW_KVM}" = "ENABLED" ] && echo 'vhv.enable = "TRUE"' >> "${TMPCONFIG}" -fi -# TODO: Need a way to check if supported by hardware before enabling! -#grep -qi '^vpmc\.enable' "${TMPCONFIG}" || echo 'vpmc.enable = "TRUE"' >> "${TMPCONFIG}" - -# Disable space check warnings -sed -i '/^mainMem.freeSpaceCheck/Id' "${TMPCONFIG}" -echo 'mainMem.freeSpaceCheck = "FALSE"' >> "${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}" - -# At last_ Let's copy it to $confdir/run-vmware.conf -if cp -p "${TMPCONFIG}" "$conffile"; then - writelog "Copied TMPDIR/IMGUUID ${TMPCONFIG} to conffile ${conffile}" -else - writelog "Could not copy TMPDIR/IMGUUID -${TMPCONFIG}- to conffile ${conffile}!" - cleanexit 1 -fi - diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/run-virt.include b/core/modules/vmware/data/opt/openslx/vmchooser/vmware/run-virt.include deleted file mode 100644 index f66bc9b8..00000000 --- a/core/modules/vmware/data/opt/openslx/vmchooser/vmware/run-virt.include +++ /dev/null @@ -1,60 +0,0 @@ -# ----------------------------------------------------------------------------- -# Copyright (c) 2009..2012 - RZ Uni Freiburg -# Copyright (c) 2009..2013 - 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 -################################################################################ - -################################################################################ -### configuration writer functions -### This needs bash, not dash or ash! (indented HEREDOC) -################################################################################ - -VMWAREINCLUDEDIR=/opt/openslx/vmchooser/vmware/includes -VM_OS_TYPE=$(rv_clean_string "$VM_OS_TYPE") - -# declaration of default variables for vmware -source "${VMWAREINCLUDEDIR}/set_vmware_include_variables.inc" && set_vmware_include_variables -# General global openslx config -source /opt/openslx/config - -# TODO: Where to put global helper functions that could be used in several units below? -vmw_cap_hw_version() { - [ -z "$1" ] && writelog "cap_hw_version called without parameter!" && return 1 - [ "$1" -lt "$maxhardwareversion" ] && maxhardwareversion="$1" -} - -# get information from downloaded vmx -source "${VMWAREINCLUDEDIR}/parse_vmx.inc" - -# determine limitations wrt RAM and CPU count of VM -source "${VMWAREINCLUDEDIR}/determine_hardware_limitations.inc" - -# create file and directory structure for vmware setup -source "${VMWAREINCLUDEDIR}/create_static_directory_structure.inc" - -# create preferences file ${vmhome}/preferences -source "${VMWAREINCLUDEDIR}/create_vmhome_preferences_file.inc" && create_vmhome_preferences_file - -# parse the given vmx file -source "${VMWAREINCLUDEDIR}/write_final_vmx.inc" - -# print summary - needs writelog() from vmchooser-run_virt -source "${VMWAREINCLUDEDIR}/log_config_summary.inc" - -# For debugging -cp "$conffile" "/tmp/vmware-last-config" - -# using the modified version of the wrapper script -VIRTCMD="/opt/openslx/bin/vmplayer" -VIRTCMDOPTS="${vmopt} ${conffile}" - diff --git a/core/modules/vmware/module.build b/core/modules/vmware/module.build index f321b084..f5009fea 100644 --- a/core/modules/vmware/module.build +++ b/core/modules/vmware/module.build @@ -98,11 +98,9 @@ build() { unlink "${MODULE_BUILD_DIR}/$VMWARE_BUNDLE_FILE" # write vmware.conf config file to be later sourced by vmware/run-virt.include. - # This file was formerly stored in data/opt/openslx/vmchooser/vmware/vmware.conf. + mkdir -p "${MODULE_BUILD_DIR}/opt/openslx/vmchooser/plugins/vmware/" || perror "Could not mkdir "${MODULE_BUILD_DIR}/opt/openslx/vmchooser/plugins/vmware/"." - mkdir -p "${MODULE_BUILD_DIR}/opt/openslx/vmchooser/vmware/" || perror "could not mkdir "${MODULE_BUILD_DIR}/opt/openslx/vmchooser/vmware/"." - - cat > "${MODULE_BUILD_DIR}/opt/openslx/vmchooser/vmware/vmware.conf" <<-EOF + cat > "${MODULE_BUILD_DIR}/opt/openslx/vmchooser/plugins/vmware/vmware.conf" <<-EOF # configuration file written by vmware/module.build vmnet0=true vmnet1=192.168.101.1/24 diff --git a/core/modules/vmware/module.conf b/core/modules/vmware/module.conf index 02770c34..50fc0d3d 100644 --- a/core/modules/vmware/module.conf +++ b/core/modules/vmware/module.conf @@ -18,7 +18,7 @@ REQUIRED_DIRECTORIES=" REQUIRED_FILES=" /usr/lib/vmware/config /usr/bin/vmware-usbarbitrator - /opt/openslx/vmchooser/vmware/vmware.conf + /opt/openslx/vmchooser/plugins/vmware/vmware.conf " REQUIRED_BINARIES=" vmnet-netifup |