home *** CD-ROM | disk | FTP | other *** search
/ tusportal.tus.k12.pa.us / tusportal.tus.k12.pa.us.tar / tusportal.tus.k12.pa.us / Wyse / latest-image.raw / 0.img / usr / bin / powersave < prev    next >
Text File  |  2009-02-20  |  6KB  |  196 lines

  1. #!/bin/bash
  2. #
  3. # legacy script for the old powersave command line client
  4. #
  5. # Copyright (C) 2008 Holger Macht <hmacht@suse.de>
  6. #
  7. # This file is released under the GPLv2.
  8. #
  9.  
  10. HAL_COMPUTER_PATH="/org/freedesktop/Hal/devices/computer"
  11.  
  12. function standby {
  13.     dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  14.     $HAL_COMPUTER_PATH \
  15.     org.freedesktop.Hal.Device.SystemPowerManagement.Standby
  16. }
  17.  
  18. function suspend_to_ram {
  19.     dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  20.     $HAL_COMPUTER_PATH \
  21.     org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0
  22. }
  23.  
  24. function suspend_to_disk {
  25.     dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  26.     $HAL_COMPUTER_PATH \
  27.     org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
  28. }
  29.  
  30. function battery_info {
  31.     C=1
  32.     for I in `hal-find-by-capability --capability battery`; do
  33.  
  34.     SEC=`hal-get-property --udi $I --key battery.remaining_time`
  35.     MIN=`echo $(($SEC / 60)) minutes`
  36.  
  37.     PERC=`hal-get-property --udi $I --key battery.charge_level.percentage`
  38.     STATE_C=`hal-get-property --udi $I --key battery.rechargeable.is_charging`
  39.     STATE_D=`hal-get-property --udi $I --key battery.rechargeable.is_discharging`
  40.  
  41.     if [ "$STATE_C" = "$STATE_D" ]; then
  42.         STATE="undefined"
  43.     else
  44.         if [ "$STATE_C" = "true" ]; then
  45.         STATE="charging"
  46.         else
  47.         STATE="discharging"
  48.         fi
  49.     fi
  50.  
  51.     echo "Battery$C:"
  52.     echo -e "\t Remaining percent: $PERC"
  53.     echo -e "\t Remaining minutes: $MIN"
  54.     echo -e "\t Charging state: $STATE"
  55.  
  56.     let C=C+1
  57.     done
  58. }
  59.  
  60. function ac_status_info {
  61.     UDI=`hal-find-by-capability --capability ac_adapter`
  62.     if [ -z "$UDI" ]; then
  63.          echo "No AC adapter found"
  64.     return
  65.     fi
  66.     AC=`hal-get-property --udi $UDI --key ac_adapter.present`
  67.  
  68.     if [ "$AC" = "false" ]; then
  69.     echo "OFFLINE"
  70.     else
  71.     echo "ONLINE"
  72.     fi
  73. }
  74.  
  75. function list_schemes {
  76.     for I in /etc/pm-profiler/*; do
  77.     [ -d $I ] && echo `basename $I`
  78.     done
  79. }
  80.  
  81. function show_scheme_description {
  82.     . /etc/pm-profiler/$1/config
  83.     echo $NAME:
  84.     echo $DESCRIPTION
  85. }
  86.  
  87. function set_active_scheme {
  88.     if [ "$UID" != "0" ]; then
  89.     echo "You must be root to enable a profile"
  90.     exit 1
  91.     fi
  92.     /usr/lib/pm-profiler/enable-profile $1
  93. }
  94.  
  95. function performance_speed {
  96.     dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  97.     $HAL_COMPUTER_PATH \
  98.     org.freedesktop.Hal.Device.CPUFreq.SetCPUFreqGovernor \
  99.     string:performance > /dev/null
  100. }
  101.  
  102. function powersave_speed {
  103.     dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  104.     $HAL_COMPUTER_PATH \
  105.     org.freedesktop.Hal.Device.CPUFreq.SetCPUFreqGovernor \
  106.     string:powersave > /dev/null
  107. }
  108.  
  109. function dynamic_speed {
  110.     dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  111.     $HAL_COMPUTER_PATH \
  112.     org.freedesktop.Hal.Device.CPUFreq.SetCPUFreqGovernor \
  113.     string:ondemand > /dev/null
  114. }
  115.  
  116. function cpufreq_state_info {
  117.     HAVE_CPUFREQ=`hal-find-by-capability --capability cpufreq_control`
  118.     if [ -z "$HAVE_CPUFREQ" ]; then
  119.          echo "CPU Frequency scaling not supported"
  120.     return
  121.     fi
  122.  
  123.     GOVERNOR="`dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  124.     $HAL_COMPUTER_PATH \
  125.     org.freedesktop.Hal.Device.CPUFreq.GetCPUFreqGovernor `"
  126.     GOVERNOR="`echo $GOVERNOR | sed -e 's/.* string "\(.*\)"/\1/'`"
  127.  
  128.     case "$GOVERNOR" in
  129.     ondemand|conservative) echo DYNAMIC ;;
  130.     performance) echo PERFORMANCE ;;
  131.     powersave) echo POWERSAVE ;;
  132.     *) echo "Unknown policy" ;;
  133.     esac
  134. }
  135.  
  136. function usage {
  137.     echo
  138.     echo -e "ATTENTION:\tThis is a legacy tool to provide basic functionality of the obsolete"
  139.     echo -e "\t\tpowersave daemon. It will vanish in future."
  140.     echo
  141.     echo "Usage: powersave [OPTIONS]"
  142.     echo
  143.     echo " Suspend/Standby:"
  144.     echo -e "\t -U, --suspend-to-disk\t\t set machine into suspend-to-disk (ACPI S4/APM suspend)"
  145.     echo -e "\t -u, --suspend-to-ram\t\t set machine into suspend-to-ram  (ACPI S3/APM suspend)"
  146.     echo -e "\t -m, --standby\t\t\t set machine into standby         (ACPI S1/APM standby)"
  147.     echo
  148.     echo " Print information:"
  149.     echo -e "\t -b, --battery-info\t\t general battery info"
  150.     echo -e "\t -a, --ac-status-info\t\t power supply info (AC/Battery)"
  151.     echo
  152.     echo " Profiles:"
  153.     echo -e "\t -x, --list-schemes\t\t show all available schemes/profiles"
  154.     echo -e "\t -X, --show-scheme-description\t show scheme description"
  155.     echo -e "\t -e <x>, --set-active-scheme <x> switch currently active scheme/profile"
  156.     echo
  157.     echo " CPUFreq modes:"
  158.     echo -e "\t -f, --performance-speed\t set cpufreq to performance mode"
  159.     echo -e "\t -l, --powersave-speed\t\t set cpufreq to powersave mode"
  160.     echo -e "\t -A, --dynamic-speed\t\t set cpufreq to dynamic mode"
  161.     echo -e "\t -c, --cpufreq-state-info\t print out the current cpufreq policy"
  162.     echo
  163. }
  164.  
  165.  
  166. TEMP=`getopt -o muUbe:ahxX:flAc --long suspend-to-ram,suspend-to-disk,set-active-scheme:,\
  167. battery-info,ac-status-info,help,list-schemes,show-scheme-description:,performance-speed,powersave-speed,\
  168. dynamic-speed,cpufreq-state-info,standby \
  169.     -n 'example.bash' -- "$@"`
  170.  
  171. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  172.    
  173. # Note the quotes around `$TEMP': they are essential!
  174. eval set -- "$TEMP"
  175.  
  176. while true ; do
  177.     case "$1" in
  178.     -m|--standby) standby ; shift ;;
  179.         -u|--suspend-to-ram) suspend_to_ram; shift ;;
  180.         -U|--suspend-to-disk) suspend_to_disk; shift ;;
  181.     -b|--battery-info) battery_info ; shift ;;
  182.     -a|--ac-status-info) ac_status_info ; shift ;;
  183.     -x|--list-schemes) list_schemes ; shift ;;
  184.     -X|--show-scheme-description) show_scheme_description $2 ; shift 2 ;;
  185.     -f|--performance-speed) performance_speed ; shift ;;
  186.     -l|--powersave-speed) powersave_speed ; shift ;;
  187.     -A|--dynamic-speed) dynamic_speed ; shift ;;
  188.     -c|--cpufreq-state-info) cpufreq_state_info ; shift ;;
  189.         -e|--set-active-scheme) set_active_scheme $2 ; shift 2 ;;
  190.     -h|--help) usage ; shift ;;
  191.         --) shift ; break ;;
  192.         *) echo "Internal error!" ; exit 1 ;;
  193.     esac
  194. done
  195.  
  196.