[ Agent ] [ Executor ] - 优化基础脚本内容

This commit is contained in:
zeaslity
2023-11-07 10:02:19 +08:00
parent ebb0759737
commit b17f1dcb52
4 changed files with 40 additions and 36 deletions

View File

@@ -4,14 +4,15 @@ import "strings"
func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator {
// todo build from env
AgentOsOperatorCache = &AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "-y",
"apt-get", "install", "--allow-downgrades", "-y",
},
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsAgentInnerWall: true,
IsAgentInnerWall: false,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
AgentServerInfo: nil,
@@ -66,16 +67,41 @@ func detectByOsType(os *AgentOsOperator, osInfo string) {
os.IsOsTypeUbuntu = true
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{
"apt-get", "install", "-y",
"apt-get", "install", "--allow-downgrades", "-y",
}
// os release code
osRealseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
os.AgentOSReleaseCode = osRealseResult[0]
osReleaseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
os.AgentOSReleaseCode = osReleaseResult[0]
}
}
func detectByInternet(os *AgentOsOperator) {
log.Info("开始检测Agent的网络连通情况!")
outsideTestUrl := "www.google.com"
innerTestUrl := "www.baidu.com"
testInternetCommand := []string{
"curl",
"-o",
"/dev/null",
"-m",
"5",
"-s",
}
if PureResultSingleExecute(append(testInternetCommand, outsideTestUrl)) {
os.CanAccessInternet = true
os.IsAgentInnerWall = false
} else if PureResultSingleExecute(append(testInternetCommand, innerTestUrl)) {
os.CanAccessInternet = true
os.IsAgentInnerWall = true
} else {
os.CanAccessInternet = false
os.IsAgentInnerWall = true
}
}