From 6806ae4a850fc7785a8c05304237cf53b5b8f951 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 23 Dec 2016 13:12:09 +0100 Subject: merge with latest dev version (tm-scripts commit f5a59daf8d70a9027118292cd40b18c221897408) --- .../system/multi-user.target.wants/pvsmgr.service | 1 + .../pvs2/data/etc/systemd/system/pvsmgr.service | 12 +++++++ core/modules/pvs2/data/opt/openslx/bin/pvsstartup | 25 +++++++++++++ .../pvs2/data/opt/openslx/iptables/rules.d/10-pvs | 11 ++++++ .../pvs2/data/opt/openslx/pvs2/lockDesktop.sh | 25 +++++++++++++ .../pvs2/data/opt/openslx/scripts/setup-pvsmgr | 28 ++++++++++++++- .../pvs2/data/opt/openslx/scripts/systemd-pvsmgr | 22 ++++++++++++ .../openslx/vmchooser/sessionstart.d/50-PVSclient | 41 +++++++++++++++++++--- core/modules/pvs2/module.build | 27 +++++++++----- core/modules/pvs2/module.conf | 6 ++++ core/modules/pvs2/module.conf.ubuntu | 7 ++-- 11 files changed, 188 insertions(+), 17 deletions(-) create mode 120000 core/modules/pvs2/data/etc/systemd/system/multi-user.target.wants/pvsmgr.service create mode 100644 core/modules/pvs2/data/etc/systemd/system/pvsmgr.service create mode 100755 core/modules/pvs2/data/opt/openslx/bin/pvsstartup create mode 100755 core/modules/pvs2/data/opt/openslx/iptables/rules.d/10-pvs create mode 100755 core/modules/pvs2/data/opt/openslx/pvs2/lockDesktop.sh create mode 100755 core/modules/pvs2/data/opt/openslx/scripts/systemd-pvsmgr (limited to 'core/modules/pvs2') diff --git a/core/modules/pvs2/data/etc/systemd/system/multi-user.target.wants/pvsmgr.service b/core/modules/pvs2/data/etc/systemd/system/multi-user.target.wants/pvsmgr.service new file mode 120000 index 00000000..cab88a66 --- /dev/null +++ b/core/modules/pvs2/data/etc/systemd/system/multi-user.target.wants/pvsmgr.service @@ -0,0 +1 @@ +../pvsmgr.service \ No newline at end of file diff --git a/core/modules/pvs2/data/etc/systemd/system/pvsmgr.service b/core/modules/pvs2/data/etc/systemd/system/pvsmgr.service new file mode 100644 index 00000000..281e1ab4 --- /dev/null +++ b/core/modules/pvs2/data/etc/systemd/system/pvsmgr.service @@ -0,0 +1,12 @@ +[Unit] +Description=Fetch up to date pvsmgr config +DefaultDependencies=no +After=tmp.target +Wants=tmp.target +Before=graphical.target + +[Service] +Type=oneshot +ExecStart=/opt/openslx/scripts/systemd-pvsmgr +RemainAfterExit=yes + diff --git a/core/modules/pvs2/data/opt/openslx/bin/pvsstartup b/core/modules/pvs2/data/opt/openslx/bin/pvsstartup new file mode 100755 index 00000000..16a01708 --- /dev/null +++ b/core/modules/pvs2/data/opt/openslx/bin/pvsstartup @@ -0,0 +1,25 @@ +#!/bin/ash + +timediff=5 +counter=0 + +. /opt/openslx/config +EXAM= +if [ -n "$SLX_EXAM" ]; then + EXAM="--exam-mode" +fi + +while [ $timediff -gt 3 ]; do + start="$(date +%s)" + pvsclient $EXAM "$@" + ret=$? + end="$(date +%s)" + /opt/openslx/pvs2/kb-unlock.sh + [ "$ret" == "0" ] && break + timediff=$(( end - start )) + counter=$(( counter + 1 )) + [ $counter -gt 8 ] && break +done + +exit $ret + diff --git a/core/modules/pvs2/data/opt/openslx/iptables/rules.d/10-pvs b/core/modules/pvs2/data/opt/openslx/iptables/rules.d/10-pvs new file mode 100755 index 00000000..a24491fa --- /dev/null +++ b/core/modules/pvs2/data/opt/openslx/iptables/rules.d/10-pvs @@ -0,0 +1,11 @@ +#!/bin/ash + +# Allow PVS ports +# Control connection - server and client perspective +iptables -I ipt-helper-INPUT 1 -i br0 -p tcp --dport 5194 -j ACCEPT +iptables -I ipt-helper-OUTPUT 1 -o br0 -p tcp --dport 5194 -j ACCEPT +# UDP discovery - server and client perspective +iptables -I ipt-helper-INPUT 1 -i br0 -p udp --dport 3492 -j ACCEPT +iptables -I ipt-helper-OUTPUT 1 -o br0 -p udp --dport 3492 -j ACCEPT +# VNC connection - incoming (client) only - small range as we use -autoport +iptables -I ipt-helper-INPUT 1 -i br0 -p tcp --dport 54112:54122 -j ACCEPT diff --git a/core/modules/pvs2/data/opt/openslx/pvs2/lockDesktop.sh b/core/modules/pvs2/data/opt/openslx/pvs2/lockDesktop.sh new file mode 100755 index 00000000..c9cfc421 --- /dev/null +++ b/core/modules/pvs2/data/opt/openslx/pvs2/lockDesktop.sh @@ -0,0 +1,25 @@ +#!/bin/ash + +# Problem: While any application (e.g. VMware) is holding the mouse and +# keyboard grab, xscreensaver couldn't grab them, so it will ignore the +# locking request. Without the keyboard grab, all input would still go +# to the vmware window below the black screen, which is, you know, bad, +# since you cannot enter your password to unlock the workstation again. + +# So we minimize vmware, lock the screen, and then restore vmware. +# TODO: Add other virtualizers (vbox, kvm) later if needed. +WINDOWS=$(xdotool search --class vmplayer) +for window in $WINDOWS; do + xdotool windowminimize $window +done +# move mouse pointer to the center of the screen to avoid some problems with ghost clicks +xdotool mousemove --polar 0 0 --sync + +# now actually lock +xscreensaver-command --lock + +# above lock call is blocking, so now xscreensaver should be active - let's restore vmware +for window in $WINDOWS; do + xdotool windowmap $window +done + diff --git a/core/modules/pvs2/data/opt/openslx/scripts/setup-pvsmgr b/core/modules/pvs2/data/opt/openslx/scripts/setup-pvsmgr index dedb0995..5531518a 100755 --- a/core/modules/pvs2/data/opt/openslx/scripts/setup-pvsmgr +++ b/core/modules/pvs2/data/opt/openslx/scripts/setup-pvsmgr @@ -1,4 +1,30 @@ #!/bin/ash +. /opt/openslx/config + +# Try to get fresh version from server +CONF= +if [ -n "$SLX_PVS_CONFIG_URL" ]; then + DST="$(mktemp)" + wget -T 5 -O "${DST}" "$SLX_PVS_CONFIG_URL" + [ -s "${DST}" ] && CONF="--config=${DST}" +fi + openbox & -exec /opt/openslx/bin/pvsmgr + +timediff=5 +counter=0 + +while [ $timediff -gt 3 ]; do + start="$(date +%s)" + /opt/openslx/bin/pvsmgr "$CONF" "$@" + ret=$? + [ "$ret" == "0" ] && break + end="$(date +%s)" + timediff=$(( end - start )) + counter=$(( counter + 1 )) + [ $counter -gt 8 ] && break +done + +exit $ret + diff --git a/core/modules/pvs2/data/opt/openslx/scripts/systemd-pvsmgr b/core/modules/pvs2/data/opt/openslx/scripts/systemd-pvsmgr new file mode 100755 index 00000000..1a56e8d0 --- /dev/null +++ b/core/modules/pvs2/data/opt/openslx/scripts/systemd-pvsmgr @@ -0,0 +1,22 @@ +#!/bin/ash + +. /opt/openslx/config +DST="/opt/openslx/pvs2/pvs2.ini" + +# Try to get fresh version from server +if [ -n "$SLX_PVS_CONFIG_URL" ]; then + wget -T 10 -O "${DST}.new" "$SLX_PVS_CONFIG_URL" + [ -s "${DST}.new" ] && mv -f "${DST}.new" "${DST}" +fi + +# If this is a dedicated PVS station, make it launch right away +if [ -n "$SLX_PVS_DEDICATED" ] && cd /opt/openslx/xsessions; then + for file in *.desktop; do + cp -f "/usr/share/xsessions/pvs2mgr.desktop" "$file" + done + # patch autologin into kdmrc + sed -i '/AutoLogin.*=/d;/^\[X-.*-Core\]/a AutoLoginEnable=true\nAutoLoginUser=demo\nAutoLoginAgain=true\nAutoLoginDelay=0' "/etc/kde/kdm/kdmrc" +fi + +exit 0 + diff --git a/core/modules/pvs2/data/opt/openslx/vmchooser/sessionstart.d/50-PVSclient b/core/modules/pvs2/data/opt/openslx/vmchooser/sessionstart.d/50-PVSclient index 0ad739e0..5ff03227 100755 --- a/core/modules/pvs2/data/opt/openslx/vmchooser/sessionstart.d/50-PVSclient +++ b/core/modules/pvs2/data/opt/openslx/vmchooser/sessionstart.d/50-PVSclient @@ -1,6 +1,6 @@ #!/bin/ash -# SESSION_TYPE can be either 'VSESSION' or 'XSESSION' - currently not evaluated +# 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= @@ -17,10 +17,43 @@ 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 [ -n "$PVS_AUTO_CONNECT" -a "$PVS_AUTO_CONNECT" == "TRUE" ]; then - pvsclient --auto & +if [ "$PVS_AUTO_CONNECT" == "TRUE" ]; then + pvsstartup "$PVSCONFIG" --auto & else - pvsclient & + 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 diff --git a/core/modules/pvs2/module.build b/core/modules/pvs2/module.build index b7ccfa47..f356e1bc 100644 --- a/core/modules/pvs2/module.build +++ b/core/modules/pvs2/module.build @@ -1,28 +1,37 @@ #!/bin/bash fetch_source() { - git clone "${REQUIRED_GIT}" src + git clone "${REQUIRED_GIT}" "${MODULE_WORK_DIR}/src" } build() { - local SRCDIR="${MODULE_WORK_DIR}/src/" - local BUILDDIR="$SRCDIR/build/" - local DESTDIR="$MODULE_BUILD_DIR/opt/openslx/bin" + local BUILDDIR="${SRCDIR}/build/" + local DESTDIR="${MODULE_BUILD_DIR}/opt/openslx/bin" # first activate qt 4 activate_qt 4 - mkdir -p "$DESTDIR" || perror "Could not mkdir $DESTDIR!" - mkdir -p "$BUILDDIR" || perror "Could not mkdir $BUILDDIR!" - cd "$BUILDDIR" || perror "Could not cd to $BUILDDIR!" + mkdir -p "${DESTDIR}" || perror "Could not mkdir ${DESTDIR}!" + mkdir -p "${BUILDDIR}" || perror "Could not mkdir ${BUILDDIR}!" + cd "${BUILDDIR}" || perror "Could not cd to ${BUILDDIR}!" pinfo "Running cmake" cmake .. || perror "'cmake ..' failed." pinfo "Running make" make || perror "'make' failed." - mv pvsmgr pvsclient $DESTDIR - cd - > /dev/null + mv pvsmgr pvsclient "${DESTDIR}" + cd .. + + # copy external scripts under 'sample_configuration' + mkdir -p "${MODULE_BUILD_DIR}/opt/openslx/pvs2/" + if [ -d "${SRCDIR}/sample_configuration" ]; then + # Do not copy lockDesktop.sh - we ship a modified one + cp "${SRCDIR}/sample_configuration"/{kb-lock,kb-unlock,switchToManager,switchBack}.sh "${MODULE_BUILD_DIR}/opt/openslx/pvs2/" \ + || perror "Could not copy external scripts to '${MODULE_BUILD_DIR}/opt/openslx/pvs2/'!" + chmod +x "${MODULE_BUILD_DIR}/opt/openslx/pvs2"/*.sh \ + || perror "Could not set executable bit for external scripts." + fi # needed for copying REQUIRED_CONTENT_PACKAGES to build/ COPYLIST="list_dpkg_output" diff --git a/core/modules/pvs2/module.conf b/core/modules/pvs2/module.conf index 9ef50afd..5e7a9a6f 100644 --- a/core/modules/pvs2/module.conf +++ b/core/modules/pvs2/module.conf @@ -2,6 +2,12 @@ REQUIRED_GIT="git://git.openslx.org/pvs2.git" REQUIRED_BINARIES=" pvsmgr pvsclient + xinput + wmctrl +" +REQUIRED_DIRECTORIES=" + /opt/openslx/pvs2/ + /usr/lib/ " REQUIRED_LIBRARIES=" " diff --git a/core/modules/pvs2/module.conf.ubuntu b/core/modules/pvs2/module.conf.ubuntu index 4dcf2794..8a48ec93 100644 --- a/core/modules/pvs2/module.conf.ubuntu +++ b/core/modules/pvs2/module.conf.ubuntu @@ -1,11 +1,12 @@ REQUIRED_INSTALLED_PACKAGES=" libqt4-dev libvncserver-dev + xinput + wmctrl " REQUIRED_CONTENT_PACKAGES=" libqt4-svg libqtgui4 -" -REQUIRED_DIRECTORIES=" - /usr/lib/ + xinput + wmctrl " -- cgit v1.2.3-55-g7522