Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
check server require version on each connect with server
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Nov 6, 2017
1 parent 495aa51 commit e93e51b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ $ adb shell /data/local/tmp/atx-agent -d

默认监听的端口是7912。

# 重要更新历史
- 0.0.8

* 支持连接Server获取最新版本,并自动升级

- 0.0.7

* 响应服务端的websocket PING请求
* 如果安装失败,尝试先卸载,然后继续安装

- 0.0.6

* 支持文件上传

- 0.0.5

* 移除每次启动时自动安装minicap, com.github.uiautomator应用

- 0.0.4

* 增加网页版的控制台
* 支持daemon模式运行

- 0.0.3

* 增加安装应用支持

# 常用接口
假设手机的地址是$DEVICE_URL (eg: `http://10.0.0.1:7912`)

Expand Down
33 changes: 33 additions & 0 deletions tunnelproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"log"
"os"
"time"

"github.com/franela/goreq"
"github.com/gorilla/websocket"
"github.com/openatx/androidutils"
"github.com/openatx/atx-server/proto"
Expand All @@ -27,7 +29,38 @@ func runTunnelProxy(serverAddr string) {
}
}

type VersionResponse struct {
ServerVersion string `json:"version"`
AgentVersion string `json:"atx-agent"`
}

func unsafeRunTunnelProxy(serverAddr string) error {
// check version update
res, err := goreq.Request{Uri: "http://" + serverAddr + "/version"}.Do()
if err != nil {
return err
}
defer res.Body.Close()
verResp := new(VersionResponse)
if err := res.Body.FromJsonTo(verResp); err != nil {
return err
}
if verResp.AgentVersion != version {
if version == "dev" {
log.Printf("dev version, skip version upgrade")
} else {
log.Printf("server require agent version: %v, but current %s, going to upgrade", verResp.AgentVersion, version)
if err := doUpdate(verResp.AgentVersion); err != nil {
log.Printf("upgrade error: %v", err)
return err
}
log.Printf("restarting server")
runDaemon()
os.Exit(0)
}
}

// keep connection with server
ws, _, err := websocket.DefaultDialer.Dial("ws://"+serverAddr+"/echo", nil)
if err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ func doUpdate(version string) (err error) {
return err
}
}
filename := fmt.Sprintf("%s_%s_%s_%sv7.tar.gz", repo, version, runtime.GOOS, runtime.GOARCH)
arch := runtime.GOARCH
if runtime.GOOS == "linux" && arch == "arm" {
arch += "v7"
}
filename := fmt.Sprintf("%s_%s_%s_%s.tar.gz", repo, version, runtime.GOOS, arch)
log.Printf("update file: %s", filename)
checksums, err := getChecksums(version)
if err != nil {
return err
Expand Down

0 comments on commit e93e51b

Please sign in to comment.