🏗️ move make sub-cmd to sub-dir
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
package maker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
"yizhisec.com/hsv2/forge/internal/opt"
|
||||
"yizhisec.com/hsv2/forge/pkg/downloader"
|
||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
"yizhisec.com/hsv2/forge/internal/opt"
|
||||
"yizhisec.com/hsv2/forge/pkg/downloader"
|
||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||
)
|
||||
|
||||
type YosguardOpt func(*yosguardOpt)
|
||||
@@ -16,8 +16,8 @@ type YosguardOpt func(*yosguardOpt)
|
||||
type yosguardOpt struct{}
|
||||
|
||||
func (m *maker) Yosguard(ctx context.Context, opts ...YosguardOpt) error {
|
||||
const (
|
||||
configTemplate = `
|
||||
const (
|
||||
configTemplate = `
|
||||
Web:
|
||||
# default listen in docker0
|
||||
Host: 172.17.0.1
|
||||
@@ -44,7 +44,7 @@ Database:
|
||||
DBPath: "/etc/yosguard/db/yosguard.db"
|
||||
SQLPath: "/etc/yosguard/db/create.sql"`
|
||||
|
||||
systemdService = `
|
||||
systemdService = `
|
||||
[Unit]
|
||||
Description=YiZhiSec YOSGuard
|
||||
After=network.target
|
||||
@@ -61,44 +61,53 @@ RestartSec=15
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target`
|
||||
binURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv2/bin/yosguard"
|
||||
)
|
||||
binURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv2/bin/yosguard"
|
||||
)
|
||||
|
||||
location := filepath.Join(opt.Cfg.Make.Dir, "dependency", "yosguard")
|
||||
location := filepath.Join(opt.Cfg.Make.Dir, "dependency", "yosguard")
|
||||
|
||||
logger.Info("☑️ MakeYosguard: 开始构建 yosguard...")
|
||||
logger.Info("☑️ maker.Yosguard: 开始构建 yosguard...")
|
||||
logger.Debug("☑️ maker.Yosguard: 创建目录 %s", location)
|
||||
if err := os.MkdirAll(location, 0755); err != nil {
|
||||
logger.Debug("❌ maker.Yosguard: 创建 yosguard 目录失败: %v", err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("✅ maker.Yosguard: 创建目录 %s 成功", location)
|
||||
|
||||
if err := os.MkdirAll(location, 0755); err != nil {
|
||||
logger.Debug("❌ MakeYosguard: 创建 yosguard 目录失败: %v", err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("☑️ maker.Yosguard: 下载 yosguard 二进制文件..., url = %s, dest = %s", binURL, filepath.Join(location, "yosguard"))
|
||||
if err := downloader.Download(
|
||||
ctx,
|
||||
binURL,
|
||||
filepath.Join(location, "yosguard"),
|
||||
downloader.WithInsecureSkipVerify(),
|
||||
downloader.WithFileMode(0755),
|
||||
); err != nil {
|
||||
logger.Debug("❌ maker.Yosguard: 下载 yosguard 失败, url = %s, err = %v", binURL, err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("✅ maker.Yosguard: 下载 yosguard 成功, url = %s", binURL)
|
||||
|
||||
if err := downloader.Download(
|
||||
ctx,
|
||||
binURL,
|
||||
filepath.Join(location, "yosguard"),
|
||||
downloader.WithInsecureSkipVerify(),
|
||||
downloader.WithFileMode(0755),
|
||||
); err != nil {
|
||||
logger.Debug("❌ MakeYosguard: 下载 yosguard 失败: %v", err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("☑️ maker.Yosguard: 写入 config_template.yml 文件..., dest = %s", filepath.Join(location, "config_template.yml"))
|
||||
if err := os.WriteFile(filepath.Join(location, "config_template.yml"), []byte(configTemplate), 0644); err != nil {
|
||||
logger.Debug("❌ maker.Yosguard: 写入 config_template.yml 失败, dest = %s, err = %v", filepath.Join(location, "config_template.yml"), err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("✅ maker.Yosguard: 写入 config_template.yml 文件成功, dest = %s", filepath.Join(location, "config_template.yml"))
|
||||
|
||||
if err := os.WriteFile(filepath.Join(location, "config_template.yml"), []byte(configTemplate), 0644); err != nil {
|
||||
logger.Debug("❌ MakeYosguard: 生成 config_template.yml 失败: %v", err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("☑️ maker.Yosguard: 写入 create.sql 文件..., dest = %s", filepath.Join(location, "create.sql"))
|
||||
if err := os.WriteFile(filepath.Join(location, "create.sql"), resource.SQLYosguard, 0644); err != nil {
|
||||
logger.Debug("❌ maker.Yosguard: 写入 create.sql 失败, dest = %s, err = %v", filepath.Join(location, "create.sql"), err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("✅ maker.Yosguard: 写入 create.sql 文件成功, dest = %s", filepath.Join(location, "create.sql"))
|
||||
|
||||
if err := os.WriteFile(filepath.Join(location, "create.sql"), resource.SQLYosguard, 0644); err != nil {
|
||||
logger.Debug("❌ MakeYosguard: 生成 create.sql 失败: %v", err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("☑️ maker.Yosguard: 写入 yosguard.service 文件..., dest = %s", filepath.Join(location, "yosguard.service"))
|
||||
if err := os.WriteFile(filepath.Join(location, "yosguard.service"), []byte(systemdService), 0644); err != nil {
|
||||
logger.Debug("❌ maker.Yosguard: 写入 yosguard.service 失败, dest = %s, err = %v", filepath.Join(location, "yosguard.service"), err)
|
||||
return err
|
||||
}
|
||||
logger.Debug("✅ maker.Yosguard: 写入 yosguard.service 文件成功, dest = %s", filepath.Join(location, "yosguard.service"))
|
||||
|
||||
if err := os.WriteFile(filepath.Join(location, "yosguard.service"), []byte(systemdService), 0644); err != nil {
|
||||
logger.Debug("❌ MakeYosguard: 生成 yosguard.service 失败: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("✅ MakeYosguard: 构建 yosguard成功!!!")
|
||||
return nil
|
||||
logger.Info("✅ maker.Yosguard: 构建 yosguard 成功!!!")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user