chore: 完善个模块打包
This commit is contained in:
@@ -2,6 +2,7 @@ package maker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -12,24 +13,27 @@ import (
|
||||
|
||||
type YosguardOpt func(*yosguardOpt)
|
||||
|
||||
type yosguardOpt struct{}
|
||||
type yosguardOpt struct {
|
||||
Pkg bool
|
||||
}
|
||||
|
||||
func WithYosguardPkg(makePkg bool) YosguardOpt {
|
||||
return func(o *yosguardOpt) {
|
||||
o.Pkg = makePkg
|
||||
}
|
||||
}
|
||||
|
||||
func (m *maker) Yosguard(ctx context.Context, opts ...YosguardOpt) error {
|
||||
const (
|
||||
_config = `
|
||||
AsController: true
|
||||
AsGateway: false
|
||||
ControllerServer:
|
||||
Host: dasheng.zhsftech.debug
|
||||
Port: 443
|
||||
Web:
|
||||
Host: __ip__
|
||||
Port: 7788
|
||||
Database:
|
||||
SQLite:
|
||||
DBPath: /etc/yosguard/db/yosguard.db
|
||||
HeartbeatDuration: 5
|
||||
UUIDFilePath: /etc/yosguard/uuid
|
||||
Web:
|
||||
Host: __ip__
|
||||
Port: 7788
|
||||
`
|
||||
|
||||
systemdService = `
|
||||
@@ -52,10 +56,23 @@ WantedBy=multi-user.target`
|
||||
binURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv2/bin/yosguard"
|
||||
)
|
||||
|
||||
location := filepath.Join(m.workdir, "dependency", "yosguard")
|
||||
var (
|
||||
location = filepath.Join(m.workdir, "dependency", "yosguard")
|
||||
o = &yosguardOpt{}
|
||||
)
|
||||
|
||||
for _, fn := range opts {
|
||||
fn(o)
|
||||
}
|
||||
|
||||
logger.Info("☑️ maker.Yosguard: 开始构建 yosguard...")
|
||||
logger.Debug("☑️ maker.Yosguard: 创建目录 %s", location)
|
||||
|
||||
if err := os.RemoveAll(location); err != nil {
|
||||
logger.Debug("❌ maker.Yosguard: 删除 yosguard 目录失败, dir = %s, err = %v", location, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(location, 0755); err != nil {
|
||||
logger.Debug("❌ maker.Yosguard: 创建 yosguard 目录失败: %v", err)
|
||||
return err
|
||||
@@ -96,6 +113,15 @@ WantedBy=multi-user.target`
|
||||
}
|
||||
logger.Debug("✅ maker.Yosguard: 写入 yosguard.service 文件成功, dest = %s", filepath.Join(location, "yosguard.service"))
|
||||
|
||||
if o.Pkg {
|
||||
_cmd := fmt.Sprintf("cd %s && 7za a -pRrPt7Uo9WM1dkXOJmHps56T8BZY2qA4g -mhe=on yosguard.pkg *", location)
|
||||
logger.Debug("☑️ maker.Yosguard: start create yosguard.pkg by 7zip, cmd = '%s'", _cmd)
|
||||
if err := m.RunCommand(ctx, location, _cmd); err != nil {
|
||||
logger.Debug("❌ maker.Yosguard: 创建 yosguard.pkg 失败, err = %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("✅ maker.Yosguard: 构建 yosguard 成功!!!")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user