From 6eea8f48ac415be6208ffb55167b67a539874ac4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Sep 2016 12:34:05 +0200 Subject: [pvs2] Support fetching remote pvs2.ini; honor exam mode, dedicated flag --- .../system/multi-user.target.wants/pvsmgr.service | 1 + .../pvs2/data/etc/systemd/system/pvsmgr.service | 12 +++++++++ .../modules/pvs2/data/opt/openslx/bin/pvsstartup | 13 +++++++++- .../pvs2/data/opt/openslx/scripts/setup-pvsmgr | 8 ++++++ .../pvs2/data/opt/openslx/scripts/systemd-pvsmgr | 30 ++++++++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 120000 remote/modules/pvs2/data/etc/systemd/system/multi-user.target.wants/pvsmgr.service create mode 100644 remote/modules/pvs2/data/etc/systemd/system/pvsmgr.service create mode 100644 remote/modules/pvs2/data/opt/openslx/scripts/systemd-pvsmgr diff --git a/remote/modules/pvs2/data/etc/systemd/system/multi-user.target.wants/pvsmgr.service b/remote/modules/pvs2/data/etc/systemd/system/multi-user.target.wants/pvsmgr.service new file mode 120000 index 00000000..cab88a66 --- /dev/null +++ b/remote/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/remote/modules/pvs2/data/etc/systemd/system/pvsmgr.service b/remote/modules/pvs2/data/etc/systemd/system/pvsmgr.service new file mode 100644 index 00000000..281e1ab4 --- /dev/null +++ b/remote/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/remote/modules/pvs2/data/opt/openslx/bin/pvsstartup b/remote/modules/pvs2/data/opt/openslx/bin/pvsstartup index b77dcd51..dc7bd48a 100755 --- a/remote/modules/pvs2/data/opt/openslx/bin/pvsstartup +++ b/remote/modules/pvs2/data/opt/openslx/bin/pvsstartup @@ -1,7 +1,15 @@ #!/bin/ash -# TODO UNTESTED! timediff=5 +counter=0 + +. /opt/openslx/config +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}')" + wget -O "$HOME/.config/openslx/pvs2/pvs2.ini" "$SLX_PVS_CONFIG_URL" +fi + while [ $timediff -gt 3 ]; do start="$(date +%s)" pvsclient "$@" @@ -10,6 +18,9 @@ while [ $timediff -gt 3 ]; do /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/remote/modules/pvs2/data/opt/openslx/scripts/setup-pvsmgr b/remote/modules/pvs2/data/opt/openslx/scripts/setup-pvsmgr index 7a6c13d9..f58ce099 100755 --- a/remote/modules/pvs2/data/opt/openslx/scripts/setup-pvsmgr +++ b/remote/modules/pvs2/data/opt/openslx/scripts/setup-pvsmgr @@ -1,4 +1,12 @@ #!/bin/ash openbox & + +. /opt/openslx/config +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}')" + wget -O "$HOME/.config/openslx/pvs2/pvs2.ini" "$SLX_PVS_CONFIG_URL" +fi + exec /opt/openslx/bin/pvsmgr --manager-only diff --git a/remote/modules/pvs2/data/opt/openslx/scripts/systemd-pvsmgr b/remote/modules/pvs2/data/opt/openslx/scripts/systemd-pvsmgr new file mode 100644 index 00000000..34ae61d5 --- /dev/null +++ b/remote/modules/pvs2/data/opt/openslx/scripts/systemd-pvsmgr @@ -0,0 +1,30 @@ +#!/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 -O "${DST}.new" "$SLX_PVS_CONFIG_URL" + [ -s "${DST}.new" ] && mv -f "${DST}.new" "${DST}" +fi + +# Patch exam mode according to what our fetched config says +if [ -n "$SLX_EXAM" ]; then + EMODE=True +else + EMODE=False +fi +sed -i "/^examMode/d;/^\\[General\\]/a examMode=$EMODE" "$DST" + +# 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 + -- cgit v1.2.3-55-g7522