diff --git a/backend/networking/shutdown.go b/backend/networking/shutdown.go index d238b966..b98fce57 100644 --- a/backend/networking/shutdown.go +++ b/backend/networking/shutdown.go @@ -2,7 +2,9 @@ package networking import ( "errors" + "fmt" "os/exec" + "runtime" "time" "github.com/pocketbase/pocketbase/models" @@ -10,11 +12,23 @@ import ( func ShutdownDevice(device *models.Record) error { shutdown_cmd := device.GetString("shutdown_cmd") - if shutdown_cmd != "" { - cmd := exec.Command(shutdown_cmd) - if err := cmd.Run(); err != nil { - return err - } + if shutdown_cmd == "" { + return fmt.Errorf("%s: no shutdown_cmd definded", device.GetString("name")) + } + + var shell string + var shell_arg string + if runtime.GOOS == "windows" { + shell = "cmd" + shell_arg = "/C" + } else { + shell = "/bin/sh" + shell_arg = "-c" + } + + cmd := exec.Command(shell, shell_arg, shutdown_cmd) + if err := cmd.Run(); err != nil { + return err } // check state every second for 2 min diff --git a/frontend/.husky/pre-commit b/frontend/.husky/pre-commit index d24fdfc6..3712cb79 100755 --- a/frontend/.husky/pre-commit +++ b/frontend/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx lint-staged +cd frontend && npx lint-staged diff --git a/frontend/package.json b/frontend/package.json index 0e130c26..574d20e7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -38,7 +38,7 @@ "svelte-fa": "^3.0.3" }, "lint-staged": { - "*.{js,svelte}": "eslint --fix --ignore-path .gitignore frontend/", - "*.{js,css,md,svelte,scss}": "prettier --write --ignore-path .gitignore --plugin-search-dir=frontend/ frontend/" + "*.{js,svelte}": "eslint --fix --ignore-path ../.gitignore .", + "*.{js,css,md,svelte,scss}": "prettier --write --ignore-path ../.gitignore --plugin-search-dir=. ." } } diff --git a/frontend/src/components/DeviceForm.svelte b/frontend/src/components/DeviceForm.svelte index 1038f7ad..73fbbd63 100644 --- a/frontend/src/components/DeviceForm.svelte +++ b/frontend/src/components/DeviceForm.svelte @@ -346,7 +346,7 @@