feat: 🚛 完成了 client 资源创建
This commit is contained in:
176
internal/cmd/makecmd/client.go
Normal file
176
internal/cmd/makecmd/client.go
Normal file
@@ -0,0 +1,176 @@
|
||||
package makecmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
"github.com/spf13/cobra"
|
||||
"yizhisec.com/hsv2/forge/internal/controller/maker"
|
||||
"yizhisec.com/hsv2/forge/internal/opt"
|
||||
tc "yizhisec.com/hsv2/forge/pkg/tool/client"
|
||||
)
|
||||
|
||||
func Client() *cobra.Command {
|
||||
_cmd := &cobra.Command{
|
||||
Use: "client",
|
||||
Short: "make client pkg",
|
||||
}
|
||||
|
||||
_cmd.AddCommand(
|
||||
clientMac(),
|
||||
clientWin(),
|
||||
clientLinux(),
|
||||
)
|
||||
|
||||
return _cmd
|
||||
}
|
||||
|
||||
func clientMac() *cobra.Command {
|
||||
_cmd := &cobra.Command{
|
||||
Use: "mac",
|
||||
Aliases: []string{"macos"},
|
||||
Short: "make client-mac pkg",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
const (
|
||||
DMG_URL = "https://artifactory.yizhisec.com/artifactory/yizhisec-release/hs_appleclient-csgElink/release/2.1.0-std/hybridscope-client-mac.dmg"
|
||||
PKG_URL = "https://artifactory.yizhisec.com/artifactory/yizhisec-release/hs_appleclient-csgElink/release/2.1.0-std/hybridscope-client-mac.pkg"
|
||||
VERSION_URL = "https://artifactory.yizhisec.com/artifactory/yizhisec-release/hs_appleclient/release/2.1.0-std/mac_version.json"
|
||||
)
|
||||
|
||||
var (
|
||||
err error
|
||||
version string
|
||||
)
|
||||
|
||||
if version, err = clientVersion(VERSION_URL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mk := maker.NewMaker(opt.Cfg.Make.Dir)
|
||||
return mk.ClientPKG(
|
||||
cmd.Context(),
|
||||
"mac",
|
||||
version,
|
||||
"/api/v2_2/_client/mac",
|
||||
maker.WithClientPKGDownload(DMG_URL, "hybridscope-client-mac.dmg"),
|
||||
maker.WithClientPKGDownload(PKG_URL, "hybridscope-client-mac.pkg"),
|
||||
maker.WithClientPKGDownload(VERSION_URL, "version.json"),
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
return _cmd
|
||||
}
|
||||
|
||||
func clientWin() *cobra.Command {
|
||||
_cmd := &cobra.Command{
|
||||
Use: "win",
|
||||
Short: "make client-win pkg",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
const (
|
||||
ZIP_URL = "https://artifactory.yizhisec.com/artifactory/yizhisec-release/hs_client-yizhianquan/release/2.1.0-std/hs_client.zip"
|
||||
VERSION_URL = "https://artifactory.yizhisec.com/artifactory/yizhisec-release/hs_client-yizhianquan/release/2.1.0-std/windows_version.json"
|
||||
)
|
||||
|
||||
var (
|
||||
err error
|
||||
version string
|
||||
)
|
||||
|
||||
if version, err = clientVersion(VERSION_URL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mk := maker.NewMaker(opt.Cfg.Make.Dir)
|
||||
return mk.ClientPKG(
|
||||
cmd.Context(),
|
||||
"win",
|
||||
version,
|
||||
"/api/v2_2/_client/win",
|
||||
maker.WithClientPKGDownload(ZIP_URL, "hs_client.zip"),
|
||||
maker.WithClientPKGDownload(VERSION_URL, "version.json"),
|
||||
maker.WithClientPKGCMD("unzip /data/hs_client.zip"),
|
||||
maker.WithClientPKGCMD("mv resources/app.7z /data/app.7z"),
|
||||
maker.WithClientPKGCMD("mv resources/hybridscope_offline_installer.exe /data/hybridscope_offline_installer.exe"),
|
||||
maker.WithClientPKGCMD("mv resources/hybridscope-client-setup-zh.exe /data/hybridscope-client-setup-zh.exe"),
|
||||
maker.WithClientPKGCMD("mv resources/hybridscope-client-setup-en.exe /data/hybridscope-client-setup-en.exe"),
|
||||
maker.WithClientPKGCMD("rm -rf /data/hs_client.zip"),
|
||||
maker.WithClientPKGCMD("rm -rf resources"),
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
return _cmd
|
||||
}
|
||||
|
||||
func clientLinux() *cobra.Command {
|
||||
_cmd := &cobra.Command{
|
||||
Use: "linux",
|
||||
Short: "make client-linux pkg",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
const (
|
||||
DEB_URL = "https://artifactory.yizhisec.com/artifactory/yizhisec-release/universal-hsclient-linux/release/2.1.0/hscore-linux-2.1.0-csgElink-amd64.deb"
|
||||
VERSION_URL = "https://artifactory.yizhisec.com/artifactory/yizhisec-release/universal-hsclient-linux/release/2.1.0/hscore-linux-2.1.0-std-amd64.json"
|
||||
)
|
||||
|
||||
var (
|
||||
err error
|
||||
version string
|
||||
)
|
||||
|
||||
if version, err = clientVersion(VERSION_URL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mk := maker.NewMaker(opt.Cfg.Make.Dir)
|
||||
return mk.ClientPKG(
|
||||
cmd.Context(),
|
||||
"linux",
|
||||
version,
|
||||
"/api/v2_2/_client/linux",
|
||||
maker.WithClientPKGDownload(DEB_URL, "hybridscope-client-linux.deb"),
|
||||
maker.WithClientPKGDownload(VERSION_URL, "version.json"),
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
return _cmd
|
||||
}
|
||||
|
||||
func clientVersion(_url string) (string, error) {
|
||||
type Res struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
rr *http.Response
|
||||
res Res
|
||||
bs []byte
|
||||
)
|
||||
|
||||
logger.Debug("clientVersion: getting client version with url = %s", _url)
|
||||
if rr, err = tc.HttpClient().Get(_url); err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer rr.Body.Close()
|
||||
|
||||
if bs, err = io.ReadAll(rr.Body); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
logger.Debug("clientVersion: got client version body raw: %s, url = %s", string(bs), _url)
|
||||
|
||||
if err = json.Unmarshal(bs, &res); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if res.Version == "" {
|
||||
return "", fmt.Errorf("get version empty, url = %s", _url)
|
||||
}
|
||||
|
||||
return res.Version, nil
|
||||
}
|
||||
Reference in New Issue
Block a user