#!/bin/sh -e

# Are we a mac?
if test -d /proc/pmu; then
        batteries=$(grep Battery /proc/pmu/info| cut -f2 -d:)
        if test "$batteries" -ne 0; then
#                echo "We're a laptop" &>2;
                exit 0
        fi
        exit 1
fi

if [ -x /usr/sbin/dmidecode ]; then
        # dmidecode to grab the Chassis type
        dmitype=$(dmidecode|grep Chassis -A 10|grep -m1 Type|sed -e 's/.*Type: \(.*\)/\1/')

        if test "$dmitype" = "Notebook" || test "$dmitype" = "Portable"; then
#               echo "We're a laptop" >&2;
                exit 0;
        fi

        # turn back on for debugging
        #echo "$dmitype"
fi

# check for any ACPI batteries
if [ -d /proc/acpi/battery ]; then
        results=`find /proc/acpi/battery/ -mindepth 1 -type d`
        if [ ! -z "$results" ]; then
        #we're almost certainly a laptop
#                echo "We're a laptop" >&2;
                exit 0
        fi
fi

#probably not a laptop; exit 
exit 1
