blob: 6ef6969c4125ce9e4260bfb29d8b01a268da53cf (
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
69
70
71
72
73
74
75
76
77
|
#!/bin/ash
if [ "$(whoami)" != "root" ]; then
echo "Only root can call this"
exit 1
fi
if [ $# -ne 1 ]; then
echo "$0 <reboot|poweroff>"
exit 1
fi
MODE=$1
if [ "$MODE" != "reboot" ] && [ "$MODE" != "poweroff" ]; then
slxlog "idleaction-failed-call" "Invalid call to idleaction-scheduled_action. Mode '$MODE' unknown."
exit 1
fi
NUM=$(who | wc -l)
[ "$NUM" = "0" ] && $MODE # Easy way out - machine is idle
# Someone logged in
for MINUTES in 5 X X X X X X X 3 X X X 2 X X X 1 X X X; do
NUM=$(who | wc -l)
[ "$NUM" = "0" ] && break
if [ "$MINUTES" != "X" ]; then
USERS=0
if [ "$MODE" = "reboot" ]; then
MESSAGE="Das System wird in $MINUTES Minute(n) neugestartet, bitte beenden Sie Ihre Sitzung.
The system will reboot in $MINUTES minute(s). Please save your work and end the session."
else
MESSAGE="Dieser Rechner wird in $MINUTES Minute(n) abgeschaltet, bitte beenden Sie Ihre Sitzung.
The system will power off in $MINUTES minute(s). Please save your work and end the session."
fi
for d in $(who | awk '{print $2}' | sort -u); do
if [ "${d:0:1}" = ":" ]; then
# X11
export DISPLAY=$d
export XAUTHORITY=$(ps a | grep " $DISPLAY " | grep -o -- '-auth.*$' | grep -m1 -v grep | awk '{print $2}')
# TODO: Don't look... We need to pick a proper util for this
/opt/openslx/cups/printergui --error "$MESSAGE" &
unset DISPLAY XAUTHORITY
USERS=$(( $USERS + 1 ))
elif [ "${d:0:3}" = "tty" ]; then
# Regular tty
cat > "/dev/$d" <<-EOF
*
***************************
$MESSAGE
***************************
*
EOF
USERS=$(( $USERS + 1 ))
elif [ "${d:0:3}" = "pts" ]; then
# pts - xterm or ssh session
cat > "/dev/pts/${d:3}" <<-EOF
*
***************************
$MESSAGE
***************************
*
EOF
USERS=$(( $USERS + 1 ))
fi
done
FILE=$(mktemp)
who > "$FILE"
slxlog "idleaction-busy" "Postponed $MODE ($MINUTES minutes max.) - $USERS user(s) still active"
sleep 1
rm -- "$FILE"
fi
sleep 15
done
$MODE
|