need help converting script to user bearer token

giang
New Contributor II

need help converting script to user bearer token. script below:

#!/bin/bash

 

## API information

apiURL="https://jamfcloud.com:8443"

apiUser=“test”

apiPass=“test”1234

 

## Get a list of all sites and their IDs

allSiteData=$(curl -H "Accept: text/xml" -sfku "${apiUser}:${apiPass}" $apiURL/JSSResource/sites | xmllint --format - | awk -F'>|<' '/<name>|<id>/{print $3}')

 

## Split out Site Names and Site IDs into arrays

allSiteNames=("$(echo "$allSiteData" | awk 'NR % 2 == 0' | grep -v 'Provisioning' | grep -v 'Ground Control')")

 

## Prompt for a Site selection

chosenSite=$(/usr/bin/osascript << EOF

tell application "System Events"

activate

set siteNames to do shell script "printf '%s\\n' \"${allSiteNames[@]}\""

set namesForDisplay to paragraphs of siteNames

set chosenSite to choose from list namesForDisplay with prompt "Choose a Site"

end tell

EOF)

 

sleep 5

 

## Get the computer serial number

computerSerial=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')

 

## Update/change the Site for the computer

echo "<computer><general><site><name>$chosenSite</name></site></general></computer>" | curl -sfku $apiUser:$apiPass -d @- "$apiURL/JSSResource/computers/serialnumber/$computerSerial/subset/general" -X PUT -H "Content-Type: application/xml"

 

siteName=$(curl -H "Accept: text/xml" -sfku "${apiUser}:${apiPass}" $apiURL/JSSResource/computers/serialnumber/${computerSerial}/subset/general | xmllint --format - | grep '<name>Provisioning</name>')

 

if [[ $siteName == *"Provisioning"* ]]

then

sh /Library/test/Scripts/site.sh

else

/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -title "" -icon "/usr/local/CHOP_Logo.icns" -heading "Configuration Completed " -description "Shutting Down!""" &

sleep 10

echo completed > /tmp/completed.txt

exit 0

fi

0 REPLIES 0