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