-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremove-1.0.py
executable file
·50 lines (45 loc) · 1.48 KB
/
remove-1.0.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
#!/usr/bin/env python3
# remove.py
# ARW 2020-06-09 Added prefs handling for either format
import sys
from os import path
import plistlib
import requests
import xml.etree.ElementTree as ET
# Which pref format to use, autopkg or jss_importer
autopkg = False
if autopkg:
plist = path.expanduser("~/Library/Preferences/com.github.autopkg.plist")
fp = open(plist, "rb")
prefs = plistlib.load(fp)
base = prefs["JSS_URL"] + "/JSSResource/"
auth = (prefs["API_USERNAME"], prefs["API_PASSWORD"])
else:
plist = path.expanduser("~/Library/Preferences/JPCImporter.plist")
fp = open(plist, "rb")
prefs = plistlib.load(fp)
base = prefs["url"] + "/JSSResource/"
auth = (prefs["user"], prefs["password"])
hdrs = {"Accept": "application/json"}
for line in sys.stdin:
print("Doing %s" % line)
parts = line.rstrip().split("\t")
url = base + "packages/id/" + parts[0]
# sanity check
ret = requests.get(url, auth=auth, headers=hdrs)
if ret.status_code != 200:
print("Failed to get %s" % line)
continue
if ret.json()["package"]["name"] != parts[1]:
print(
"Sanity 1 fail %s %s %s" % (line, ret.json()["package"]["name"], parts[1])
)
continue
ret = requests.delete(url, auth=auth)
if ret.status_code != 200:
print("Failed to delete %s" % line)
continue
root = ET.fromstring(ret.text)
if root.findtext("id") == parts[1]:
print("Failed delete sanity %s" % line)
continue