Sunday, February 15, 2015

openbox shutdown

There are a few different approaches to take for rebooting or shutting down the computer when you're running Openbox. In the past, I've simply exited the window manager and then rebooted or shut down from the login screen. CrunchBang uses the Python script cb-exit; I decided to take a different approach in Debian Jessie.

First, I installed gxmessage from the Debian repos. Then I ran visudo (as root) and edited the /etc/sudoers file, adding the following lines to the end of the file:

# Cmnd alias specification
Cmnd_Alias      SHUTDOWN = /sbin/shutdown

# User privilege specification
steve ALL=SHUTDOWN
steve ALL=NOPASSWD: SHUTDOWN


Tested that with:

$ sudo shutdown -k now


Created ~/shutdown-script:

#!/bin/bash

gmessage "Shut down the computer?" -center -title "Take action" -font "Sans bold 10" -default "Cancel" -buttons "_Cancel":1,"_Log Out":2,"_Reboot":3,"_Shut Down":4 >/dev/null 

case $? in
1)
echo "Exit";;
2)
openbox --exit;;
3)
sudo shutdown -r now;;
4)
sudo shutdown -h now;;
esac


Made that executable. Added a Shut Down option to the Openbox menu that uses the command /home/steve/shutdown-script. Done.




See: Giving ordinary users root privileges, selectively at debian-administration.org and the "Allow users to shutdown computer from a window manager" thread at debianuserforums.org.

Also see: https://urukrama.wordpress.com/openbox-guide/#shutdown and https://urukrama.wordpress.com/2007/12/03/confirm-to-shut-down-reboot-or-log-out-in-openbox/

No comments: