Commit 16b50ca6 authored by szh's avatar szh

增加linux x86_64架构的兼容

parent 7884dc8b
//+build go1.9
package main package main
import ( import (
...@@ -12,6 +14,7 @@ import ( ...@@ -12,6 +14,7 @@ import (
log "github.com/33cn/chain33/common/log/log15" log "github.com/33cn/chain33/common/log/log15"
"net/http" "net/http"
"time" "time"
"flag"
) )
func init() { func init() {
...@@ -25,7 +28,10 @@ func init() { ...@@ -25,7 +28,10 @@ func init() {
} }
var tlog = log.New("main", "main.go") var tlog = log.New("main", "main.go")
var (
versionCmd = flag.Bool("v", false, "version")
testCmd = flag.Bool("t",false,"test")
)
// @title Golang Gin API // @title Golang Gin API
// @version 1.0 // @version 1.0
// @description An example of gin // @description An example of gin
...@@ -33,6 +39,15 @@ var tlog = log.New("main", "main.go") ...@@ -33,6 +39,15 @@ var tlog = log.New("main", "main.go")
// @license.name MIT // @license.name MIT
// @license.url https://chain33-pai/blob/master/LICENSE // @license.url https://chain33-pai/blob/master/LICENSE
func main() { func main() {
flag.Parse()
if *versionCmd {
fmt.Println(app.GetVersion())
return
}
if *testCmd {
fmt.Println("app sys:",app.GetLocalArchType(),app.GetArchType())
return
}
gin.SetMode(setting.ServerSetting.RunMode) gin.SetMode(setting.ServerSetting.RunMode)
//区域网广播设备 //区域网广播设备
go app.Broadcast() go app.Broadcast()
......
package app
import (
"os/exec"
"bytes"
"strings"
)
func GetLocalArchType() string {
cmd := exec.Command("arch")
var buf bytes.Buffer
cmd.Stdout = &buf
cmd.Run()
if buf.String() != "" {
lines := strings.Split(buf.String(),"\n")
if len(lines) == 2 {
return strings.Trim(lines[0]," ")
}
return ""
}
return ""
}
func GetLocalUuid() string {
cmd := exec.Command("bash","-c","dmidecode | grep UUID")
var buf bytes.Buffer
cmd.Stdout = &buf
cmd.Run()
if buf.String() != "" {
lines := strings.Split(buf.String(),"\n")
if len(lines) == 2 {
return strings.Trim(lines[0]," ")
}
return ""
}
return ""
}
\ No newline at end of file
package app
//默认arm架构的树莓派 其他x86_64系统
var (
ArchType string
)
func GetArchType() string {
if ArchType != "" {
return ArchType
}
return "arm"
}
\ No newline at end of file
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
"chain33-pai/pkg/app"
) )
var ( var (
...@@ -91,17 +92,26 @@ func (p *Pai) GetConfig() bool { ...@@ -91,17 +92,26 @@ func (p *Pai) GetConfig() bool {
if p.Serial != "" { if p.Serial != "" {
return true return true
} }
config, err := getPaiConfig("cat", "/proc/cpuinfo") if app.GetArchType() == "arm" {
if err != nil { config, err := getPaiConfig("cat", "/proc/cpuinfo")
p.Err = err.Error() if err != nil {
return false p.Err = err.Error()
} return false
if _, ok := config["serial"]; ok { }
p.Serial = config["serial"] if _, ok := config["serial"]; ok {
p.Hardware = config["hardware"] p.Serial = config["serial"]
p.Revision = config["revision"] p.Hardware = config["hardware"]
return true p.Revision = config["revision"]
return true
}
} else if app.GetArchType() == "x86_64" {
uuid := app.GetLocalUuid()
if uuid != "" {
p.Serial = uuid
return true
}
} }
return false return false
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment