Skip to content

Commit

Permalink
Merge pull request #101 from salopensource/pending_from_prefs
Browse files Browse the repository at this point in the history
Read pending updates from the cache preference if present
  • Loading branch information
grahamgilbert authored Jan 20, 2023
2 parents 266b64b + 91f8af7 commit 8fc7d8b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
11 changes: 8 additions & 3 deletions luggage/luggage.make
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,22 @@ ${PACKAGE_PLIST}: ${PLIST_PATH}

define PYTHON_PLISTER
import plistlib
component = plistlib.readPlist('${SCRATCH_D}/luggage.pkg.component.plist')
file_name = '${SCRATCH_D}/luggage.pkg.component.plist'
with open(file_name, 'rb') as infile:
component = plistlib.load(infile)

for payload in component:
if payload.get('BundleIsRelocatable'):
payload['BundleIsRelocatable'] = False
plistlib.writePlist(component, '${SCRATCH_D}/luggage.pkg.component.plist')

with open(file_name, 'wb') as outfile:
plistlib.dump(component, outfile)
endef

export PYTHON_PLISTER

kill_relocate:
@-sudo /usr/bin/python -c "$${PYTHON_PLISTER}"
@-sudo python3 -c "$${PYTHON_PLISTER}"

# Target directory rules

Expand Down
41 changes: 40 additions & 1 deletion payload/usr/local/sal/checkin_modules/apple_sus_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import datetime
import os
import pathlib
import platform
import plistlib
Expand All @@ -12,7 +13,7 @@
import sal


__version__ = "1.1.0"
__version__ = "1.2.0"


def main():
Expand Down Expand Up @@ -105,6 +106,11 @@ def _get_log_time(line):


def get_pending():
if os.path.exists("/Library/Preferences/com.apple.SoftwareUpdate.plist"):
pending_items = get_pending_updates_from_preferences()
if pending_items != None:
return pending_items

pending_items = {}
cmd = ["softwareupdate", "-l", "--no-scan"]
try:
Expand Down Expand Up @@ -174,12 +180,45 @@ def get_pending():
if "recommended" in m.group("recommended")
else "FALSE",
"action": _bracket_cleanup(m, "action"),
"type": "Apple SUS Install",
},
}
for m in rexp.finditer(output)
}


def get_pending_updates_from_preferences():
pending = {}
try:
pref = plistlib.loads(
pathlib.Path(
"/Library/Preferences/com.apple.SoftwareUpdate.plist"
).read_bytes()
)
except (IOError, plistlib.InvalidFileException):
return None

recommended_updates = pref.get("RecommendedUpdates", None)
if not recommended_updates:
return pending

# Convert local time to UTC time represented as a ISO 8601 str.
now = datetime.datetime.now().astimezone(datetime.timezone.utc).isoformat()
for update in recommended_updates:
name = update.get("Display Name")
version = update.get("Display Version")
item = {}
item["date_managed"] = now
item["status"] = "PENDING"
item["data"] = {
"version": version,
"recommended": "TRUE",
"type": "Apple SUS Install",
}
pending[name] = item
return pending


def _bracket_cleanup(match, key):
"""Strip out [ and ] and uppercase SUS output"""
return re.sub(r"[\[\]]", "", match.group(key) or "").upper()
Expand Down
4 changes: 3 additions & 1 deletion payload/usr/local/sal/checkin_modules/machine_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def get_friendly_model(serial, udid):
data[0]
.get("product-name")
.decode("ascii", "ignore")
.strip().strip('\x00').strip()
.strip()
.strip("\x00")
.strip()
)
except:
pass
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sal_python_pkg/
pyobjc==7.2
pyobjc==8.5
#urllib3==1.26.5
requests==2.26.0
MacSesh==0.3.0
Expand Down
2 changes: 1 addition & 1 deletion sal_python_pkg/sal/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.2.1"
__version__ = "4.3.0"

0 comments on commit 8fc7d8b

Please sign in to comment.