From 3ba5a58e5b04b771e6ee99ee6d6f772991c1c236 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 2 Aug 2013 17:27:28 +0200 Subject: [vmchooser] moved all vmchooser specific files and scripts to /opt/openslx. Renamed 'var/lib/virt' to 'mnt/vmstore'. Added bwlehrpool theme for vmchooser# --- .../vmchooser/data/opt/openslx/scripts/run-virt.sh | 466 --------------------- .../opt/openslx/scripts/systemd-mount_vm_store | 6 +- .../data/opt/openslx/scripts/systemd-vmchooser_env | 112 +++++ .../data/opt/openslx/scripts/vmchooser-run_virt | 464 ++++++++++++++++++++ .../data/opt/openslx/scripts/vmchooser-xml_filter | 64 +++ 5 files changed, 642 insertions(+), 470 deletions(-) delete mode 100755 remote/modules/vmchooser/data/opt/openslx/scripts/run-virt.sh create mode 100755 remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env create mode 100755 remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt create mode 100755 remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-xml_filter (limited to 'remote/modules/vmchooser/data/opt/openslx/scripts') diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/run-virt.sh b/remote/modules/vmchooser/data/opt/openslx/scripts/run-virt.sh deleted file mode 100755 index 473dfbc7..00000000 --- a/remote/modules/vmchooser/data/opt/openslx/scripts/run-virt.sh +++ /dev/null @@ -1,466 +0,0 @@ -#!/bin/bash -# ----------------------------------------------------------------------------- -# Copyright (c) 2007..2010 - RZ Uni FR -# Copyright (c) 2007..2011 - 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.sh -# - This is the generic wrapper for the several virtualization solutions. -# The idea is to setup a set of variables used by at least two different -# tools and then include the specific plugin which configures the speci- -# fied virtualization tool. -################################################################################ - -################################################################################ -### Define default dirs / get configs -################################################################################ - -PLUGINCONFROOT=/etc/opt/openslx/plugins -PLUGINCONFDIR=/etc/opt/openslx/plugins/vmchooser -# include general configuration from vmchooser -[ -f /etc/openslx/vmchooser/vmchooser.conf ] && \ -. /etc/openslx/vmchooser/vmchooser.conf -# load general virtualization information -[ -f /etc/openslx/vmchooser/virtualization.conf ] && \ -. /etc/openslx/vmchooser/virtualization.conf - -################################################################################ -### Functions used throughout the script -################################################################################ - -# function to write to stdout and logfile -LOGFILE=/var/log/openslx/run-virt.${USER}.$$.log -writelog () { - # write to stdout - echo -e "$1" - # log into file - echo -e "$1" >> ${LOGFILE} -} - -# remove config dirs when exit -cleanexit () { - if echo "${RMDIRS}" 2>/dev/null | grep -q ${xmlvirt}; then - writelog "${xmlvirt} exited. Cleanning up... \c" - rm -rf ${RMDIRS} >/dev/null 2>&1 - writelog "done" - fi - - exit "$1" -} - -# check for important files used -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 -} - -################################################################################ -### Get XML file and dir -################################################################################ - -## Added for persistent support. -diskmode='nonpersistent' -xmlfile="$1" -if [[ "$(grep --extended-regexp '< *persistent *param=".+"' "$xmlfile")" ]]; then - imageFilePath="$(grep -io '/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")" - -################################################################################ -### Sanity checks -################################################################################ - -# test if the xml file is valid -if ! [ -r "${xmlfile}" ]; then - writelog "${xmlfile} not a readable XML file!" - exit 1 -fi - -# test if XML file -if ! grep '/dev/null 2>&1; then - writelog "Submitted configuration file ${xmlfile} seems to have wrong XML format" - exit 1 -fi - -# check for running in graphical environment otherwise no much use here -[ -z "$DISPLAY" ] && echo -e "\n\tStart only within a graphical desktop!\n" \ -&& exit 1 - -################################################################################ -### Logo for console -################################################################################ - -cat </dev/null | grep -q '^/' >/dev/null 2>&1; 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}" 2>/dev/null | grep -q '^/tmp/' >/dev/null 2>&1; then - vmpath="$imgname" - imgname="$(basename "${imgname}")" - ## Added for persistent support. - elif [[ "$userBranchFilePath" ]]; then - vmpath="$userBranchFilePath" - ## - # Else use same path as xml -else - imgpath="${xmlpath}" - vmpath="${imgpath}/${imgname}" -fi - -# Check if virtual machine container file exists -if ! [ -e "${vmpath}" ]; then - writelog "Virtual machine image ${vmpath} not found!" - exit 1 -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 '/dev/null | \ -awk -F '=' {'print $2'} | tr "[A-Z]" "[a-z]") - -# Add rw share -sharepath="${HOME}" -sharename="home" - -# Set hostname: using original hostname and adding string -hostname="virt-$(hostname)" - -writelog "\tVM Hostname:\t\t$hostname" - -################################################################################ -### Setup the rest of the environment and run the configured vm -################################################################################ -# 8086:1e20 -if lspci -n | grep -E -i '8086:1e20( |$)'; then - VOL="100%" # bwPC 4: Speaker too quiet :-( -else - VOL="80%" -fi -# Adjust sound volume -#writelog "Unmuting sound...\c " -amixer -q sset Master "$VOL" unmute 2>/dev/null -amixer -q sset PCM "$VOL" unmute 2>/dev/null -amixer -q sset CD "$VOL" unmute 2>/dev/null -amixer -q sset Headphone "$VOL" unmute 2>/dev/null -amixer -q sset Front "$VOL" unmute 2>/dev/null # in SUSE 11.0 it's headphone -amixer -q sset Speaker "$VOL" unmute 2>/dev/null # annoying built-in speaker -#writelog "finished\n" - -# Load kvm modules -if [ "$vtflag" = "1" -a -n "$kvm_module" ]; then - modprobe "$kvm_module" -fi - -# Copy guest configuration (with added information) config.xml to be accessed -# via virtual floppy -cp "$xmlfile" "/etc/openslx/vmchooser/fd-loop/config.xml" -# Add another file with resolution information -xrandr | grep -o -E 'current\s*[0-9]+\s*x\s*[0-9]+' | cut -c 8- | sed -r 's/(\s|\t|\n)//g' | head -n 1 > "/etc/openslx/vmchooser/fd-loop/hostres.txt" - -# Get all virtual machine specific stuff from the respective include file -if [ -e /etc/openslx/"${xmlvirt}"/run-virt.include ] ; then - self="${xmlvirt}" - . /etc/openslx/"${xmlvirt}"/run-virt.include - # start a windowmanager for easier handling - # (expect problems /w windows opening in background /w vmware without wm) - for dm in twm xfwm4 metacity openbox blackbox kwin fvwm2 ; do - if which $dm >/dev/null 2>&1 ; then - if [ "$dm" = "fvwm2" ] ; then - echo "EdgeScroll 0 0" > ${redodir}/fvwm - fvwm2 -f ${redodir}/fvwm >/dev/null 2>&1 & - else - $dm >/dev/null 2>&1 & - fi - break - fi - done - # Start poolvideoswitch if we find the autostarter file - #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 - eval ${VIRTCMD} ${VIRTCMDOPTS} - writelog "Bye." - - # Postrun for commands after virtualization finishes - if [ -n "${POSTRUN}" ]; then - eval ${POSTRUN} >/dev/null 2>&1 - fi - - cleanexit 0 -else - writelog "Failed because of missing ${xmlvirt} plugin." - cleanexit 1 -fi - -# Postrun for commands after virtualization finishes -if [ -n "${POSTRUN}" ]; then - eval ${POSTRUN} >/dev/null 2>&1 -fi - -cleanexit 0 -exit 0 diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store index 27a8f55c..75af39fe 100755 --- a/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store @@ -2,7 +2,5 @@ . /opt/openslx/config || exit 1 -export PATH="$PATH:/opt/openslx/bin:/opt/openslx/usr/bin:/opt/openslx/sbin:/opt/openslx/usr/sbin" - -mkdir -p /var/lib/virt -mount -t nfs -o ro,async,nolock,vers=3 "$SLX_VM_NFS" /var/lib/virt +mkdir -p /mnt/vmstore +mount -t nfs -o ro,async,nolock,vers=3 "$SLX_VM_NFS" /mnt/vmstore diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env new file mode 100755 index 00000000..50eace20 --- /dev/null +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env @@ -0,0 +1,112 @@ +#!/bin/sh + +export PATH=$PATH:/opt/openslx/bin:/opt/openslx/sbin:/opt/openslx/usr/bin:/opt/openslx/usr/sbin + +#source config file with vars (e.g. ipaddr, macaddr, hostname) +. /opt/openslx/config + +#from plugins/vmchooser/40-started-hw-config/run-virt.sh +#TODO: extra systemd-service for hwinfo +hwinfo --cdrom | grep -i "Device File:" | awk {'print $3'} >/etc/openslx/hwinfo.cdrom +hwinfo --floppy | grep -i "Device File:" | awk {'print $3'} >/etc/openslx/hwinfo.floppy + +#from plugins/vmchooser/XX_vmchooser.sh +VMCHOOSER_CONF_DIR=/opt/openslx/etc/vmchooser + +mkdir -p ${VMCHOOSER_CONF_DIR}/loopimg +mkdir -p ${VMCHOOSER_CONF_DIR}/fd-loop -m 1777 + +# mount a clean tempfs (bug in UnionFS prevents loopmount to work) +grep -qE "unionfs |aufs " /proc/mounts && \ +mount -n -o size=1500k -t tmpfs vm-loopimg ${VMCHOOSER_CONF_DIR}/loopimg + +# create an empty floppy image of 1.4MByte size +dd if=/dev/zero of=${VMCHOOSER_CONF_DIR}/loopimg/fd.img count=2880 bs=512 2>/dev/null +chmod 0777 ${VMCHOOSER_CONF_DIR}/loopimg/fd.img + +# use dos formatter copied into stage3 +mkdosfs ${VMCHOOSER_CONF_DIR}/loopimg/fd.img >/dev/null 2>&1 #|| error +mount -n -t msdos -o loop,umask=000 ${VMCHOOSER_CONF_DIR}/loopimg/fd.img \ + ${VMCHOOSER_CONF_DIR}/fd-loop + +#pvs integration +#if [ $vmchooser_pvs -ne 0 ]; then +# sed -i /usr/share/xsessions/default.desktop \ +# -e "s,vmchooser$,vmchooser --pvs," +#fi + +# setup more scratch space for virtual machines, if configured +mkdir -p /tmp/virt +mkdir -p /var/log/samba + +# enable normal users to setup the extended virtual machine redo file space +# and image source via network block device (NBD only at the moment) +# allow to start/stop samba on virtual devices (latter one ignores multiple +# independent daemons) + +#cat >> /mnt/etc/sudoers << EOF +# allow to start and stop the special /tmp redo file space (RAM + NBD/NFS server RAID) +#ALL ALL=NOPASSWD: /sbin/losetup /dev/loop* +#ALL ALL=NOPASSWD: /sbin/mdadm -C /dev/md0 -l linear --raid-devices=2 /dev/loop* /dev/* +#ALL ALL=NOPASSWD: /opt/openslx/rootfs/usr/sbin/nbd-client * * /dev/nbd* +# allow to configure and start/stop samba services +#ALL ALL=NOPASSWD: /opt/openslx/rootfs/bin/sed -i /etc/*/smb.conf -e * +#ALL ALL=NOPASSWD: /usr/sbin/nmbd -s /etc/*/smb.conf +#ALL ALL=NOPASSWD: /usr/sbin/smbd -s /etc/*/smb.conf +#ALL ALL=NOPASSWD: /opt/openslx/rootfs/usr/bin/killall nmbd smbd +#EOF + +#from plugins/vmchooser/80-after-plugins/virtualization.sh + +# change 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="$[ ( $mem_free + $mem_cached + $mem_swapcached ) / 1024 ]" +echo "totalmem=${totalmem}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + +# 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 +else + echo 'cpu_cores=1' >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +fi + +# arch +echo "host_arch=$(uname -m)" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + +# VT enabled cpu? +if grep -q ^flags.*\\\ /proc/cpuinfo; then + echo "vtflag=1" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + echo 'kvm_module="kvm_intel"' >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + elif grep -q ^flags.*\\\ /proc/cpuinfo; then + echo "vtflag=1" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + echo 'kvm_module="kvm_amd"' >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + else + echo "vtflag=0" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +fi + +# write mac +echo "hostmacaddr=${SLX_PXE_MAC}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +# ip addr +echo "hostip=${SLX_PXE_CLIENT_IP}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +# hostname +echo "hostname=${SLX_HOSTNAME}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + +# get further hw information +j=0 +for i in $(cat /etc/openslx/hwinfo.cdrom); do + echo "cdrom_$j=$i" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + j=$(expr $j + 1) +done + +j=0 +for i in $(cat /etc/openslx/hwinfo.floppy); do + echo "floppy_$j=$i" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + j=$(expr $j + 1) +done + diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt new file mode 100755 index 00000000..874669dd --- /dev/null +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt @@ -0,0 +1,464 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Copyright (c) 2007..2010 - RZ Uni FR +# Copyright (c) 2007..2011 - 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.sh +# - This is the generic wrapper for the several virtualization solutions. +# The idea is to setup a set of variables used by at least two different +# tools and then include the specific plugin which configures the speci- +# fied virtualization tool. +################################################################################ + +################################################################################ +### Define default dirs / get configs +################################################################################ + +# include general configuration from vmchooser +[ -f /opt/openslx/etc/vmchooser/vmchooser.conf ] && \ +. /opt/openslx/etc/vmchooser/vmchooser.conf +# load general virtualization information +[ -f /opt/openslx/etc/vmchooser/virtualization.conf ] && \ +. /opt/openslx/etc/vmchooser/virtualization.conf + +################################################################################ +### Functions used throughout the script +################################################################################ + +# function to write to stdout and logfile +LOGFILE=/var/log/openslx/run-virt.${USER}.$$.log +writelog () { + # write to stdout + echo -e "$1" + # log into file + echo -e "$1" >> ${LOGFILE} +} + +# remove config dirs when exit +cleanexit () { + if echo "${RMDIRS}" 2>/dev/null | grep -q ${xmlvirt}; then + writelog "${xmlvirt} exited. Cleanning up... \c" + rm -rf ${RMDIRS} >/dev/null 2>&1 + writelog "done" + fi + + exit "$1" +} + +# check for important files used +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 +} + +################################################################################ +### Get XML file and dir +################################################################################ + +## Added for persistent support. +diskmode='nonpersistent' +xmlfile="$1" +if [[ "$(grep --extended-regexp '< *persistent *param=".+"' "$xmlfile")" ]]; then + imageFilePath="$(grep -io '/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")" + +################################################################################ +### Sanity checks +################################################################################ + +# test if the xml file is valid +if ! [ -r "${xmlfile}" ]; then + writelog "${xmlfile} not a readable XML file!" + exit 1 +fi + +# test if XML file +if ! grep '/dev/null 2>&1; then + writelog "Submitted configuration file ${xmlfile} seems to have wrong XML format" + exit 1 +fi + +# check for running in graphical environment otherwise no much use here +[ -z "$DISPLAY" ] && echo -e "\n\tStart only within a graphical desktop!\n" \ +&& exit 1 + +################################################################################ +### Logo for console +################################################################################ + +cat </dev/null | grep -q '^/' >/dev/null 2>&1; 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}" 2>/dev/null | grep -q '^/tmp/' >/dev/null 2>&1; then + vmpath="$imgname" + imgname="$(basename "${imgname}")" + ## Added for persistent support. + elif [[ "$userBranchFilePath" ]]; then + vmpath="$userBranchFilePath" + ## + # Else use same path as xml +else + imgpath="${xmlpath}" + vmpath="${imgpath}/${imgname}" +fi + +# Check if virtual machine container file exists +if ! [ -e "${vmpath}" ]; then + writelog "Virtual machine image ${vmpath} not found!" + exit 1 +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 '/dev/null | \ +awk -F '=' {'print $2'} | tr "[A-Z]" "[a-z]") + +# Add rw share +sharepath="${HOME}" +sharename="home" + +# Set hostname: using original hostname and adding string +hostname="virt-$(hostname)" + +writelog "\tVM Hostname:\t\t$hostname" + +################################################################################ +### Setup the rest of the environment and run the configured vm +################################################################################ +# 8086:1e20 +if lspci -n | grep -E -i '8086:1e20( |$)'; then + VOL="100%" # bwPC 4: Speaker too quiet :-( +else + VOL="80%" +fi +# Adjust sound volume +#writelog "Unmuting sound...\c " +amixer -q sset Master "$VOL" unmute 2>/dev/null +amixer -q sset PCM "$VOL" unmute 2>/dev/null +amixer -q sset CD "$VOL" unmute 2>/dev/null +amixer -q sset Headphone "$VOL" unmute 2>/dev/null +amixer -q sset Front "$VOL" unmute 2>/dev/null # in SUSE 11.0 it's headphone +amixer -q sset Speaker "$VOL" unmute 2>/dev/null # annoying built-in speaker +#writelog "finished\n" + +# Load kvm modules +if [ "$vtflag" = "1" -a -n "$kvm_module" ]; then + modprobe "$kvm_module" +fi + +# Copy guest configuration (with added information) config.xml to be accessed +# via virtual floppy +cp "$xmlfile" "/opt/openslx/etc/vmchooser/fd-loop/config.xml" +# Add another file with resolution information +xrandr | grep -o -E 'current\s*[0-9]+\s*x\s*[0-9]+' | cut -c 8- | sed -r 's/(\s|\t|\n)//g' | head -n 1 > "/opt/openslx/etc/vmchooser/fd-loop/hostres.txt" + +# Get all virtual machine specific stuff from the respective include file +if [ -e /opt/openslx/etc/"${xmlvirt}"/run-virt.include ] ; then + self="${xmlvirt}" + . /opt/openslx/etc/"${xmlvirt}"/run-virt.include + # start a windowmanager for easier handling + # (expect problems /w windows opening in background /w vmware without wm) + for dm in twm xfwm4 metacity openbox blackbox kwin fvwm2 ; do + if which $dm >/dev/null 2>&1 ; then + if [ "$dm" = "fvwm2" ] ; then + echo "EdgeScroll 0 0" > ${redodir}/fvwm + fvwm2 -f ${redodir}/fvwm >/dev/null 2>&1 & + else + $dm >/dev/null 2>&1 & + fi + break + fi + done + # Start poolvideoswitch if we find the autostarter file + #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 + eval ${VIRTCMD} ${VIRTCMDOPTS} + writelog "Bye." + + # Postrun for commands after virtualization finishes + if [ -n "${POSTRUN}" ]; then + eval ${POSTRUN} >/dev/null 2>&1 + fi + + cleanexit 0 +else + writelog "Failed because of missing ${xmlvirt} plugin." + cleanexit 1 +fi + +# Postrun for commands after virtualization finishes +if [ -n "${POSTRUN}" ]; then + eval ${POSTRUN} >/dev/null 2>&1 +fi + +cleanexit 0 +exit 0 diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-xml_filter b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-xml_filter new file mode 100755 index 00000000..67e49d3e --- /dev/null +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-xml_filter @@ -0,0 +1,64 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Copyright (c) 2007..2009 - RZ Uni FR +# Copyright (c) 2007..2011 - 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/ +# ----------------------------------------------------------------------------- +# xmlfilter.sh +# - This script is invoked by the vmchooser tool. It simply filters xml- +# files (taking the path to these files in $1). You might modify it in any +# way to match your needs, e.g. ask some database instead. You can re- +# implement it in any other programming language too. You simply have to +# return a list of proper xml files to be interpreted by the vmchooser +# binary). Please check for vmchooser.sh too ... +# ----------------------------------------------------------------------------- + +# This script . +# +# currently: +# - filter for slxgrp (which comes from /etc/machine-setup) +# + +# include default directories +. /etc/opt/openslx/openslx.conf + +if [ -f ${OPENSLX_DEFAULT_CONFDIR}/plugins/vmchooser/vmchooser.conf ]; then + . ${OPENSLX_DEFAULT_CONFDIR}/plugins/vmchooser/vmchooser.conf +fi + +function handlePersistentVM() { + if [[ "$(grep --extended-regexp \ + "