mirror of
https://github.com/munki/munki.git
synced 2026-05-14 16:28:58 -05:00
Add initial implmentation of updatecheck/download; Update for new capabilites of convenience function managedInstallsDir()
This commit is contained in:
@@ -218,7 +218,7 @@ func saveAppData() {
|
||||
appInventory.append(inventoryItem)
|
||||
}
|
||||
do {
|
||||
let appInventoryPath = (managedInstallsDir() as NSString).appendingPathComponent("ApplicationInventory.plist")
|
||||
let appInventoryPath = managedInstallsDir(subpath: "ApplicationInventory.plist")
|
||||
try writePlist(appInventory, toFile: appInventoryPath)
|
||||
} catch {
|
||||
displayWarning("Unable to save application inventory: \(error.localizedDescription)")
|
||||
|
||||
@@ -77,7 +77,7 @@ func getConditions() async -> PlistDict {
|
||||
// which can be placed into /usr/local/munki/conditions
|
||||
|
||||
let conditionalScriptDir = conditionalScriptsDir()
|
||||
let conditionalItemsPath = (managedInstallsDir() as NSString).appendingPathComponent("ConditionalItems.plist")
|
||||
let conditionalItemsPath = managedInstallsDir(subpath: "ConditionalItems.plist")
|
||||
let filemanager = FileManager.default
|
||||
try? filemanager.removeItem(atPath: conditionalItemsPath)
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ func installItem(_ item: PlistDict) async -> (Int, Bool) {
|
||||
let itemName = item["name"] as? String ?? "<unknown>"
|
||||
let installerType = item["installer_type"] as? String ?? "pkg_install"
|
||||
let installerItem = item["installer_item"] as? String ?? ""
|
||||
let cachePath = (managedInstallsDir() as NSString).appendingPathComponent("Cache")
|
||||
let cachePath = managedInstallsDir(subpath: "Cache")
|
||||
let installerItemPath = (cachePath as NSString).appendingPathComponent(installerItem)
|
||||
|
||||
// if installer_type is not nopkg, ensure the payload exists
|
||||
@@ -340,7 +340,7 @@ func installWithInstallInfo(
|
||||
// with choicesXML files applied to a distribution package or
|
||||
// multiple packages being installed from a single DMG
|
||||
let installerItem = item["installer_item"] as? String ?? ""
|
||||
let cachePath = (managedInstallsDir() as NSString).appendingPathComponent("Cache")
|
||||
let cachePath = managedInstallsDir(subpath: "Cache")
|
||||
let installerItemPath = (cachePath as NSString).appendingPathComponent(installerItem)
|
||||
|
||||
var stillNeeded = false
|
||||
@@ -470,7 +470,7 @@ func uninstallItem(_ item: PlistDict) async -> (Int, Bool) {
|
||||
displayError("No uninstall item specified for \(itemName)")
|
||||
return (-99, false)
|
||||
}
|
||||
let uninstallerItemPath = (managedInstallsDir() as NSString).appendingPathComponent("Cache/" + uninstallerItem)
|
||||
let uninstallerItemPath = managedInstallsDir(subpath: "Cache/" + uninstallerItem)
|
||||
if !pathExists(uninstallerItemPath) {
|
||||
displayError("Uninstall package \(uninstallerItem) for \(itemName) was missing from the cache.")
|
||||
return (-99, false)
|
||||
@@ -600,7 +600,7 @@ func doInstallsAndRemovals(onlyUnattended: Bool = false) async -> Int {
|
||||
let caffeinator = Caffeinator(
|
||||
reason: "managedsoftwareupdate is installing software")
|
||||
|
||||
let installInfoPath = (managedInstallsDir() as NSString).appendingPathComponent("InstallInfo.plist")
|
||||
let installInfoPath = managedInstallsDir(subpath: "InstallInfo.plist")
|
||||
if pathExists(installInfoPath),
|
||||
let installInfo = try? readPlist(fromFile: installInfoPath) as? PlistDict
|
||||
{
|
||||
|
||||
@@ -494,9 +494,16 @@ func getResourceIfChangedAtomically(
|
||||
pkginfo: pkginfo
|
||||
)
|
||||
} else if resolvedURL.scheme == "file" {
|
||||
changed = try getFileIfChangedAtomically(
|
||||
resolvedURL.path, destinationPath: destinationPath
|
||||
)
|
||||
if let sourcePath = resolvedURL.path.removingPercentEncoding {
|
||||
changed = try getFileIfChangedAtomically(
|
||||
sourcePath, destinationPath: destinationPath
|
||||
)
|
||||
} else {
|
||||
throw FetchError.connection(
|
||||
errorCode: -1,
|
||||
description: "Invalid path in URL \(url)"
|
||||
)
|
||||
}
|
||||
} else {
|
||||
throw FetchError.connection(
|
||||
errorCode: -1,
|
||||
@@ -586,7 +593,7 @@ func checkServer(_ urlString: String) -> (Int, String) {
|
||||
if let host = url.host, host != "localhost" {
|
||||
return (-1, "Non-local hostnames not supported for file:// URLs")
|
||||
}
|
||||
if pathExists(url.path) {
|
||||
if let path = url.path.removingPercentEncoding, pathExists(path) {
|
||||
return (0, "OK")
|
||||
}
|
||||
return (-1, "Path \(url.path) does not exist")
|
||||
|
||||
@@ -173,9 +173,14 @@ func pref(_ prefName: String) -> Any? {
|
||||
return prefValue
|
||||
}
|
||||
|
||||
func managedInstallsDir() -> String {
|
||||
func managedInstallsDir(subpath: String?) -> String {
|
||||
// convenience function to return the path to the Managed Installs dir
|
||||
return pref("ManagedInstallDir") as? String ?? DEFAULT_MANAGED_INSTALLS_DIR
|
||||
// or a subpath of that directory
|
||||
let managedInstallsDir = pref("ManagedInstallDir") as? String ?? DEFAULT_MANAGED_INSTALLS_DIR
|
||||
if let subpath {
|
||||
return (managedInstallsDir as NSString).appendingPathComponent(subpath)
|
||||
}
|
||||
return managedInstallsDir
|
||||
}
|
||||
|
||||
struct prefsDomain {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// download.swift
|
||||
// munki
|
||||
//
|
||||
// Created by Greg Neagle on 8/15/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@@ -45,7 +45,7 @@ func removeItemFromSelfServeSection(itemname: String, section: String) {
|
||||
// Remove the given itemname from the self-serve manifest's
|
||||
// managed_uninstalls list
|
||||
displayDebug1("Removing \(itemname) from SelfServeManifest's \(section)...")
|
||||
let manifestPath = (managedInstallsDir() as NSString).appendingPathComponent("manifests/SelfServeManifest")
|
||||
let manifestPath = managedInstallsDir(subpath: "manifests/SelfServeManifest")
|
||||
if !pathExists(manifestPath) {
|
||||
displayDebug1("\(manifestPath) doesn't exist.")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user