diff options
author | Simon Rettberg | 2018-10-11 15:07:41 +0200 |
---|---|---|
committer | Simon Rettberg | 2018-10-11 15:07:41 +0200 |
commit | 60f365e413be60cd7d7a616c62200c33361e43f8 (patch) | |
tree | 48fdd7c7aef11632b817aad491a6c4c207184029 | |
parent | [speedcheck] Remove defunct helper call (diff) | |
download | mltk-60f365e413be60cd7d7a616c62200c33361e43f8.tar.gz mltk-60f365e413be60cd7d7a616c62200c33361e43f8.tar.xz mltk-60f365e413be60cd7d7a616c62200c33361e43f8.zip |
[xscreensaver] Build bwlp-screensaver
4 files changed, 131 insertions, 23 deletions
diff --git a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script index cb3c50fa..d60799a6 100755 --- a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script +++ b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script @@ -22,6 +22,25 @@ get_sessions() { done } +gen_runfile() { + # Calc next reboot/shutdown/standby + local i dateline ts + dateline= + for i in $SLX_REBOOT_SCHEDULE $SLX_SHUTDOWN_SCHEDULE; do + ts=$(date -d "today $i" +%s) + [ "$ts" -gt "$NOW" ] || ts=$(date -d "tomorrow $i" +%s) + [ "$ts" -gt "$NOW" ] || continue + if [ -z "$dateline" ] || [ "$ts" -lt "$dateline" ]; then + dateline="$ts" + fi + done + cat <<EDOC +[General] +lockDeadline=0 +shutdownDeadline=$dateline +EDOC +} + # # 1) Check for idle timeout # @@ -43,26 +62,57 @@ if [ -n "${SLX_LOGOUT_TIMEOUT}" ] && [ "${SLX_LOGOUT_TIMEOUT}" -gt 0 ]; then if [ -n "$DISPLAY" ]; then # Seems to be x11 IDLE= + LOCK= export XAUTHORITY=$(ps a | grep " $DISPLAY " | grep -o -- '-auth.*$' | grep -m1 -v grep | awk '{print $2}') - [ -n "$XAUTHORITY" ] && [ -f "$XAUTHORITY" ] && IDLE=$(xprintidle) + [ -n "$XAUTHORITY" ] && [ -f "$XAUTHORITY" ] && LOCK=$(xprintlocktime) # Now that we have DISPLAY and XAUTHORITY set, xprintidle should work - if [ -z "$IDLE" ]; then + if [ -z "$LOCK" ]; then # Try user's xauth USERID=$(id -u "$NAME") [ -z "$USERID" ] && USERID="$NAME" USRHOME=$(/usr/bin/getent passwd "$USERID" | awk -F ':' '{print $6}') export XAUTHORITY="$USRHOME/.Xauthority" - [ -f "$XAUTHORITY" ] && IDLE=$(xprintidle) fi - if [ -n "$IDLE" ]; then - IDLE=$(( $IDLE / 1000 )) - if [ -z "$IDLE" ] || [ "$IDLE" -lt "$SLX_LOGOUT_TIMEOUT" ]; then - IS_IDLE=no + if [ -f "$XAUTHORITY" ]; then + [ -z "$LOCK" ] && LOCK=$(xprintlocktime) + IDLE=$(xprintidle) + [ -n "$IDLE" ] && IDLE=$(( NOW - ( IDLE / 1000 ) )) + fi + # Now consider locking - if the screen is locked, we don't want to consider the current idle time, but + # the idle time of when the screen was locked - look it up and if not found, write current value + RUNFILE="/run/idleaction-$DISPLAY" + [ -f "$RUNFILE" ] || gen_runfile > "$RUNFILE" + if [ -z "$LOCK" ]; then + # Not locked anymore, nuke old value + sed -i '/^lockIdleTime=/d' "$RUNFILE" + else + # Screen is locked, ignore further idle time updates + RET=$(awk -F= '{if ($1 == "lockIdleTime") { print $2; exit } }' "$RUNFILE") + if [ -z "$RET" ]; then + if [ -z "$IDLE" ]; then + IDLE="$LOCK" + fi + echo "lockIdleTime=$IDLE" >> "$RUNFILE" else + # Use previous value + IDLE="$RET" # XXX + fi + fi + if [ -z "$IDLE" ] && [ -n "$LOCK" ]; then + IDLE="$LOCK" + fi + if [ -n "$IDLE" ] && [ "$IDLE" -gt 0 ]; then + TIMEOUT=$(( IDLE + SLX_LOGOUT_TIMEOUT )) + + if [ "$TIMEOUT" -lt "$NOW" ]; then date +%s > /run/openslx/session-killed loginctl terminate-session "$ses" + else + IS_IDLE=no + sed -i "s/^lockDeadline=.*$/lockDeadline=$TIMEOUT/" "$RUNFILE" fi - else # xprintidle did not work + else + # xprint* did not work? IS_IDLE=no fi continue # Done with this session, skip normal tty/ssh checks diff --git a/core/modules/xscreensaver/data/etc/X11/Xsession.d/95-xscreensaver b/core/modules/xscreensaver/data/etc/X11/Xsession.d/95-xscreensaver index 469e090a..d8bd831a 100755 --- a/core/modules/xscreensaver/data/etc/X11/Xsession.d/95-xscreensaver +++ b/core/modules/xscreensaver/data/etc/X11/Xsession.d/95-xscreensaver @@ -1,34 +1,79 @@ #!/bin/ash +DPMS=False if which xscreensaver; then [ -z "$UID" ] && UID=$(id -u) [ -z "$HOME" ] && HOME="$(getent passwd "$UID" | head -n 1 | awk -F ':' '{print $6}')" - if ! [ -s "$HOME/.xscreensaver" ]; then - . /opt/openslx/config - NUM=${SLX_SCREEN_STANDBY_TIMEOUT} - [ -n "${SLX_EXAM}" ] && NUM=0 - if [ -n "$NUM" ] && [ "$NUM" -gt 60 ]; then - SECS=0$(( NUM % 60 )) - MINS=0$(( ( NUM / 60 ) % 60 )) - HRS=0$(( ( NUM / 3600 ) % 60 )) - STANDBY="${HRS:$(( ${#HRS} - 2 )):2}:${MINS:$(( ${#MINS} - 2 )):2}:${SECS:$(( ${#SECS} - 2 )):2}" - else - STANDBY=0:00:00 + . /opt/openslx/config + SBY=${SLX_SCREEN_STANDBY_TIMEOUT} + if [ -n "${SLX_EXAM}" ]; then + SLX_LOGOUT_TIMEOUT=0 + SBY=0 + elif [ -z "$SBY" ]; then + SBY=0 + elif [ "$SBY" -gt 0 ] && [ "$SBY" -lt 60 ]; then + SBY=60 + elif ! [ "$SBY" -ge 0 ]; then # isNumeric? + SBY=0 + fi + # Make sure standby timeout is less than logout timeout, otherwise, disable standby + if [ "$SBY" -gt 0 ]; then + if [ "$SLX_LOGOUT_TIMEOUT" -gt 0 ]; then + if [ "$SBY" -lt 300 ]; then + SBY=300 + fi + if [ "$SLX_LOGOUT_TIMEOUT" -lt "$SBY" ]; then + SBY=0 + fi fi + fi + # Create config value for standby timeout + [ "$NUM" -gt 0 ] && DPMS=True + NUM=$SBY + SECS=0$(( NUM % 60 )) + MINS=0$(( ( NUM / 60 ) % 60 )) + HRS=0$(( ( NUM / 3600 ) % 60 )) + STANDBY="${HRS:$(( ${#HRS} - 2 )):2}:${MINS:$(( ${#MINS} - 2 )):2}:${SECS:$(( ${#SECS} - 2 )):2}" + # Create config for screensaver activation timeout + if [ "$SLX_LOGOUT_TIMEOUT" -gt 0 ] && [ "$SBY" -eq 0 ]; then + # Standby is disabled, consider logout timeout + TMO=$SLX_LOGOUT_TIMEOUT + else + # Consider standby timeout + TMO=$SBY + fi + # Start screen saver 3 minutes before forced logout, or screen enters standby + TMO=$(( TMO - 180 )) + if [ "$TMO" -gt 0 ]; then + [ "$TMO" -gt 1200 ] && TMO=$(( TMO - 300 )) + NUM=$TMO + SECS=0$(( NUM % 60 )) + MINS=0$(( ( NUM / 60 ) % 60 )) + HRS=0$(( ( NUM / 3600 ) % 60 )) + TIMEOUT="${HRS:$(( ${#HRS} - 2 )):2}:${MINS:$(( ${#MINS} - 2 )):2}:${SECS:$(( ${#SECS} - 2 )):2}" + else + TIMEOUT="99:00:00" + fi + if ! [ -s "$HOME/.xscreensaver" ]; then cat > "$HOME/.xscreensaver" <<EOF -mode: blank -timeout: 24:00:00 +mode: one +cycle: 99:00:00 +timeout: $TIMEOUT lock: True lockTimeout: 0:00:10 fade: False unfade: False -dpmsEnabled: True +dpmsEnabled: $DPMS dpmsStandby: $STANDBY dpmsSuspend: $STANDBY dpmsOff: $STANDBY +newLoginCommand: +programs: /opt/openslx/bin/bwlp-screensaver +selected: 0 EOF fi xscreensaver -no-splash & fi + true diff --git a/core/modules/xscreensaver/module.build b/core/modules/xscreensaver/module.build index 5fa3a36f..c78497fb 100644 --- a/core/modules/xscreensaver/module.build +++ b/core/modules/xscreensaver/module.build @@ -1,9 +1,16 @@ #!/bin/bash fetch_source() { - : + git clone "${REQUIRED_GIT}" "${MODULE_WORK_DIR}/src" || perror "Could not clone $REQUIRED_GIT" } build() { + [ ! -d "${MODULE_BUILD_DIR}/${REQUIRED_PREFIX}" ] && mkdir -p "${MODULE_BUILD_DIR}/${REQUIRED_PREFIX}" + cd "${MODULE_BUILD_DIR}/${REQUIRED_PREFIX}" + + pinfo "Running cmake" + + cmake "$SRCDIR" || perror "'cmake $SRCDIR' failed." + make || perror "'make' failed." COPYLIST="list_dpkg_output" list_packet_files > "$COPYLIST" tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" diff --git a/core/modules/xscreensaver/module.conf b/core/modules/xscreensaver/module.conf index e4d90404..defefddf 100644 --- a/core/modules/xscreensaver/module.conf +++ b/core/modules/xscreensaver/module.conf @@ -1,7 +1,13 @@ #!/bin/bash +REQUIRED_MODULES=" + qt5core +" +REQUIRED_GIT="git://git.openslx.org/openslx-ng/bwlp-screensaver.git" +REQUIRED_PREFIX="/opt/openslx/bin" REQUIRED_BINARIES=" xscreensaver xscreensaver-command + bwlp-screensaver " REQUIRED_LIBRARIES="" REQUIRED_DIRECTORIES=" |