Скрипт управления питанием через HAL
Скрипт я написал еще в то время, когда в portage был только Xfce 4.5, в диалоге выключения которого, как известно, режимов suspend to ram и suspend to disk нет. Скрипт простой, непритязательный, и сейчас для меня довольно бесполезный. Однако, может быть, кому-нибудь и пригодится. Лицензия GPLv2, чтобы не расслаблялись :) А вообще скрипт вполне ничего себе пример использования Xdialog для взаимодействия с пользователем и qdbus для взаимодействия с DBus вообще и с HAL в частности.
#!/bin/bash
#Copyright (C) 2009 Nikolay "Livid" Yakimov
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You can get GNU General Public License version 2 at
#http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
function Usage {
echo "Usage: "
echo $0 "hibernate|reboot|shutdown|suspend|suspendh"
echo $0 "h|r|sd|ss|sh"
echo $0 "setps true|false"
echo $0 "gui"
echo -e "Command\t Syn Description"
echo -e "shutdown sd Shut the system down"
echo -e "reboot r Reboots the system"
echo -e "suspend\t ss Suspends system"
echo -e "suspendh sh Tries to hybrid-suspend system (unsupported now)"
echo -e "hibernate h Hibernates system"
echo -e "setps SetPowerSave"
}
if [ "$1" == "gui" ]; then
COMMAND=`Xdialog --title "Power Control" --no-tags --menubox "Select mode" 0 0 5 sd "Shutdown" r "Reboot" ss "Suspend" h "Hibernate" 2>&1`
else
COMMAND="$1"
fi
case "$COMMAND" in
h|hibernate)
qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
;;
r|reboot)
qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Reboot
;;
sd|shutdown)
qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
;;
ss|suspend)
qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend 0
;;
sh|suspendh)
echo "Currently unsuppoted. Sorry."
#qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.SuspendHybrid 0
;;
setps)
if [ "$2" == "true" ] || [ "$2" == "false" ]; then
qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.SetPowerSave $2
else
Usage
fi
;;
*)
Usage
esac