home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / sbin / pmi < prev    next >
Encoding:
Text File  |  2007-04-10  |  2.2 KB  |  92 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 -o -f /var/run/do-not-hibernate ]; then
  33.                                 result=1
  34.                         else
  35.                                 result=0
  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.             [ -f /var/run/do-not-hibernate ] && echo "Default kernel has been upgraded" >&2 && exit 1
  54.                         /etc/acpi/hibernate.sh force
  55.                 ;;
  56.         restart)
  57.                [ -f /var/lock/acpisleep ] && exit 0
  58.                shutdown -r now
  59.         ;;
  60.         shutdown)
  61.                [ -f /var/lock/acpisleep ] && exit 0
  62.                shutdown -h now
  63.         ;;
  64.         esac
  65. }
  66.                 
  67. capabilities () {
  68.         for i in "hibernate" "suspend"; do
  69.                 query $i
  70.                 [ $result -eq 0 ] && caps="$caps $i"
  71.         done
  72.         echo $caps
  73. }
  74.  
  75. case "$command" in
  76.         query)
  77.                 query $event
  78.                 exit $result
  79.                 ;;
  80.         action)
  81.                 run $event
  82.                 ;;
  83.         capabilities)
  84.                 capabilities
  85.                 ;;
  86.         *)
  87.                 usage
  88.                 ;;
  89. esac
  90.  
  91. exit 0
  92.