From 19c74d4a56c353556c6f6b4f62e642c2bafc24e1 Mon Sep 17 00:00:00 2001 From: Christian Rößler Date: Tue, 25 Jun 2019 16:38:25 +0200 Subject: [run-virt] Linux scripts +adminrun --- .../vmchooser/data/linux/includes/00_vars.inc | 11 ++- .../vmchooser/data/linux/includes/10_functions.inc | 14 +++ .../vmchooser/data/linux/includes/80_adminrun.inc | 42 +++++++++ .../vmchooser/data/linux/includes/90_runscript.inc | 99 ++++++++++++---------- .../data/opt/openslx/vmchooser/data/linux/openslx | 4 +- .../opt/openslx/vmchooser/data/linux/resolution | 8 +- .../vmchooser/data/linux/resolution_standalone | 8 +- 7 files changed, 128 insertions(+), 58 deletions(-) create mode 100644 core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/80_adminrun.inc (limited to 'core/modules/run-virt/data/opt/openslx') diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/00_vars.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/00_vars.inc index 5b69d90c..93f0d3db 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/00_vars.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/00_vars.inc @@ -1,5 +1,11 @@ ### Variablen ##################################### +DISKMOUNTDIR=/mnt/diskmount +ADMINRUNDIR="$DISKMOUNTDIR"/adminrun +SLXCONFIGFILE="$DISKMOUNTDIR"/openslx.ini +CONFIGFILE="$DISKMOUNTDIR"/shares.dat +LOGINUSER=$(grep '^username=' "$SLXCONFIGFILE" | cut -d '=' -f 2) + ##### User related################# LOCALUSER=student USERHOME=/home/"$LOCALUSER" @@ -10,9 +16,6 @@ USERLOGFILE="$USERDESKTOP"/openslx.log ##### Mounting, network, PW ####### -DISKMOUNTDIR=/mnt/diskmount -SLXCONFIGFILE="$DISKMOUNTDIR"/openslx.ini -CONFIGFILE="$DISKMOUNTDIR"/shares.dat KEYTEMP=$(mktemp -t XXXXXXXXXX.dat) RAWKEYTEMP=$(mktemp -t XXXXXXXXXX.dat) BYTES=256 @@ -41,7 +44,7 @@ GLOBALUSER=$(echo "$GLOBALDOMAINUSER" | cut -d '\' -f 2) REMAPMODE=$(grep '^remapMode=' "$SLXCONFIGFILE" | cut -d '=' -f 2) CREATEMISSING=$(grep '^createMissingRemap=' "$SLXCONFIGFILE" | cut -d '=' -f 2) -##### Script (Autostart ) ######### +##### Script (Autostart & admin) ######### SCRIPTUSER=$(grep '^scriptUser=' "$SLXCONFIGFILE" | cut -d '=' -f 2) SCRIPTVISIBILITY=$(grep '^scriptVisibility=' "$SLXCONFIGFILE" | cut -d '=' -f 2) SCRIPTEXT=$(grep scriptExt "$DISKMOUNTDIR/openslx.ini" | cut -f 2 -d "=") diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/10_functions.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/10_functions.inc index 1649e795..3c110204 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/10_functions.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/10_functions.inc @@ -152,5 +152,19 @@ function mount_home() ### Funktionen Mounter Ende ####################### +set_userpart(); +{ + case "$SCRIPTUSER" in + 0) USERPART="" + ;; + 1) USERPART=" su -c - $LOCALUSER " + ;; + *) logger "openslx utility: runscript: Unknown script user or script user not set. Running as user ${LOCALUSER}." + # USERPART="" # old default: Running as root + USERPART=" su -c - $LOCALUSER " + ;; + esac +} + ### Funktionen Ende ############################### diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/80_adminrun.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/80_adminrun.inc new file mode 100644 index 00000000..6e4a9e0a --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/80_adminrun.inc @@ -0,0 +1,42 @@ +# vim:ft=sh + +spawn_process() +{ + if [ "$USERCREDS" -eq 1 ]; then + get_creds + USERNAME="$LOGINUSER" PASSWORD="$PW" runscript_visibility "$SCRIPT" "$USERPART" "$VISIBILITY" & + unset PASSWORD + unset PW + else + runscript_visibility "$SCRIPT" "$USERPART" "$VISIBILITY" & + fi + + local WAITPID="$!" + wait $WAITPID + local ERR=$? + logger "openslx utility: adminrun: script ${SCRIPT} (PID ${WAITPID}) finished, errorlevel ${ERR}." +} + +function adminrun() +{ + logger "openslx utility: adminrun: started." + + if [ ! -d "$ADMINRUNDIR" ]; then + logger "openslx utility: adminrun: no adminrun directory found." + return + fi + + logger "openslx utility: adminrun: adminrun directory found, starting scripts." + set_userpart + for SCRIPT in "$ADMINRUNDIR"/*; do + USERPART=" su -c - $LOCALUSER " # adminrun: not as user + # USERPART=" " + VISIBILITY=$(echo ${SCRIPT%%.*}|cut -f 2 -d "-") # visibility: 0 versteckt, 1 normal, 2 minimiert + USERCREDS=$(echo ${SCRIPT%%.*}|cut -f 3 -d "-") # user/pass: 0 nein, 1 ja + logger "openslx utility: adminrun: starting script ${SCRIPT} using visibility ${VISIBILITY} and usercreds ${USERCREDS}." + spawn_process & + done + + + +} diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/90_runscript.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/90_runscript.inc index 2b291dfc..6536d9a5 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/90_runscript.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/includes/90_runscript.inc @@ -1,9 +1,55 @@ function wait_for_wm() { # This just waits until there's a window manager. + logger "openslx utility: wait_for_wm: Waiting for window manager." while [[ "$(DISPLAY=:0.0 XAUTHORITY=${XAUTHORITY} xprop -root _NET_SUPPORTING_WM_CHECK)" =~ "no such atom" ]]; do sleep 2 done + logger "openslx utility: wait_for_wm: Window manager detected." +} + +function runscript_visibility() +{ + local SCRIPT="$1" + local USERPART="$2" + local VISIBILITY="$3" + + case "$VISIBILITY" in + 0) # 0=hidden + logger "openslx utility: runscript_visibility: Starting script $SCRIPT hidden(${VISIBILITY}): $USERPART" + $USERPART "$SCRIPT" + ;; + 1) # 1=normal + get_xauthfile + wait_for_wm + if [ -n "$USERPART" ]; then + logger "openslx utility: runscript_visibility: Starting script $SCRIPT maximised(${VISIBILITY}), no USERPART." + DISPLAY=:0.0 XAUTHORITY="${XAUTHORITY}" $USERPART "xterm $SCRIPT" + else + logger "openslx utility: runscript_visibility: Starting script $SCRIPT maximised(${VISIBILITY}), $USERPART." + DISPLAY=:0.0 XAUTHORITY="${XAUTHORITY}" $USERPART xterm "$SCRIPT" + fi + ;; + 2) # 2=minimized (xterm -iconic) + logger "openslx utility: runscript_visibility: starting script $SCRIPT minimised(${VISIBILITY}). $USERPART" + get_xauthfile + wait_for_wm + + # Truly not the best way to wait until the desktop environment is ready, but there's no common way to + # check for DE readiness. Until then, we'll sleep. + # sleep 20 + if [ -n "$USERPART" ]; then + logger "openslx utility: runscript_visibility: Starting script $SCRIPT minimised(${VISIBILITY}), no USERPART." + DISPLAY=:0.0 XAUTHORITY="${XAUTHORITY}" $USERPART "xterm -iconic $SCRIPT" + else + logger "openslx utility: runscript_visibility: Starting script $SCRIPT minimised(${VISIBILITY}), $USERPART." + DISPLAY=:0.0 XAUTHORITY="${XAUTHORITY}" $USERPART xterm -iconic "$SCRIPT" + fi + ;; + *) # *=? + logger "openslx utility: runscript_visibility: script $SCRIPT unkown scriptVisibility $SCRIPTVISIBILITY." + ;; + esac } function runscript() @@ -16,52 +62,11 @@ function runscript() if [ -f "$DISKMOUNTDIR/runscript${SCRIPTEXT}" ]; then logger "openslx utility: runscript: found script $DISKMOUNTDIR/runscript${SCRIPTEXT}." logger "openslx utility: runscript: script options: scriptuser: ${SCRIPTUSER}, scriptvisibility: ${SCRIPTVISIBILITY}." - - case "$SCRIPTUSER" in - 0) USERPART="" - ;; - 1) USERPART=" su -c - $LOCALUSER " - ;; - *) logger "openslx utility: runscript: Unknown script user or script user not set. Running as user ${LOCALUSER}." - # USERPART="" # old default: Running as root - USERPART=" su -c - $LOCALUSER " - ;; - esac - case "$SCRIPTVISIBILITY" in - 0) # 0=hidden - logger "openslx utility: runscript: Starting script hidden." - echo "$USERPART $DISKMOUNTDIR/runscript${SCRIPTEXT}" - $USERPART "$DISKMOUNTDIR/runscript${SCRIPTEXT}" & - ;; - 1) # 1=normal - logger "openslx utility: runscript: Starting script maximised." - get_xauthfile - wait_for_wm - if [ -n "$USERPART" ]; then - DISPLAY=:0.0 XAUTHORITY="${XAUTHORITY}" $USERPART "xterm $DISKMOUNTDIR/runscript${SCRIPTEXT}" & - else - DISPLAY=:0.0 XAUTHORITY="${XAUTHORITY}" $USERPART xterm "$DISKMOUNTDIR/runscript${SCRIPTEXT}" & - fi - ;; - 2) # 2=minimized (xterm -iconic) - logger "openslx utility: runscript: starting script minimised." - get_xauthfile - wait_for_wm - - # Truly not the best way to wait until the desktop environment is ready, but there's no common way to - # check for DE readiness. Until then, we'll sleep. - sleep 20 - if [ -n "$USERPART" ]; then - DISPLAY=:0.0 XAUTHORITY="${XAUTHORITY}" $USERPART "xterm -iconic $DISKMOUNTDIR/runscript${SCRIPTEXT}" & - else - DISPLAY=:0.0 XAUTHORITY="${XAUTHORITY}" $USERPART xterm -iconic "$DISKMOUNTDIR/runscript${SCRIPTEXT}" & - fi - ;; - *) # *=? - logger "openslx utility: runscript: unkown scriptVisibility $SCRIPTVISIBILITY." - ;; - esac - + set_userpart + runscript_visibility "$DISKMOUNTDIR/runscript${SCRIPTEXT}" "$USERPART" "$SCRIPTVISIBILITY" & + SCRIPTPID=$! + wait $SCRIPTPID + ERR=$? if [ "$ERR" -eq 0 ]; then logger "openslx utility: runscript: runscript${SCRIPTEXT} ok, errorlevel ${ERR}." else @@ -72,7 +77,7 @@ function runscript() fi else logger "openslx utility: runscript: Could not find $SLXCONFIGFILE." - exit 1 + return 1 fi } diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/openslx b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/openslx index 03617bcc..fe823026 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/openslx +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/openslx @@ -28,13 +28,15 @@ mutesound & logger "openslx utility script: spawning share mounter..." mnt_shares & MNTPID=$! - logger "openslx utility script: Waiting for mounter..." # Best to wait until any shares are mounted (and perhaps resolution setting, too?), as perhaps # an user supplied runscript needs a network share? wait $MNTPID # ${RSPID[*]} logger "openslx utility script: mounter finished." +logger "openslx adminrun: looking for adminrun scripts." +adminrun & + logger "openslx utility script: starting runscript..." runscript logger "openslx utility script: runscript finished." diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/resolution b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/resolution index 84775db7..08a4853a 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/resolution +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/resolution @@ -1,8 +1,10 @@ #!/bin/bash -# Dieses Skript liest die Auflösungsdate HOSTRES.TXT aus der Diskette 2 (/dev/fd1). In dieser -# Datei wird die native (maximale) Auflösung des Grundsystems bereitgestellt. fd1 wird vom -# openslx-Grundsystem geliefert. Es loggt nach SYSLOG (syslog oder messages). +# Achtung: Dieses Skript ist veraltet und sollte nur noch zur Anschauung bzw. zu Debugzwecken +# genutzt werden. Stattdessen sollte das Skriptpaket openslx genutzt werden. +# Es liest die Datei openslx.ini aus, in der die Auflösung des Grundsystems bereitgestellt +# wird. Die (Pseudo-)Floppy fd1 wird vom openslx-Grundsystem geliefert. Es loggt nach SYSLOG ( +# syslog oder messages). # # Zu erledigen: Jede Menge, zB anständiges Trapping, Fehler abfangen usw... # set -x diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/resolution_standalone b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/resolution_standalone index 0f93c718..954fe4d7 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/resolution_standalone +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/resolution_standalone @@ -1,8 +1,10 @@ #!/bin/bash -# Dieses Skript liest die Auflösungsdate HOSTRES.TXT aus der Diskette 2 (/dev/fd1). In dieser -# Datei wird die native (maximale) Auflösung des Grundsystems bereitgestellt. fd1 wird vom -# openslx-Grundsystem geliefert. Es loggt nach SYSLOG (syslog oder messages). +# Achtung: Dieses Skript ist veraltet und sollte nur noch zur Anschauung bzw. zu Debugzwecken +# genutzt werden. Stattdessen sollte das Skriptpaket openslx genutzt werden. +# Es liest die Datei openslx.ini aus, in der die Auflösung des Grundsystems bereitgestellt +# wird. Die (Pseudo-)Floppy fd1 wird vom openslx-Grundsystem geliefert. Es loggt nach SYSLOG ( +# syslog oder messages). # # Zu erledigen: Jede Menge, zB anständiges Trapping, Fehler abfangen usw... # set -x -- cgit v1.2.3-55-g7522