grml-lock: use vlock also for X session. v1.2.5
authorMichael Prokop <mika@grml.org>
Fri, 19 Feb 2010 16:02:06 +0000 (17:02 +0100)
committerMichael Prokop <mika@grml.org>
Fri, 19 Feb 2010 16:02:06 +0000 (17:02 +0100)
debian/changelog
usr_bin/grml-lock

index 1d80d82..de47b1d 100644 (file)
@@ -1,3 +1,10 @@
+grml-scripts (1.2.5) unstable; urgency=low
+
+  * grml-lock: use vlock also for X session and slightly improve
+    its usage.
+
+ -- Michael Prokop <mika@grml.org>  Fri, 19 Feb 2010 17:01:31 +0100
+
 grml-scripts (1.2.4) unstable; urgency=low
 
   * zsh-login:
index a46d681..dd97c75 100755 (executable)
 
 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
-   if [ -z "$DISPLAY" ] ; then
-      check4progs vlock sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 }
-  else
-      check4progs xlock sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 }
-   fi
+   check4progs vlock sudo chpasswd dialog || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 }
 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_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
 
-welcome_screen() {
-dialog --stdout --title "$PN" --yes-label Continue --no-label Quit --yesno "Welcome to $PN!
-
-This script will lock virtual consoles when running
-on console or lock X server when running X.
-
-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)!
-
-Report bugs, send wishes and feedback to the grml team:
-http://www.grml.org/ - contact (at) grml.org
-" 16 65
-
-  case $? in
-      (0)   # everything ok
-            ;;
-      (1)   echo "Cancel pressed." ; exit 1 ;;
-      (255) echo "ESC pressed."    ; exit 255 ;;
-  esac
-}
-
-lockcons()
-{
-  vlock -a
-}
-
-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 ! isgrmlcd ; then
-   [[ $(tty) == /dev/tty* ]] && lockcons || lockx
+  lock_desktop
 else
-   if [[ $(tty) == /dev/tty* ]] ; then
-     welcome_screen
-     askpwd
-     askvlock
-   elif [ -n "$DISPLAY" ] ; then
-     welcome_screen
-     askpwd
-     askxlock
-   fi
+  is_passwd_set || askpwd
+  lock_desktop
 fi
 
 ## END OF FILE #################################################################