Created
November 2, 2018 17:12
-
-
Save krispayne/1a9bba7da3b14278d4c27e07ca459ae3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
# preflight to check for profile installed by Jamf | |
profile_id="SAMPLE-SAMPLE-SAMPLE-SAMPLE" | |
# Get logged in user | |
loggedInUser=$(/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 + "\n");') | |
#loggedInUID=$(id -u "$loggedInUser") | |
# First, see if the profile is there | |
installed_profile_cmd=$(profiles -L -v -U "${loggedInUser}" | awk -F: '/attribute: profileIdentifier/{print $NF}' | sed 's/ //' | grep "${profile_id}") | |
if [ -z "${installed_profile_cmd}" ]; then | |
echo "${profile_id} not found..." | |
exit 0 | |
elif [ "${installed_profile_cmd}" = "${profile_id}" ]; then | |
echo "we should try and remove ${profile_id}" | |
# might have to run this as the user? Not sure. Tests have shown I can run as root/sudo and it works. | |
#/bin/launchctl asuser "$loggedInUID" sudo -iu "$loggedInUser" /usr/bin/profiles -v -I -F "${profile}" | |
# attempt to remove the profile in profile_id | |
echo "Attempting to remove ${profile_id}..." | |
/usr/bin/profiles remove -user "${loggedInUser}" -identifier "${profile_id}" | |
else | |
echo "Unknown state. Exiting sadly..." | |
exit 2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment