Files
main/hardware/info/dmidecode/files/laptop-detect
T
2015-07-28 10:10:58 +03:00

32 lines
864 B
Bash

#!/bin/sh -e
if [ -r /dev/mem -a -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
exit 0;
fi
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
exit 0
fi
fi
# check for APM batteries. This sucks, because we'll only get a valid response
# if the laptop has a battery fitted at the time
if [ -f /proc/apm ]; then
battery=`awk '{print $6}' </proc/apm`
if [ "$battery" != "0xff" ] && [ "$battery" != "0x80" ]; then
# There's a battery
exit 0;
fi
fi
#probably not a laptop; exit
exit 1