3 # vlock.sh -- start script for vlock, the VT locking program for linux
5 # This program is copyright (C) 2007 Frank Benkstein, and is free
6 # software which is freely distributable under the terms of the
7 # GNU General Public License version 2, included as the file COPYING in this
8 # distribution. It is NOT public domain software, and any
9 # redistribution not permitted by the GNU General Public License is
10 # expressly forbidden without prior written permission from
13 # Ignore some signals.
14 trap : HUP INT QUIT TSTP
19 # Magic characters to clear the terminal.
20 CLEAR_SCREEN
="`echo -e '\033[H\033[J'`"
22 # Enter message that is common to different the messages.
23 VLOCK_ENTER_PROMPT
="Please press [ENTER] to unlock."
25 # Message that is displayed when console switching is disabled.
26 VLOCK_ALL_MESSAGE
="${CLEAR_SCREEN}\
27 The entire console display is now completely locked.
28 You will not be able to switch to another virtual console.
30 ${VLOCK_ENTER_PROMPT}"
32 # Message that is displayed when only the current terminal is locked.
33 VLOCK_CURRENT_MESSAGE
="${CLEAR_SCREEN}\
34 This TTY is now locked.
36 ${VLOCK_ENTER_PROMPT}"
39 if [ -r "${HOME}/.vlockrc" ] ; then
43 # "Compile" time variables.
44 VLOCK_MAIN
="%PREFIX%/sbin/vlock-main"
45 VLOCK_VERSION
="%VLOCK_VERSION%"
46 # If set to "y" plugin support is enabled in vlock-main.
47 VLOCK_USE_PLUGINS
="%VLOCK_USE_PLUGINS%"
50 echo >&2 "vlock: locks virtual consoles, saving your current session."
51 if [ "${VLOCK_USE_PLUGINS}" = "y" ] ; then
52 echo >&2 "Usage: vlock [options] [plugins...]"
54 echo >&2 "Usage: vlock [options]"
56 echo >&2 " Where [options] are any of:"
57 echo >&2 "-c or --current: lock only this virtual console, allowing user to"
58 echo >&2 " switch to other virtual consoles."
59 echo >&2 "-a or --all: lock all virtual consoles by preventing other users"
60 echo >&2 " from switching virtual consoles."
61 if [ "${VLOCK_USE_PLUGINS}" = "y" ] ; then
62 echo >&2 "-n or --new: allocate a new virtual console before locking,"
63 echo >&2 " implies --all."
64 echo >&2 "-s or --disable-sysrq: disable SysRq while consoles are locked to"
65 echo >&2 " prevent killing vlock with SAK, implies --all."
66 echo >&2 "-t <seconds> or --timeout <seconds>: run screen saver plugins"
67 echo >&2 " after the given amount of time."
69 echo >&2 "-v or --version: Print the version number of vlock and exit."
70 echo >&2 "-h or --help: Print this help message and exit."
73 # Export variables only if they are set. Some shells create an empty variable
74 # on export even if it was previously unset.
76 while [ $# -gt 0 ] ; do
77 if eval [ "\"\${$1+set}\"" = "set" ] ; then
85 local options long_options short_options plugins
88 long_options
="all,current,version,help"
90 if [ "${VLOCK_USE_PLUGINS}" = "y" ] ; then
91 short_options
="${short_options}nst:"
92 long_options
="${long_options},new,disable-sysrq,timeout:"
95 # Test for GNU getopt.
96 ( getopt
-T >/dev
/null
)
98 if [ $?
-eq 4 ] ; then
100 options
=`getopt -o "${short_options}" --long "${long_options}" -n vlock -- "$@"` || getopt_error
=1
102 # Other getopt, e.g. BSD.
103 options
=`getopt "${short_options}" "$@"` || getopt_error
=1
106 if [ -n "${getopt_error}" ] ; then
111 eval set -- "${options}"
116 plugins
="${plugins} all"
124 plugins
="${plugins} new"
128 plugins
="${plugins} nosysrq"
141 if [ "${VLOCK_USE_PLUGINS}" = "y" ] ; then
142 echo >&2 "vlock version ${VLOCK_VERSION}"
144 echo >&2 "vlock version ${VLOCK_VERSION} (no plugin support)"
149 # End of option list.
154 echo >&2 "getopt error: $1"
160 # Export variables for vlock-main.
161 export_if_set VLOCK_TIMEOUT VLOCK_PROMPT_TIMEOUT
162 export_if_set VLOCK_MESSAGE VLOCK_ALL_MESSAGE VLOCK_CURRENT_MESSAGE
164 if [ "${VLOCK_USE_PLUGINS}" = "y" ] ; then
165 exec "${VLOCK_MAIN}" ${plugins} ${VLOCK_PLUGINS} "$@
"
167 exec "${VLOCK_MAIN}" ${plugins}