Created
September 30, 2016 20:06
-
-
Save bruienne/291821762ec4adece4f9ce3ff73cd18c to your computer and use it in GitHub Desktop.
Sample MDM push agent
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>KeepAlive</key> | |
<dict> | |
<key>PathState</key> | |
<dict> | |
<key>/Library/Managed Preferences/org.my.push.plist</key> | |
<true/> | |
</dict> | |
</dict> | |
<key>Label</key> | |
<string>org.my.pushagent</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/pushtool</string> | |
<string>org.my.push</string> | |
</array> | |
<key>RunAtLoad</key> | |
<false/> | |
<key>StandardErrorPath</key> | |
<string>/tmp/org.my.pushagent.stderr</string> | |
<key>StandardOutPath</key> | |
<string>/tmp/org.my.pushagent.stdout</string> | |
</dict> | |
</plist> |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>PayloadContent</key> | |
<array> | |
<dict> | |
<key>PayloadContent</key> | |
<dict> | |
<key>my.org.push</key> | |
<dict> | |
<key>Forced</key> | |
<array> | |
<dict> | |
<key>mcx_preference_settings</key> | |
<dict> | |
<key>Command</key> | |
<string>/usr/local/munki/managedsoftwareupdate -q</string> | |
<key>Schedule</key> | |
<string>now</string> | |
</dict> | |
</dict> | |
</array> | |
</dict> | |
</dict> | |
<key>PayloadEnabled</key> | |
<true/> | |
<key>PayloadIdentifier</key> | |
<string>MCXToProfile.11eb30a2-32e8-4ed2-986c-70fbfb0a1730.alacarte.customsettings.da1bab9b-2fcc-467b-bf48-9a8de3364e6f</string> | |
<key>PayloadType</key> | |
<string>com.apple.ManagedClient.preferences</string> | |
<key>PayloadUUID</key> | |
<string>da1bab9b-2fcc-467b-bf48-9a8de3364e6f</string> | |
<key>PayloadVersion</key> | |
<integer>1</integer> | |
</dict> | |
</array> | |
<key>PayloadDescription</key> | |
<string>Included custom settings: | |
my.org.push | |
Git revision: a14a19d7f0</string> | |
<key>PayloadDisplayName</key> | |
<string>MCXToProfile: my.org.push</string> | |
<key>PayloadIdentifier</key> | |
<string>my.org.push</string> | |
<key>PayloadOrganization</key> | |
<string></string> | |
<key>PayloadRemovalDisallowed</key> | |
<true/> | |
<key>PayloadScope</key> | |
<string>System</string> | |
<key>PayloadType</key> | |
<string>Configuration</string> | |
<key>PayloadUUID</key> | |
<string>11eb30a2-32e8-4ed2-986c-70fbfb0a1730</string> | |
<key>PayloadVersion</key> | |
<integer>1</integer> | |
</dict> | |
</plist> |
This file contains hidden or 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 os, sys | |
import subprocess | |
sys.path.append('/usr/local/munki/munkilib') | |
from munkicommon import FoundationPlist as plistlib | |
identifier = sys.argv[1] | |
pushpl = '/Library/Managed Preferences/%s.plist' % identifier | |
def do_cmd(pushcmd, sched): | |
'''Run command from plist''' | |
cmd = pushcmd.split() | |
print('Running command %s' % cmd) | |
proc = subprocess.Popen( | |
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
proc.communicate() | |
if proc.returncode != 0: | |
print( | |
'Command %s execution failed: %s' % (cmd, proc.stderr)) | |
return False | |
return True | |
def remove_profile(identifier): | |
'''Removes a profile with the given identifier. Returns True on success, | |
False otherwise''' | |
cmd = ['/usr/bin/profiles', '-Rp', identifier] | |
proc = subprocess.Popen( | |
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
proc.communicate() | |
if proc.returncode != 0: | |
print( | |
'Profile %s removal failed: %s' % (identifier, proc.stderr)) | |
return False | |
return True | |
if os.path.exists(pushpl): | |
pl = plistlib.readPlist(pushpl) | |
pushcmd = pl['Command'] | |
schedule = pl['Schedule'] | |
print('Using command %s and schedule %s' % (pushcmd, schedule)) | |
if do_cmd(pushcmd, schedule): | |
if remove_profile(identifier): | |
sys.exit(0) | |
else: | |
sys.exit(-1) | |
else: | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment