summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc
blob: eb9030fa601adb2891edafd688fd1d6f7dd9d9f4 (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
# -----------------------------------------------------------------------------
#
# Copyright (c) 2009..2021 bwLehrpool-Projektteam
#
# This program/file is free software distributed under the GPL version 2.
# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
#
# If you have any feedback please consult https://bwlehrpool.de and
# send your feedback to support@bwlehrpool.de.
#
# General information about bwLehrpool can be found at https://bwlehrpool.de
#
# -----------------------------------------------------------------------------
# Utils and functions to parse Linux kernel command line options
# -----------------------------------------------------------------------------

#
# Return     :
function create_rw_diskimage() {
	# writelog "Creating rw image for qemu to safe and upload the snapshot later"

	# Register upload function to trigger before the cleanup deletes the tmp image snapshot
	add_cleanup upload_qemu_rw

	# If the edit checkbox is checked the environment variable VMCHOOSER_ADMIN_MODE is TRUE
	# ALLOW_EDIT=${VMCHOOSER_ADMIN_MODE}
}

# Helper to safe and upload the image before the cleanup deletes everything
upload_qemu_rw() {

	# writelog "Calling scp task trigger on SAT"
	# SERVERIP=$SLX_PXE_SERVER_IP
	# Call slx-admin api to trigger taskmanager ScpSnapshot task with all the info needed
	# LECTUREID=$IMGUUID
	# CLIENTIP=$SLX_PXE_CLIENT_IP
	# curl "http://$SERVERIP/slx-admin/api.php?do=remoteaccess&action=scp&lectureid=$LECTUREID&clientip=$CLIENTIP"
	# Image will be deleted by SAT via SSH after finished downloading


	# LECTUREID=$IMGUUID
	# CLIENTIP=$SLX_PXE_CLIENT_IP
	SERVERIP=$SLX_PXE_SERVER_IP
	SESSIONID=$(cat /var/lib/lightdm/editsession.id)

	# Open firefox where the user can either safe or cancel
	# Prepare firefox to not start the privacy "first launch" Page
	firefox --CreateProfile progress
	FFPROFILE=$(realpath ~/.mozilla/firefox/*.progress)
	echo 'user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);' >> $FFPROFILE/user.js

	# Start firefox and wait for the process
	firefox --kiosk http://$SERVERIP:5000/progress/$SESSIONID -P progress &
	FFPID="$!"
	writelog "FF PID IS: $FFPID"
	writelog "Waiting for firefox to exit"
	wait $!
	writelog "Firefox exited"

	# At this point the snapshot was either downloaded by the sat or the edit session was cancelled and can be deleted
	rm -rf /tmp/upload

	# No permission to delete this file
	# rm -f /var/lib/lightdm/editsession.id
	# Remove the /var/lib/lightdm/edit.desktop that the slxgreeter created for autostart-editmode-login
	# rm /var/lib/lightdm/edit.desktop
}