-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add reshctl status and reshctl update
- Loading branch information
Showing
10 changed files
with
192 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/curusarn/resh/cmd/control/status" | ||
"github.com/curusarn/resh/pkg/msg" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var statusCmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "show RESH status (aka systemctl status)", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("resh " + version) | ||
fmt.Println() | ||
fmt.Println("Resh versions ...") | ||
fmt.Println(" * installed: " + version + " (" + commit + ")") | ||
resp, err := getDaemonStatus(config.Port) | ||
if err != nil { | ||
fmt.Println(" * daemon: NOT RUNNING!") | ||
} else { | ||
fmt.Println(" * daemon: " + resp.Version + " (" + resp.Commit + ")") | ||
} | ||
versionEnv, found := os.LookupEnv("__RESH_VERSION") | ||
if found == false { | ||
versionEnv = "UNKNOWN!" | ||
} | ||
commitEnv, found := os.LookupEnv("__RESH_REVISION") | ||
if found == false { | ||
commitEnv = "unknown" | ||
} | ||
fmt.Println(" * this session: " + versionEnv + " (" + commitEnv + ")") | ||
if version != resp.Version || version != versionEnv { | ||
fmt.Println(" * THERE IS A MISMATCH BETWEEN VERSIONS!") | ||
fmt.Println(" * Please REPORT this here: https://github.com/curusarn/resh/issues") | ||
fmt.Println(" * Please RESTART this terminal window") | ||
} | ||
|
||
fmt.Println() | ||
fmt.Println("Arrow key bindnigs ...") | ||
if config.BindArrowKeysBash { | ||
fmt.Println(" * bash future sessions: ENABLED (not recommended)") | ||
} else { | ||
fmt.Println(" * bash future sessions: DISABLED (recommended)") | ||
} | ||
if config.BindArrowKeysZsh { | ||
fmt.Println(" * zsh future sessions: ENABLED (recommended)") | ||
} else { | ||
fmt.Println(" * zsh future sessions: DISABLED (not recommended)") | ||
} | ||
exitCode = status.ReshStatus | ||
}, | ||
} | ||
|
||
func getDaemonStatus(port int) (msg.StatusResponse, error) { | ||
mess := msg.StatusResponse{} | ||
url := "http://localhost:" + strconv.Itoa(port) + "/status" | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
log.Println("Daemon is not running!", err) | ||
return mess, err | ||
} | ||
defer resp.Body.Close() | ||
jsn, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal("Error while reading 'daemon /status' response:", err) | ||
} | ||
err = json.Unmarshal(jsn, &mess) | ||
if err != nil { | ||
log.Fatal("Error while decoding 'daemon /status' response:", err) | ||
} | ||
return mess, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/curusarn/resh/cmd/control/status" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var updateCmd = &cobra.Command{ | ||
Use: "update", | ||
Short: "checks for updates and updates RESH", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
url := "https://raw.githubusercontent.com/curusarn/resh/master/scripts/rawinstall.sh" | ||
execCmd := exec.Command("bash", "-c", "curl -fsSL "+url+" | bash") | ||
execCmd.Stdout = os.Stdout | ||
execCmd.Stderr = os.Stderr | ||
err := execCmd.Run() | ||
if err == nil { | ||
exitCode = status.Success | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters