mirror of
https://github.com/munki/munki.git
synced 2026-05-22 22:28:38 -05:00
Implement parsing of installer-environment key=value pairs
This commit is contained in:
@@ -169,6 +169,23 @@ struct ApplePackageOptions: ParsableArguments {
|
||||
help: ArgumentHelp("Specifies a key/value pair to set environment variables for use by /usr/sbin/installer. A key/value pair of USER=CURRENT_CONSOLE_USER indicates that USER be set to the GUI user, otherwise root. Can be specified multiple times.", valueName: "key=value")
|
||||
)
|
||||
var installerEnvironment = [String]()
|
||||
|
||||
var installerEnvironmentDict: [String: String] {
|
||||
var dict = [String: String]()
|
||||
for line in installerEnvironment {
|
||||
let parts = line.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
|
||||
if parts.count == 2 {
|
||||
dict[String(parts[0])] = String(parts[1])
|
||||
}
|
||||
}
|
||||
return dict
|
||||
}
|
||||
|
||||
mutating func validate() throws {
|
||||
if !installerEnvironment.isEmpty, installerEnvironmentDict.isEmpty {
|
||||
throw ValidationError("'installer-environment' values must take the form of 'key=value")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct UnattendedInstallOptions: ParsableArguments {
|
||||
|
||||
@@ -522,8 +522,7 @@ func makepkginfo(_ filepath: String?,
|
||||
pkginfo["uninstallable"] = true
|
||||
}
|
||||
if !options.pkg.installerEnvironment.isEmpty {
|
||||
// TODO: actually support installer_environment correctly
|
||||
pkginfo["installer_environment"] = options.pkg.installerEnvironment
|
||||
pkginfo["installer_environment"] = options.pkg.installerEnvironmentDict
|
||||
}
|
||||
if let notes = options.other.notes {
|
||||
pkginfo["notes"] = readFileOrString(notes)
|
||||
|
||||
Reference in New Issue
Block a user