Skip to content

Instantly share code, notes, and snippets.

@nmcspadden
Last active September 28, 2015 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmcspadden/6b0391e433655616cd02 to your computer and use it in GitHub Desktop.
Save nmcspadden/6b0391e433655616cd02 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Credit to Erik Gomez, 2015, for this script.
if [ -e "/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app" ]
then
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -R -f -trusted "/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app"
fi
if [ -e "/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/Microsoft AU Daemon.app" ]
then
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -R -f -trusted "/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/Microsoft AU Daemon.app"
fi
#! /usr/bin/python
"""
Post install script to create licensing plist for Office.
"""
import os
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
from objc import NULL
# You'll need to figure out how you can incorporate this into your python path
import FoundationPlist
# Determine current user
# https://github.com/pudquick/pymaIdentity/blob/master/pymaidentity.py#L7-L14
def CurrentDesktopUser():
# User account currently logged in locally to the machine, sitting at the Desktop
# This works even with Fast User Switching
# http://developer.apple.com/library/mac/#qa/qa1133/_index.html
current_user = (SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL) or [NULL])[0]
if (current_user == u'loginwindow') or (current_user == NULL):
current_user = None
return User(current_user)
user = CurrentDesktopUser()
if user in ['root', None]:
# at the login window, so we naively use the first non-admin user in /Users
userlist = glob.glob('/Users/*')
if '/Users/admin' in userlist:
userlist.remove('/Users/admin')
if '/Users/Shared' in userlist:
userlist.remove('/Users/Shared')
# make the naive assumption that the next name in the list is the user
user = userlist[0].split('/')[2]
# Create the LaunchDaemon plist to configure the stupid trusted autoupdater
plist_path = '/Library/LaunchDaemons/com.cpe.office.autoupdate.plist'
launchd = {
'Label': 'com.cpe.office.autoupdate',
'ProgramArguments': [
'/Library/CPE/msoffice2016_autoupdate.sh'
],
'RunAtLoad': True,
'UserName': user
}
print "Dict: %s" % launchd
FoundationPlist.writePlist(launchd, plist_path)
print "Exists? %s" % os.path.exists(plist_path)
os.chmod(plist_path, 0644)
os.chown(plist_path, 0, 0)
cmd = '/bin/launchctl load %s' % plist_path
result = shell_tools.run(cmd)
print "Result: %s" % result['stdout']
print "Errors: %s" % result['stderr']
print "Deleting file..."
os.remove(plist_path)
print "Deleted! All done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment