mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
27 lines
693 B
Swift
27 lines
693 B
Swift
/*
|
|
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
import Foundation
|
|
|
|
enum InstallError: Error {
|
|
case failedToInstall(String)
|
|
}
|
|
|
|
func installIfMissing(
|
|
_ command: String,
|
|
_ installCommand: String,
|
|
installCommandEnv: [String: String]? = nil
|
|
) throws {
|
|
if commandExists(command) {
|
|
print("\(command) is installed.")
|
|
} else {
|
|
print("\(command) is missing. Installing...")
|
|
guard shell(installCommand, env: installCommandEnv) == 0 else {
|
|
throw InstallError.failedToInstall("Failed to install \(command).")
|
|
}
|
|
print("\(command) installed.")
|
|
}
|
|
}
|