|
1 |
| -#!/bin/bash |
2 |
| - |
| 1 | +#! /usr/bin/env sh |
3 | 2 |
|
4 | 3 | # Time before dialog appears, defined in minutes
|
5 | 4 | DIALOG_TIME=$1
|
6 |
| -if [ -z $DIALOG_TIME ] |
| 5 | +if [ -z "$DIALOG_TIME" ] |
7 | 6 | then
|
8 | 7 | echo 'Please insert the time the user has to be inactive before dialog is shown.'
|
9 |
| - exit -1 |
| 8 | + exit 1 |
10 | 9 | fi
|
11 | 10 |
|
12 | 11 | # Time before user is logged out, defined in minutes
|
13 | 12 | LOGOUT_TIME=$2
|
14 |
| -if [ -z $LOGOUT_TIME ] |
| 13 | +if [ -z "$LOGOUT_TIME" ] |
15 | 14 | then
|
16 | 15 | echo 'Please insert the time the user has to be inactive before being logged out.'
|
17 |
| - exit -1 |
| 16 | + exit 1 |
18 | 17 | fi
|
19 | 18 |
|
20 | 19 | if [ "$DIALOG_TIME" -gt "$LOGOUT_TIME" ]
|
21 | 20 | then
|
22 | 21 | echo 'Dialog time is greater than logout time and dialog will therefore not be shown. Edit dialog time!'
|
23 |
| - exit -1 |
| 22 | + exit 1 |
24 | 23 | fi
|
25 | 24 |
|
26 | 25 | # Text to be shown in the dialog
|
27 | 26 | DIALOG_TEXT=$3
|
28 |
| -if [ -z $DIALOG_TEXT ] |
| 27 | +if [ -z "$DIALOG_TEXT" ] |
29 | 28 | then
|
30 | 29 | echo 'Please insert the text to be displayed in the dialog.'
|
31 |
| - exit -1 |
| 30 | + exit 1 |
32 | 31 | fi
|
33 | 32 |
|
34 |
| -# Text to be shown in the dialog button |
| 33 | +# Text to be shown on the dialog button |
35 | 34 | BUTTON_TEXT=$4
|
36 |
| -if [ -z $BUTTON_TEXT ] |
| 35 | +if [ -z "$BUTTON_TEXT" ] |
37 | 36 | then
|
38 |
| - echo 'Please insert the text to be displayed in the dialog button.' |
39 |
| - exit -1 |
| 37 | + echo 'Please insert the text to be displayed on the dialog button.' |
| 38 | + exit 1 |
40 | 39 | fi
|
41 | 40 |
|
42 | 41 | # Install xprintidle
|
| 42 | +# Stop Debconf from doing anything |
| 43 | +export DEBIAN_FRONTEND=noninteractive |
43 | 44 | apt-get update
|
44 | 45 | apt-get install -y xprintidle
|
45 | 46 |
|
46 | 47 | # if line already added to crontab skip
|
47 | 48 | TEMP=$(crontab -l | grep "inactive_logout.sh")
|
48 |
| -if [[ -z "$TEMP" ]] |
| 49 | +if [ -z "$TEMP" ] |
49 | 50 | then
|
50 | 51 | line="* * * * * /usr/share/os2borgerpc/bin/inactive_logout.sh"
|
51 | 52 | (crontab -l -u root; echo "$line") | crontab -u root -
|
|
54 | 55 |
|
55 | 56 | # New auto_logout file
|
56 | 57 | cat << EOF > /usr/share/os2borgerpc/bin/inactive_logout.sh
|
57 |
| -#!/usr/bin/env bash |
| 58 | +#! /usr/bin/env sh |
58 | 59 |
|
59 | 60 | # If the user is inactive for too long, a dialog will appear, warning the user that the session will end.
|
60 | 61 | # If the user do not touch the mouse or press any keyboard key the session will end.
|
61 | 62 |
|
62 |
| -# who | sed -rn 's/.*(:[0-9]*).*/\1/p' |
63 | 63 | USER_DISPLAY=\$(who | grep -w 'user' | sed -rn 's/.*(:[0-9]*).*/\1/p')
|
64 | 64 |
|
65 | 65 | export XAUTHORITY=/home/user/.Xauthority
|
66 | 66 | export DISPLAY=\$USER_DISPLAY
|
67 | 67 |
|
68 | 68 | su - user -s /bin/bash -c 'xhost +localhost'
|
69 | 69 |
|
70 |
| -FILE=/usr/share/os2borgerpc/bin/dialogshown.txt |
71 |
| -
|
72 | 70 | # LOG_DIR=/usr/share/os2borgerpc/bin/inactive_logout.log
|
73 |
| -NEW_LOGOUT_TIME=$( expr $LOGOUT_TIME "*" 60 "*" 1000) |
| 71 | +NEW_LOGOUT_TIME=$(( LOGOUT_TIME * 60 * 1000 )) |
74 | 72 | # echo \$NEW_LOGOUT_TIME \$(xprintidle) >> \$LOG_DIR
|
75 | 73 |
|
76 | 74 | if [ \$(xprintidle) -ge \$NEW_LOGOUT_TIME ]
|
77 | 75 | then
|
78 | 76 | # echo 'Logging user out' >> \$LOG_DIR
|
79 | 77 | pkill -KILL -u user
|
80 |
| - rm \$FILE |
81 | 78 | exit 0
|
82 | 79 | fi
|
83 |
| -
|
84 |
| -NEW_DIALOG_TIME=$( expr $DIALOG_TIME "*" 60 "*" 1000) |
85 |
| -# hvis idle time er større end dialog tid, vis da dialog. |
| 80 | +NEW_DIALOG_TIME=$(( DIALOG_TIME * 60 * 1000 )) |
| 81 | +# if idle time is past the dialog time: show the dialog |
86 | 82 | if [ \$(xprintidle) -ge \$NEW_DIALOG_TIME ]
|
87 | 83 | then
|
88 |
| - # hvis dialog ikke allerede er vist |
89 |
| - if [ ! -f "\$FILE" ] |
90 |
| - then |
91 |
| - # echo 'Running zenity...' >> \$LOG_DIR |
92 |
| - zenity --warning --text="$DIALOG_TEXT" --ok-label="$BUTTON_TEXT" --no-wrap --display=\$USER_DISPLAY |
93 |
| - echo 'Dialog shown' >> \$FILE |
94 |
| - if [ $? = 0 ] ; then |
95 |
| - rm \$FILE |
96 |
| - fi |
97 |
| - fi |
| 84 | + # ...but only create a dialog if one doesn't already exist |
| 85 | + if ! pgrep --full 'Inaktivitet' > /dev/null |
| 86 | + then |
| 87 | + # echo 'Running zenity...' >> \$LOG_DIR |
| 88 | + # We use the --title to match against above |
| 89 | + zenity --warning --text="$DIALOG_TEXT" --ok-label="$BUTTON_TEXT" --no-wrap --display=\$USER_DISPLAY --title "Inaktivitet" |
| 90 | + fi |
98 | 91 | fi
|
99 | 92 |
|
100 | 93 | exit 0
|
|
0 commit comments