This commit is contained in:
@@ -1,33 +1,43 @@
|
||||
import { exec } from "child_process"
|
||||
|
||||
type DiskSource = {
|
||||
key: string
|
||||
key: "remote" | "local"
|
||||
label: string
|
||||
command: string
|
||||
args?: string[]
|
||||
}
|
||||
|
||||
const diskSources: DiskSource[] = [
|
||||
{
|
||||
key: "remote",
|
||||
label: "Serveur distant",
|
||||
command: "ssh",
|
||||
args: []
|
||||
label: "Serveur distant"
|
||||
},
|
||||
{
|
||||
key: "local",
|
||||
label: "Machine locale",
|
||||
command: "bash",
|
||||
args: []
|
||||
label: "Machine locale"
|
||||
}
|
||||
]
|
||||
|
||||
function getDefaultCommand(source: DiskSource) {
|
||||
const localScriptDir = process.env.DISK_LOCAL_SCRIPT_DIR || "/home/malio/Malio-ops/CheckStorage"
|
||||
const remoteHost = process.env.DISK_REMOTE_HOST || "malio-b"
|
||||
const remoteScriptDir = process.env.DISK_REMOTE_SCRIPT_DIR || "/home/malio-b/Malio-ops/CheckStorage"
|
||||
|
||||
if (source.key === "local") {
|
||||
return `cd ${localScriptDir} && bash check-storage.sh`
|
||||
}
|
||||
|
||||
return `ssh ${remoteHost} "cd ${remoteScriptDir} && ./check-storage.sh"`
|
||||
}
|
||||
|
||||
function getEnvCommand(source: DiskSource) {
|
||||
const envKey = `DISK_COMMAND_${source.key.toUpperCase()}`
|
||||
const legacyEnvKey =
|
||||
source.key === "remote" ? "DISK_REMOTE_COMMAND" : source.key === "local" ? "DISK_LOCAL_COMMAND" : ""
|
||||
|
||||
return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || null
|
||||
return (
|
||||
process.env[envKey] ||
|
||||
(legacyEnvKey ? process.env[legacyEnvKey] : undefined) ||
|
||||
getDefaultCommand(source)
|
||||
)
|
||||
}
|
||||
|
||||
function runShellCommand(command: string): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user