def handle_icons(itemlist): """Download icons and build the package.""" print("Downloading icons.") pkg_output_file = os.path.join(CACHE, 'munki_icons.pkg') # Set the local directory to the AutoDMG cache old_managed = prefs.pref('ManagedInstallDir') prefs.set_pref('ManagedInstallDir', CACHE) # Downloads all icons into the icon directory in the Munki cache download.download_icons(itemlist) # Put the actual Munki cache dir back prefs.set_pref('ManagedInstallDir', old_managed) # Build a package of optional Munki icons, so we don't need to cache success = build_pkg( os.path.join(CACHE, 'icons'), 'munki_icons', 'com.facebook.cpe.munki_icons', '/Library/Managed Installs/icons', CACHE, 'Creating the icon package.' ) # Add the icon package to the additional packages list for the template. if success: return pkg_output_file else: print("Failed to build icon package!", file=sys.stderr) return None
def formated_prefs(): """Formated dictionary object for output to plist""" my_dict = {} for pref in munki_prefs(): pref_value = pref_to_str(prefs.pref(pref)) my_dict.update({pref: pref_value}) return my_dict
def formatted_prefs(): """Formatted dictionary object for output to plist""" my_dict = {} for pref in munki_prefs(): pref_value = pref_to_str(prefs.pref(pref)) my_dict.update({pref: pref_value}) return my_dict
def handle_custom(): """Download custom resources and build the package.""" print("Downloading Munki client resources.") # Set the local directory to the AutoDMG cache old_managed = prefs.pref('ManagedInstallDir') prefs.set_pref('ManagedInstallDir', CACHE) # Downloads client resources into the AutoDMG cache download.download_client_resources() # Put the actual Munki cache dir back prefs.set_pref('ManagedInstallDir', old_managed) resource_dir = os.path.join( CACHE, 'client_resources') resource_file = os.path.join(resource_dir, 'custom.zip') if os.path.isfile(resource_file): # Client Resources are stored in # /Library/Managed Installs/client_resources/custom.zip destination_path = '/Library/Managed Installs/client_resources' pkg_output_file = os.path.join(CACHE, 'munki_custom.pkg') success = build_pkg( resource_dir, 'munki_custom', 'com.facebook.cpe.munki_custom', destination_path, CACHE, 'Creating the Munki custom resources package.' ) if success: return pkg_output_file else: print( "Failed to build Munki custom resources package!", file=sys.stderr ) return None
def handle_custom(): """Download custom resources and build the package.""" print("Downloading Munki client resources.") # Set the local directory to the AutoDMG cache old_managed = prefs.pref('ManagedInstallDir') prefs.set_pref('ManagedInstallDir', CACHE) # Downloads client resources into the AutoDMG cache download.download_client_resources() # Put the actual Munki cache dir back prefs.set_pref('ManagedInstallDir', old_managed) resource_dir = os.path.join(CACHE, 'client_resources') resource_file = os.path.join(resource_dir, 'custom.zip') if os.path.isfile(resource_file): # Client Resources are stored in # /Library/Managed Installs/client_resources/custom.zip destination_path = '/Library/Managed Installs/client_resources' pkg_output_file = os.path.join(CACHE, 'munki_custom.pkg') success = build_pkg(resource_dir, 'munki_custom', 'com.facebook.cpe.munki_custom', destination_path, CACHE, 'Creating the Munki custom resources package.') if success: return pkg_output_file else: print("Failed to build Munki custom resources package!", file=sys.stderr) return None
def get_munkiprotocol(): """The protocol munki is using""" software_repo_url = pref_to_str(prefs.pref('SoftwareRepoURL')) try: url_parse = urlparse.urlparse(software_repo_url) return url_parse.scheme except AttributeError: return 'Could not obtain protocol'
def gather_install_list(manifest): """Gather the list of install items.""" # First, swap out for our cache dir old_managed = prefs.pref('ManagedInstallDir') prefs.set_pref('ManagedInstallDir', CACHE) # Process the manifest for managed_installs (cataloglist, managed_installs) = obtain_manifest(manifest) install_list = [] for item in managed_installs: print('Processing %s' % item) detail = catalogs.get_item_detail(item, cataloglist) if detail: install_list.append(detail) # Put the actual Munki cache dir back prefs.set_pref('ManagedInstallDir', old_managed) return install_list
def handle_icons(itemlist): """Download icons and build the package.""" print("Downloading icons.") pkg_output_file = os.path.join(CACHE, 'munki_icons.pkg') # Set the local directory to the AutoDMG cache old_managed = prefs.pref('ManagedInstallDir') prefs.set_pref('ManagedInstallDir', CACHE) # Downloads all icons into the icon directory in the Munki cache download.download_icons(itemlist) # Put the actual Munki cache dir back prefs.set_pref('ManagedInstallDir', old_managed) # Build a package of optional Munki icons, so we don't need to cache success = build_pkg(os.path.join(CACHE, 'icons'), 'munki_icons', 'com.facebook.cpe.munki_icons', '/Library/Managed Installs/icons', CACHE, 'Creating the icon package.') # Add the icon package to the additional packages list for the template. if success: return pkg_output_file else: print("Failed to build icon package!", file=sys.stderr) return None
except ImportError: print("Using plistlib") import plistlib try: import munkilib.display as display import munkilib.fetch as fetch import munkilib.prefs as prefs import munkilib.updatecheck.catalogs as catalogs import munkilib.updatecheck.manifestutils as manifestutils import munkilib.updatecheck.download as download except ImportError as err: print("Something went wrong! %s" % err) MUNKI_URL = prefs.pref('SoftwareRepoURL') PKGS_URL = MUNKI_URL + '/pkgs' BASIC_AUTH = prefs.pref('AdditionalHttpHeaders') CACHE = '/tmp' # download functions def download_url_to_cache(url, cache, force=False): """Take a URL and downloads it to a local cache.""" cache_path = os.path.join( cache, urllib2.unquote(download.get_url_basename(url)) ) custom_headers = [''] if BASIC_AUTH: # custom_headers = ['Authorization: Basic %s' % BASIC_AUTH]
import FoundationPlist as plistlib except ImportError: print("Using plistlib") import plistlib try: import munkilib.display as display import munkilib.fetch as fetch import munkilib.prefs as prefs import munkilib.updatecheck.catalogs as catalogs import munkilib.updatecheck.manifestutils as manifestutils import munkilib.updatecheck.download as download except ImportError as err: print("Something went wrong! %s" % err) MUNKI_URL = prefs.pref('SoftwareRepoURL') PKGS_URL = MUNKI_URL + '/pkgs' BASIC_AUTH = prefs.pref('AdditionalHttpHeaders') CACHE = '/tmp' # download functions def download_url_to_cache(url, cache, force=False): """Take a URL and downloads it to a local cache.""" cache_path = os.path.join(cache, urllib2.unquote(download.get_url_basename(url))) custom_headers = [''] if BASIC_AUTH: # custom_headers = ['Authorization: Basic %s' % BASIC_AUTH] custom_headers = BASIC_AUTH if force: