Commit 16b50ca6 authored by szh's avatar szh

增加linux x86_64架构的兼容

parent 7884dc8b
//+build go1.9
package main
import (
......@@ -12,6 +14,7 @@ import (
log "github.com/33cn/chain33/common/log/log15"
"net/http"
"time"
"flag"
)
func init() {
......@@ -25,7 +28,10 @@ func init() {
}
var tlog = log.New("main", "main.go")
var (
versionCmd = flag.Bool("v", false, "version")
testCmd = flag.Bool("t",false,"test")
)
// @title Golang Gin API
// @version 1.0
// @description An example of gin
......@@ -33,6 +39,15 @@ var tlog = log.New("main", "main.go")
// @license.name MIT
// @license.url https://chain33-pai/blob/master/LICENSE
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)
//区域网广播设备
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 (
"os/exec"
"strconv"
"strings"
"chain33-pai/pkg/app"
)
var (
......@@ -91,17 +92,26 @@ func (p *Pai) GetConfig() bool {
if p.Serial != "" {
return true
}
config, err := getPaiConfig("cat", "/proc/cpuinfo")
if err != nil {
p.Err = err.Error()
return false
}
if _, ok := config["serial"]; ok {
p.Serial = config["serial"]
p.Hardware = config["hardware"]
p.Revision = config["revision"]
return true
if app.GetArchType() == "arm" {
config, err := getPaiConfig("cat", "/proc/cpuinfo")
if err != nil {
p.Err = err.Error()
return false
}
if _, ok := config["serial"]; ok {
p.Serial = config["serial"]
p.Hardware = config["hardware"]
p.Revision = config["revision"]
return true
}
} else if app.GetArchType() == "x86_64" {
uuid := app.GetLocalUuid()
if uuid != "" {
p.Serial = uuid
return true
}
}
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