fix shutdown cmd args

This commit is contained in:
Maxi Quoß
2023-01-28 15:22:25 +01:00
parent 3d0ad679ee
commit 0ef4b4ac02
4 changed files with 23 additions and 9 deletions

View File

@@ -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

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged
cd frontend && npx lint-staged

View File

@@ -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=. ."
}
}

View File

@@ -346,7 +346,7 @@
<li>Windows: "net rpc shutdown -I 192.168.1.13 -U test%test"</li>
<li>
Linux: "sshpass -p your_password ssh -o 'StrictHostKeyChecking=no'
user@hostname 'sudo shutdown'"
user@hostname 'sudo poweroff'"
</li>
</ul>
<p class="m-0">