Skip to content

Instantly share code, notes, and snippets.

@cshepp1211
Created February 24, 2016 22:53
Show Gist options
  • Save cshepp1211/95b1018e82da68647901 to your computer and use it in GitHub Desktop.
Save cshepp1211/95b1018e82da68647901 to your computer and use it in GitHub Desktop.
Office 2016 Installation script for use with Self Service
#!/bin/bash
# Set up log file, folder and function
LOGFOLDER="/private/var/log/gov.fnal"
LOG=$LOGFOLDER"/Office-2016-Install.log"
error=0
if [ ! -d "$LOGFOLDER" ];
then
mkdir $LOGFOLDER
fi
logme()
{
# Check to see if function has been called correctly
if [ -z "$1" ]
then
echo $( date )" - logme function call error: no text passed to function! Please recheck code!"
exit 1
fi
# Log the passed details
echo $( date )" - "$1 >> $LOG
echo "" >> $LOG
}
osascript -e 'tell app "System Events" to display dialog "The Office 2016 for Mac installation can take up to 15 minutes to complete. Once the installation has completed, a message will appear confirming that the installation is successful." buttons {"OK"} default button 1'
# Office 2011 Install location
office2011="/Applications/Microsoft Office 2011"
logme "Checking if Office 2011 is present"
# If installed, then clean up files
if [ -d "$office2011" ];
then
logme "Office 2011 installation detected. Removing."
# Stop Office 2011 background processes
logme "Stopping Office 2011 background processes"
osascript -e 'tell application "Microsoft Database Daemon" to quit' | tee -a ${LOG}
osascript -e 'tell application "Microsoft AU Daemon" to quit' | tee -a ${LOG}
osascript -e 'tell application "Office365Service" to quit' | tee -a ${LOG}
# Delete external applications apart from Lync and Remote Desktop
logme "Deleting Office 2011 applications"
rm -R '/Applications/Microsoft Communicator.app/' | tee -a ${LOG}
rm -R '/Applications/Microsoft Messenger.app/' | tee -a ${LOG}
rm -R '/Applications/Microsoft Office 2011/' | tee -a ${LOG}
# Delete MS working folder
logme "Deleting /Library/Application Support/Microsoft"
rm -R '/Library/Application Support/Microsoft/' | tee -a ${LOG}
# Remove all Automator actions
logme "Deleting Automator actions"
rm -R /Library/Automator/*Excel* | tee -a ${LOG}
rm -R /Library/Automator/*Office* | tee -a ${LOG}
rm -R /Library/Automator/*Outlook* | tee -a ${LOG}
rm -R /Library/Automator/*PowerPoint* | tee -a ${LOG}
rm -R /Library/Automator/*Word* | tee -a ${LOG}
rm -R /Library/Automator/*Workbook* | tee -a ${LOG}
rm -R '/Library/Automator/Get Parent Presentations of Slides.action' | tee -a ${LOG}
rm -R '/Library/Automator/Set Document Settings.action' | tee -a ${LOG}
# Remove Office Fonts and copy disabled ones back into place
logme "Deleting Microsoft Fonts folder"
rm -R /Library/Fonts/Microsoft/ | tee -a ${LOG}
logme "Moving previously disabled fonts back to main fonts folder"
mv '/Library/Fonts Disabled/Arial Bold Italic.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Arial Bold.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Arial Italic.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Arial.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Brush Script.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Times New Roman Bold Italic.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Times New Roman Bold.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Times New Roman Italic.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Times New Roman.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Verdana Bold Italic.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Verdana Bold.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Verdana Italic.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Verdana.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Wingdings 2.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Wingdings 3.ttf' /Library/Fonts | tee -a ${LOG}
mv '/Library/Fonts Disabled/Wingdings.ttf' /Library/Fonts | tee -a ${LOG}
# Remove Sharepoint plugin
logme "Deleting Sharepoint folder"
rm -R /Library/Internet\ Plug-Ins/SharePoint* | tee -a ${LOG}
# Finally remove LaunchDaemons, preference files and any helper tools
logme "Deleting LaunchDaemons, Prefs and helper tools"
rm -R /Library/LaunchDaemons/com.microsoft.* | tee -a ${LOG}
rm -R /Library/Preferences/com.microsoft.* | tee -a ${LOG}
rm -R /Library/PrivilegedHelperTools/com.microsoft.* | tee -a ${LOG}
else
logme "Office 2011 not installed. Skipping uninstallation."
fi
logme "Starting Installation of Microsoft Office 2016"
# Determine working directory
install_dir=`dirname $0`
logme "Working Directory: $install_dir"
# Install all the packages
logme "Caching Office 2016"
jamf policy -trigger cache-office2016-installer ${LOG}
logme "Installing Cached Office 2016"
jamf policy -trigger run-office2016-install ${LOG}
# Register Microsoft AU Daemon for all users
# Set up variables
register_trusted_cmd="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -R -f -trusted"
application="/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/Microsoft AU Daemon.app"
logme "Registering the Microsoft Auto Update Daemon"
$register_trusted_cmd "$application" | tee -a ${LOG}
# Let's make sure the first run prompting is disabled where possible.
logme "Disabling the application first run prompting"
defaults write /Library/Preferences/com.microsoft.Excel kSubUIAppCompletedFirstRunSetup1507 -bool true | tee -a ${LOG}
defaults write /Library/Preferences/com.microsoft.onenote.mac kSubUIAppCompletedFirstRunSetup1507 -bool true | tee -a ${LOG}
defaults write /Library/Preferences/com.microsoft.Outlook kSubUIAppCompletedFirstRunSetup1507 -bool true | tee -a ${LOG}
defaults write /Library/Preferences/com.microsoft.Outlook FirstRunExperienceCompletedO15 -bool true | tee -a ${LOG}
defaults write /Library/Preferences/com.microsoft.PowerPoint kSubUIAppCompletedFirstRunSetup1507 -bool true | tee -a ${LOG}
defaults write /Library/Preferences/com.microsoft.Word kSubUIAppCompletedFirstRunSetup1507 -bool true | tee -a ${LOG}
logme "Package installation completed."
osascript -e 'tell app "System Events" to display alert "Office 2016 for Mac successfully Installed" message "You may click on the Open Link button below for instructions on how to setup Office 2016." as critical buttons {"Open Link" , "Cancel"} default button 1
set response to button returned of the result
if response is "Open Link" then open location "https://KB_URL"'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment