Skip to content

Instantly share code, notes, and snippets.

@bruienne
Created March 30, 2016 00:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruienne/c1b4d36220b95f20d2b6e43191738c36 to your computer and use it in GitHub Desktop.
Save bruienne/c1b4d36220b95f20d2b6e43191738c36 to your computer and use it in GitHub Desktop.
#!/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