Skip to content

Commit

Permalink
Update J24_SetupYourMac_With_API_Calls.bash
Browse files Browse the repository at this point in the history
a few changes and api bits are working
  • Loading branch information
monodata committed Feb 5, 2023
1 parent f61488d commit 422db89
Showing 1 changed file with 67 additions and 24 deletions.
91 changes: 67 additions & 24 deletions Setup Your Mac/J24_SetupYourMac_With_API_Calls.bash
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,76 @@ function createAPIToken() {

}

createAPIToken

# Gets the JSS ID from the device serial
get_computer_id=$(
/usr/bin/curl \
--silent \
--request GET \
--url "$serial_url" | xmllint --xpath '/computer/general/id/text()' - \
--header 'Accept: application/xml' \
--header "Authorization: Bearer ${api_token}" 2>/dev/null
)

# Build the URL for the extension attribute subset
ext_url="$jamf_url/JSSResource/computers/id/${get_computer_id}/subset/ExtensionAttributes"
# Gets the JSS_ID from the device serial then populates the device role extension attribute
get_device_role() {
# Gets the JSS ID from the device serial
serial_url="$jamf_url/JSSResource/computers/serialnumber/${serial_number}"

# returns the JSS ID
get_computer_id=$(
/usr/bin/curl \
--silent \
--request GET \
--url "$serial_url" \
--header 'Accept: application/xml' \
--header "Authorization: Bearer ${api_token}" 2>/dev/null
)

# Returns the device ID
jss_id="$(echo $get_computer_id | xmllint --xpath '/computer/general/id/text()' -)"

# Returns the users building
user_location="$(echo $get_computer_id | xmllint --xpath '/computer/location/building/text()' -)"

# Build the URL for the extension attribute subset
ext_url="$jamf_url/JSSResource/computers/id/${jss_id}/subset/ExtensionAttributes"

# The 'Device Role' extension attribute is 1
eaID="1"

device_role=$(
/usr/bin/curl \
--silent \
--header 'Accept: application/xml' \
--header "Authorization: Bearer ${api_token}" \
--request GET \
--url "$ext_url" | xpath "//*[id=$eaID]/value/text()" 2>/dev/null
)
}

# The 'Device Role' extension attributer is 1
eaID="1"
# Create an API token to get started with some queries
createAPIToken

deviceRole=$(
/usr/bin/curl \
--silent \
--header 'Accept: application/xml' \
--header "Authorization: Bearer ${api_token}" \
--request GET \
--url "$ext_url" | xpath "//*[id=$EAID]/value/text()" 2>/dev/null
# Check if Inventory Preload exists for the device
preload_counter=1
while [[ $preload_counter < 10 ]]; do

# increment the counter
((preload_counter += 1))

preload_status=$(
/usr/bin/curl \
--header "accept: application/json" \
--header "Authorization: Bearer ${api_token}" \
--request GET \
--url "${jamf_url}/api/v2/inventory-preload/records?filter=serialNumber==${serial_number}" \
--silent | grep -ic ${serial_number}
)

# check if inventory preload returns data
if [[ $preload_status -gt 0 ]]; then
# preload exists
welcomeDialog="false"
break
else
sleep 2
fi
done

)
if [[ $preload_status -eq 0 ]]; then
# run the Welcome window
welcomeDialog="true"
fi

####################################################################################################
#
Expand Down

0 comments on commit 422db89

Please sign in to comment.