mirror of https://bitbucket.org/ausocean/av.git
revid/config/config.go: Validation for ShowWindows, so that windows cannot be opened on the raspberry pi.
This commit is contained in:
parent
55981f8ae9
commit
442ad27e98
|
@ -27,6 +27,8 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"bitbucket.org/ausocean/av/codec/codecutil"
|
"bitbucket.org/ausocean/av/codec/codecutil"
|
||||||
|
@ -447,9 +449,29 @@ func (c *Config) Validate() error {
|
||||||
c.PSITime = defaultPSITime
|
c.PSITime = defaultPSITime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.ShowWindows == true {
|
||||||
|
os, err := osName()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if os == "Raspbian GNU/Linux" {
|
||||||
|
c.Logger.Log(logger.Info, "ShowWindows disabled on Raspbian GNU/Linux")
|
||||||
|
c.ShowWindows = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func osName() (string, error) {
|
||||||
|
out, err := exec.Command("grep", "^NAME=", "/etc/os-release").Output()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("could not get OS name: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(out)[6 : len(out)-2], nil
|
||||||
|
}
|
||||||
|
|
||||||
// stringInSlice returns true if want is in slice.
|
// stringInSlice returns true if want is in slice.
|
||||||
func stringInSlice(want string, slice []string) bool {
|
func stringInSlice(want string, slice []string) bool {
|
||||||
for _, s := range slice {
|
for _, s := range slice {
|
||||||
|
|
Loading…
Reference in New Issue