Skip to content

Commit

Permalink
change query version api to synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
rwby-ovo committed Sep 9, 2022
1 parent 59984a6 commit dc5b65b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
21 changes: 13 additions & 8 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@ func apiStart(br *broker) {
return
}
name := jsoniter.Get(content, "name").ToString()
call_url := jsoniter.Get(content, "call_url").ToString()
onlyid := devidGetOnlyid(br, devid)
if len(onlyid) == 0 {
c.JSON(http.StatusOK, gin.H{
Expand All @@ -975,13 +974,19 @@ func apiStart(br *broker) {
"data": nil,
})
} else {
c.JSON(http.StatusOK, gin.H{
"ret": 1,
"msg": "success",
"data": gin.H{
"token": hiVersionDevice(br, devid, name, call_url),
},
})
cmdr, terr := hi.CreateCmdr(db, devid, onlyid, hi.VersionCmd(name))
if terr != nil {
c.JSON(http.StatusOK, gin.H{
"ret": 0,
"msg": "创建失败",
"data": gin.H{
"error": terr.Error(),
},
})
return
}
hiExecRequest(br, c, cmdr)
return
}
return
}
Expand Down
19 changes: 0 additions & 19 deletions hi.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,6 @@ func hiRebootDevice(br *broker, devid string) string {
return hiExecBefore(br, db, devid, "#!/bin/sh\nreboot", "")
}

// 版本信息
func hiVersionDevice(br *broker, devid string, name string, call_url string) string {
if len(br.cfg.HiApiUrl) == 0 {
log.Info().Msgf("api url is empty")
return ""
}
db, err := hi.InstanceDB(br.cfg.DB)
if err != nil {
return ""
}
var cmds string
if name == "firmware" {
cmds = "[ -e '/etc/glversion' ] && {\ncat /etc/glversion ; exit 0\n}\ncat /etc/openwrt_release|grep DISTRIB_RELEASE |awk -F'=' '{print $2}'"
} else {
cmds = fmt.Sprintf("opkg info %s |grep 'Version' |awk '{print $2=$2}'", name)
}
return hiExecBefore(br, db, devid, fmt.Sprintf("#!/bin/sh\n%s", cmds), call_url)
}

// 固件升级
func hiDeviceFirmwareUpgrade(br *broker, devid string, path string, callback string) string {
if len(br.cfg.HiApiUrl) == 0 {
Expand Down
14 changes: 12 additions & 2 deletions hi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type StaticLeasesModel struct {
func IpkUpgradeCmd(path string) string {
var cmds []string
cmds = append(cmds, "#!/bin/sh")
cmds = append(cmds, fmt.Sprintf("curl -4 -s -o /tmp/speedbox.ipk '%s' >/dev/null", path))
cmds = append(cmds, "opkg install /tmp/speedbox.ipk")
cmds = append(cmds, fmt.Sprintf("curl -4 -s -o /tmp/software.ipk '%s' >/dev/null", path))
cmds = append(cmds, "opkg install /tmp/software.ipk")
return strings.Join(cmds, "\n")
}

Expand All @@ -28,6 +28,16 @@ func FirmwareUpgradeCmd(path string) string {
return strings.Join(cmds, "\n")
}

func VersionCmd(name string) string {
var cmds string
if name == "firmware" {
cmds = "[ -e '/etc/glversion' ] && {\ncat /etc/glversion ; exit 0\n}\ncat /etc/openwrt_release|grep DISTRIB_RELEASE |awk -F'=' '{print $2}'"
} else {
cmds = fmt.Sprintf("opkg info %s |grep 'Version' |awk '{print $2=$2}'", name)
}
return cmds
}

func WireguardCmd(wg WgModel) string {
var cmds []string
//
Expand Down

0 comments on commit dc5b65b

Please sign in to comment.