diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | mowgli.py | 31 |
2 files changed, 26 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc
\ No newline at end of file @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +"""Microsoft AutoUpdate Command Line Utility.""" import os import sys @@ -22,22 +23,28 @@ NAMES = { BASEURL = '/pr/%s/OfficeMac/' % UUID +PREF_PATH = 'Library/Preferences/com.microsoft.autoupdate2.plist' def get_plist(path): - """Return plist dict regardless of format. - - """ + """Return plist dict regardless of format.""" plist = subprocess.check_output(['/usr/bin/plutil', '-convert', 'xml1', path, '-o', '-']) return plistlib.readPlistFromString(plist) -def check(home=None, pref='Library/Preferences/com.microsoft.autoupdate2.plist'): - """Collect info about available updates. +def set_pref(k='HowToCheck', v='Manual'): + """Set AU pref k to v.""" + subprocess.call(['/usr/bin/defaults', + 'write', + 'com.microsoft.autoupdate2', + k, + v]) + - """ +def check(home=None, pref=PREF_PATH): + """Collect info about available updates.""" results = [] if home is None: @@ -113,6 +120,7 @@ def check(home=None, pref='Library/Preferences/com.microsoft.autoupdate2.plist') def download(url): + """Download url to temporary folder.""" temp = os.path.join(tempfile.gettempdir(), 'mowgli') if not os.path.exists(temp): @@ -128,6 +136,7 @@ def download(url): def install(pkg): + """Install a package.""" r = subprocess.call(['/usr/sbin/installer', '-pkg', pkg, '-target', '/']) if r > 0: raise Exception('Failed to install package %s' % pkg) @@ -141,6 +150,16 @@ if __name__ == '__main__': print("usage: {0} [-l | -i [home]".format(os.path.basename(sys.argv[0]))) sys.exit(1) + if sys.argv[1] == 'enable': + set_pref('HowToCheck', 'Manual') + print('* Automatic updates enabled') + sys.exit(0) + + if sys.argv[1] == 'disable': + set_pref('HowToCheck', 'Automatic') + print('* Automatic updates disabled') + sys.exit(0) + print("* Finding available software") if len(sys.argv) > 2: |