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 / laptop-detect < prev    next >
Encoding:
Text File  |  2007-03-02  |  1.2 KB  |  48 lines

  1. #!/bin/sh -e
  2.  
  3. # Are we a mac?
  4. if test -d /proc/pmu; then
  5.         batteries=$(grep Battery /proc/pmu/info| cut -f2 -d:)
  6.         if test "$batteries" -ne 0; then
  7. #                echo "We're a laptop" &>2;
  8.                 exit 0
  9.         fi
  10.         exit 1
  11. fi
  12.  
  13. if [ -r /dev/mem -a -x /usr/sbin/dmidecode ]; then
  14.         # dmidecode to grab the Chassis type
  15.         dmitype=$(dmidecode -s chassis-type)
  16.  
  17.         if test "$dmitype" = "Notebook" || test "$dmitype" = "Portable"; then
  18. #               echo "We're a laptop" >&2;
  19.                 exit 0;
  20.         fi
  21.  
  22.         # turn back on for debugging
  23.         #echo "$dmitype"
  24. fi
  25.  
  26. # check for any ACPI batteries
  27. if [ -d /proc/acpi/battery ]; then
  28.         results=`find /proc/acpi/battery/ -mindepth 1 -type d`
  29.         if [ ! -z "$results" ]; then
  30.         #we're almost certainly a laptop
  31. #                echo "We're a laptop" >&2;
  32.                 exit 0
  33.         fi
  34. fi
  35.  
  36. # check for APM batteries. This sucks, because we'll only get a valid response
  37. # if the laptop has a battery fitted at the time
  38. if [ -f /proc/apm ]; then
  39.     battery=`awk '{print $6}' </proc/apm`
  40.     if [ "$battery" != "0xff" ] && [ "$battery" != "0x80" ]; then
  41.     # There's a battery
  42.     exit 0;
  43.     fi
  44. fi
  45.  
  46. #probably not a laptop; exit 
  47. exit 1
  48.