summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc
blob: b3bc1cdfe48d5f09d547fa7e393b02197773316e (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
#!/bin/bash
################################################
# 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 TMPDIR="/tmp/virt/${USER}/$$"

# Check if the path to the logfile was given externally (by the wrapper)
unset WRAPPED
if notempty LOGFILE; then
	if [ ! -w "${LOGFILE}" ]; then
		# given logfile is not writeable or non-existant
		# so handle it ourself (so do not set WRAPPED)
		rm -f "${LOGFILE}"
		unset LOGFILE
	else
		# given logfile was ok, mark that we are wrapped
		# (for cleanexit to not slxlog the log since
		# the wrapper is handling that for us)
		declare -rg WRAPPED=aye
	fi
fi
isset LOGFILE || declare -rg LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log"

# 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

# Determine if /tmp resides on the hdd
# This variable is empty (but set!) if no hard drive was mounted on /tmp
# else it will be non-empty (check with helper function 'notempty').
declare -g TMP_ON_HDD=
if ! grep -q -E '\s+/tmp\s+tmpfs\s+' '/proc/mounts'; then
	writelog "Hard drive partition mounted on /tmp"
	TMP_ON_HDD=1
	readonly TMP_ON_HDD
fi

# Get a unique VM_ID for the current invocation
get_vm_id