cleanup old agent files on upgrade

This commit is contained in:
wh1te909 2020-10-17 15:33:32 -07:00
parent 8cf4d1bae6
commit 5e39db030e
2 changed files with 45 additions and 0 deletions

View File

@ -818,3 +818,47 @@ func (a *WindowsAgent) installerMsg(msg, alert string) {
a.Logger.Fatalln(msg)
}
}
// CleanupPythonAgent cleans up files from the old python agent if this is an upgrade
func (a *WindowsAgent) CleanupPythonAgent() {
cderr := os.Chdir(a.ProgramDir)
if cderr != nil {
return
}
fileMatches := []string{
"*.dll",
"*.pyd",
"base_library*",
"*.manifest",
"onit.ico",
"VERSION",
}
for _, match := range fileMatches {
files, err := filepath.Glob(match)
if err == nil {
for _, f := range files {
os.Remove(f)
}
}
}
folderMatches := []string{
"certifi",
"Include",
"lib2to3",
"psutil",
"tcl",
"tk",
}
for _, match := range folderMatches {
folders, err := filepath.Glob(match)
if err == nil {
for _, f := range folders {
os.RemoveAll(f)
}
}
}
}

View File

@ -32,6 +32,7 @@ type HelloPatch struct {
// WinAgentSvc tacticalagent windows nssm service
func (a *WindowsAgent) WinAgentSvc() {
a.Logger.Infoln("Agent service started")
a.CleanupPythonAgent()
var data map[string]interface{}
var sleep int