forked from majnemer/davesdots
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lock
executable file
·71 lines (63 loc) · 2.41 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
62
63
64
65
66
67
68
69
70
71
#! /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
sudo -K
# 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'
LIGHT_LOCK='light-locker-command --lock'
XSCREEN_LOCK='xscreensaver-command -lock || xlock'
if ps -e | grep -w lightdm >/dev/null 2>/dev/null ; then
# lightdm is running, probably xfce or similar.
# very similar to the gnome versions
light-locker >/dev/null 2>/dev/null &
eval $LIGHT_LOCK 2>/dev/null && exit
elif ps -e | grep -w 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 -w 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 -w xdm >/dev/null 2>/dev/null || ps -e | grep -w xscreensaver >/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
light-locker >/dev/null 2>/dev/null &
eval $LIGHT_LOCK 2>/dev/null && exit
gnome-screensaver >/dev/null 2>/dev/null &
eval $GNOME_LOCK 2>/dev/null && exit
xscreensaver & >/dev/null 2>/dev/null
eval $XSCREEN_LOCK 2>/dev/null && exit
echo "Could not lock your screen."
exit 1