[ Agent ] [ Base ] - add support for centos/openeuler ; todo chronyToMasterExec centos

This commit is contained in:
zeaslity
2024-01-19 18:34:36 +08:00
parent 7b57a2a422
commit 42dee262cf
7 changed files with 290 additions and 128 deletions

View File

@@ -150,6 +150,52 @@ func BasicFindContentInFile(content string, fileName string) bool {
return false
}
func BasicFindDeleteContendLineInFile(content string, fileName string) bool {
// Open the file
file, err := os.Open(fileName)
if err != nil {
log.ErrorF("[FindDeleteContendLineInFile] - file not exits ")
return false
}
defer file.Close()
// Create a scanner to read the file line by line
scanner := bufio.NewScanner(file)
// Set the split function for the scanner
scanner.Split(bufio.ScanLines)
// 创建一个新的文件内容变量
var newContent string
// Iterate over the lines of the file
for scanner.Scan() {
// Get the current line
line := scanner.Text()
// Check if the current line contains the search term
if !strings.Contains(line, content) {
newContent += line + "\n"
}
}
// Check for any errors that occurred during scanning
if err := scanner.Err(); err != nil {
log.ErrorF("[BasicFindContentInFile] - scanner error ! %s", err.Error())
return false
}
// 将修改后的内容写回文件
err = os.WriteFile(fileName, []byte(newContent), os.ModePerm)
if err != nil {
log.ErrorF("[FindDeleteContendLineInFile] - write file %s error with contend %s", fileName, newContent)
return false
}
return true
}
func BasicDockerImageExists(imageName, imageVersion string) bool {
if !BasicCommandExistByPath("docker") {