vlock 2.0
[vlock.git] / src / vlock.sh
blob6cae0618dc7ad2917d757065c143c942695bad6f
1 #!%BOURNE_SHELL%
3 # ignore some signals
4 trap : HUP INT QUIT TSTP
6 VLOCK_ALL=%PREFIX%/sbin/vlock-all
7 VLOCK_NEW=%PREFIX%/sbin/vlock-new
8 VLOCK_NOSYSRQ=%PREFIX%/sbin/vlock-nosysrq
9 VLOCK_CURRENT=%PREFIX%/sbin/vlock-current
10 VLOCK_VERSION=%VLOCK_VERSION%
12 print_help() {
13 echo >&2 "vlock: locks virtual consoles, saving your current session."
14 echo >&2 "Usage: vlock [options]"
15 echo >&2 " Where [options] are any of:"
16 echo >&2 "-c or --current: lock only this virtual console, allowing user to"
17 echo >&2 " switch to other virtual consoles."
18 echo >&2 "-a or --all: lock all virtual consoles by preventing other users"
19 echo >&2 " from switching virtual consoles."
20 echo >&2 "-n or --new: allocate a new virtual console before locking,"
21 echo >&2 " implies --all."
22 echo >&2 "-s or --disable-sysrq: disable sysrq while consoles are locked to"
23 echo >&2 " prevent killing vlock with SAK, requires --all."
24 echo >&2 "-v or --version: Print the version number of vlock and exit."
25 echo >&2 "-h or --help: Print this help message and exit."
26 exit $1
29 checked_exec() {
30 if [ -f "$1" ] && [ ! -x "$1" ] ; then
31 echo >&2 "vlock: cannot execute \`$1': Permission denied"
32 echo >&2 "Please check the documentation for more information."
33 exit 1
34 else
35 exec "$@"
39 main() {
40 local opts lock_all lock_new nosysrq
42 opts=`getopt -o acnsvh --long current,all,new,disable-sysrq,version,help \
43 -n vlock -- "$@"`
45 if [ $? -ne 0 ] ; then
46 print_help 1
49 eval set -- "$opts"
51 lock_all=0
52 lock_new=0
53 nosysrq=0
55 while true ; do
56 case "$1" in
57 -a|--all)
58 lock_all=1
59 shift
61 -c|--current)
62 lock_all=0
63 shift
65 -s|--disable-sysrq)
66 nosysrq=1
67 shift
69 -n|--new)
70 lock_new=1
71 lock_all=1
72 shift
74 -h|--help)
75 print_help 0
77 -v|--version)
78 echo "vlock version $VLOCK_VERSION" >&2
79 exit
81 --) shift ; break ;;
82 *)
83 echo "getopt error: $1" >&2
84 exit 1
86 esac
87 done
89 if [ $lock_new -ne 0 ] ; then
90 # work around an annoying X11 bug
91 sleep 1
94 if [ $lock_all -ne 0 ] ; then
95 VLOCK_MESSAGE="\
96 The entire console display is now completely locked.
97 You will not be able to switch to another virtual console.
99 export VLOCK_MESSAGE
101 if [ $nosysrq -ne 0 ] ; then
102 if [ $lock_new -ne 0 ] ; then
103 export VLOCK_NEW=1
104 else
105 unset VLOCK_NEW
108 checked_exec "$VLOCK_NOSYSRQ"
109 elif [ $lock_new -ne 0 ] ; then
110 checked_exec "$VLOCK_NEW"
111 else
112 checked_exec "$VLOCK_ALL"
114 else
115 VLOCK_MESSAGE="This TTY is now locked."
116 export VLOCK_MESSAGE
118 checked_exec "$VLOCK_CURRENT"
122 main "$@"