summaryrefslogtreecommitdiffstats
path: root/remote/modules/pvs2/data/opt/openslx/vmchooser/sessionstart.d/50-PVSclient
blob: 5ff03227d8d6b90ed7afe3445aaf2e192fb6b6d0 (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
#!/bin/ash

# SESSION_TYPE can be either 'VSESSION' or 'XSESSION'

# detect session command of the PVS-Manager session by looking at the xsession file
PVSMGR_SESSION_CMD=
PVSMGR_XSESSION_FILE="pvs2mgr.desktop"
# the second directory should not be needed, but lets be compatible with the old crap......
for DIR in "/usr/share/xsessions" "/opt/openslx/xsessions/"; do
	if [ -f "${DIR}/${PVSMGR_XSESSION_FILE}" ]; then
		# extract the exact command string
		PVSMGR_SESSION_CMD="$(grep -E "^Exec=.*$" "${DIR}/${PVSMGR_XSESSION_FILE}" |cut -c 6-)"
		break
	fi
done
if [ -n "${PVSMGR_SESSION_CMD}" ]; then
	# do not start pvsclient if we are running the pvs manager session
	[ "x${SESSION_CMD}" == "x${PVSMGR_SESSION_CMD}" ] && exit 0
fi

# Download fresh copy of config file if possible
. /opt/openslx/config
PVSCONFIG=
if [ -n "$SLX_PVS_CONFIG_URL" ]; then
		[ -z "$UID" ] && UID="$(id -u)"
		[ -z "$HOME" ] && HOME="$(getent passwd "$UID" | head -n 1 | awk -F ':' '{print $6}')"
		mkdir -p "$HOME/.tmp"
		if wget -T 5 -O "$HOME/.tmp/pvs2.ini.tmp" "$SLX_PVS_CONFIG_URL"; then
			mv -f "$HOME/.tmp/pvs2.ini.tmp" "$HOME/.tmp/pvs2.ini"
		fi
		if ! [ -s "$HOME/.tmp/pvs2.ini" ] && [ -s "/opt/openslx/pvs2/pvs2.ini" ]; then
			cp -f "/opt/openslx/pvs2/pvs2.ini" "$HOME/.tmp/pvs2.ini"
		fi
		if [ -s "$HOME/.tmp/pvs2.ini" ]; then
			PVSCONFIG="--config=$HOME/.tmp/pvs2.ini"
		fi
fi

# If the ENV var PVS has been set by vmchooser start pvsclient
if [ "$PVS_AUTO_CONNECT" == "TRUE" ]; then
	pvsstartup "$PVSCONFIG" --auto &
else
	pvsstartup "$PVSCONFIG" &
fi

# Finally, handle hybrid mode where the pvsmgr is launched on the second desktop
# alongside the actual vm. (make sure this is a VSESSION!)
if [ "$SESSION_TYPE" == "VSESSION" ]; then
	{
		wt="PVS2-Manager"
		pvsmgr "$PVSCONFIG" --manager-only &
		for i in 100 100 200 200 200 300 500 500 1000; do
			usleep $(( i * 1000 )) || sleep 1
			wmctrl -r "$wt" -t 1
		done
	} &
fi

exit 0