nextcloud-desktop/admin/osx/mac-crafter/Sources/Utils/Install.swift
Andy Scherzinger 00994aa9e8
docs(reuse): Migrate to SPDX header
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
2025-04-16 15:19:26 +02:00

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.")
}
}