Created
March 9, 2012 01:19
-
-
Save treydock/2004467 to your computer and use it in GitHub Desktop.
Preflight for Munki using Munkiserver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import os | |
import subprocess | |
from munkilib import fetch | |
from munkilib import FoundationPlist | |
#Dynamic Config Munki Preflight Script by John Rozewicki | |
#2010-12-08 | |
# | |
#Script merges config from Munki repo into local config if newer. | |
RepoURL = "CHANGE ME" | |
ConfigName = "ManagedInstalls.plist" | |
ServerConfigName = "ManagedMunkiServer.plist" | |
ConfigDir = "/Library/Preferences" | |
ConfigPath = os.path.join(ConfigDir, ConfigName) | |
ServerConfigURL = os.path.join(RepoURL, ServerConfigName) | |
ServerConfigPath = os.path.join(ConfigDir, ServerConfigName) | |
mac = subprocess.Popen(['ifconfig en0 | awk \'/ether/ {print $2}\''], shell=True, stdout=subprocess.PIPE) | |
munkiIdKey="ClientIdentifier" | |
def readToPlist(): | |
ToPlistData = FoundationPlist.readPlist(ConfigPath) | |
return ToPlistData | |
def MergePlists(FromPlist, ToPlist): | |
FromPlistData = FoundationPlist.readPlist(FromPlist) | |
ToPlistData = readToPlist() | |
for item in FromPlistData: | |
ToPlistData[item] = FromPlistData[item] | |
FoundationPlist.writePlist(ToPlistData, ToPlist) | |
def checkClientIdentifier(ToPlist,key): | |
ToPlistData = readToPlist() | |
currentId = ToPlistData[key] | |
mac_address = mac.communicate()[0].replace('\n', '') | |
correctId = mac_address + '.plist' | |
if currentId != correctId: | |
print " Updating ClientIdentifier to: %s" % munkiIdKey | |
ToPlistData[munkiIdKey] = correctId | |
FoundationPlist.writePlist(ToPlistData, ToPlist) | |
if (sys.argv[1] != "logoutinstall") and (sys.argv[1] != "installwithnologout"): | |
print "Checking for new %s" % (ServerConfigName) | |
if fetch.getResourceIfChangedAtomically(ServerConfigURL, ServerConfigPath): | |
print " Merging new server settings into configuration." | |
MergePlists(ServerConfigPath, ConfigPath) | |
checkClientIdentifier(ConfigPath, munkiIdKey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment