Update soundtest
[grml-scripts.git] / usr_bin / grml-lock
1 #!/bin/zsh
2 # Filename:      grml-lock
3 # Purpose:       lock console
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Mon Jun 04 22:49:37 CEST 2007 [mika]
8 ################################################################################
9
10 PN="$0"
11
12 if [ -r /etc/grml/script-functions ] ; then
13    . /etc/grml/script-functions
14    if [ -x /usr/bin/X ] ; then
15       check4progs vlock xlock sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 }
16    else
17       check4progs vlock sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 }
18    fi
19 fi
20
21 if [ -r /etc/grml_version ] ; then
22 else
23   dialog --stdout --title "$PN" --msgbox "Warning: this system does not look like a grml-system
24 it might not work as intended." 7 70
25 fi
26
27 welcome_screen() {
28 dialog --stdout --title "$PN" --yes-label Continue --no-label Quit --yesno "Welcome to $PN!
29
30 This script will lock virtual consoles when running
31 on console or lock X server when running X.
32
33 Notice that you can not lock a GNU screen-session
34 via this script, use the lockscreen command
35 instead (default is pressing ctrl-a x inside
36 GNU screen)!
37
38 Report bugs, send wishes and feedback to the grml team:
39 http://www.grml.org/ - contact (at) grml.org
40 " 16 65
41
42   case $? in
43       (0)   # everything ok
44             ;;
45       (1)   echo "Cancel pressed." ; exit 1 ;;
46       (255) echo "ESC pressed."    ; exit 255 ;;
47   esac
48 }
49
50 lockcons()
51 {
52   vlock -a
53 }
54
55 lockx()
56 {
57   xlock
58 }
59
60 askxlock()
61 {
62   dialog --stdout --title "$PN" --yesno "Now lock X?" 0 0
63   retval=$?
64   case $retval in
65     0)
66        lockx
67        ;;
68   esac
69 }
70
71 askvlock()
72 {
73   dialog --stdout --title "$PN" --yesno "Now lock consoles?" 0 0
74   retval=$?
75   case $retval in
76     0)
77        lockcons
78        ;;
79   esac
80 }
81
82 askpwd()
83 {
84 dialog --stdout --title "$PN" --yesno "Set password for user $USER?" 0 0
85 retval=$?
86 case $retval in
87   0)
88      while [ -z "$PASSWD" ] ; do
89        PASSWD=$(dialog --stdout --title "$PN" --passwordbox "Set password (hidden typing):" 0 0)
90        if [ -n "$PASSWD" ] ; then
91          echo "$USER:$PASSWD" | sudo chpasswd
92        else
93          dialog --stdout --title "$PN" --msgbox "Error while setting password. Empty passwords are not accepted." 6 65
94        fi
95      done
96      ;;
97   *)
98 #     asklock
99      ;;
100 esac
101 }
102
103 if ! isgrmlcd ; then
104    [[ $(tty) == /dev/tty* ]] && lockcons || lockx
105 else
106    if [[ $(tty) == /dev/tty* ]] ; then
107      welcome_screen
108      askpwd
109      askvlock
110    elif [ -n "$DISPLAY" ] ; then
111      welcome_screen
112      askpwd
113      askxlock
114    fi
115 fi
116
117 ## END OF FILE #################################################################