home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / sbin / pmi < prev    next >
Encoding:
Text File  |  2006-03-20  |  2.1 KB  |  91 lines

  1. #!/bin/bash
  2.  
  3. # This is the ACPI version of the shell version of PMI
  4.  
  5. # calling convention: pmi <event>
  6.  
  7. . /etc/default/acpi-support
  8. . /usr/share/acpi-support/device-funcs
  9.  
  10. DeviceConfig
  11.  
  12. command="$1"
  13. event="$2"
  14.  
  15. usage () {
  16.         echo "Usage: $0 query|action <event>" >&2
  17.         echo "       $0 capabilities" >&2
  18.         exit 254
  19. }
  20.  
  21. query () {
  22.         [ ! -z "$1" ] && event="$1" 
  23.         case "$event" in
  24.                 suspend|sleep)
  25.                         if [ "$ACPI_SLEEP" = true ]; then
  26.                                 result=0
  27.                         else
  28.                                 result=1
  29.                         fi
  30.                 ;;
  31.                 hibernate)
  32.                         if [ "$ACPI_HIBERNATE" = true ]; then
  33.                                 result=0
  34.                         else
  35.                                 result=1
  36.                         fi
  37.                 ;;
  38.                 *)
  39.                         result=1
  40.                         echo "No such event found" >&2
  41.                         ;;
  42.         esac
  43. }
  44.                         
  45. run () {
  46.         case "$event" in
  47.                 suspend|sleep)
  48.                         [ -f /var/lock/acpisleep ] && exit 0
  49.                         /etc/acpi/sleep.sh force
  50.                 ;;
  51.                 hibernate)
  52.                 [ -f /var/lock/acpisleep ] && exit 0
  53.                         /etc/acpi/hibernate.sh force
  54.                 ;;
  55.         restart)
  56.                [ -f /var/lock/acpisleep ] && exit 0
  57.                shutdown -r now
  58.         ;;
  59.         shutdown)
  60.                [ -f /var/lock/acpisleep ] && exit 0
  61.                shutdown -h now
  62.         ;;
  63.         esac
  64. }
  65.                 
  66. capabilities () {
  67.         for i in "hibernate" "suspend"; do
  68.                 query $i
  69.                 [ $result -eq 0 ] && caps="$caps $i"
  70.         done
  71.         echo $caps
  72. }
  73.  
  74. case "$command" in
  75.         query)
  76.                 query $event
  77.                 exit $result
  78.                 ;;
  79.         action)
  80.                 run $event
  81.                 ;;
  82.         capabilities)
  83.                 capabilities
  84.                 ;;
  85.         *)
  86.                 usage
  87.                 ;;
  88. esac
  89.  
  90. exit 0
  91.