-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock
executable file
·61 lines (54 loc) · 2.01 KB
/
lock
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
#! /bin/sh
# Yell if they are trying to lock remotely. This won't work.
# Even if it does, it's wrong.
if [ "${SSH_TTY}" ] && [ -z "${STY}" ] ; then
echo "You're doing it wrong. Don't try to lock a remote computer."
exit 1
fi
# Graphically locking on Macs is simple.
# If we're not in screen, attempt to graphically lock it.
if [ `uname -s` = 'Darwin' ] && [ -z "${STY}" ] ; then
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
exit
fi
# Handle non-graphical locking
if [ -z "${DISPLAY}" ] ; then
if [ -z "${STY}" ] ; then # not running screen
if ( command -v vlock >/dev/null 2>/dev/null ) ; then
vlock
exit
else
echo "You don't have vlock. Maybe try locking in screen."
fi
else
echo "You are in screen. Use 'C-a x' to lock"
fi
exit 1
fi
# Try to lock sanely on X11.
# Certain combinations of desktop managers and locking programs
# allow new sessions to be started.
KDE_LOCK='kdesktop_lock --forcelock || krunner_lock --forcelock || /usr/libexec/kde4/krunner_lock --forcelock || /usr/lib/kde4/libexec/krunner_lock --forcelock'
GNOME_LOCK='gnome-screensaver-command --lock'
XSCREEN_LOCK='xscreensaver-command -lock || xlock'
if ( ps -e | grep gdm >/dev/null 2>/dev/null ) ; then
# looks like Gnome. They probably want gnome-screensaver.
# start gnome-screensaver to ensure it's running
gnome-screensaver >/dev/null 2>/dev/null
eval $GNOME_LOCK 2>/dev/null && exit
elif ( ps -e | grep kdm >/dev/null 2>/dev/null ) ; then
# looks like some version of KDE. They probably want kde's screensaver.
eval $KDE_LOCK 2>/dev/null && exit
elif ( ps -e | grep xdm >/dev/null 2>/dev/null ) ; then
xscreensaver & >/dev/null 2>/dev/null
eval $XSCREEN_LOCK 2>/dev/null && exit
fi
echo "Could not decide what desktop manager you are using."
echo "Trying fallback locking."
eval $KDE_LOCK 2>/dev/null && exit
gnome-screensaver >/dev/null 2>/dev/null
eval $GNOME_LOCK 2>/dev/null
xscreensaver & >/dev/null 2>/dev/null
eval $XSCREEN_LOCK 2>/dev/null && exit
echo "Could not lock your screen."
exit 1