We need to bind our machines to specific OUs based on location and whether it's a laptop or desktop. I wrote (read: adapted from other scripts) this script up, but my scripting skills are pretty bad, would someone take a look at it and see if my logic/syntax is correct?
basically it looks if the device is a laptop and if so looks at the host name to determine location, then binds to location a or location b. if not a MacBook then bind to location c or d, via jamf policy triggers.
Is there a cleaner or better way to do this?
#!/bin/sh
LOGPATH='/private/var/log'
LOGFILE=/private/var/log/bind-$(date +%Y%m%d-%H%M).logging
osVersion=`sw_vers -productVersion | cut -d. -f1,2`
modelName=`system_profiler SPHardwareDataType | awk -F': ' '/Model Name/{print $NF}'`
shortModel=`system_profiler SPHardwareDataType | grep 'Model Name:' | awk '{ print $3 }'`
location=`hostname | cut -b 5-6`
## Setup logging
# mkdir $LOGPATH
set -xv; exec 1> $LOGPATH/postimagelogbind.txt 2>&1
##########################################
# Bind to AD
##########################################
#/bin/echo "Binding to AD"
#/bin/date
# Detects if this Mac is a laptop or not by checking the model ID for the word "Book" in the name.
IS_LAPTOP=`/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | grep "Book"`
if [[ $shortModel == "MacBook" ]]; then
if [[$location == SA]]; then
jamf policy -trigger LocationLTBind
exit 0
elif [[$location == SB]]; then
jamf policy -trigger LocationLTBind
exit 0
fi
if [[ $shortModel != "MacBook" ]]; then
if [[$location == SA]]; then
jamf policy -trigger LocationDTBind
exit 0
elif [[$location == SB]]; then
jamf policy -trigger LocationDTBind
exit 0
fi
else
exit 0
fi
#/bin/echo "Done binding to AD"
#/bin/date