devicetype-detect-0.03/0000755000000000000000000000000011614365044011735 5ustar devicetype-detect-0.03/devicename-detect.in0000644000000000000000000000636711614362617015652 0ustar #! /bin/sh # # Copyright 2010 Emmet Hikory # # With thanks to Evan Dandrea for pointing the way # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. usage () { echo "Usage: $0 [-h|--help|-v|--verbose|-V|--version]" echo "" echo " -h | --help print this help" echo " -V | --version print version information" } if [ "$1" != "" ]; then case "$1" in "-h" | "--help") usage exit 1 ;; "-V" | "--version") echo "Version: @VERSION@" exit 1 ;; --debug) set -x ;; esac fi amd64name() { # Some things are the same i386name } armelname() { # The contents vary wildly, but the location is always the same NAME=$(grep Hardware /proc/cpuinfo | cut -d: -f2) } i386name() { # The logic here comes mostly from ubiquity MANUFACTURER="" if [ -x "/usr/sbin/dmidecode" ]; then MANUFACTURER=$(dmidecode --string system-manufacturer | tr [A-Z] [a-z]) fi if [ -z "$MANUFACTURER" ] || \ echo "$MANUFACTURER" | grep -q "to be filled"; then NAME="" elif echo "$MANUFACTURER" | grep -q "bochs" || echo "$MANUFACTURER" | grep -q "vmware"; then NAME="virtual machine" else KEY="system-product-name" echo "$MANUFACTURER" | grep -q "lenovo" && KEY="system-version" echo "$MANUFACTURER" | grep -q "ibm" && KEY="system-version" NAME=$(dmidecode --string "$KEY" ) echo "$MANUFACTURER" | grep -q "apple" && \ NAME=$(echo $NAME | sed 's/[,d]*$//') fi } powerpcname() { # Some machines have proper kernel detection NAME=$(grep ^detected /proc/cpuinfo | cut -d: -f2 | \ sed 's/.*(\(.*\))/\1/' ) # Others store the information in the "machine" field if [ -z "$NAME" ]; then NAME=$(grep ^machine /proc/cpuinfo | cut -d: -f2 | tr [A-Z] [a-z] ) grep -q Power "$NAME" && NAME=$(cat "$NAME" | sed s/[,\d]*$//) grep -q '(' "$NAME" && NAME=$(cat "$NAME" | sed 's/.*(\(.*\))/\1/') fi # Sony is special if [ -z "$NAME" ]; then NAME=$(grep ^model /proc/cpuinfo | cut -d: -f2 | tr [A-Z] [a-z]) fi } # Get the base name in an architecture-dependent way NAME="" FUNCTION=$(dpkg --print-architecture)name if type $FUNCTION > /dev/null; then $FUNCTION else echo "Not ported yet" 1>&2 fi # Either clean it up, or try with devicetype-detect if [ ! -z "$NAME" ]; then NAME=$(echo $NAME | sed -e 's/^[\ -]*//' -e 's/[\ -]*$//' -e 's/\ /-/g') else NAME=$(devicetype-detect) fi echo "$NAME" devicetype-detect-0.03/Makefile0000644000000000000000000000070511471304016013370 0ustar #! /usr/bin/make -f VERSION?=UNRELEASED MODULES:=devicename-detect devicetype-detect SCRIPTS=$(foreach module,${MODULES},${module}.sh) all: ${SCRIPTS} %.sh: %.in sed -e "s/@VERSION@/${VERSION}/" < $< > $@ clean: -rm -r ${SCRIPTS} install: ${SCRIPTS} install -D -m 755 devicename-detect.sh \ ${DESTDIR}/usr/bin/devicename-detect install -D -m 755 devicetype-detect.sh \ ${DESTDIR}/usr/bin/devicetype-detect .PHONY: all clean install devicetype-detect-0.03/devicename-detect.10000644000000000000000000000101011471265555015364 0ustar .TH DEVICENAME-DETECT 1 .SH NAME devicename-detect \- Pick a default name for a device .SH SYNOPSIS .B devicename-detect [\fB\-h\fR|\fB\-\-help\fR|\fB\-V\fR|\fB\-\-version\fR] .SH DESCRIPTION .B devicename-detect outputs a default name for the device based on autodetectable information from various sources (dmidecode, devicetype-detect, cpuinfo). .SH OPTIONS .TP .BR \-h ", " \-\-help display a usage message and exit .TP .BR \-V ", " \-\-version output version information and exit .SH AUTHOR Written by Emmet Hikory devicetype-detect-0.03/debian/0000755000000000000000000000000011614365044013157 5ustar devicetype-detect-0.03/debian/changelog0000644000000000000000000000167711614365021015037 0ustar devicetype-detect (0.03) oneiric; urgency=low * devicetype-detect.in: Fix sed expression for i386/amd64 apple laptops * devicetype-detect.in: Uncomment and fix /proc ACPI tests -- Emmet Hikory Fri, 29 Jul 2011 07:57:01 +0900 devicetype-detect (0.02) oneiric; urgency=low * devicetype-detect.in: Wrap xrandr calls in conditionals (LP: #702416) * devicetype-detect.in: Syntax cleanups when battery is detected * devicename-detect.in: don't use -e: shell doesn't notice all the tests * devicename-detect.in: clean up missing ports analysis * debian/control: Update description to promote devicename-detect * debian/control: Add Suggests for x11-xserver-utils for xrandr * Bump standards to 3.9.2 (no changes) -- Emmet Hikory Fri, 29 Jul 2011 02:17:02 +0900 devicetype-detect (0.01) natty; urgency=low * Initial release. -- Emmet Hikory Fri, 19 Nov 2010 03:28:01 +0900 devicetype-detect-0.03/debian/clean0000644000000000000000000000004311471275213014160 0ustar debian/devicetype-detect.substvars devicetype-detect-0.03/debian/control0000644000000000000000000000131311614266266014566 0ustar Source: devicetype-detect Section: utils Priority: optional Maintainer: Ubuntu Developers Build-Depends: debhelper (>= 7.0.50~) Standards-Version: 3.9.2 Package: devicetype-detect Architecture: all Depends: ${misc:Depends} Recommends: dmidecode (>> 2.7) Suggests: x11-xserver-utils (>> 7.4+2) Description: attempt to detect the type of the current device devicetype-detect attempts to determine device class of the running system based on the display size, display resolution, and presence or absence of a battery. . devicename-detect attempts to determine the name of the device, to the best knowledge of the device itself, for use as a sensible default model name. devicetype-detect-0.03/debian/compat0000644000000000000000000000000211471270045014352 0ustar 7 devicetype-detect-0.03/debian/copyright0000644000000000000000000000165111471270367015121 0ustar Format Specifcation: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135 Name: devicetype-detect Maintainer: Emmet Hikory Files: * Copyright: 2010, Emmet Hikory License: ISC Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. devicetype-detect-0.03/debian/rules0000755000000000000000000000023611471275630014242 0ustar #!/usr/bin/make -f export VERSION:=$(shell dpkg-parsechangelog \ | grep Version: \ | sed 's/^Version: \(.*\)/\1/g') %: dh $@ devicetype-detect-0.03/debian/source/0000755000000000000000000000000011471270555014462 5ustar devicetype-detect-0.03/debian/source/format0000644000000000000000000000001511471270653015670 0ustar 3.0 (native) devicetype-detect-0.03/debian/devicetype-detect.manpages0000644000000000000000000000005011471270032020267 0ustar devicename-detect.1 devicetype-detect.1 devicetype-detect-0.03/devicetype-detect.10000644000000000000000000000337011471265574015441 0ustar .TH DEVICETYPE-DETECT 1 .SH NAME devicetype-detect \- attempt to detect the type of the current device .SH SYNOPSIS .B devicetype-detect [\fB\-h\fR|\fB\-\-help\fR|\fB\-v\fR|\fB\-\-verbose\fR|\fB\-V\fR| \fB\-\-version\fR|\fB\-\-compat\fR] .SH DESCRIPTION .B devicetype-detect attempts to determine device class of the running system based on the display size, display resolution, and presence or absence of a battery. Depending on the detected device, one of "phone", "desktop", "netbook", or "laptop" will be printed to STDOUT. .SH OPTIONS .TP .BR \-h ", " \-\-help display a usage message and exit .TP .BR \-v ", " \-\-verbose print extra information to STDERR during detection .TP .BR \-V ", " \-\-version output version information and exit .TP .BR \-\-compat Attempt to mimic the return codes for .BR laptop-detect (1) .SH EXIT STATUS .TP .BR 0 Detection was successfully attempted .TP .BR 1 Detection was successfully attempted, and device is a desktop (has no battery) [only in \fB\-\-compat\fR mode] .TP .BR 2 Invalid Options .TP .BR Others Errors in the detection process (please report a bug) .SH NOTES The device type detection is necessarily crude, and would benefit hugely from clearer product differentiation. With "phones" having resolutions of 1280x720 or greater, "laptops" available down to 3.7" diagonal, "desktops" with internal batteries for "power conditioning", and an increasing presence of modems, both AT and 3G in devices of all classes, device class is often determined by the usage model of specific individuals, rather than objective measurements of the device. .SH BUGS It would be a great boon to be able to detect tablets by determining if there is a physical keyboard available. .SH SEE ALSO .BR laptop-detect (1) .SH AUTHOR Written by Emmet Hikory devicetype-detect-0.03/devicetype-detect.in0000644000000000000000000001123211614364371015675 0ustar #! /bin/sh -e # # Copyright 2010 Emmet Hikory # # With thanks to Thom May and Otavio Salvador for documenting battery # detection interfaces in laptop-detect # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. usage () { echo "Usage: $0 [-h|--help|-v|--verbose|-V|--version]" echo "" echo " -h | --help print this help" echo " -v | --verbose be verbose (messages go to STDERR)" echo " -V | --version print version information" } VERBOSE="" DESKRET="0" if [ "$1" != "" ]; then case "$1" in "-h" | "--help") usage exit 2 ;; "-V" | "--version") echo "Version: @VERSION@" exit 2 ;; --debug) set -x ;; "-v" | "--verbose") VERBOSE="Tell Me Everything!!!" ;; --compat) DESKRET=1 ;; esac fi # Get resolution and screen size if [ -x /usr/bin/xrandr ]; then RESOLUTION=$(/usr/bin/xrandr -q | awk -F, '/current/ {print $2 }') SIZE=$(/usr/bin/xrandr -q | awk -F\ '/ connected/ {print $(NF-2) " x " $NF }') [ -z "$VERBOSE" ] || xrandr --current --query 1>&2 XRES=$(echo "$RESOLUTION" | cut -d\ -f3) [ -z "$VERBOSE" ] || echo X Resolution appears to be $XRES 1>&2 YRES=$(echo "$RESOLUTION" | cut -d\ -f5) [ -z "$VERBOSE" ] || echo Y Resolution appears to be $YRES 1>&2 XSIZE=$(echo "$SIZE" | cut -dx -f1 | tr -d \ m ) [ -z "$VERBOSE" ] || echo X Size appears to be $XSIZE 1>&2 YSIZE=$(echo "$SIZE" | cut -dx -f2 | tr -d \ m ) [ -z "$VERBOSE" ] || echo Y Size appears to be $YSIZE 1>&2 else XRES=0 YRES=0 XSIZE=0 YSIZE=0 fi # Check for batteries BATTERIES=0 BATTERY="/bin/false" # ACPI Batteries (/proc/ interface) if [ -d /proc/acpi/battery ]; then # Lie and pretend any battery detection is a single battery [ ! -z $(find /proc/acpi/battery -mindepth 1 -type d) ] && BATTERIES="1" [ -z "$VERBOSE" -o "$BATTERIES" -ne "0" ] || \ echo Found ACPI Battery 1>&2 fi "$BATTERY" || [ "$BATTERIES" -ne "0" ] && BATTERY="/bin/true" # APM Batteries if [ -d /proc/apm ]; then # Lie and pretend any battery detection is a single battery BATMASK=$(cut -d\ -f6 < /proc/apm) [ "$BATMASK" != "0xff" -a $BATMASK != "0x80" ] && BATTERIES="1" [ -z "$VERBOSE" -o "$BATTERIES" -ne "0" ] || \ echo Found APM Battery 1>&2 fi "$BATTERY" || [ "$BATTERIES" -ne "0" ] && BATTERY="/bin/true" # PMU Batteries if [ -d /proc/pmu ]; then BATTERIES=$(grep Battery /proc/pmu/info | cut -d: -f2) [ -z "$VERBOSE" -o "$BATTERIES" -ne "0" ] || \ echo Found "$BATTERIES PMU" Batteries 1>&2 fi "$BATTERY" || [ "$BATTERIES" -ne "0" ] && BATTERY="/bin/true" # ACPI Batteries (/sys/ interface) if [ -d /sys/class/power_supply ]; then BATTERIES=$(grep Battery /sys/class/power_supply/*/type 2>/dev/null | wc -l) [ -z "$VERBOSE" -o "$BATTERIES" -ne "0" ] || \ echo Found "$BATTERIES" ACPI Batteries 1>&2 fi "$BATTERY" || [ "$BATTERIES" -ne "0" ] && BATTERY="/bin/true" # TODO: parse /proc/bus/input/devices to determine if there is a keyboard # Determine the device type # If the screen is tiny, it's probably a phone if [ "$XSIZE" -ne "0" -a "$XSIZE" -lt "100" -a \ "$YSIZE" -ne "0" -a "$YSIZE" -lt "60" ]; then [ -z "$VERBOSE" ] || echo "The screen is very small: probably a phone" 2>&1 echo "phone" "$BATTERY" && exit 0 || exit "$DESKRET" fi # If there is no battery, it's probably a desktop if ! "$BATTERY"; then [ -z "$VERBOSE" ] || echo "There is no battery: probably a desktop" 2>&1 echo "desktop" exit "$DESKRET" fi # If the resolution is low, it's probably a netbook if [ "$XRES" -ne "0" -a "$XRES" -lt "1025" -a \ "$YRES" -ne "0" -a "$YRES" -lt "601" ]; then [ -z "$VERBOSE" ] || echo "The resolution is low: probably a netbook" 2>&1 echo "netbook" exit 0 fi # Otherwise, it's probably a laptop echo "laptop" [ -z "$VERBOSE" ] || echo "Battery, sufficient screen: call it a laptop" 1>&2 exit 0