Skip to content

Commit

Permalink
support for BSD and darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
charliemaiors committed Jun 26, 2023
1 parent a7ce11b commit c40a475
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions server/solserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Result struct {
const (
baseLinux = "systemctl"
baseWindows = "shutdown -f"
baseDarwin = "shutdown"
baseBSD = "shutdown"
)

var (
Expand All @@ -35,6 +37,16 @@ func init() {
case "linux":
fmt.Println("###############\nPlease be sure that this script has sudo priviledges in order to run commands from this script\n################")
shutdownFunc = shutdownLinux
case "darwin":
fmt.Println("###############\nPlease be sure that this script has sudo priviledges in order to run commands from this script\n################")
shutdownFunc = shutdownDarwin
case "freebsd":
case "openbsd":
case "netbsd":
case "dragonfly":
case "illumos":
fmt.Println("###############\nPlease be sure that this script has sudo priviledges in order to run commands from this script\n################")
shutdownFunc = shutdownBSD
default:
panic("Your os is not yet supported")
}
Expand Down Expand Up @@ -109,3 +121,33 @@ func shutdownWindows(command string) error {
}
return nil
}

func shutdownDarwin(command string) error {
var commandEx *exec.Cmd
switch command {
case "suspend":
commandEx = exec.Command(baseDarwin, "-s")
case "hibernate":
return errors.New("Hibernate is not supported on Darwin")
case "reboot":
commandEx = exec.Command(baseDarwin, "-r now")
case "poweroff":
commandEx = exec.Command(baseDarwin, "-h now")
}
return commandEx.Run()
}

func shutdownBSD(command string) error {
var commandEx *exec.Cmd
switch command {
case "suspend":
commandEx = exec.Command(baseBSD, "-s")
case "hibernate":
return errors.New("Hibernate is not supported on Darwin")
case "reboot":
commandEx = exec.Command(baseBSD, "-r")
case "poweroff":
commandEx = exec.Command(baseBSD, "-h")
}
return commandEx.Run()
}

0 comments on commit c40a475

Please # to comment.