def GetAppleSUSCatalog(): """Fetches an Apple Software Update Service catalog from the server.""" url = GetServerURL() try: new = updatecheck.getResourceIfChangedAtomically( '%s/applesus/' % url, APPLE_SUS_CATALOG) except fetch.MunkiDownloadError: logging.exception('MunkiDownloadError getting Apple SUS catalog.') return if new: # SUS catalog changed, clear last check date to run softwareupdate soon. munkicommon.set_pref('LastAppleSoftwareUpdateCheck', None) try: sus_catalog = fpl.readPlist(APPLE_SUS_PLIST) except fpl.NSPropertyListSerializationException: # plist may not exist, but will be created when softwareupdate is run, then # the next execution of of this code will set the CatalogURL. logging.exception('Failed to read Apple SoftwareUpdate plist.') return # Update the CatalogURL setting in com.apple.SoftwareUpdate.plist. sus_catalog['CatalogURL'] = urlparse.urljoin( 'file://localhost/', urllib.quote(APPLE_SUS_CATALOG)) fpl.writePlist(sus_catalog, APPLE_SUS_PLIST)
def GetAppleSUSCatalog(): """Fetches an Apple Software Update Service catalog from the server.""" url = GetServerURL() try: new = updatecheck.getResourceIfChangedAtomically( '%s/applesus/' % url, APPLE_SUS_CATALOG) except fetch.MunkiDownloadError as e: logging.exception(u'MunkiDownloadError getting Apple SUS catalog: %s', e) return if new: # SUS catalog changed, clear last check date to run softwareupdate soon. munkicommon.set_pref('LastAppleSoftwareUpdateCheck', None) try: sus_catalog = fpl.readPlist(APPLE_SUS_PLIST) except fpl.NSPropertyListSerializationException: # plist may not exist, but will be created when softwareupdate is run, then # the next execution of of this code will set the CatalogURL. logging.exception('Failed to read Apple SoftwareUpdate plist.') return # Update the CatalogURL setting in com.apple.SoftwareUpdate.plist. sus_catalog['CatalogURL'] = urlparse.urljoin( 'file://localhost/', urllib.quote(APPLE_SUS_CATALOG)) fpl.writePlist(sus_catalog, APPLE_SUS_PLIST)
def _SetCustomCatalogURL(catalog_url): """Sets Software Update's CatalogURL to custom value.""" key = 'SimianCatalogURL' if munkicommon.pref(key) == catalog_url: return munkicommon.set_pref(key, catalog_url) os_version_tuple = munkicommon.getOsVersion(as_tuple=True) # set custom catalog url on each preflight for apple updates if os_version_tuple >= (10, 11): Exec(['/usr/sbin/softwareupdate', '--set-catalog', catalog_url]) Exec([ '/usr/bin/defaults', 'write', APPLE_SUS_PLIST, 'CatalogURL', catalog_url])
# try to import from the default place Munki installs it try: from munkilib import FoundationPlist, munkicommon except: sys.path.append('/usr/local/munki') from munkilib import FoundationPlist, munkicommon import os from datetime import datetime FILE_LOCATION = "/Users/Shared/.msc-dnd.plist" # Does the file exist? if not os.path.isfile(FILE_LOCATION): # File isn't here, set the Munki pref to False munkicommon.set_pref('SuppressUserNotification', False) sys.exit(0) # If it does, get the current date? else: plist = FoundationPlist.readPlist(FILE_LOCATION) if 'DNDEndDate' not in plist: # The key we need isn't in there, remove the file, set pref and exit os.remove(FILE_LOCATION) munkicommon.set_pref('SuppressUserNotification', False) sys.exit(0) else: # Is the current date greater than the DND date? saved_time = datetime.strptime(str(plist['DNDEndDate']), "%Y-%m-%d %H:%M:%S +0000") current_time = datetime.now() if saved_time < current_time: