Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #35 from trueos/chore_exit
Browse files Browse the repository at this point in the history
CHORE: Allow WS client to quit sysup
  • Loading branch information
kmoore134 authored May 8, 2019
2 parents 90d9dff + 67d58a2 commit ac7e449
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/signal"
"os/user"
"strconv"
"strings"
"time"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -124,6 +125,15 @@ func readws(w http.ResponseWriter, r *http.Request) {
log.Println("Warning: Invalid JSON message received")
log.Println(err)
}

// We don't care about casing
env.Method = strings.ToLower(env.Method)

// A few ways to say die
if env.Method == "quit" || env.Method == "exit" {
env.Method = "shutdown"
}

switch env.Method {
case "check":
pkg.CheckForUpdates()
Expand All @@ -136,6 +146,9 @@ func readws(w http.ResponseWriter, r *http.Request) {
case "updatebootloader":
update.UpdateLoader("")
ws.SendMsg("Finished bootloader process", "updatebootloader")
case "shutdown":
ws.SendMsg("Shutting down sysup", "shutdown")
os.Exit(0)
default:
log.Println("Uknown JSON Method:", env.Method)
}
Expand Down

0 comments on commit ac7e449

Please sign in to comment.