Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Commit

Permalink
Only perform auto ugprades on dig
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed Dec 9, 2013
1 parent 24556e3 commit b79be25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 28 additions & 0 deletions cmd/mole/cmd-dig.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"code.google.com/p/go.net/proxy"
"github.com/calmh/mole/ansi"
"github.com/calmh/mole/conf"
"github.com/calmh/mole/upgrade"
)

func init() {
Expand Down Expand Up @@ -111,6 +112,8 @@ func commandDig(args []string) {
go verify(dialer, cfg)
}

go autoUpgrade()

shell(fwdChan, cfg, dialer)

okln("Done")
Expand Down Expand Up @@ -244,3 +247,28 @@ func verify(dialer Dialer, cfg *conf.Config) {
okf(msgTunnelRtt, minRtt, okFwd, allFwd)
}
}

func autoUpgrade() {
if moleIni.Get("upgrades", "automatic") == "no" {
debugln("automatic upgrades disabled")
return
}

// Only do the actual upgrade once we've been running for a while
time.Sleep(10 * time.Second)
build, err := latestBuild()
if err == nil {
bd := time.Unix(int64(build.BuildStamp), 0)
if isNewer := bd.Sub(buildDate).Seconds() > 0; isNewer {
err = upgrade.UpgradeTo(build)
if err == nil {
if moleIni.Get("upgrades", "automatic") != "yes" {
infoln(msgAutoUpgrades)
}
okf(msgUpgraded, build.Version)
} else {
warnln("Automatic upgrade failed:", err)
}
}
}
}
28 changes: 0 additions & 28 deletions cmd/mole/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/calmh/ini"
"github.com/calmh/mole/ansi"
"github.com/calmh/mole/upgrade"
)

var (
Expand Down Expand Up @@ -83,8 +82,6 @@ func main() {
printVersion()
}

go autoUpgrade()

// Early beta versions of mole4 wrote the fingerprint in lower case which
// is incompatible with both mole 3 and current 4+. Rewrite the fingerprint
// to upper case if necessary.
Expand Down Expand Up @@ -174,31 +171,6 @@ func parseFlags() []string {
return args
}

func autoUpgrade() {
if moleIni.Get("upgrades", "automatic") == "no" {
debugln("automatic upgrades disabled")
return
}

// Only do the actual upgrade once we've been running for a while
time.Sleep(10 * time.Second)
build, err := latestBuild()
if err == nil {
bd := time.Unix(int64(build.BuildStamp), 0)
if isNewer := bd.Sub(buildDate).Seconds() > 0; isNewer {
err = upgrade.UpgradeTo(build)
if err == nil {
if moleIni.Get("upgrades", "automatic") != "yes" {
infoln(msgAutoUpgrades)
}
okf(msgUpgraded, build.Version)
} else {
warnln("Automatic upgrade failed:", err)
}
}
}
}

func serverAddress() string {
port, _ := strconv.Atoi(moleIni.Get("server", "port"))
return moleIni.Get("server", "host") + ":" + strconv.Itoa(port)
Expand Down

0 comments on commit b79be25

Please sign in to comment.