Skip to content

Instantly share code, notes, and snippets.

@48kRAM
Created October 3, 2014 16:23
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 48kRAM/8632d33b9b1b05c67b5d to your computer and use it in GitHub Desktop.
Save 48kRAM/8632d33b9b1b05c67b5d to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# encoding: utf-8
'''Postflight script'''
from munkilib import munkicommon
from munkilib import reportcommon
from munkilib import FoundationPlist
import hashlib
import sys
import os
def main():
'''Main'''
# get runtype
if (len(sys.argv) > 1):
runtype = sys.argv[1]
else:
runtype = 'custom'
# Get serial
hardware_info = munkicommon.get_hardware_info()
serial = hardware_info.get('serial_number', 'NO_SERIAL')
invPath = r"/Library/Managed Installs/ApplicationInventory.plist"
plugins = r"/Library/Internet Plug-Ins/"
directoryListing = os.listdir(plugins)
appinv = FoundationPlist.readPlist(invPath)
print "Adding %i plugins" % len(directoryListing)
for x in directoryListing:
path = os.path.join(plugins, x, 'Contents/Info.plist')
try:
info = FoundationPlist.readPlist(path)
plugin = {}
plugin['CFBundleName'] = info.get('CFBundleName', x)
plugin['bundleid'] = info.get('CFBundleIdentifier', 'N/A')
plugin['version'] = info.get('CFBundleVersion','N/A')
plugin['path'] = os.path.join(plugins, x)
plugin['name'] = info.get('CFBundleName', os.path.splitext(os.path.basename(x))[0])
appinv.append(plugin.copy())
except Exception, message:
pass
FoundationPlist.writePlist(appinv, invPath)
items = {} # item list
report_info = {}
report_info['console_user'] = "%s" % munkicommon.getconsoleuser()
report_info['runtype'] = runtype
report_info['runstate'] = 'done'
report_info_plist = FoundationPlist.writePlistToString(report_info)
items = {'Reportdata':{'hash':hashlib.md5(report_info_plist).hexdigest(), \
'data':report_info_plist}}
# Read config file /Library/Preferences/Munkireport.plist
config_items = reportcommon.pref('ReportItems') or {}
for key, val in config_items.items():
print "Requesting %s" % key
items[key] = {'path':val}
reportcommon.process(serial, items)
exit(0)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment