tangent: can I see that script? Could help us eliminate a step of our "a few touches" deployment.
Here it is. We are leveraging Enterprise Connect instead of AD binding.
#!/bin/bash
function main() {
local username=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
local adUser=$(/usr/bin/security find-generic-password -l "Enterprise Connect" /Users/$username/Library/Keychains/login.keychain-db | awk -F "=" '/acct/ {print $2}' | tr -d """)
local user_email=$(ldapsearch -o ldif-wrap=no -h ad.chgofirm.com -s sub -b `defaults read com.apple.Enterprise-Connect defaultNamingContext` sAMAccountName=$adUser mail 2>/dev/null|grep mail:| sed 's/mail: //'| awk -F: '{print $NF}')
echo "C42_USERNAME=${user_email}"
echo "C42_USER_HOME=$(dscl . -read "/users/$username" NFSHomeDirectory | cut -d ' ' -f 2)"
}
main "$@"
@macmanmk @robertliebsch I want to to jump in here real quick. To be specific, that script should belong in the deployment policy section of the web console for Code42. Second, EC is now on it's way out... ish. I recently made the move to the cloud authority and decided to use the email addresses that we have in the JSS for the devices (Oddly, pulled from either EC or during initialization).Code42 hooked me up with this example and it's working rather well!
jssUser="API-User"
jssPass="API-Password";
jssUrl="https://jssURL: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