-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathAddOptionalInstalls.py
62 lines (57 loc) · 2.31 KB
/
AddOptionalInstalls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/local/munki/munki-python
import os
import plistlib
import sys
# Apps to add to the SelfServeManifest
# Feel free to modify and put in whatever apps you actually want to install
# Go with the name (not the display_name) of the Munki item
default_apps = [ 'Firefox', 'GoogleChrome', 'VirtualBox' ]
# Location of the SelfServeManifest
self_serve_manifest = '/Library/Managed Installs/manifests/SelfServeManifest'
def main():
# Check that the SelfServeManifest exists
if os.path.isfile(self_serve_manifest):
# Try to read its current contents
try:
manifest_file = open(self_serve_manifest, 'rb')
except:
print("ERROR: Unable to open {}".format(self_serve_manifest))
sys.exit(1)
try:
manifest_contents = plistlib.load(manifest_file)
except:
print("ERROR: Unable to read contents of {}".format(self_serve_manifest))
sys.exit(1)
manifest_file.close()
# Initialize test variable
file_changed = 0
if 'managed_installs' not in manifest_contents.keys():
manifest_contents['managed_installs'] = []
for default_app in default_apps:
if default_app not in manifest_contents['managed_installs']:
# Change test variable
if file_changed == 0:
file_changed = 1
print("Adding {} to SelfServeManifest".format(default_app))
manifest_contents['managed_installs'].append(default_app)
# Try to write the contents back
if file_changed == 1:
try:
manifest_file = open(self_serve_manifest, 'wb')
except:
print("ERROR: Unable to open {}".format(self_serve_manifest))
sys.exit(1)
try:
plistlib.dump(manifest_contents, manifest_file)
except:
print("ERROR: Unable to write changes to {}".format(self_serve_manifest))
sys.exit(1)
manifest_file.close()
print("Changes written back to {}".format(self_serve_manifest))
else:
print("Nothing changed in the SelfServeManifest file")
else:
print("ERROR: {} does not exist".format(self_serve_manifest))
sys.exit(1)
if __name__ == "__main__":
main()