diff --git a/code/client/munkilib/appleupdates.py b/code/client/munkilib/appleupdates.py index b3f90c6a..8e7442bc 100755 --- a/code/client/munkilib/appleupdates.py +++ b/code/client/munkilib/appleupdates.py @@ -127,8 +127,7 @@ def checkForSoftwareUpdates(): retcode = 0 else: # there was an error - print >>sys.stderr, "softwareupdate error: %s" % retcode - munkicommon.log("softwareupdate error: %s" % retcode) + munkicommon.display_error("softwareupdate error: %s" % retcode) if osvers == 9: # put mode back for Software Update.app @@ -469,7 +468,7 @@ def installAppleUpdates(): # define this here so we can access it in multiple functions -appleUpdatesFile = '/Library/Managed Installs/AppleUpdates.plist' +appleUpdatesFile = os.path.join(munkicommon.pref('ManagedInstallDir'),'AppleUpdates.plist') def main(): diff --git a/code/client/munkilib/installer.py b/code/client/munkilib/installer.py index 5c3fad8e..04222a49 100644 --- a/code/client/munkilib/installer.py +++ b/code/client/munkilib/installer.py @@ -157,7 +157,7 @@ def installall(dirpath, choicesXMLpath=None): munkicommon.display_info("Mounting disk image %s" % item) mountpoints = munkicommon.mountdmg(itempath) if mountpoints == []: - munkicommon.display_error("ERROR: No filesystems mounted from %s" % item) + munkicommon.display_error("No filesystems mounted from %s" % item) return (retcode, restartflag) if munkicommon.stopRequested(): munkicommon.unmountdmg(mountpoints[0]) @@ -239,8 +239,9 @@ def installWithInfo(dirpath, installlist, appleupdates=False): return restartflag if "installer_item" in item: itemindex = itemindex + 1 + display_name = item.get('display_name') or item.get('name') + version_to_install = item.get('version_to_install','') if munkicommon.munkistatusoutput: - display_name = item.get('display_name') or item.get('name') munkistatus.message("Installing %s (%s of %s)..." % (display_name, itemindex, len(installlist))) munkistatus.detail("") munkistatus.percent(-1) @@ -258,12 +259,14 @@ def installWithInfo(dirpath, installlist, appleupdates=False): if retcode == 8: # Adobe Setup says restart needed restartflag = True + retcode = 0 elif installer_type == "AdobeSetup": # Adobe CS4 updater retcode = adobeutils.runAdobeSetup(itempath) if retcode == 8: # Adobe Setup says restart needed restartflag = True + retcode = 0 elif installer_type == "appdmg": retcode = copyAppFromDMG(itempath) else: @@ -277,7 +280,7 @@ def installWithInfo(dirpath, installlist, appleupdates=False): munkicommon.display_status("Mounting disk image %s" % item["installer_item"]) mountpoints = munkicommon.mountdmg(itempath) if mountpoints == []: - munkicommon.display_error("ERROR: No filesystems mounted from %s" % item["installer_item"]) + munkicommon.display_error("No filesystems mounted from %s" % item["installer_item"]) return restartflag if munkicommon.stopRequested(): munkicommon.unmountdmg(mountpoints[0]) @@ -300,7 +303,13 @@ def installWithInfo(dirpath, installlist, appleupdates=False): (retcode, needsrestart) = installall(itempath, choicesXMLfile) if needsrestart: restartflag = True - + + # record install success/failure + if retcode == 0: + munkicommon.log("Install of %s-%s: SUCCESS" % (display_name, version_to_install), "Install.log") + else: + munkicommon.log("Install of %s-%s: FAILED with return code: %s" % (display_name, version_to_install, retcode), "Install.log") + # check to see if this installer item is needed by any additional items in installinfo # this might happen if there are mulitple things being installed with choicesXML files # applied to a metapackage @@ -368,7 +377,7 @@ def processRemovals(removallist): elif uninstallmethod[0] == "AdobeUberUninstaller": if "uninstaller_item" in item: - managedinstallbase = munkicommon.ManagedInstallDir() + managedinstallbase = munkicommon.pref('ManagedInstallDir') itempath = os.path.join(managedinstallbase, 'Cache', item["uninstaller_item"]) if os.path.exists(itempath): pkgname = item.get("adobe_package_name","") @@ -439,6 +448,14 @@ def processRemovals(removallist): else: munkicommon.log("Uninstall of %s failed because there was no valid uninstall method." % name) + retcode = -99 + + # record removal success/failure + if retcode == 0: + munkicommon.log("Removal of %s: SUCCESS" % name, "Install.log") + else: + munkicommon.log("Removal of %s: FAILED with return code: %s" % (name, retcode), "Install.log") + return restartFlag @@ -446,7 +463,7 @@ def processRemovals(removallist): def run(): - managedinstallbase = munkicommon.ManagedInstallDir() + managedinstallbase = munkicommon.pref('ManagedInstallDir') installdir = os.path.join(managedinstallbase , 'Cache') needtorestart = removals_need_restart = installs_need_restart = False diff --git a/code/client/munkilib/munkicommon.py b/code/client/munkilib/munkicommon.py index 99adbe97..fa9cebc3 100644 --- a/code/client/munkilib/munkicommon.py +++ b/code/client/munkilib/munkicommon.py @@ -152,6 +152,30 @@ def display_debug2(msg): print msg.encode('UTF-8') if logginglevel > 2: log(msg) + + +def reset_warnings(): + warningsfile = os.path.join(os.path.dirname(logfile), "warnings.log") + if os.path.exists(warningsfile): + rotatelog(warningsfile) + + +def display_warning(msg): + """ + Prints warning msgs to stderr and the log + """ + global warnings + warning = "WARNING: %s" % msg + print >>sys.stderr, warning.encode('UTF-8') + log(warning) + # append this warning to our warnings log + log(warning, "warnings.log") + + +def reset_errors(): + errorsfile = os.path.join(os.path.dirname(logfile), "errors.log") + if os.path.exists(errorsfile): + rotatelog(errorsfile) def display_error(msg): @@ -159,20 +183,55 @@ def display_error(msg): Prints msg to stderr and the log """ global errors - print >>sys.stderr, msg.encode('UTF-8') errmsg = "ERROR: %s" % msg + print >>sys.stderr, errmsg.encode('UTF-8') log(errmsg) + # append this error to our errors log + log(errmsg, "errors.log") # collect the errors for later reporting errors = errors + msg + '\n' -def log(msg): +def log(msg, logname=''): + if not logname: + # use our regular logfile + logpath = logfile + else: + logpath = os.path.join(os.path.dirname(logfile), logname) try: - f = open(logfile, mode='a', buffering=1) + f = open(logpath, mode='a', buffering=1) print >>f, time.ctime(), msg.encode('UTF-8') f.close() except: pass + + +def rotatelog(logname=''): + if not logname: + # use our regular logfile + logpath = logfile + else: + logpath = os.path.join(os.path.dirname(logfile), logname) + if os.path.exists(logpath): + for x in range(3,-1,-1): + try: + os.unlink(logpath+"."+str(x+1)) + except: + pass + try: + os.rename(logpath+"."+str(x), logpath+"."+str(x+1)) + except: + pass + try: + os.rename(logpath, logpath+".0") + except: + pass + + +def rotate_main_log(): + if os.path.exists(logfile): + if os.path.getsize(logfile) > 1000000: + rotatelog(logfile) # misc functions @@ -187,20 +246,7 @@ def stopRequested(): return False -def getconsoleuser(): - # workaround no longer needed, but leaving this here for now... - #osvers = int(os.uname()[2].split('.')[0]) - #if osvers > 9: - # cmd = ['/usr/bin/who | /usr/bin/grep console'] - # p = subprocess.Popen(cmd, shell=True, bufsize=1, stdin=subprocess.PIPE, - # stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # (output, err) = p.communicate() - # return output - #else: - # from SystemConfiguration import SCDynamicStoreCopyConsoleUser - # cfuser = SCDynamicStoreCopyConsoleUser( None, None, None ) - # return cfuser[0] - +def getconsoleuser(): from SystemConfiguration import SCDynamicStoreCopyConsoleUser cfuser = SCDynamicStoreCopyConsoleUser( None, None, None ) return cfuser[0] @@ -311,8 +357,14 @@ def getManagedInstallsPrefs(): # define default values prefs = {} prefs['ManagedInstallDir'] = "/Library/Managed Installs" - prefs['ManifestURL'] = "http://munki/repo/manifests/" + # deprecated; to be replaced with CatalogURL and PackageURL prefs['SoftwareRepoURL'] = "http://munki/repo" + # effective defaults for the following three; though if they + # are not in the prefs plist, they are calculated relative + # to the SoftwareRepoURL + #prefs['ManifestURL'] = "http://munki/repo/manifests/" + #prefs['CatalogURL'] = "http://munki/repo/catalogs/" + #prefs['PackageURL'] = "http://munki/repo/pkgs/" prefs['ClientIdentifier'] = '' prefs['LogFile'] = "/Library/Managed Installs/Logs/ManagedSoftwareUpdate.log" prefs['LoggingLevel'] = 1 @@ -346,27 +398,6 @@ def getManagedInstallsPrefs(): return prefs -# Added by bcw -def UseClientCertificate(): - prefs = getManagedInstallsPrefs() - return prefs['UseClientCertificate'] - - -def ManagedInstallDir(): - prefs = getManagedInstallsPrefs() - return prefs['ManagedInstallDir'] - - -def ManifestURL(): - prefs = getManagedInstallsPrefs() - return prefs['ManifestURL'] - - -def SoftwareRepoURL(): - prefs = getManagedInstallsPrefs() - return prefs['SoftwareRepoURL'] - - def pref(prefname): return getManagedInstallsPrefs().get(prefname,'') @@ -846,11 +877,13 @@ debug = False verbose = 1 munkistatusoutput = False errors = "" +warnings = "" tmpdir = tempfile.mkdtemp() logfile = pref('LogFile') logginglevel = pref('LoggingLevel') + def main(): print "This is a library of support tools for the Munki Suite." diff --git a/code/client/munkilib/removepackages.py b/code/client/munkilib/removepackages.py index 5a5c01ba..01f70237 100755 --- a/code/client/munkilib/removepackages.py +++ b/code/client/munkilib/removepackages.py @@ -215,7 +215,7 @@ def ImportPackage(packagepath, c): # Every machine I've seen has a bogus BSD.pkg, so we won't print a warning for # that specific one. if pkgname != "BSD.pkg": - munkicommon.display_error("%s is not a valid receipt. Skipping." % packagepath) + munkicommon.display_warning("%s is not a valid receipt. Skipping." % packagepath) return if not os.path.exists(bompath): @@ -224,11 +224,11 @@ def ImportPackage(packagepath, c): bompath = os.path.join(packagepath, "Contents/Resources", bomname) if not os.path.exists(bompath): - munkicommon.display_error("%s has no BOM file. Skipping." % packagepath) + munkicommon.display_warning("%s has no BOM file. Skipping." % packagepath) return if not os.path.exists(infopath): - munkicommon.display_error("%s has no Info.plist. Skipping." % packagepath) + munkicommon.display_warning("%s has no Info.plist. Skipping." % packagepath) return timestamp = os.stat(packagepath).st_mtime @@ -809,7 +809,7 @@ def removeFilesystemItems(removalpaths, forcedeletebundles): try: os.rmdir(pathtoremove) except Exception, err: - msg = "ERROR: couldn't remove directory %s - %s" % (pathtoremove, err) + msg = "Couldn't remove directory %s - %s" % (pathtoremove, err) munkicommon.display_error(msg) removalerrors = removalerrors + "\n" + msg else: @@ -818,10 +818,10 @@ def removeFilesystemItems(removalpaths, forcedeletebundles): # remove it anyway - no use having a broken bundle hanging # around if (forcedeletebundles and isBundle(pathtoremove)): - munkicommon.display_detail("WARNING: Removing non-empty bundle: %s" % pathtoremove) + munkicommon.display_warning("Removing non-empty bundle: %s" % pathtoremove) retcode = subprocess.call(['/bin/rm', '-r', pathtoremove]) if retcode: - msg = "ERROR: couldn't remove bundle %s" % pathtoremove + msg = "Couldn't remove bundle %s" % pathtoremove munkicommon.display_error(msg) removalerrors = removalerrors + "\n" + msg else: @@ -829,7 +829,7 @@ def removeFilesystemItems(removalpaths, forcedeletebundles): # bundles, we don't need to warn because it's going to be removed with the # bundle. Otherwise, we should warn about non-empty directories. if not insideBundle(pathtoremove) or not forcedeletebundles: - msg = "WARNING: Did not remove %s because it is not empty." % pathtoremove + msg = "Did not remove %s because it is not empty." % pathtoremove munkicommon.display_error(msg) removalerrors = removalerrors + "\n" + msg @@ -844,7 +844,7 @@ def removeFilesystemItems(removalpaths, forcedeletebundles): try: os.remove(pathtoremove) except Exception, err: - msg = "ERROR: couldn't remove item %s: %s" % (pathtoremove, err) + msg = "Couldn't remove item %s: %s" % (pathtoremove, err) munkicommon.display_error(msg) removalerrors = removalerrors + "\n" + msg @@ -907,7 +907,7 @@ def removepackages(pkgnames, forcedeletebundles=False, listfiles=False, # some globals -packagedb = os.path.join(munkicommon.ManagedInstallDir(), "b.receiptdb") +packagedb = os.path.join(munkicommon.pref('ManagedInstallDir'), "b.receiptdb") def main(): # command-line options diff --git a/code/client/munkilib/updatecheck.py b/code/client/munkilib/updatecheck.py index 233da200..aa2eb31d 100644 --- a/code/client/munkilib/updatecheck.py +++ b/code/client/munkilib/updatecheck.py @@ -600,9 +600,12 @@ def download_installeritem(location): """ Downloads a installer item. """ - ManagedInstallDir = munkicommon.ManagedInstallDir() - sw_repo_baseurl = munkicommon.SoftwareRepoURL() - downloadbaseurl = sw_repo_baseurl + "/pkgs/" + ManagedInstallDir = munkicommon.pref('ManagedInstallDir') + downloadbaseurl = munkicommon.pref('PackageURL') or munkicommon.pref('SoftwareRepoURL') + "/pkgs/" + if not downloadbaseurl.endswith('/'): + downloadbaseurl = downloadbaseurl + "/" + munkicommon.display_debug2("Download base URL is: %s" % downloadbaseurl) + mycachedir = os.path.join(ManagedInstallDir, "Cache") # build a URL, quoting the the location to encode reserved characters @@ -617,8 +620,7 @@ def download_installeritem(location): oldverbose = munkicommon.verbose munkicommon.verbose = oldverbose + 1 - dl_message = "Downloading %s from %s" % (pkgname, pkgurl) - munkicommon.log(dl_message) + munkicommon.log("Downloading %s from %s" % (pkgname, location)) dl_message = "Downloading %s..." % pkgname (path, err) = getHTTPfileIfNewerAtomically(pkgurl, destinationpath, message=dl_message) @@ -822,10 +824,10 @@ def enoughDiskSpace(manifestitem_pl, uninstalling=False): return True else: if uninstalling: - munkicommon.display_info("There is insufficient disk space to download the uninstaller for %s." % manifestitem_pl.get('name')) + munkicommon.display_warning("There is insufficient disk space to download the uninstaller for %s." % manifestitem_pl.get('name')) else: - munkicommon.display_info("There is insufficient disk space to download and install %s." % manifestitem_pl.get('name')) - munkicommon.display_info(" %sMB needed; %sMB available" % (diskspaceneeded, availablediskspace)) + munkicommon.display_warning("There is insufficient disk space to download and install %s." % manifestitem_pl.get('name')) + munkicommon.display_warning(" %sMB needed; %sMB available" % (diskspaceneeded, availablediskspace)) return False @@ -964,7 +966,8 @@ def processInstall(manifestitem, cataloglist, installinfo): pl = getItemDetail(manifestitem, cataloglist) if not pl: - munkicommon.display_info("Could not process item %s for install because could not get detail." % manifestitem) + munkicommon.display_warning("Could not process item %s for install: " % manifestitem) + munkicommon.display_warning("No pkginfo for %s found in catalogs: %s" % (manifestitem, ', '.join(cataloglist))) return False # check to see if item is already in the installlist: @@ -1014,7 +1017,7 @@ def processInstall(manifestitem, cataloglist, installinfo): dependenciesMet = False if not dependenciesMet: - munkicommon.display_info("Didn't attempt to install %s because could not resolve all dependencies." % manifestitemname) + munkicommon.display_warning("Didn't attempt to install %s because could not resolve all dependencies." % manifestitemname) return False iteminfo = {} @@ -1063,7 +1066,7 @@ def processInstall(manifestitem, cataloglist, installinfo): installinfo['managed_installs'].append(iteminfo) return False else: - munkicommon.display_info("Can't install %s because there's no download info for the installer item" % manifestitemname) + munkicommon.display_warning("Can't install %s because there's no download info for the installer item" % manifestitemname) iteminfo['installed'] = False iteminfo['note'] = "Download info missing" installinfo['managed_installs'].append(iteminfo) @@ -1115,7 +1118,7 @@ def processManifestForInstalls(manifestpath, installinfo, parentcatalogs=[]): is_or_will_be_installed = processInstall(item, cataloglist, installinfo) else: - munkicommon.display_error("WARNING: manifest %s has no 'catalogs'" % manifestpath) + munkicommon.display_warning("Manifest %s has no 'catalogs'" % manifestpath) return installinfo @@ -1167,7 +1170,7 @@ def processRemoval(manifestitem, cataloglist, installinfo): infoitems = getAllItemsWithName(manifestitemname,cataloglist) if not infoitems: - munkicommon.display_info("Could not get information for %s" % manifestitemname_withversion) + munkicommon.display_warning("Could not get information for %s" % manifestitemname_withversion) return False for item in infoitems: @@ -1175,7 +1178,7 @@ def processRemoval(manifestitem, cataloglist, installinfo): # if so, that's bad - it means it's scheduled to be installed # _and_ removed. We'll warn, and do nothing with this item. if isItemInInstallInfo(item, installinfo['managed_installs']): - munkicommon.display_info("Will not attempt to remove %s because some version of it is in the list of managed installs, or it is required by another managed install." % manifestitemname_withversion) + munkicommon.display_warning("Will not attempt to remove %s because some version of it is in the list of managed installs, or it is required by another managed install." % manifestitemname_withversion) return False for item in infoitems: @@ -1230,7 +1233,7 @@ def processRemoval(manifestitem, cataloglist, installinfo): if not uninstall_item: # we didn't find an item that seems to match anything on disk. - munkicommon.display_info("Could not find uninstall info for %s." % manifestitemname_withversion) + munkicommon.display_warning("Could not find uninstall info for %s." % manifestitemname_withversion) return False # if we got this far, we have enough info to attempt an uninstall. @@ -1245,7 +1248,7 @@ def processRemoval(manifestitem, cataloglist, installinfo): # and we're supposed to remove SomePackage--1.0.1.0.0... what do we do? # dependentitemsremoved = True - ManagedInstallDir = munkicommon.ManagedInstallDir() + ManagedInstallDir = munkicommon.pref('ManagedInstallDir') catalogsdir = os.path.join(ManagedInstallDir, 'catalogs') # make a list of the name and aliases of the current uninstall_item @@ -1291,7 +1294,7 @@ def processRemoval(manifestitem, cataloglist, installinfo): dependentitemsremoved = False if not dependentitemsremoved: - munkicommon.display_info("Will not attempt to remove %s because could not remove all items dependent on it." % manifestitemname_withversion) + munkicommon.display_warning("Will not attempt to remove %s because could not remove all items dependent on it." % manifestitemname_withversion) return False # Finally! We can record the removal information! @@ -1315,12 +1318,12 @@ def processRemoval(manifestitem, cataloglist, installinfo): packagesToReallyRemove.append(pkg) else: # This shouldn't happen - munkicommon.display_error("WARNING: pkg id %s missing from pkgdata" % pkg) + munkicommon.display_warning("pkg id %s missing from pkgdata" % pkg) if packagesToReallyRemove: iteminfo['packages'] = packagesToReallyRemove else: # no packages that belong to this item only. - munkicommon.display_error("WARNING: could not find unique packages to remove for %s" % iteminfo["name"]) + munkicommon.display_warning("could not find unique packages to remove for %s" % iteminfo["name"]) return False iteminfo["uninstall_method"] = uninstallmethod @@ -1336,7 +1339,7 @@ def processRemoval(manifestitem, cataloglist, installinfo): iteminfo['uninstaller_item'] = filename iteminfo['adobe_package_name'] = uninstall_item.get('adobe_package_name','') else: - munkicommon.display_error("WARNING: Failed to download the uninstaller for %s" % iteminfo["name"]) + munkicommon.display_warning("Failed to download the uninstaller for %s" % iteminfo["name"]) return False elif uninstallmethod == "remove_app": if uninstall_item.get('installs',None): @@ -1388,7 +1391,7 @@ def processManifestForRemovals(manifestpath, installinfo, parentcatalogs=[]): is_or_will_be_removed = processRemoval(item, cataloglist, installinfo) else: - munkicommon.display_error("WARNING: manifest %s has no 'catalogs'" % manifestpath) + munkicommon.display_warning("Manifest %s has no 'catalogs'" % manifestpath) return installinfo @@ -1410,16 +1413,17 @@ def getCatalogs(cataloglist): Retreives the catalogs from the server and populates our catalogs dictionary """ global catalog - managedinstallprefs = munkicommon.prefs() - sw_repo_baseurl = managedinstallprefs['SoftwareRepoURL'] - catalog_dir = os.path.join(managedinstallprefs['ManagedInstallDir'], "catalogs") + catalogbaseurl = munkicommon.pref('CatalogURL') or munkicommon.pref('SoftwareRepoURL') + "/catalogs/" + if not catalogbaseurl.endswith('?') and not catalogbaseurl.endswith('/'): + catalogbaseurl = catalogbaseurl + "/" + munkicommon.display_debug2("Catalog base URL is: %s" % catalogbaseurl) + catalog_dir = os.path.join(munkicommon.pref('ManagedInstallDir'), "catalogs") for catalogname in cataloglist: if not catalogname in catalog: - catalogurl = sw_repo_baseurl + "/catalogs/" + urllib2.quote(catalogname) + catalogurl = catalogbaseurl + urllib2.quote(catalogname) catalogpath = os.path.join(catalog_dir, catalogname) - message = "Getting catalog %s from %s..." % (catalogname, catalogurl) - munkicommon.log(message) + munkicommon.log("Getting catalog %s..." % catalogname) message = "Retreiving catalog '%s'..." % catalogname (newcatalog, err) = getHTTPfileIfNewerAtomically(catalogurl, catalogpath, message=message) if newcatalog: @@ -1433,22 +1437,23 @@ def getmanifest(partialurl, suppress_errors=False): """ Gets a manifest from the server """ - managedinstallprefs = munkicommon.prefs() - sw_repo_baseurl = managedinstallprefs['SoftwareRepoURL'] - manifest_dir = os.path.join(managedinstallprefs['ManagedInstallDir'], "manifests") + manifestbaseurl = munkicommon.pref('ManifestURL') or munkicommon.pref('SoftwareRepoURL') + "/manifests/" + if not manifestbaseurl.endswith('?') and not manifestbaseurl.endswith('/'): + manifestbaseurl = manifestbaseurl + "/" + munkicommon.display_debug2("Manifest base URL is: %s" % manifestbaseurl) + manifest_dir = os.path.join(munkicommon.pref('ManagedInstallDir'), "manifests") - if partialurl.startswith("http"): + if partialurl.startswith("http://"): # then it's really a request for the client's primary manifest manifesturl = partialurl manifestname = "client_manifest.plist" else: # request for nested manifest + munkicommon.log("Getting manifest %s..." % partialurl) manifestname = os.path.split(partialurl)[1] - manifesturl = sw_repo_baseurl + "/manifests/" + urllib2.quote(partialurl) + manifesturl = manifestbaseurl + urllib2.quote(partialurl) manifestpath = os.path.join(manifest_dir, manifestname) - message = "Getting manifest %s from %s..." % (manifestname, manifesturl) - munkicommon.log(message) message = "Retreiving list of software for this machine..." (newmanifest, err) = getHTTPfileIfNewerAtomically(manifesturl, manifestpath, message=message) if not newmanifest and not suppress_errors: @@ -1464,35 +1469,32 @@ def getPrimaryManifest(alternate_id): """ global errors manifest = "" - managedinstallprefs = munkicommon.prefs() - manifesturl = managedinstallprefs['ManifestURL'] - clientidentifier = managedinstallprefs.get('ClientIdentifier','') - + manifesturl = munkicommon.pref('ManifestURL') or munkicommon.pref('SoftwareRepoURL') + "/manifests/" if not manifesturl.endswith('?') and not manifesturl.endswith('/'): manifesturl = manifesturl + "/" - if alternate_id: - # use id passed in at command-line - manifesturl = manifesturl + urllib2.quote(alternate_id) - elif clientidentifier: - # use client_identfier from /Library/Preferences/ManagedInstalls.plist - manifesturl = manifesturl + urllib2.quote(clientidentifier) - else: + clientidentifier = alternate_id or munkicommon.pref('ClientIdentifier') + + munkicommon.display_debug2("Manifest base URL is: %s" % manifesturl) + if not clientidentifier: # no client identifier specified, so use the hostname hostname = os.uname()[1] - munkicommon.display_detail("No client id specified. Requesting %s..." % (manifesturl + hostname)) - manifest = getmanifest(manifesturl + hostname,suppress_errors=True) + clientidentifier = hostname + munkicommon.display_detail("No client id specified. Requesting %s..." % clientidentifier) + manifest = getmanifest(manifesturl + clientidentifier, suppress_errors=True) if not manifest: # try the short hostname - munkicommon.display_detail("Request failed. Trying %s..." % (manifesturl + hostname.split('.')[0])) - manifest = getmanifest(manifesturl + hostname.split('.')[0], suppress_errors=True) + clientidentifier = hostname.split('.')[0] + munkicommon.display_detail("Request failed. Trying %s..." % clientidentifier) + manifest = getmanifest(manifesturl + clientidentifier, suppress_errors=True) if not manifest: # last resort - try for the site_default manifest - munkicommon.display_detail("Request failed. Trying %s..." % (manifesturl + "site_default")) - manifesturl = manifesturl + "site_default" - + clientidentifier = "site_default" + munkicommon.display_detail("Request failed. Trying ..." % clientidentifier) + if not manifest: - manifest = getmanifest(manifesturl) + manifest = getmanifest(manifesturl + urllib2.quote(clientidentifier)) if manifest: + munkicommon.display_detail("Using manifest: %s" % clientidentifier) # clear out any errors we got while trying to find # the primary manifest errors = "" @@ -1592,8 +1594,8 @@ def httpDownload(url, filename, headers={}, postData=None, reporthook=None, mess pemfile = 'munki.pem' # Grab the prefs for UseClientCertificate and construct a loc for the cert, bcw - ManagedInstallDir = munkicommon.ManagedInstallDir() - UseClientCertificate = munkicommon.UseClientCertificate() + ManagedInstallDir = munkicommon.pref('ManagedInstallDir') + UseClientCertificate = munkicommon.pref('UseClientCertificate') cert = os.path.join(ManagedInstallDir, 'certs', pemfile) reqObj = urllib2.Request(url, postData, headers) @@ -1761,7 +1763,7 @@ def check(id=''): getMachineFacts() - ManagedInstallDir = munkicommon.ManagedInstallDir() + ManagedInstallDir = munkicommon.pref('ManagedInstallDir') if munkicommon.munkistatusoutput: munkistatus.activate()