X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_bin%2Fgrml-lock;h=e3c775c9b47abddb28f607240b092b15ba50fd0d;hb=5b0c6b200fe0a76b7a78c984733defdb3120ea6a;hp=9d63aaacc9ad6a71295a20164a87160921ac5011;hpb=594106bdaed1436c748160234766e0fbb5f697db;p=grml-scripts.git diff --git a/usr_bin/grml-lock b/usr_bin/grml-lock index 9d63aaa..e3c775c 100755 --- a/usr_bin/grml-lock +++ b/usr_bin/grml-lock @@ -1,113 +1,102 @@ -#!/bin/zsh +#!/bin/bash # Filename: grml-lock # Purpose: lock console # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Son Mai 06 15:52:16 CEST 2007 [mika] ################################################################################ -PN=$0 +PN="$(basename $0)" -if [ -r /etc/grml/script-functions ] ; then - . /etc/grml/script-functions - if [ -x /usr/bin/X ] ; then - check4progs vlock xlock sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 } - else - check4progs sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 } - fi +[ -n "$USER" ] || USER=grml + +if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then + echo "${PN}: wrapper script to lock desktop + +This script is a wrapper to lock your desktop session +through the vlock application. + +Usage: just execute $PN without any further options." + exit 0 fi -if [ -r /etc/grml_version ] ; then -else - dialog --stdout --title "$PN" --msgbox "Warning: this system does not look like a grml-system -it might not work as intended." 7 70 +if [ -r /etc/grml/script-functions ] ; then + . /etc/grml/script-functions + check4progs vlock sudo chpasswd dialog || { echo "Sorry, necessary tools missing - can not continue. Exiting.">&2 ; exit 1 ; } fi -welcome_screen() { -dialog --stdout --title "$PN" --yes-label Continue --no-label Quit --yesno "Welcome to $PN! +PWD_TEXT1="Set password (hidden typing):" +PWD_TEXT2="Retype new password:" -This script will lock virtual consoles when running -on console or lock X server when running X. +# by default use console frontend +DIALOG='dialog' +PWD_CMD="dialog --stdout --title $PN --passwordbox" -Notice that you can not lock a GNU screen-session -via this script, use the lockscreen command -instead (default is pressing ctrl-a x inside -GNU screen)! +# only if using X and gdialog + zenity are available use graphical frontend +if [ -n "$DISPLAY" ] && [ -x "$(which gdialog)" ] && [ -x "$(which zenity)" ] ; then + DIALOG='gdialog' + PWD_CMD="zenity --title $PN --entry --hide-text" +fi -Report bugs, send wishes and feedback to the grml team: -http://www.grml.org/ - contact (at) grml.org -" 16 65 +if ! [ -r /etc/grml_version ] ; then + $DIALOG --title "$PN" --msgbox "Warning: this system does not look like a Grml (based) system +and therefore might not work as intended." 7 70 +fi - case $? in - (0) # everything ok - ;; - (1) echo "Cancel pressed." ; exit 1 ;; - (255) echo "ESC pressed." ; exit 255 ;; - esac +lock_desktop() { + vlock -a -n -s } -lockcons() -{ - vlock -a +is_passwd_set() { + if sudo grep -q "$USER:\*:" /etc/shadow ; then + return 1 + else + return 0 + fi } -lockx() -{ - xlock -} +set_passwd() { + if [ "$DIALOG" = "gdialog" ] ; then + PASSWD1="$($PWD_CMD --text="$PWD_TEXT1")" + PASSWD2="$($PWD_CMD --text="$PWD_TEXT2")" + else + PASSWD1="$($PWD_CMD "$PWD_TEXT1" 0 0)" + PASSWD2="$($PWD_CMD "$PWD_TEXT2" 0 0)" + fi -askxlock() -{ - dialog --stdout --title "$PN" --yesno "Now lock X?" 0 0 - retval=$? - case $retval in - 0) - lockx - ;; - esac + if [ -z "$PASSWD1" ] ; then + $DIALOG --title "$PN" --msgbox "Error retrieving password. Exiting." 0 0 + exit 1 + fi + if [ "$PASSWD1" = "$PASSWD2" ] ; then + echo "$USER:$PASSWD2" | sudo chpasswd + else + $DIALOG --title "$PN" --msgbox "Error: passwords to not match. Exiting." 0 0 + exit 1 + fi } -askvlock() -{ - dialog --stdout --title "$PN" --yesno "Now lock consoles?" 0 0 - retval=$? - case $retval in - 0) - lockcons - ;; - esac -} +askpwd() { + if [ "$DIALOG" = "gdialog" ] ; then + 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?" + RC=$? + else + $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 + RC=$? + fi -askpwd() -{ -dialog --stdout --title "$PN" --yesno "Set password for user $USER?" 0 0 -retval=$? -case $retval in - 0) - while [ -z "$PASSWD" ] ; do - PASSWD=$(dialog --stdout --title "$PN" --passwordbox "Set password (hidden typing):" 0 0) - if [ -n "$PASSWD" ] ; then - echo "$USER:$PASSWD" | sudo chpasswd - else - dialog --stdout --title "$PN" --msgbox "Error while setting password. Empty passwords are not accepted." 6 65 - fi - done - ;; - *) -# asklock - ;; -esac + if [ "$RC" = "0" ] ; then + set_passwd + else + exit 1 + fi } -if [[ $(tty) == /dev/tty* ]] ; then - welcome_screen - askpwd - askvlock -elif [ -n "$DISPLAY" ] ; then - welcome_screen - askpwd - askxlock +if ! isgrmlcd ; then + lock_desktop +else + is_passwd_set || askpwd + [ "$?" = "0" ] && lock_desktop || exit 1 fi ## END OF FILE #################################################################