Skip to content

Commit 4df9b45

Browse files
author
Marcus Funch Mogensen
committed
Merge branch 'task/43099_improve_timeout_logout_scripts' into 'master'
improve timeout logout scripts: Move to new repo See merge request os2borgerpc/os2borgerpc-scripts!3
2 parents 4421f20 + 58709d3 commit 4df9b45

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

system/always_logout_after_time.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
if [ $# -ne 1 ]
66
then
77
echo "This job takes exactly one parameter."
8-
exit -1
8+
exit 1
99
fi
1010

1111

@@ -15,6 +15,7 @@ HAS_AT=$?
1515

1616
if [[ $HAS_AT == 1 ]]
1717
then
18+
export DEBIAN_FRONTEND=noninteractive
1819
apt-get update
1920
apt-get install -y at
2021
fi
@@ -76,5 +77,3 @@ EOF
7677
chmod +x /home/.skjult/.config/autostart/auto_logout.sh.desktop
7778

7879
exit 0
79-
80-

system/setup_inactive_logout.sh

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
1-
#!/bin/bash
2-
1+
#! /usr/bin/env sh
32

43
# Time before dialog appears, defined in minutes
54
DIALOG_TIME=$1
6-
if [ -z $DIALOG_TIME ]
5+
if [ -z "$DIALOG_TIME" ]
76
then
87
echo 'Please insert the time the user has to be inactive before dialog is shown.'
9-
exit -1
8+
exit 1
109
fi
1110

1211
# Time before user is logged out, defined in minutes
1312
LOGOUT_TIME=$2
14-
if [ -z $LOGOUT_TIME ]
13+
if [ -z "$LOGOUT_TIME" ]
1514
then
1615
echo 'Please insert the time the user has to be inactive before being logged out.'
17-
exit -1
16+
exit 1
1817
fi
1918

2019
if [ "$DIALOG_TIME" -gt "$LOGOUT_TIME" ]
2120
then
2221
echo 'Dialog time is greater than logout time and dialog will therefore not be shown. Edit dialog time!'
23-
exit -1
22+
exit 1
2423
fi
2524

2625
# Text to be shown in the dialog
2726
DIALOG_TEXT=$3
28-
if [ -z $DIALOG_TEXT ]
27+
if [ -z "$DIALOG_TEXT" ]
2928
then
3029
echo 'Please insert the text to be displayed in the dialog.'
31-
exit -1
30+
exit 1
3231
fi
3332

34-
# Text to be shown in the dialog button
33+
# Text to be shown on the dialog button
3534
BUTTON_TEXT=$4
36-
if [ -z $BUTTON_TEXT ]
35+
if [ -z "$BUTTON_TEXT" ]
3736
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
4039
fi
4140

4241
# Install xprintidle
42+
# Stop Debconf from doing anything
43+
export DEBIAN_FRONTEND=noninteractive
4344
apt-get update
4445
apt-get install -y xprintidle
4546

4647
# if line already added to crontab skip
4748
TEMP=$(crontab -l | grep "inactive_logout.sh")
48-
if [[ -z "$TEMP" ]]
49+
if [ -z "$TEMP" ]
4950
then
5051
line="* * * * * /usr/share/os2borgerpc/bin/inactive_logout.sh"
5152
(crontab -l -u root; echo "$line") | crontab -u root -
@@ -54,47 +55,39 @@ fi
5455

5556
# New auto_logout file
5657
cat << EOF > /usr/share/os2borgerpc/bin/inactive_logout.sh
57-
#!/usr/bin/env bash
58+
#! /usr/bin/env sh
5859
5960
# If the user is inactive for too long, a dialog will appear, warning the user that the session will end.
6061
# If the user do not touch the mouse or press any keyboard key the session will end.
6162
62-
# who | sed -rn 's/.*(:[0-9]*).*/\1/p'
6363
USER_DISPLAY=\$(who | grep -w 'user' | sed -rn 's/.*(:[0-9]*).*/\1/p')
6464
6565
export XAUTHORITY=/home/user/.Xauthority
6666
export DISPLAY=\$USER_DISPLAY
6767
6868
su - user -s /bin/bash -c 'xhost +localhost'
6969
70-
FILE=/usr/share/os2borgerpc/bin/dialogshown.txt
71-
7270
# 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 ))
7472
# echo \$NEW_LOGOUT_TIME \$(xprintidle) >> \$LOG_DIR
7573
7674
if [ \$(xprintidle) -ge \$NEW_LOGOUT_TIME ]
7775
then
7876
# echo 'Logging user out' >> \$LOG_DIR
7977
pkill -KILL -u user
80-
rm \$FILE
8178
exit 0
8279
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
8682
if [ \$(xprintidle) -ge \$NEW_DIALOG_TIME ]
8783
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
9891
fi
9992
10093
exit 0

0 commit comments

Comments
 (0)