#!/bin/zsh # 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. ################################################################################ PN="$0" [ -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/script-functions ] ; then . /etc/grml/script-functions check4progs vlock sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 } fi 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 lock_desktop() { vlock -a -n -s } is_passwd_set() { if sudo grep -q "$USER:\*:" /etc/shadow ; then return 1 else return 0 fi } 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 "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 ! isgrmlcd ; then lock_desktop else is_passwd_set || askpwd lock_desktop fi ## END OF FILE #################################################################