Files
ProjectOctopus/agent-wdd/cmd/Base.go

107 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"agent-wdd/config"
"agent-wdd/log"
"agent-wdd/op"
"fmt"
"github.com/spf13/cobra"
)
var (
ubuntuCommonTools = []string{
"iputils-ping", "net-tools", "dnsutils", "lsof", "curl", "wget", "mtr-tiny", "vim", "htop", "lrzsz",
}
centosCommonTools = []string{
"deltarpm", "net-tools", "iputils", "bind-utils", "lsof", "curl", "wget", "vim", "mtr", "htop",
}
)
// 添加base子命令
func addBaseSubcommands(cmd *cobra.Command) {
// 1.1 docker
dockerCmd := &cobra.Command{
Use: "docker",
Short: "Docker相关操作",
}
addDockerSubcommands(dockerCmd)
// 1.2 dockercompose
dockerComposeCmd := &cobra.Command{
Use: "dockercompose",
Short: "Docker Compose相关操作",
}
addDockerComposeSubcommands(dockerComposeCmd)
// 其他base子命令...
// 通用工具安装
commonToolsInstall := &cobra.Command{
Use: "tools",
Short: "通用工具安装 利用本机的yumapt等从网络安装常用的软件",
Run: func(cmd *cobra.Command, args []string) {
log.Info("Common tool installation!")
// Whether It can connect to internet
if config.CanConnectInternet() <= 1 {
log.Error("服务器无法连接互联网无法执行tools")
return
}
// package install
// only support ubuntu(debian) centos(debian openEuler)
packOperator := op.AgentPackOperator
packOperator.PackageInit()
os := config.ConfigCache.Agent.OS
if os.IsUbuntuType {
packOperator.Install(ubuntuCommonTools)
} else {
packOperator.Install(centosCommonTools)
}
},
}
cmd.AddCommand(
dockerCmd,
dockerComposeCmd,
commonToolsInstall,
// 其他命令...
)
}
// 添加docker子命令
func addDockerSubcommands(cmd *cobra.Command) {
onlineCmd := &cobra.Command{
Use: "online [version]",
Short: "网络安装Docker",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Installing Docker version: %s\n", args[0])
},
}
removeCmd := &cobra.Command{
Use: "remove",
Short: "卸载Docker",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Removing Docker...")
},
}
localCmd := &cobra.Command{
Use: "local [path]",
Short: "本地安装Docker",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Installing Docker from: %s\n", args[0])
},
}
cmd.AddCommand(onlineCmd, removeCmd, localCmd)
}
func addDockerComposeSubcommands(cmd *cobra.Command) {
}