Created
January 28, 2018 17:57
-
-
Save bwmorales/72ee151cdb9034aa1f82d1206aa1f641 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
#!/usr/bin/env bash | |
# | |
# Remove Microsoft Office 2016 from macOS | |
# Store file in a place that is readable by all users | |
export LOG_FILE="/Library/Logs/Microsoft/uninstall.log" | |
export TODAY=$(date +"%Y-%m-%d") | |
export RED='\033[0;31m' | |
export GREEN='\033[0;32m' | |
export YELLOW='\033[0;33m' | |
export NC='\033[0;0m' | |
backup() { | |
if [[ -e "${1}" ]]; then | |
cp "${1}" "${1}.${TODAY}.bak" | |
if [[ -e "${1}.${TODAY}.bak" ]]; then | |
printlog $(printf "${GREEN}Backup of '%s' succeeded.${NC}\n" "${1}") | |
return 0 | |
else | |
printlog $(printf "${RED}Backup of '%s' failed.${NC}\n" "${1}") | |
return 1 | |
fi | |
else | |
printlog $(printf "${YELLOW}'%s' does not exist. Skipping.${NC}\n" "${1}") | |
return 0 | |
fi | |
} | |
printlog() { | |
logger -is -p local3.info -t O2016UNINSTALL "$*" | |
} | |
remove() { | |
if [[ -e "${1}" ]]; then | |
rm -Rf "${1}" | |
if [[ -e "${1}" ]]; then | |
printlog $(printf "${RED}Removal of '%s' failed.${NC}\n" "${1}") | |
return 1 | |
else | |
printlog $(printf "${GREEN}Removal of '%s' succeeded.${NC}\n" "${1}") | |
return 0 | |
fi | |
else | |
printlog $(printf "${YELLOW}'%s' does not exist. Skipping.${NC}\n" "${1}") | |
return 0 | |
fi | |
} | |
userIteration() { | |
for ITERATED_USER in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do | |
su $ITERATED_USER -c "$*" | |
done | |
} | |
# Export functions to make accesible to userIteration | |
export -f backup | |
export -f printlog | |
export -f remove | |
# Check that script is running as root | |
if ! [ $(id -u) = 0 ]; then | |
printf "Must be run as root.\n" | |
exit 1 | |
fi | |
# Change directory to avoid ugly errors | |
cd $(dirname $(realpath $0)) | |
# Check that $LOG_FILE exists; create if not. | |
if [[ -e $LOG_FILE ]]; then | |
continue | |
else | |
if [[ -d $(dirname $LOG_FILE) ]]; then | |
touch $LOG_FILE | |
else | |
mkdir -p $(dirname $LOG_FILE) | |
touch $LOG_FILE | |
fi | |
fi | |
# Remove Application Bundles | |
remove "/Applications/Microsoft Excel.app" | |
remove "/Applications/Microsoft OneNote.app" | |
remove "/Applications/Microsoft Outlook.app" | |
remove "/Applications/Microsoft PowerPoint.app" | |
remove "/Applications/Microsoft Word.app" | |
# Remove supporting files from Library | |
remove "/Library/LaunchDaemons/com.microsoft.office.licensingV2.helper.plist" | |
remove "/Library/LaunchDaemons/com.microsoft.autoupdate.helper.plist" | |
remove "/Library/PrivilegedHelperTools/com.microsoft.office.licensingV2.helper" | |
remove "/Library/PrivilegedHelperTools/com.microsoft.autoupdate.helper" | |
remove "/Library/Preferences/com.microsoft.office.licensingV2.plist" | |
# Remove supporting files from user libraries | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.errorreporting' | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.Excel' | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.netlib.shipassertprocess' | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.Office365ServiceV2' | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.Outlook' | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.Powerpoint' | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.RMS-XPCService' | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.Word' | |
userIteration 'remove $HOME/Library/Containers/com.microsoft.onenote.mac' | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.ms' | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.Office' | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.OfficeOsfWebHost' | |
# Remove any perpetual or volume license | |
backup "/Library/Preferences/com.microsoft.office.licensingV2.plist" | |
remove "/Library/Preferences/com.microsoft.office.licensingV2.plist" | |
# Remove supporting files from user library group containers | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.Office/com.microsoft.Office365.plist' | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.Office/com.microsoft.e0E2OUQxNUY1LTAxOUQtNDQwNS04QkJELTAxQTI5M0JBOTk4O.plist' | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.Office/e0E2OUQxNUY1LTAxOUQtNDQwNS04QkJELTAxQTI5M0JBOTk4O' | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.Office/com.microsoft.Office365V2.plist' | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.Office/com.microsoft.O4kTOBJ0M5ITQxATLEJkQ40SNwQDNtQUOxATL1YUNxQUO2E0e.plist' | |
userIteration 'remove $HOME/Library/Group Containers/UBF8T346G9.Office/O4kTOBJ0M5ITQxATLEJkQ40SNwQDNtQUOxATL1YUNxQUO2E0e' | |
# Remove any keychain entries for Office | |
userIteration '/usr/bin/security delete-internet-password -s "msoCredentialSchemeADAL"' | |
userIteration '/usr/bin/security delete-internet-password -s "msoCredentialSchemeLiveId"' | |
userIteration '/usr/bin/security delete-generic-password -l "Microsoft Office Identities Settings 2"' | |
userIteration '/usr/bin/security delete-generic-password -l "Microsoft Office Identities Cache 2"' | |
# Remove the "Belongs To" information | |
userIteration '/usr/bin/defaults delete com.microsoft.office OfficeActivationEmailAddress' | |
# Reset the first run experience for each licensed app | |
userIteration '/usr/bin/defaults write com.microsoft.Word kSubUIAppCompletedFirstRunSetup1507 -bool FALSE' | |
userIteration '/usr/bin/defaults write com.microsoft.Excel kSubUIAppCompletedFirstRunSetup1507 -bool FALSE' | |
userIteration '/usr/bin/defaults write com.microsoft.Powerpoint kSubUIAppCompletedFirstRunSetup1507 -bool FALSE' | |
userIteration '/usr/bin/defaults write com.microsoft.Outlook FirstRunExperienceCompletedO15 -bool FALSE' | |
# Restart the CFPreferences daemon to ensure that all caches are flushed | |
/usr/bin/killall cfprefsd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment