重构架构

This commit is contained in:
2026-02-20 18:44:43 +08:00
parent aba7b68439
commit cc71248ef4
52 changed files with 1404 additions and 2360 deletions

View File

@@ -0,0 +1,38 @@
package soft
import (
"fmt"
"os"
"os/exec"
log "sunhpc/pkg/logger"
"sunhpc/pkg/utils"
)
// installViaPackageManager 使用系统包管理器安装软件
func installViaPackageManager(name, pkgType string) error {
var cmd *exec.Cmd
switch pkgType {
case "rpm":
// RHEL/CentOS
if utils.CommandExists("yum") {
cmd = exec.Command("yum", "install", "-y", name)
} else if utils.CommandExists("dnf") {
cmd = exec.Command("dnf", "install", "-y", name)
} else {
return fmt.Errorf("未找到 yum 或 dnf 包管理器")
}
case "deb":
// Debian/Ubuntu
if !utils.CommandExists("apt-get") {
return fmt.Errorf("未找到 apt-get 包管理器")
}
cmd = exec.Command("apt-get", "install", "-y", name)
default:
return fmt.Errorf("不支持的包类型: %s", pkgType)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
log.Infof("执行命令: %s", cmd.String())
return cmd.Run()
}