xsay: add support for sselp and xclip; output error message
[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 Mär 18 16:41:49 CET 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" --msgbox "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
39 lockcons()
40 {
41   vlock -a
42 }
43
44 lockx()
45 {
46   xlock
47 }
48
49 askxlock()
50 {
51   dialog --stdout --title "$PN" --yesno "Now lock X?" 0 0
52   retval=$?
53   case $retval in
54     0) 
55        lockx
56        ;;
57   esac
58 }
59
60 askvlock()
61 {
62   dialog --stdout --title "$PN" --yesno "Now lock consoles?" 0 0
63   retval=$?
64   case $retval in
65     0)
66        lockcons
67        ;;
68   esac
69 }
70
71 askpwd()
72 {
73 dialog --stdout --title "$PN" --yesno "Set password for user $USER?" 0 0
74 retval=$?
75 case $retval in
76   0) 
77      while [ -z "$PASSWD" ] ; do
78        PASSWD=$(dialog --stdout --title "$PN" --passwordbox "Set password (hidden typing):" 0 0)
79        if [ -n "$PASSWD" ] ; then
80          echo "$USER:$PASSWD" | sudo chpasswd
81        else
82          dialog --stdout --title "$PN" --msgbox "Error while setting password. Empty passwords are not accepted." 6 65
83        fi
84      done
85      ;;
86   *)
87 #     asklock
88      ;;
89 esac
90 }
91
92 if [[ $(tty) == /dev/tty* ]] ; then
93   welcome_screen
94   askpwd
95   askvlock
96 elif [ -n "$DISPLAY" ] ; then
97   welcome_screen
98   askpwd
99   askxlock
100 fi
101
102 ## END OF FILE #################################################################