Created
November 4, 2017 05:06
-
-
Save stevewood-tx/ebefed251a613cede35e1954992992bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Name: addPackages.sh | |
# Date: 3 nov 2017 | |
# Author: Steve Wood (swood@integer.com) | |
# Purpose: used to stub out packages in the Jamf Pro database | |
# The CSV file needs to be saved as a UNIX file with LF, not CR | |
# Version: 1.0 | |
# | |
# A good portion of this script is re-purposed from the script posted in the following JAMF Nation article: | |
# | |
# https://jamfnation.jamfsoftware.com/discussion.html?id=13118#respond | |
# | |
args=("$@") | |
jssAPIUsername="${args[0]}" | |
jssAPIPassword="${args[1]}" | |
jssAddress="https://your.jss.address:8443" | |
file="${args[2]}" | |
#Verify we can read the file | |
data=`cat $file` | |
if [[ "$data" == "" ]]; then | |
echo "Unable to read the file path specified" | |
echo "Ensure there are no spaces and that the path is correct" | |
exit 1 | |
fi | |
#Set a counter for the loop | |
counter="0" | |
duplicates=[] | |
echo $data | |
#Loop through the CSV and submit data to the API | |
while [ $counter -lt $computerqty ] | |
do | |
counter=$[$counter+1] | |
line=`echo "$data" | head -n $counter | tail -n 1` | |
package=`echo "$line" | awk -F , '{print $1}'` | |
apiData="<package><id>0</id><filename>${package}</filename><name>${package}</name></package>" | |
output=`curl -sS -k -i -u ${jssAPIUsername}:${jssAPIPassword} -X POST -H "Content-Type: text/xml" -d "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>$apiData" ${jssAddress}/JSSResource/packages` | |
echo $output | |
error="" | |
error=`echo $output | grep "Conflict"` | |
if [[ $error != "" ]]; then | |
duplicates+=($serialnumber) | |
fi | |
done | |
echo "The following packages could not be created:" | |
printf -- '%s\n' "${duplicates[@]}" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment