Skip to content

Commit

Permalink
Only attempt to download the required security update
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Dec 17, 2021
1 parent 91576ce commit 7b0d2e7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Nudge/Utilities/SoftwareUpdate.swift
Expand Up @@ -86,7 +86,7 @@ class SoftwareUpdate {
do {
try task.run()
} catch {
let msg = "Error downloading software updates"
let msg = "Error downloading software update"
softwareupdateListLog.error("\(msg, privacy: .public)")
}

Expand All @@ -99,7 +99,7 @@ class SoftwareUpdate {
let _ = String(decoding: errorData, as: UTF8.self)

if task.terminationStatus != 0 {
softwareupdateDownloadLog.error("Error downloading software updates: \(output, privacy: .public)")
softwareupdateDownloadLog.error("Error downloading software update: \(output, privacy: .public)")
} else {
let msg = "softwareupdate successfully downloaded available update application - updating application paths"
softwareupdateListLog.notice("\(msg, privacy: .public)")
Expand All @@ -114,13 +114,18 @@ class SoftwareUpdate {
}
} else {
let softwareupdateList = self.List()
var updateLabel = ""
for update in softwareupdateList.components(separatedBy: "\n") {
if update.contains("Label:") {
updateLabel = update.components(separatedBy: ": ")[1]
}
}

if softwareupdateList.contains("restart") {
let msg = "softwareupdate found available updates requiring a restart - attempting download"
softwareupdateListLog.notice("\(msg, privacy: .public)")
if softwareupdateList.contains(requiredMinimumOSVersionNormalized) && updateLabel.isEmpty == false {
softwareupdateListLog.notice("softwareupdate found \(updateLabel, privacy: .public) available for download - attempting download")
let task = Process()
task.launchPath = "/usr/sbin/softwareupdate"
task.arguments = ["--download", "--all"]
task.arguments = ["--download", "\(updateLabel)"]

let outputPipe = Pipe()
let errorPipe = Pipe()
Expand All @@ -131,7 +136,7 @@ class SoftwareUpdate {
do {
try task.run()
} catch {
let msg = "Error downloading software updates"
let msg = "Error downloading software update"
softwareupdateListLog.error("\(msg, privacy: .public)")
}

Expand All @@ -146,13 +151,12 @@ class SoftwareUpdate {
if task.terminationStatus != 0 {
softwareupdateDownloadLog.error("Error downloading software updates: \(error, privacy: .public)")
} else {
let msg = "softwareupdate successfully downloaded available updates"
let msg = "softwareupdate successfully downloaded available update"
softwareupdateListLog.notice("\(msg, privacy: .public)")
softwareupdateDownloadLog.info("\(output, privacy: .public)")
}
} else {
let msg = "softwareupdate did not find any available updates requiring a restart - skipping download"
softwareupdateListLog.notice("\(msg, privacy: .public)")
softwareupdateListLog.notice("softwareupdate did not find \(requiredMinimumOSVersionNormalized, privacy: .public) available for download - skipping download attempt")
}
}
}
Expand Down

0 comments on commit 7b0d2e7

Please sign in to comment.