147 lines
6.2 KiB
Bash
Executable File
147 lines
6.2 KiB
Bash
Executable File
#!/bin/bash
|
|
##########################################################################
|
|
# Script : re-run the Azure Registration
|
|
# Autor : Andreas Vogel NEXT Enterprise GmbH
|
|
##########################################################################
|
|
#DefaultBrowser='com.google.chrome'
|
|
DefaultBrowser='com.apple.safari'
|
|
#DefaultBrowser='org.mozilla.firefox'
|
|
|
|
|
|
PlistBuddy='/usr/libexec/PlistBuddy'
|
|
PlistDirectory="$HOME/Library/Preferences/com.apple.LaunchServices"
|
|
PlistName="com.apple.launchservices.secure.plist"
|
|
PlistLocation="$PlistDirectory/$PlistName"
|
|
|
|
PrefsToAdd=("{ LSHandlerContentType = \"public.url\"; LSHandlerPreferredVersions = { LSHandlerRoleViewer = \"-\"; }; LSHandlerRoleViewer = \"$DefaultBrowser\"; }"
|
|
"{ LSHandlerContentType = \"public.html\"; LSHandlerPreferredVersions = { LSHandlerRoleAll = \"-\"; }; LSHandlerRoleAll = \"$DefaultBrowser\"; }"
|
|
"{ LSHandlerPreferredVersions = { LSHandlerRoleAll = \"-\"; }; LSHandlerRoleAll = \"$DefaultBrowser\"; LSHandlerURLScheme = https; }"
|
|
"{ LSHandlerPreferredVersions = { LSHandlerRoleAll = \"-\"; }; LSHandlerRoleAll = \"$DefaultBrowser\"; LSHandlerURLScheme = http; }"
|
|
)
|
|
|
|
lsregister='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister'
|
|
defaultBrowser=$(defaults read $HOME/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure | awk -F'"' '/http;/{print window[(NR)-1]}{window[NR]=$2}')
|
|
|
|
if [[ $defaultBrowser != "com.apple.safari" ]]
|
|
then
|
|
echo "Default Browser $defaultBrowser "
|
|
if [ -f "$PlistLocation" ]
|
|
then
|
|
|
|
Counter=0
|
|
|
|
DictResult='PLACEHOLDER'
|
|
|
|
while [[ ! -z "$DictResult" ]]; do
|
|
DictResult=$("$PlistBuddy" -c "Print LSHandlers:$Counter" "$PlistLocation")
|
|
|
|
|
|
if [[ "$DictResult" == *"public.url"* ]] || [[ "$DictResult" == *"public.html"* ]] || [[ "$DictResult" == *"LSHandlerURLScheme = https"* ]] || [[ "$DictResult" == *"LSHandlerURLScheme = http"* ]]; then
|
|
|
|
"$PlistBuddy" -c "Delete :LSHandlers:$Counter" "$PlistLocation"
|
|
/bin/echo "Deleting $Counter from Plist"
|
|
fi
|
|
|
|
|
|
Counter=$((Counter+1))
|
|
|
|
|
|
done
|
|
|
|
|
|
else
|
|
echo "Plist does not exist."
|
|
fi
|
|
|
|
defaultBrowser=$(defaults read $HOME/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure | awk -F'"' '/http;/{print window[(NR)-1]}{window[NR]=$2}')
|
|
|
|
|
|
for PrefToAdd in "${PrefsToAdd[@]}"
|
|
do
|
|
/usr/bin/defaults write "$PlistLocation" LSHandlers -array-add "$PrefToAdd"
|
|
done
|
|
|
|
|
|
if [ -f "$lsregister" ]
|
|
then
|
|
echo "Rebuilding Launch services. This may take a few moments."
|
|
|
|
"$lsregister" -kill -r -domain local -domain system -domain user
|
|
else
|
|
echo "You may need to log out or reboot for changes to take effect. Cannot find location of lsregister at $lsregister"
|
|
fi
|
|
else
|
|
echo "Safari is already standard Browser"
|
|
fi
|
|
|
|
|
|
currentuser=`stat -f "%Su" /dev/console`
|
|
AAD_ID=$(su "$currentuser" -c "security find-certificate -a -Z | grep -B 9 "MS-ORGANIZATION-ACCESS" | awk '/\"alis\"<blob>=\"/ {print $NF}' | sed 's/ \"alis\"<blob>=\"//;s/.$//'")
|
|
#CERT_BY_SHA=$(su "$currentuser" -c "security find-certificate -a -Z | grep -B 9 "MS-ORGANIZATION-ACCESS" | grep "SHA-1" | awk '{print $3}'")
|
|
|
|
echo ""
|
|
echo "Removing items for jamfAAD"
|
|
echo ""
|
|
echo "Removing items for com.jamfsoftware.selfservice.mac.savedState"
|
|
rm -rf /Users/"$currentuser"/Library/Saved\ Application\ State/com.jamfsoftware.selfservice.mac.savedState
|
|
|
|
echo "Removing items for com.jamf.management.jamfAAD.binarycookies"
|
|
rm -r /Users/"$currentuser"/Library/Cookes/com.jamf.management.jamfAAD.binarycookies
|
|
|
|
echo "Removing items for com.jamf.management.jamfAAD.savedState"
|
|
rm -rf /Users/"$currentuser"/Library/Saved\ Application\ State/com.jamf.management.jamfAAD.savedState
|
|
su "$currentuser" -c "/Library/Application Support/JAMF/Jamf.app/Contents/MacOS/JamfAAD.app/Contents/MacOS/JamfAAD clean"
|
|
|
|
echo ""
|
|
echo "Removing items for Company Portal app"
|
|
echo ""
|
|
echo "Removing items for com.microsoft.CompanyPortalMac.binarycookies"
|
|
rm -r /Users/"$currentuser"/Library/Cookies/com.microsoft.CompanyPortalMac.binarycookies
|
|
|
|
echo "Removing items for com.microsoft.CompanyPortalMac.savedState"
|
|
rm -rf /Users/"$currentuser"/Library/Saved\ Application\ State/com.microsoft.CompanyPortalMac.savedState
|
|
|
|
echo "Removing items for com.microsoft.CompanyPortalMac.plist"
|
|
rm -r /Users/"$currentuser"/Library/Preferences/com.microsoft.CompanyPortalMac.plist
|
|
|
|
echo "Removing items for com.microsoft.CompanyPortalMac.plist"
|
|
rm -r /Library/Preferences/com.microsoft.CompanyPortalMac.plist
|
|
|
|
echo "Removing items for com.microsoft.CompanyPortalMac"
|
|
rm -rf /Users/"$currentuser"/Library/Application\ Support/com.microsoft.CompanyPortalMac
|
|
|
|
echo "Removing items for com.microsoft.CompanyPortalMac.usercontext.info"
|
|
rm -rf /Users/"$currentuser"/Library/Application\ Support/com.microsoft.CompanyPortalMac.usercontext.info
|
|
|
|
echo ""
|
|
echo "Removing keychain password items for Company Portal app"
|
|
echo ""
|
|
echo "Removing com.jamf.management.jamfAAD"
|
|
su "$currentuser" -c "security delete-generic-password -l 'com.jamf.management.jamfAAD'"
|
|
|
|
echo "Removing com.microsoft.adalcache"
|
|
su "$currentuser" -c "security delete-generic-password -l 'com.microsoft.adalcache'"
|
|
|
|
echo "Removing enterpriseregistration.windows.net"
|
|
su "$currentuser" -c "security delete-generic-password -l 'enterpriseregistration.windows.net'"
|
|
|
|
echo "Removing com.microsoft.workplacejoin.thumbprint"
|
|
su "$currentuser" -c "security delete-generic-password -a 'com.microsoft.workplacejoin.thumbprint'"
|
|
|
|
echo "Removing com.microsoft.workplacejoin.registeredUserPrincipalName"
|
|
su "$currentuser" -c "security delete-generic-password -a 'com.microsoft.workplacejoin.registeredUserPrincipalName'"
|
|
|
|
echo "Removing https://device.login.microsoftonline.com"
|
|
su "$currentuser" -c "security delete-generic-password -l 'https://device.login.microsoftonline.com'"
|
|
|
|
echo "Removing https://device.login.microsoftonline.com/"
|
|
su "$currentuser" -c "security delete-generic-password -l 'https://device.login.microsoftonline.com/'"
|
|
|
|
echo "Removing WPJ for Device AAD ID $AAD_ID for $currentuser"
|
|
su "$currentuser" -c "security delete-identity -c $AAD_ID"
|
|
#echo "Removing WPJ for Device AAD ID $AAD_ID for $currentuser from SHA hash $CERT_BY_HASH"
|
|
|
|
echo "re-run the Azure Registration"
|
|
jamf policy -id 51
|
|
|
|
exit 0 |