2018-08-31 13:16:11 +00:00
|
|
|
#!/usr/bin/swift
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2021-12-31 13:23:45 +03:00
|
|
|
struct SwiftErr: TextOutputStream {
|
|
|
|
public static var stream = SwiftErr()
|
2022-05-30 14:59:14 +01:00
|
|
|
|
2021-12-31 13:23:45 +03:00
|
|
|
mutating func write(_ string: String) {
|
|
|
|
fputs(string, stderr)
|
|
|
|
}
|
2018-08-31 13:16:11 +00:00
|
|
|
}
|
|
|
|
|
2021-12-31 13:23:45 +03:00
|
|
|
// TODO: tell which arguments have to be provided
|
|
|
|
guard CommandLine.arguments.count >= 4 else {
|
|
|
|
exit(2)
|
|
|
|
}
|
2018-09-04 21:11:29 +00:00
|
|
|
|
2021-12-31 13:23:45 +03:00
|
|
|
var dataLocationURL = URL(fileURLWithPath: CommandLine.arguments[1])
|
|
|
|
|
|
|
|
let quarantineProperties: [String: Any] = [
|
2018-09-04 21:11:29 +00:00
|
|
|
kLSQuarantineAgentNameKey as String: "Homebrew Cask",
|
|
|
|
kLSQuarantineTypeKey as String: kLSQuarantineTypeWebDownload,
|
|
|
|
kLSQuarantineDataURLKey as String: CommandLine.arguments[2],
|
|
|
|
kLSQuarantineOriginURLKey as String: CommandLine.arguments[3]
|
2021-12-31 13:23:45 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
// Check for if the data location URL is reachable
|
|
|
|
do {
|
|
|
|
let isDataLocationURLReachable = try dataLocationURL.checkResourceIsReachable()
|
|
|
|
guard isDataLocationURLReachable else {
|
|
|
|
print("URL \(dataLocationURL.path) is not reachable. Not proceeding.", to: &SwiftErr.stream)
|
|
|
|
exit(1)
|
2018-09-04 21:11:29 +00:00
|
|
|
}
|
2021-12-31 13:23:45 +03:00
|
|
|
} catch {
|
|
|
|
print(error.localizedDescription, to: &SwiftErr.stream)
|
|
|
|
exit(1)
|
2018-08-31 13:16:11 +00:00
|
|
|
}
|
2021-12-31 13:23:45 +03:00
|
|
|
|
|
|
|
// Quarantine the file
|
|
|
|
do {
|
|
|
|
var resourceValues = URLResourceValues()
|
|
|
|
resourceValues.quarantineProperties = quarantineProperties
|
|
|
|
try dataLocationURL.setResourceValues(resourceValues)
|
|
|
|
} catch {
|
|
|
|
print(error.localizedDescription, to: &SwiftErr.stream)
|
|
|
|
exit(1)
|
2018-08-31 13:16:11 +00:00
|
|
|
}
|