Posted on 11-16-2017 11:19 AM
Is anyone out there trying to take inventory of which machines in their ecosystems are compatible with High Sierra? I looked around JAMF and Git Hub but I couldn't find anything so I've been trying to write an extension attribute for it but I'm having a heck of a time getting the syntax right for a word list array.
Here is the code I have written so far:
#!/bin/sh
# Author: R.C. Schmittgen
######################################################################
# This script checks for High Seirra Hardware Compatibility.
######################################################################
# This variable defines the model identifier of this particular machine.
Model="sysctl hw.model"
$Model
# This array is the list of compatible macs
CompatibleList=(
"iMac10,1"
"iMac11,1"
"iMac11,3"
"iMac12,1"
"iMac12,2"
"iMac13,1"
"iMac13,2"
"iMac18,2"
"iMac18,3"
"MacBook6,1"
"MacBook7,1"
"MacBook8,1"
"MacBook9,1"
"MacBook10,1"
"MacBookAir3,1"
"MacBookAir3,2"
"MacBookPro6,2"
"MacBookPro6,1"
"MacBookPro8,1"
"MacBookPro8,2"
"MacBookPro8,3"
"MacBookPro9,2"
"MacBookPro9,1"
"MacBookPro11,1"
"MacBookPro11,2"
"MacBookPro11,3"
"MacBookPro12,1"
"MacBookPro11,4"
"MacBookPro11,5"
"MacBookPro13,1"
"Macmini6,2"
"Macmini7,1"
"MacPro5,1"
"iMac14,1"
"iMac14,3"
"iMac14,2"
"iMac14,4"
"iMac15,1"
"iMac16,1"
"iMac16,2"
"iMac17,1"
"iMac18,1"
"MacBookAir4,1"
"MacBookAir4,2"
"MacBookAir5,1"
"MacBookAir5,2"
"MacBookAir6,1"
"MacBookAir6,2"
"MacBookAir7,1"
"MacBookAir7,2"
"MacBookPro7,1"
"MacBookPro10,"
"MacBookPro10,2"
"MacBookPro13,2"
"MacBookPro13,3"
"MacBookPro14,1"
"MacBookPro14,2"
"MacBookPro14,3"
"Macmini4,1"
"Macmini5,1"
"Macmini5,2"
"Macmini5,3"
"Macmini6,1"
"MacPro6,1"
)
# This is so i can test the the array to make sure I can grep out what I need:
for i in ${CompatibleList[*]}
do
echo $i | grep $Model
done
###########################################################################
# This is the program - it checks if the model of the current machine is
# inside the CompatibleList and if so says "yes" if not says "no."
if [ $Model = $CompatibleList | grep "$Model" ];
then
answer="Yes"
else
answer="no"
fi
echo $answer
# This gives the answer to JSS:
<result>$answer</result>
Basically There is a command that is placed into the Variable $Model and then I have list of Macs that are compatible that I'm trying to place into an array. The next piece of code show I can grep out what I need. Then the final bit of code is the actual program that gives me a simple yes or no answer to compatibility that I ca have display in the JSS to create a nice smart group for it.
Does anyone have suggestions on how I can get this array to grep so I can pull the info I need? Or alternatively know where someone has already written this extension attribute so I don't have to? I feel like it has to be out there somewhere.
Thanks!
Posted on 11-16-2017 11:26 AM
in my enviroment I have no need on doing that, but I guess creating "Smart Computer Groups" would be the easy way.
Posted on 11-16-2017 11:29 AM
We used this and works great.
Posted on 11-16-2017 11:32 AM
this is an example:
Posted on 11-16-2017 02:54 PM
Regarding the Smart Group link, it's insane to include that many criteria items in a Smart Group. Jamf doesn't recommend going above like 7 or something like that. I think the most I've ever used was 11 or 12. Doing something like that puts a heavy strain on the MySQL database on each computer inventory update.
It would be better to do this with an Extension Attribute looking for compatible board ids (or incompatible ones if you prefer to go that route)
For our Sierra upgrade "enrollment" policy, I used a script that contained all the compatible board ids in a simple list, had the script get the current machine's board id and check for that in the list and return a result. That worked out fine for us.
Posted on 11-17-2017 09:07 AM
@mm2270 Not to get too far off topic but I've never heard of those recommended limits in smart groups. Does the same apply if you nest the criteria and use different smart groups and pull that into one? In other words if I had a smart group for each model Apple has manufactured that checks they're compatible and then collect that into one smart group to display all models. An example would be a smart group for iMacs that check if they're compatible, a smart group for Mac minis, MacBook Airs, etc. Lastly a smart group that pulls in all of those groups and then displays what's not compatible.
I suspect I might now know the answer to this but thought I'd ask. I'm pretty heavy on smart group usage so now I'm thinking I might want to revisit some of my solution implementations.
Posted on 11-17-2017 09:51 AM
I agree with @mm2270 about this--- I mean i pretty much treat Derflounder as gospel, he's super legit and the smart group will work, but I have also heard about the limitations of smart groups... I was told about this by JAMF support.... The smaller the better.... (They can tell you all about this when they run a yearly 'health check' on your JSS)
Using a script/EA offloads the processing on the SQL server and puts it on the client. Then you can easily create a smart group based on a single condition (yes/no) and it's a lot less stressful on the server.
Just think if everyone turned on their computers at 9AM, and all those machines ran their inventory updates, and the server had to process that huge smart group for hundreds or thousands of machines.
Posted on 11-17-2017 10:11 AM
Darklordbrock wrote a pretty nice script for this
https://github.com/darklordbrock/Max-OS-Version/blob/master/MaxOS-Ext.sh
#!/bin/bash
#Writen by Emmitt Houston and Kyle Brockman while working at UW-Milwaukee.
#Based off code from http://stackoverflow.com/questions/14366390/bash-if-condition-check-if-element-is-present-in-array
#And an idea from UWM's JAMF support repo.
array_contains () {
local array="$1[@]"
local seeking=$2
local in=1
for element in "${!array}"; do
if [[ $element == $seeking ]]; then
in=0
break
fi
done
return $in
}
latest="10.13"
sysmodel=`sysctl hw.model | awk '{print $2}'`
#sysmodel="RackMac1,1" # 10.5 Test true
#sysmodel="MacBookPro1,1" # 10.6 Test true
#sysmodel="MacBook2,1" # 10.7 Test true
#sysmodel="iMac7,1" # 10.11 Test true
# Hardware Arraies
arr10_5=(PowerMac3,5 PowerMac3,6 PowerMac4,4 PowerMac6,1 PowerMac6,3 PowerMac6,4 PowerMac7,2 PowerMac7,3 PowerMac8,1 PowerMac8,2 PowerMac9,1 PowerMac10,1 PowerMac10,2 PowerMac11,2 PowerMac12,1 RackMac1,1 RackMac1,2 RackMac3,1 PowerBook3,5 PowerBook5,1 PowerBook5,2 PowerBook5,3 PowerBook5,4 PowerBook5,5 PowerBook5,6 PowerBook5,7 PowerBook5,8 PowerBook5,9 PowerBook6,1 PowerBook6,2 PowerBook6,3 PowerBook6,4 PowerBook6,5 PowerBook6,7 PowerBook6,8)
arr10_6=(iMac4,1 iMac4,2 Macmini1,1 MacBook1,1 MacBookPro1,1 MacBookPro1,2)
arr10_7=(iMac5,2 iMac5,1 iMac6,1 Macmini2,1 MacPro1,1 MacPro2,1 MacBook2,1 MacBook3,1 MacBook4,1 MacBookAir1,1 MacBookPro2,2 MacBookPro2,1 Xserve1,1 Xserve2,1)
arr10_11=(iMac7,1 iMac8,1 iMac9,1 Macmini3,1 MacPro3,1 MacPro4,1 MacBook5,1 MacBook5,2 MacBookAir2,1 MacBookPro3,1 MacBookPro4,1 MacBookPro5,1 MacBookPro5,2 MacBookPro5,3 MacBookPro5,4 MacBookPro5,5 Xserve3,1)
#array_contains2 arr10_7 "$sysmodel" && echo yes || echo no
if array_contains arr10_5 "$sysmodel"; then
echo "<result>10.5</result>"
else
if array_contains arr10_6 "$sysmodel"; then
echo "<result>10.6</result>"
else
if array_contains arr10_7 "$sysmodel"; then
echo "<result>10.7</result>"
else
if array_contains arr10_11 "$sysmodel"; then
echo "<result>10.11</result>"
else
echo "<result>$latest</result>"
fi
fi
fi
fi