On 06/09/2012 02:49 AM, Nathaniel Parker wrote:
> I'm running Window Maker on CentOS 5.8 (i386). How can I add a command
> to the Window Maker Menu to Shut Down the Computer? 
> 
While i don't favor the notion to let normal users shutdown the machine
on actual multiuser systems, i guess it is fully acceptable for private
machines which are typically used by single users only.

Also, i don't know how this would properly translate to CentOS or any
other rpm based distribution, but here is how this can be achieved in
Debian/Ubuntu. Please adapt accordingly for your CentOS system.

If it is not already the case, add yourself to the sudoers by creating
following file ("username" should be your user name on the system):

-------- snip --------
# cat /etc/sudoers.d/username
# enabling shutdown for normal user:
username ALL=(root) NOPASSWD: /sbin/shutdown
-------- snip --------

This allows to directly shutdown if you add a suitable entry for a
shutdown call to the wmaker root menu. Downside of this approach is that
this executes the shutdown without any questions asked. So if you run
this from the wmaker root menu with an entry like "/sbin/shutdown -h
now" , it will take immediate effect, even if you only chose this menu
entry by accident.

For this reason it is advisable to safeguard oneself by using a little
wrapper script as an additinal layer in between, and add this one to the
wmaker root menu instead. Here is a possible approach (requires
installation of the gxmessage utility):

-------- snip --------
$ cat /usr/local/sbin/wmlive-shutdown
#!/bin/sh
#set -x

GXMSG="/usr/bin/gxmessage -center -wrap -name Shutdown"
HOMEGSTEPDIR="$HOME/GNUstep"

if [ "$DISPLAY" != "" ] && [ "$(grep $USER /etc/passwd | cut -d: -f3)" =
"1000" ] && [ -f /etc/sudoers.d/$USER ]
then
    $GXMSG -buttons "Cancel:1,Shutdown:0" -title "Shutdown the computer"
-file - << EOF

    Do you really want to shutdown and turn off the computer?
EOF
        if [ "$(echo "$?")" = "0" ]
        then
            sudo shutdown -h now
        else
            exit 0
        fi
else
    echo "Sorry, you are missing the privileges to shutdown the system."
fi
-------- snip --------

Use the WPrefs menu editor to add a suitable entry to your wmaker root
menu by dragging "Run Program" to the menu and editing this entry to
your liking. It is pretty much self explaining.

For the wmlive distribution (see wmlive.sf.net for information), i found
it to be a better approach to *not* add any such entry to any normal
user's wmaker root menu. Instead, we have normal users shutdown the
machine exclusively via the login manager GDM after having logged out
from his/her desktop session. GDM doesn't allow for easy shutdown if
other user sessions are still open on the same machine, unless the
sysadmin enforces it.

Hope this helps!

Paul


-- 
To unsubscribe, send mail to [email protected].

Reply via email to