mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 18:44:33 +00:00
40 lines
1.5 KiB
Swift
40 lines
1.5 KiB
Swift
import Foundation
|
|
|
|
enum ProleEnv {
|
|
static func proleHome() -> URL {
|
|
let env = ProcessInfo.processInfo.environment
|
|
let home = env["HOME"] ?? NSHomeDirectory()
|
|
let proleHome = env["PROLE_HOME"] ?? home
|
|
return URL(fileURLWithPath: proleHome, isDirectory: true)
|
|
}
|
|
|
|
static func logsDir() -> URL {
|
|
return proleHome().appendingPathComponent("logs", isDirectory: true)
|
|
}
|
|
|
|
static func confDir() -> URL {
|
|
return proleHome().appendingPathComponent("conf", isDirectory: true)
|
|
}
|
|
|
|
static func bootstrap() {
|
|
let fm = FileManager.default
|
|
// Ensure base, logs, conf
|
|
for dir in [proleHome(), logsDir(), confDir()] {
|
|
try? fm.createDirectory(at: dir, withIntermediateDirectories: true)
|
|
}
|
|
// Ensure conf/port-mappings.conf exists
|
|
let pm = confDir().appendingPathComponent("port-mappings.conf")
|
|
if !fm.fileExists(atPath: pm.path) {
|
|
let tpl = """
|
|
# Port mappings for Prole Tools (read by scripts).
|
|
# Format examples:
|
|
# grafana: local=3000 remote=80 ns=default svc=prometheus-community-grafana address=0.0.0.0
|
|
# db: local=5432 remote=5432 ns=default svc=prole-db-rw address=0.0.0.0
|
|
|
|
# Add your mappings below. One mapping per line as key=value tokens.
|
|
"""
|
|
try? tpl.trimmingCharacters(in: .whitespacesAndNewlines).appending("\n").write(to: pm, atomically: true, encoding: .utf8)
|
|
}
|
|
}
|
|
}
|