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