Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Created November 16, 2020 06:25
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talkingmoose/e1848e3b410395f05c9fcd9ed78386a5 to your computer and use it in GitHub Desktop.
Save talkingmoose/e1848e3b410395f05c9fcd9ed78386a5 to your computer and use it in GitHub Desktop.
Runs when called by a Jamf Pro policy triggered by Enrollment Complete. Installs third party software that Apple's Volume Purchase Program (VPP) cannot install and runs maintenance routines (bind to Active Directory, set time zone etc.).
#!/bin/zsh
<<'ABOUT_THIS_SCRIPT'
-----------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
https://gist.github.com/e1848e3b410395f05c9fcd9ed78386a5
Originally posted: November 15, 2020
Purpose: Runs when called by a Jamf Pro policy triggered
by Enrollment Complete.
1. Prompts user to enter asset tag.
2. Runs specified policies by trigger name.
3. Updates inventory.
4. Restarts computer.
Instructions: Add this script to Jamf Pro and then add it to a new
Jamf Pro policy triggered by Enrollment Complete. This should be the
only policy triggered by Enrollment Complete. Edit the $policyList
below with policy names and policy triggers separated by a comma.
Except where otherwise noted, this work is licensed under
http://creativecommons.org/licenses/by/4.0/
“I'm not so sure he's mad, Father. Just a little devious in his sanity.”
-----------------------------------------------------------------------
ABOUT_THIS_SCRIPT
# Policy names and policy triggers separated by ","
policyList="Installing Google Chrome,maininstallgooglechrome
Installing Microsoft Office 2019,maininstallmicrosoftoffice
Installing Zoom,main-zoom
Setting Time Zone,settimezonechicago"
# Set variables
logFile="/var/log/Provisioning.log"
function logresult() {
if [ $? = 0 ] ; then
/bin/date "+%Y-%m-%d %H:%M:%S $1" >> "$logFile"
echo "$1" # for the policy log
else
/bin/date "+%Y-%m-%d %H:%M:%S $2" >> "$logFile"
echo "$2" # for the policy log
fi
}
# Create log file
/usr/bin/touch $logFile
# Provide path to jamfHelper
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
# wait until the Dock process has started
while [[ "$setupProcess" = "" ]]
do
echo "Waiting for Dock"
setupProcess=$( /usr/bin/pgrep "Dock" )
sleep 3
done
sleep 3
# get currently logged in user
currentUser=$( /usr/bin/stat -f "%Su" /dev/console )
echo "Current user is $currentUser"
# prompt for asset tag
while [[ "$assetTag" = "" ]];
do
theCommand="display dialog \"Enter the asset tag you received for your computer and then affix the sticker to the bottom...\" default answer \"\" with title \"Asset Tag\" buttons {\"Stop\", \"OK\"} default button {\"OK\"} with icon file posix file \"/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns\""
results=$( /bin/launchctl asuser "$currentUser" sudo -iu "$currentUser" /usr/bin/osascript -e "$theCommand" )
theButton=$( echo "$results" | /usr/bin/awk -F "button returned:|," '{print $2}' )
assetTag=$( echo "$results" | /usr/bin/awk -F "text returned:" '{print $2}' )
if [ "$theButton" = "Stop" ]; then
echo "Asset tag prompt canceled. Stopping script."
exit 1
fi
done
echo "Asset tag is \"$assetTag\""
# run policies
while IFS= read -r aPolicy
do
policy=$( echo "$aPolicy" | /usr/bin/awk -F "," '{ print $1 }' )
trigger=$( echo "$aPolicy" | /usr/bin/awk -F "," '{ print $2 }' )
"$jamfHelper" -windowType fs -heading "Preparing your Mac" -description "$policy..." -icon /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns &
/usr/local/bin/jamf policy -event "$trigger"
logresult "Success: $policy" "Fail: $policy"
done <<< "$policyList"
# update inventory and asset tag
/usr/local/bin/jamf recon -assetTag "$assetTag"
logresult "Updating inventory and asset tag." "Failed updating inventory and asset tag."
# restart the Mac
"$jamfHelper" -windowType fs -heading "Preparing your Mac" -description "Restarting your Mac..." -icon /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns &
/sbin/shutdown -r +1 &
logresult "Restarting computer." "Failed restarting computer."
exit 0
@mani2care
Copy link

hey moose I just tried this script without enrolling /without Jamf binary

find this error

I is that possible to add department on this script.

XW-L-host:Desktop mani$ sudo ./enroller.sh 
-----------------------------------------------------------------------

	Written by:William Smith
	Professional Services Engineer
	Jamf
	bill@talkingmoose.net
	https://gist.github.com/e1848e3b410395f05c9fcd9ed78386a5
	
	Originally posted: November 15, 2020

	Purpose: Runs when called by a Jamf Pro policy triggered
	by Enrollment Complete.

	1. Prompts user to enter asset tag.
	2. Runs specified policies by trigger name.
	3. Updates inventory.
	4. Restarts computer.
	
	Instructions: Add this script to Jamf Pro and then add it to a new
	Jamf Pro policy triggered by Enrollment Complete. This should be the
	only policy triggered by Enrollment Complete. Edit the $policyList
	below with policy names and policy triggers separated by a comma.
	
	Except where otherwise noted, this work is licensed under
	http://creativecommons.org/licenses/by/4.0/

	“I'm not so sure he's mad, Father. Just a little devious in his sanity.”
	
-----------------------------------------------------------------------
Waiting for Dock
Current user is mani
2022-10-13 01:03:45.779 osascript[49362:736405] XType: com.apple.fonts is not accessible.
2022-10-13 01:03:45.779 osascript[49362:736405] XType: XTFontStaticRegistry is enabled.
Asset tag is "rr"
./enroller.sh:102: no such file or directory: /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
./enroller.sh:103: no such file or directory: /usr/local/bin/jamf
Fail: Installing Google Chrome
./enroller.sh:102: no such file or directory: /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
./enroller.sh:103: no such file or directory: /usr/local/bin/jamf
Fail: Installing Microsoft Office 2019
./enroller.sh:102: no such file or directory: /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
./enroller.sh:103: no such file or directory: /usr/local/bin/jamf
Fail: Installing Zoom
./enroller.sh:102: no such file or directory: /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
./enroller.sh:103: no such file or directory: /usr/local/bin/jamf
Fail: Setting Time Zone
./enroller.sh:108: no such file or directory: /usr/local/bin/jamf
Failed updating inventory and asset tag.
./enroller.sh:112: no such file or directory: /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
Restarting computer.
XW-L-host:Desktop mani$ Shutdown at Thu Oct 13 01:04:53 2022.
shutdown: [pid 49415]
                                                                               
*** System shutdown message from mani@XW-L-host ***                  
System going down in 1 minute                                                  
                                                                               
                                                                               
                                                                               
*** System shutdown message from mani@XW-L-host ***                  
System going down in 30 seconds                                                
                                                                               
                                                                               

  [Restored 13-Oct-2022 at 1:05:37 AM]
Last login: Thu Oct 13 01:05:33 on console

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
XW-L-host:Desktop mani$ 

@talkingmoose
Copy link
Author

hey moose I just tried this script without enrolling /without Jamf binary

Hi @mani2care! I’m not sure I understand. The script is meant to be used with Jamf Pro. It will require enrollment and that the binary be installed.

@mani2care
Copy link

mani2care commented Oct 13, 2022 via email

@talkingmoose
Copy link
Author

I still don’t understand what you’re trying to tell me.

The script is meant to run after enrolling into Jamf Pro. The script does not enroll computers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment