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