Run a script based on hardware

noah_swanson
New Contributor

Is it possible to direct a script based on hardware (laptop or desktop)? PGP is only required on our Laptops. In order to help out our Audit team, I'd like a script to first detect if the machine is a laptop; if it's not, it can simply return "PGP WDE Not Required". If the machine is a laptop it can then report pgp status. For some reason telling them "Macbook Pro" means laptop and "MacPro" means desktop is too much.

I tried loading this into a variable:
ModelName=system_profiler | grep "Model Name" | sed -e 's/Model Name://g'

But when I "if" that variable to "MacBook Pro" it didn't seem to want to accept that.

Is there an easier way to do this? Or is it even possible?

Thanks!
Noah Swanson
Imaging Specialist
Enterprise Desktop Services
Phone: 309-765-3153
SwansonNoah at johndeere.com

3 REPLIES 3

bentoms
Release Candidate Programs Tester

Why not create a smart group that's Hardware model is like book & assign the policy to only install on machines in that smart group?

Ben Toms
IT Support Analyst GREY Group
The Johnson Building, 77 Hatton Garden, London, EC1N 8JS
T: +44 (0) 20-3037-3819 |
Main: +44 (0) 20 3037 3000 | IT Helpdesk: +44 (0) 20 3037 3883

noah_swanson
New Contributor

Audit wants this to be listed in their reports, so I wanted this to report this to Inventory. In addition, I wanted Desktops to return something like "Desktop: Does not require PGPWDE"

I've been told to comply to their "every request". However, I think I found a way...Instead of calling the model name from system profiler I can call the "Sudden Motion Sensor". Laptops are the only platform that have this installed correct?

tlarkin
Honored Contributor

This gets really tricky because of several factors

1) system_profiler command over the years and models has changed, so
making it "future-proof" could be an issue

2) Apple likes to change their models around, iMac 9,1 10,1 etc

So, I would maybe look at doing it like this, with a case construct

#!/bin/bash

# get the current model name of the machine

ModelName=`system_profiler SPHardwareDataType | awk '/Model Name:/ {
print $3 }'`

# now create a case construct to determine what to do

case $ModelName in

MacBook ) # computer type is laptop

/bin/echo "Model is a laptop, installing PGP'

/usr/sbin/jamf policy -trigger installPGP

;;

MacMini ) # computer is a desktop, and create receipt

/bin/echo "Model is a laptop, no need to install PGP"

/Library/Reciepts/pgp.txt

;;

iMac ) # Model is a desktop

/bin/echo "Model is a laptop, no need to install PGP" >
/Library/Reciepts/pgp.txt

;;

MacbookPro ) # model is a laptop

/bin/echo "Model is a laptop, installing PGP'

/usr/sbin/jamf policy -trigger installPGP

;; esac

exit 0

This is totally proof of concept, you gotta test that out on your own. I think you can maybe even wild card macbook, if the word "MacBook" is
in every single laptop Apple makes. So you could change MacBook to
MacBook* and not have to maintain every MacBook model in your script.

-Tom