Skip to content

Instantly share code, notes, and snippets.

@acidprime
Created November 9, 2011 04:33
Show Gist options
  • Save acidprime/1350393 to your computer and use it in GitHub Desktop.
Save acidprime/1350393 to your computer and use it in GitHub Desktop.
BASH Hardware Test
#!/bin/bash
declare -x awk="/usr/bin/awk"
declare -x ioreg="/usr/sbin/ioreg"
declare -x sysctl="/usr/sbin/sysctl"
# Intel and future systems test
declare IOREG="$($ioreg -l |
$awk 'BEGIN {FS="[<>]"}
/.*\"system-type\".=./{
systype=$2
if ( systype == 1 )
{ print "D" ; exit 0 }
# System type 1 is a Desktop
else if ( systype == 2 )
{ print "L" ; exit 0 }
# System type 2 is a Laptop
}')"
# PowerPC test , hopefully can go aways some day
declare SYSCTL="$($sysctl hw.model |
$awk 'BEGIN {}
$2~/.*(b|B)ook.*/{
# RegEx any thing with Book,basic but works
print "L" ; exit 0 }
# If we did not exit then desktop
{print "D" ;exit}')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment