Merge pull request #8 from curusarn/dev

version and revision checking
pull/15/head
Šimon Let 7 years ago committed by GitHub
commit fee9700de0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      Makefile
  2. 39
      collect/resh-collect.go
  3. 5
      common/resh-common.go
  4. 9
      daemon/resh-daemon.go
  5. 7
      shellrc.sh
  6. 1
      version

@ -1,5 +1,7 @@
SHELL=/bin/bash
VERSION=$(shell cat version)
REVISION=$(shell [ -z "$(git status --untracked-files=no --porcelain)" ] && git rev-parse --short=12 HEAD || echo "no_revision")
GOFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Revision=${REVISION}"
autoinstall:
./install_helper.sh
@ -39,7 +41,7 @@ install: build | $(HOME)/.resh $(HOME)/.resh/bin $(HOME)/.config $(HOME)/.resh/r
##########################################################
#
# WHAT'S NEXT
# Please close all open terminal windows (or reload your rc files)
# Please RESTART ALL OPEN TERMINAL WINDOWS (or reload your rc files)
# Your resh history is located in `~/.resh_history.json`
# You can look at it using e.g. `tail -f ~/.resh_history.json | jq`
#
@ -54,10 +56,10 @@ uninstall:
-rm -rf ~/.resh/
resh-daemon: daemon/resh-daemon.go common/resh-common.go
go build -o $@ $<
go build ${GOFLAGS} -o $@ $<
resh-collect: collect/resh-collect.go common/resh-common.go
go build -o $@ $<
go build ${GOFLAGS} -o $@ $<
$(HOME)/.resh $(HOME)/.resh/bin $(HOME)/.config:

@ -4,12 +4,13 @@ import (
"bytes"
"encoding/json"
"flag"
"fmt"
"github.com/BurntSushi/toml"
common "github.com/curusarn/resh/common"
"io/ioutil"
"log"
"net/http"
// "os"
"os"
// "os/exec"
"os/user"
"path/filepath"
@ -17,6 +18,9 @@ import (
"strings"
)
var Version string
var Revision string
func main() {
usr, _ := user.Current()
dir := usr.HomeDir
@ -29,6 +33,11 @@ func main() {
if _, err := toml.DecodeFile(configPath, &config); err != nil {
log.Fatal("Error reading config:", err)
}
showVersion := flag.Bool("version", false, "Show version and exit")
showRevision := flag.Bool("revision", false, "Show git revision and exit")
requireVersion := flag.String("requireVersion", "", "abort if version doesn't match")
requireRevision := flag.String("requireRevision", "", "abort if revision doesn't match")
cmdLine := flag.String("cmdLine", "", "command line")
exitCode := flag.Int("exitCode", -1, "exit code")
@ -84,6 +93,28 @@ func main() {
"on session start $EPOCHREALTIME")
flag.Parse()
if *showVersion == true {
fmt.Println(Version)
os.Exit(0)
}
if *showRevision == true {
fmt.Println(Revision)
os.Exit(0)
}
if *requireVersion != "" && *requireVersion != Version {
fmt.Println("Please restart/reload this terminal session " +
"(resh version: " + Version +
" resh version of this terminal session: " + *requireVersion +
")")
os.Exit(3)
}
if *requireRevision != "" && *requireRevision != Revision {
fmt.Println("Please restart/reload this terminal session " +
"(resh revision: " + Revision +
" resh revision of this terminal session: " + *requireRevision +
")")
os.Exit(3)
}
realtimeAfter, err := strconv.ParseFloat(*rta, 64)
if err != nil {
log.Fatal("Flag Parsing error (rta):", err)
@ -185,13 +216,16 @@ func main() {
GitRealDir: gitRealDir,
GitOriginRemote: *gitRemote,
MachineId: readFileContent(machineIdPath),
ReshUuid: readFileContent(reshUuidPath),
OsReleaseId: *osReleaseId,
OsReleaseVersionId: *osReleaseVersionId,
OsReleaseIdLike: *osReleaseIdLike,
OsReleaseName: *osReleaseName,
OsReleasePrettyName: *osReleasePrettyName,
ReshUuid: readFileContent(reshUuidPath),
ReshVersion: Version,
ReshRevision: Revision,
}
sendRecord(rec, strconv.Itoa(config.Port))
}
@ -293,3 +327,4 @@ func getTimezoneOffsetInSeconds(zone string) float64 {
// }
// return strings.TrimSuffix(string(out), "\n")
// }
// }

@ -50,13 +50,16 @@ type Record struct {
GitRealDir string `json:"gitRealDir"`
GitOriginRemote string `json:"gitOriginRemote"`
MachineId string `json:"machineId"`
ReshUuid string `json:"reshUuid"`
OsReleaseId string `json:"osReleaseId"`
OsReleaseVersionId string `json:"osReleaseVersionId"`
OsReleaseIdLike string `json:"osReleaseIdLike"`
OsReleaseName string `json:"osReleaseName"`
OsReleasePrettyName string `json:"osReleasePrettyName"`
ReshUuid string `json:"reshUuid"`
ReshVersion string `json:"reshVersion"`
ReshRevision string `json:"reshRevision"`
}
type Config struct {

@ -16,7 +16,13 @@ import (
"strings"
)
var Version string
var Revision string
func main() {
log.Println("Daemon starting... \n" +
"version: " + Version +
" revision: " + Revision)
usr, _ := user.Current()
dir := usr.HomeDir
pidfilePath := filepath.Join(dir, ".resh/resh.pid")
@ -67,7 +73,8 @@ func main() {
}
func statusHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK\n"))
w.Write([]byte("OK; version: " + Version +
"; revision: " + Revision + "\n"))
log.Println("Status OK")
}

@ -96,6 +96,9 @@ elif [ $__RESH_MACOS -eq 1 ]; then
__RESH_RT_SESS_SINCE_BOOT=$(sysctl -n kern.boottime | awk '{print $4}' | sed 's/,//g')
fi
__RESH_VERSION=$(resh-collect -version)
__RESH_REVISION=$(resh-collect -revision)
__resh_run_daemon
__resh_preexec() {
@ -149,7 +152,9 @@ __resh_precmd() {
__RESH_TZ_AFTER=$(date +%z)
__RESH_PWD_AFTER="$PWD"
if [ -n "${__RESH_COLLECT}" ]; then
resh-collect -cmdLine "$__RESH_CMDLINE" \
resh-collect -requireVersion "$__RESH_VERSION" \
-requireRevision "$__RESH_REVISION" \
-cmdLine "$__RESH_CMDLINE" \
-exitCode "$__RESH_EXIT_CODE" \
-shell "$__RESH_SHELL" \
-uname "$__RESH_UNAME" \

@ -0,0 +1 @@
1.0.0
Loading…
Cancel
Save