summaryrefslogtreecommitdiffstats
path: root/remote/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt
blob: 10943c516335e567ea253be489c372e2ad37e9b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
# Full bash required
# -----------------------------------------------------------------------------
# Copyright (c) 2007..2010 - RZ Uni FR
# Copyright (c) 2007..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.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.
################################################################################

RUNVIRTINCLUDEDIR=/opt/openslx/vmchooser/run-virt-includes
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
fi

trap 'trap "" SIGINT SIGTERM; cleanexit' SIGINT SIGTERM
# Define default dirs / get configs
source "${RUNVIRTINCLUDEDIR}/set_runvirt_variables.inc"
# Function to detect whether we can use the new way (vmx via http) or the old way (legacy):
source "${RUNVIRTINCLUDEDIR}/detect_legacy.inc" # This yields LEGACY, IMGUUID, IMGVMX

if [ "$LEGACY" ]; then

	# No longer supported - yay

	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

	# End legacy warning
fi

# Proper meta data received - proceed normally

# check for important files used (filecheck()) - vestigial?
# This include does not currently work. TODO.
# source ${RUNVIRTINCLUDEDIR}/check_runvirt_needed_files.inc && filecheck

# Read needed variables from XML file
source ${RUNVIRTINCLUDEDIR}/get_xml_file_variables.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"

# Firewall
source "${RUNVIRTINCLUDEDIR}/setup_firewall.inc" || writelog "Could not source setup_firewall"
setup_firewall || writelog "Could not run setup_firewall"

# Sound setup
source ${RUNVIRTINCLUDEDIR}/setup_sound.inc

# Declaration of hardware relatedt variables
source ${RUNVIRTINCLUDEDIR}/set_runvirt_hardware_variables.inc

# Start printer daemon
source ${RUNVIRTINCLUDEDIR}/setup_printer_lpd.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

# Window manager required for handling of popups etc.
source ${RUNVIRTINCLUDEDIR}/start_windowmanager.inc

# Source run-virt.include of virtualizer
setup_vm_commandline

# It should have set this variable if all went well
if [ -z "${VIRTCMD}" ]; then
	error_user "Fehler beim Starten der VM-Sitzung" "
Das Start-Script für den Virtualisierer $xmlvirt hat kein Kommando
zum Starten der Sitzung definiert. Kann Sitzung nicht initialisieren."
	slxlog "virt-plugin-error" "run-virt.include for $xmlvirt did not set VIRTCMD"
	cleanexit 1
fi

writelog "VM command: eval ${VIRTCMD} ${VIRTCMDOPTS}"
# This will start the VM
eval ${VIRTCMD} ${VIRTCMDOPTS}

writelog "Virtualizer exited. Bye."

# Postrun for commands after virtualization finishes
if [ -n "${POSTRUN}" ]; then
	eval ${POSTRUN}  >/dev/null 2>&1
fi

cleanexit 0