User detection script for Code42 using the Jamf API

Daikonran
New Contributor III

I wrote up this script that you can drop into your Code42 deployment to grab the email address of your users using the JAMF API and if the email doesn't exist in JAMF the installer will prompt the user to enter their email before continuing. Hope it's useful for someone else.

jssUser="api_user"
jssPass="api_user_pass"
jssUrl="https://jss_url:8443"
username=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
user_email=$(curl -X GET -sku $jssUser:$jssPass -H "Accept: application/xml" $jssUrl/JSSResource/users/name/$username | xpath /user/email_address 2>/dev/null | sed -e 's/<email_address>//' | sed -e 's/</email_address>//')

ask () {
        osascript <<EOF - 2>/dev/null
        tell application "SystemUIServer"
        activate
        text returned of (display dialog "$1" default answer "")
        end tell
EOF
}

if [ -z "$user_email" ]; then
    name=$(ask 'CODE42 BACKUP - Your email address could not be found, please fill it in to continue: ')
    echo "C42_USERNAME=$name"
    echo "C42_USER_HOME=$(dscl . -read "/users/$username" NFSHomeDirectory | cut -d ' ' -f 2)"
else
    echo "C42_USERNAME=${user_email}"
    echo "C42_USER_HOME=$(dscl . -read "/users/$username" NFSHomeDirectory | cut -d ' ' -f 2)"
fi
3 REPLIES 3

dmaestre
Release Candidate Programs Tester

Thank you so much! You don't understand how long I've been looking for something solid that works. I've tested this out and made the appropriate edit's to match my organizations JSS. Works like a charm.

jchen1225
New Contributor III

Thank you Daikonran, this is what we are look for as well since we are not binding our Macs to AD. Would this work if we are just pulling the username off JSS api instead of the whole email address?

Daikonran
New Contributor III

Hi Jchen,

Yeh this would work for that too. There are easier ways to just get the username of the machine without quering from jamf, as you start off getting the JAMF username in order to get the email address.

Just the below line is one example of grabbing the logged in username. Much easier than using this whole script.

/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'