[ Agent ] [ APP ] - refresh app procedure

This commit is contained in:
zeaslity
2023-11-20 11:29:16 +08:00
parent f1b8f8efc8
commit 72269894db
7 changed files with 236 additions and 44 deletions

View File

@@ -244,3 +244,57 @@ func BasicConvertBufferToSlice(outputBuffer bytes.Buffer) (resultLog []string) {
return split
}
// BasicDownloadFile 从目标地址下载文件到目的地,并检测文件是否下载成功
func BasicDownloadFile(downloadUrl, desFile string) (downloadOk bool, resultLog []string) {
// wget or curl download
var ok bool
if BasicCommandExists("wget") {
ok, resultLog = AllCommandExecutor([]string{
"wget",
"--no-check-certificate",
"--timeout=5",
downloadUrl,
"-qO",
desFile,
})
} else if BasicCommandExists("curl") {
ok, resultLog = AllCommandExecutor([]string{
"curl",
"-o",
desFile,
"--insecure",
"--max-time",
"5",
downloadUrl,
})
} else {
sprintf := fmt.Sprintf("[BasicDownloadFile] - neither wget or curl exists ! can't download file [ %s ] from [ %s ]", desFile, downloadUrl)
log.Error(sprintf)
return false, []string{
sprintf,
}
}
errLog := fmt.Sprintf("[BasicDownloadFile] - download file [ %s ] from [ %s ] failed !", desFile, downloadUrl)
if !ok {
log.Error(errLog)
return false, []string{
errLog,
}
}
// check file exists
existAndNotNull := BasicFileExistAndNotNull(desFile)
if !existAndNotNull {
return false, []string{
errLog,
"[BasicDownloadFile] - file not exist !",
}
}
return true, nil
}