Logoff script

Console-based Exit Dialog

In my openbox setup I use the following script to provide a logoff dialog:

#!/bin/bash
# $HOME/bin/session-exit.sh
cat << EOF
Do you want to

 (L)og off
 (S)uspend
 (R)eboot
 (P)ower off
 ---
 (C)ancel
   
EOF
read -p "Your choice: " -n 1 action
echo " "
echo " "

case $action in 
        [Ll])
                echo "Logging off ..."
       openbox --exit
                ;;
        [Ss])
               echo "Suspending ..."
       sudo pm-suspend
                ;;
        [Rr])
                echo "Rebooting ..."
       sudo shutdown -r now
                ;;
        [Pp])
                echo "Shutting down ..."
       sudo shutdown -h now
                ;;
        [Cc])
                echo "Cancelled ..."
                sleep 1
                ;;
        *)
                echo "Invalid input $action"
                sleep 1
                ;;
esac

The following snippet in rc.xml maps it to Super-X:

    <keybind key="W-x">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Logout</name>
        </startupnotify>
        <command>terminator --geometry=300x200+500+250 -T "Exit" -e session-exit.sh</command>
      </action>
    </keybind>

What you also need is password-less execution of the shutdown / suspend commands in sudoers:

ALL ALL = NOPASSWD: /sbin/shutdown
ALL ALL = NOPASSWD: /usr/bin/pm-suspend