From 3931840e3525bc0291e2ef1e2e27cfc294d9c948 Mon Sep 17 00:00:00 2001 From: Greg Neagle Date: Fri, 6 Sep 2024 15:34:23 -0700 Subject: [PATCH] Implement still more of managedsoftwareupdate --- .../managedsoftwareupdate.swift | 76 ++++++++++++++----- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/code/cli/munki/managedsoftwareupdate/managedsoftwareupdate.swift b/code/cli/munki/managedsoftwareupdate/managedsoftwareupdate.swift index 39ee43f3..c7c69f38 100644 --- a/code/cli/munki/managedsoftwareupdate/managedsoftwareupdate.swift +++ b/code/cli/munki/managedsoftwareupdate/managedsoftwareupdate.swift @@ -90,24 +90,19 @@ struct ManagedSoftwareUpdate: AsyncParsableCommand { print("NOTE: managedsoftwareupdate is configured to process Apple Software Updates only.") } - var updateCheckResult: UpdateCheckResult? = nil - if !skipMunkiCheck { - do { - updateCheckResult = try await checkForUpdates( - clientID: configOptions.id - ) - } catch { - displayError("Error during updatecheck: \(error.localizedDescription)") - Report.shared.save() - throw ExitCode(-1) // TODO: better exit code - } - } - if let updateCheckResult { - recordUpdateCheckResult(updateCheckResult) - } + let updateCheckResult = try await doMunkiUpdateCheck(skipCheck: skipMunkiCheck) + let appleUpdatesAvailable = doAppleUpdateCheckIfAppropriate( + appleUpdatesOnly: appleupdatesonly) - let updatesAvailable = munkiUpdatesAvailable() - var appleUpdatesAvailable = 0 + // display any available update info + if updateCheckResult == .updatesAvailable { + displayUpdateInfo() + } + if let stagedOSInstallerInfo = getStagedOSInstallerInfo() { + displayStagedOSInstallerInfo(info: stagedOSInstallerInfo) + } else if appleUpdatesAvailable > 0 { + // TODO: displayAppleUpdateInfo() + } } private func handleConfigOptions() throws { @@ -306,4 +301,51 @@ struct ManagedSoftwareUpdate: AsyncParsableCommand { munkiStatusQuit() throw ExitCode(EXIT_STATUS_PREFLIGHT_FAILURE) } + + private func doMunkiUpdateCheck(skipCheck: Bool) async throws -> UpdateCheckResult? { + if !skipCheck { + do { + let updateCheckResult = try await checkForUpdates( + clientID: configOptions.id + ) + recordUpdateCheckResult(updateCheckResult) + return updateCheckResult + } catch { + displayError("Error during updatecheck: \(error.localizedDescription)") + Report.shared.save() + throw ExitCode(-1) // TODO: better exit code + } + } + return nil + } + + private func shouldDoAppleUpdates(appleUpdatesOnly: Bool) -> Bool { + if appleUpdatesOnly { + // admin told us to do them + return true + } else if commonOptions.munkiPkgsOnly { + // admin told us not to do apple updates + return false + } else if munkiUpdatesContainAppleItems() { + // shouldn't do apple updates + munkiLog("Skipping Apple Software Updates because items to be installed from the Munki repo contain Apple items.") + // if there are force_install_after_date items in a pre-existing + // AppleUpdates.plist this means we are blocking those updates. + // we need to delete AppleUpdates.plist so that other code doesn't + // mistakenly alert for forced installs it isn't actually going to + // install. + // TODO: appleupdates.clearAppleUpdateInfo() + return false + } + // check the normal preferences + return boolPref("InstallAppleSoftwareUpdates") ?? false + } + + private func doAppleUpdateCheckIfAppropriate(appleUpdatesOnly: Bool) -> Int { + // TODO: implment this + if shouldDoAppleUpdates(appleUpdatesOnly: appleUpdatesOnly) { + return 0 + } + return 0 + } }