Last active
June 25, 2024 22:33
-
-
Save opragel/bda5626c3b13c3fe5467 to your computer and use it in GitHub Desktop.
laziest_install_microsoft_office2016.sh
This file contains 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 | |
# witness the horror | |
# seriously don't do this | |
# last warning.. maybe | |
# Guess I'm putting a license in | |
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | |
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and limitations under the License. | |
# Not intended for prod ¯\_(ツ)_/¯ | |
DOWNLOAD_URLS=( \ | |
# Outlook | |
"https://go.microsoft.com/fwlink/?linkid=525137" \ | |
# Word | |
"https://go.microsoft.com/fwlink/?linkid=525134" \ | |
# Excel | |
"https://go.microsoft.com/fwlink/?linkid=525135" \ | |
# Powerpoint | |
"https://go.microsoft.com/fwlink/?linkid=525136" \ | |
# Autoupdater - comment download url below to skip install | |
"https://go.microsoft.com/fwlink/?linkid=830196" \ | |
# OneNote - uncomment download url to install | |
# "http://go.microsoft.com/fwlink/?linkid=820886" \ | |
) | |
MAU_APP_PATH="/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app" | |
DOUBLE_SECRET_MAU_PATH="/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/Microsoft AU Daemon.app" | |
INSTALLER_TARGET="LocalSystem" | |
EXPECTED_SIGNATURE="Microsoft Corporation (UBF8T346G9)" | |
for downloadUrl in "${DOWNLOAD_URLS[@]}"; do | |
finalDownloadUrl=$(curl "$downloadUrl" -s -L -I -o /dev/null -w '%{url_effective}') | |
pkgName=$(printf "%s" "${finalDownloadUrl[@]}" | sed 's@.*/@@') | |
pkgPath="/tmp/$pkgName" | |
printf "Downloading %s\n" "$pkgName" | |
curl --retry 3 -L "$finalDownloadUrl" -o "$pkgPath" | |
curlExitCode=$? | |
if [ "$curlExitCode" -ne 0 ]; then | |
printf "Failed to download: %s\n" "$downloadUrl" | |
printf "Curl exit code: %s\n" "$curlExitCode" | |
else | |
printf "Checking signature of package %s\n" "$pkgName" | |
packageSignature=$(/usr/sbin/pkgutil --check-signature "$pkgPath" | grep 'Developer ID Installer' | sed 's/[^,:]*://g' | cut -c 2-) | |
if [ "$packageSignature" != "$EXPECTED_SIGNATURE" ]; then | |
printf "Invalid package signature. Signature: %s\n" "$packageSignature" | |
exit 1 | |
fi | |
printf "Signature validated: %s\n" "$pkgName" | |
printf "Installing %s\n" "$pkgName" | |
installer -pkg "$pkgPath" -target "$INSTALLER_TARGET" -verbose | |
installerExitCode=$? | |
if [ "$installerExitCode" -ne 0 ]; then | |
printf "Failed to install: %s\n" "$pkgPath" | |
printf "Installer exit code: %s\n" "$installerExitCode" | |
fi | |
rm "$pkgPath" | |
fi | |
done | |
# This part borrowed from https://gist.github.com/erikng/7cede5be1c0ae2f85435 | |
if [ -e "$MAU_APP_PATH" ]; then | |
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -R -f -trusted "$MAU_APP_PATH" | |
if [ -e "$DOUBLE_SECRET_MAU_PATH" ]; then | |
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -R -f -trusted "$DOUBLE_SECRET_MAU_PATH" | |
fi | |
fi |
Should I make it have an exit code at the end to make sure it quits?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get an error when I run this script.
: command not foundline 9:
: command not foundline 12:
: command not foundline 13:
: command not foundline 29:
: command not foundline 33:
: command not foundline 35:
'nstallMSO2016.sh: line 36: syntax error near unexpected token
do 'nstallMSO2016.sh: line 36:
for downloadUrl in "${DOWNLOAD_URLS[@]}"; do