Files
ProjectOctopus/agent-go/executor/InitFunction.go

82 lines
1.5 KiB
Go

package executor
import "strings"
func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator {
AgentOsOperatorCache = &AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "-y",
},
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsAgentInnerWall: true,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
AgentServerInfo: nil,
OssOfflinePrefix: ossOfflinePrefix,
}
// os type
detectByOsType(AgentOsOperatorCache, osInfo)
// internet
detectByInternet(AgentOsOperatorCache)
return AgentOsOperatorCache
}
func detectByOsType(os *AgentOsOperator, osInfo string) {
ubuntuSsRealseCode := [][]string{
{
"cat",
"/etc/os-release",
},
{
"grep",
"CODE",
},
{
"head",
"-1",
},
{
"cut",
"-d",
"=",
"-f",
"2",
},
}
if strings.HasPrefix(osInfo, "Ce") {
// centos
os.IsOsTypeUbuntu = false
os.InstallCommandPrefix = []string{
"yum", "install", "-y",
}
os.RemoveCommandPrefix = []string{
"yum", "remove",
}
} else {
// ubuntu
os.IsOsTypeUbuntu = true
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{
"apt-get", "install", "-y",
}
// os release code
osRealseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
os.AgentOSReleaseCode = osRealseResult[0]
}
}
func detectByInternet(os *AgentOsOperator) {
}