X-Git-Url: http://git.grml.org/?a=blobdiff_plain;ds=inline;f=usr_bin%2Fgrml-lock;h=dd97c753356b2f940f77a53d87346bb8e037a522;hb=58e1efcae0965c5dfb2fe06d5764a1a2e3633631;hp=2d750506e8bcb2fd25de09293c7f8d5b22e18766;hpb=e720deae78f1eda5e6f62629606c194f16796762;p=grml-scripts.git diff --git a/usr_bin/grml-lock b/usr_bin/grml-lock index 2d75050..dd97c75 100755 --- a/usr_bin/grml-lock +++ b/usr_bin/grml-lock @@ -4,94 +4,68 @@ # 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: Sam Mai 27 15:12:24 CEST 2006 [mika] ################################################################################ -PN=$0 +PN="$0" -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 -fi - -welcome_screen() { -dialog --stdout --title "$PN" --msgbox "Welcome to $PN! +[ -n "$USER" ] || USER=grml -This script will lock virtual consoles when running -on console or lock X server when running X. +if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then + echo "${PN}: wrapper script to lock desktop -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)! +This script is a wrapper to lock your desktop session +through the vlock application. -Report bugs, send wishes and feedback to the grml team: -http://www.grml.org/ - contact (at) grml.org -" 16 65 -} +Usage: just execute $PN without any further options." + exit 0 +fi +if [ -r /etc/grml/script-functions ] ; then + . /etc/grml/script-functions + check4progs vlock sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 } +fi -lockcons() -{ - vlock -a -} +if ! [ -r /etc/grml_version ] ; then + dialog --stdout --title "$PN" --msgbox "Warning: this system does not look like a grml (based) system +and therefore might not work as intended." 7 70 +fi -lockx() -{ - xlock +lock_desktop() { + vlock -a -n -s } -askxlock() -{ - dialog --stdout --title "$PN" --yesno "Now lock X?" 0 0 - retval=$? - case $retval in - 0) - lockx - ;; - esac +is_passwd_set() { + if sudo grep -q "$USER:\*:" /etc/shadow ; then + return 1 + else + return 0 + fi } -askvlock() -{ - dialog --stdout --title "$PN" --yesno "Now lock consoles?" 0 0 - retval=$? - case $retval in - 0) - lockcons - ;; - esac +set_passwd() { + PASSWD1=$(dialog --stdout --title "$PN" --passwordbox "Set password (hidden typing):" 0 0) + PASSWD2=$(dialog --stdout --title "$PN" --passwordbox "Retype new password:" 0 0) + if [ "$PASSWD1" = "$PASSWD2" ] ; then + echo "$USER:$PASSWD2" | sudo chpasswd + else + dialog --stdout --title "$PN" --msgbox "Error: passwords to not match. Exiting." 0 0 + exit 1 + 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 +askpwd() { + dialog --stdout --title "$PN" --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 + if [ "$?" -eq 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 + lock_desktop fi ## END OF FILE #################################################################