When working with scripts for managing Macs on Jamf Pro, I prefer to download then and back them up to GitHub or a similar internal source control tool. The reason I do this is the following:
- I have an off-server backup for the scripts
- I can track changes to the scripts
While I’ve usually had copies of the scripts stored elsewhere, sometimes I would make changes to the scripts on Jamf Pro and then not update the offline copy of the scripts with my changes. Being able to download them from my Jamf Pro server would mean that I could always have a copy of the latest version of the script in production.
To help me with this, I’ve written a script to do the following:
- Use the Jamf Pro API to identify the Jamf Pro ID numbers of the scripts.
- Download each script using its Jamf Pro ID number as raw XML.
- Format the downloaded XML
- Identify the display name of the script
- Extract the script from the downloaded XML
- Save the script as Display Name Goes Here to a specified download directory.
For more details, please see below the jump.
For authentication, the download script can accept hard-coded values in the script, manual input or values stored in a ~/Library/Preferences/com.github.jamfpro-info.plist file.
The plist file can be created by running the following commands and substituting your own values where appropriate:
To store the Jamf Pro URL in the plist file:
defaults write com.github.jamfpro-info jamfpro_url https://jamf.pro.server.goes.here:port_number_goes_here
To store the account username in the plist file:
defaults write com.github.jamfpro-info jamfpro_user account_username_goes_here
To store the account password in the plist file:
defaults write com.github.jamfpro-info jamfpro_password account_password_goes_here
To run the download script:
/path/to/Jamf_Pro_Computer_Script_Download.sh
When run, you should see output similar to that shown below.
The downloaded scripts themselves will be stored in either a user-specified directory or, if no directory is specified, a directory created by the script.
The download script is available below, and at the following address on GitHub:
Jamf_Pro_Computer_Script_Download.sh: