-
Notifications
You must be signed in to change notification settings - Fork 4
/
version.go
54 lines (46 loc) · 1.43 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"encoding/json"
"github.com/onuragtas/docker-env/selfupdate"
"github.com/onuragtas/go-requests"
"log"
"os"
"os/exec"
"runtime"
"strings"
)
var version = "1.0.120"
func checkSelfUpdate() {
var lastRelease selfupdate.LastRelease
req := requests.Request{BaseUrl: "https://api.github.com/repos/onuragtas/redock/releases/latest"}
req.Get()
json.Unmarshal(req.GetBody(), &lastRelease)
var lastReleaseName = strings.Replace(lastRelease.Name, "v", "", 1)
log.Println("Current version:", version, "Latest version:", lastReleaseName)
if lastReleaseName != "" && version != lastReleaseName {
if getProcessOwner() != "root" {
log.Fatalln("Please run this command as root user.")
}
log.Println("https://github.com/onuragtas/redock/releases/latest/download/redock_"+runtime.GOOS+"_"+runtime.GOARCH, "downloading...")
var updater = &selfupdate.Updater{
CurrentVersion: version,
BinURL: "https://github.com/onuragtas/redock/releases/latest/download/redock_" + runtime.GOOS + "_" + runtime.GOARCH,
Dir: "update/",
CmdName: "/docker-env",
}
if updater != nil {
log.Println("update: started, please wait...")
updater.Update()
log.Fatalln("Update complete please run again command.")
}
}
}
func getProcessOwner() string {
stdout, err := exec.Command("whoami").Output()
if err != nil {
os.Exit(1)
}
owner := string(stdout)
owner = strings.TrimSpace(owner)
return owner
}