mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-08-01 09:58:42 -04:00
fix shutdown cmd args
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npx lint-staged
|
||||
cd frontend && npx lint-staged
|
||||
|
||||
@@ -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=. ."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user