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 ################################################################################
11 [ -n "$USER" ] || USER=grml
13 if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
14 echo "${PN}: wrapper script to lock desktop
16 This script is a wrapper to lock your desktop session
17 through the physlock application.
19 Usage: just execute $PN without any further options."
23 if [ -r /etc/grml/script-functions ] ; then
24 . /etc/grml/script-functions
25 check4progs physlock sudo chpasswd dialog || { echo "Sorry, necessary tools missing - can not continue. Exiting.">&2 ; exit 1 ; }
28 PWD_TEXT1="Set password (hidden typing):"
29 PWD_TEXT2="Retype new password:"
31 # by default use console frontend
33 PWD_CMD="dialog --stdout --title $PN --passwordbox"
35 # only if using X and gdialog + zenity are available use graphical frontend
36 if [ -n "$DISPLAY" ] && [ -x "$(which gdialog)" ] && [ -x "$(which zenity)" ] ; then
38 PWD_CMD="zenity --title $PN --entry --hide-text"
41 if ! [ -r /etc/grml_version ] ; then
42 $DIALOG --title "$PN" --msgbox "Warning: this system does not look like a Grml (based) system
43 and therefore might not work as intended." 7 70
47 # be backwards compatible, see https://github.com/grml/grml/issues/87
48 if physlock --help 2>&1 | grep -q -- '-u user' ; then
49 sudo physlock -u "$USER"
56 if sudo grep -q "$USER:\*:" /etc/shadow ; then
64 if [ "$DIALOG" = "gdialog" ] ; then
65 PASSWD1="$($PWD_CMD --text="$PWD_TEXT1")"
66 PASSWD2="$($PWD_CMD --text="$PWD_TEXT2")"
68 PASSWD1="$($PWD_CMD "$PWD_TEXT1" 0 0)"
69 PASSWD2="$($PWD_CMD "$PWD_TEXT2" 0 0)"
72 if [ -z "$PASSWD1" ] ; then
73 $DIALOG --title "$PN" --msgbox "Error retrieving password. Exiting." 0 0
76 if [ "$PASSWD1" = "$PASSWD2" ] ; then
77 echo "$USER:$PASSWD2" | sudo chpasswd
79 $DIALOG --title "$PN" --msgbox "Error: passwords do not match. Exiting." 0 0
85 if [ "$DIALOG" = "gdialog" ] ; then
86 zenity --title="$PN" --question --cancel-label='Exit' --ok-label='Set password' --text="User $USER has no password set yet. Without a password you will not be able to log in again. Set password for user $USER?"
89 $DIALOG --title "$PN" --no-label Exit --yes-label Continue --yesno "User $USER has no password set yet. Without a password you will not be able to log in again. Set password for user $USER?" 0 0
93 if [ "$RC" = "0" ] ; then
103 is_passwd_set || askpwd
104 [ "$?" = "0" ] && lock_desktop || exit 1
107 ## END OF FILE #################################################################