Skip to content

Commit

Permalink
fix: improve OTA function on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ArmandMeppa committed Feb 9, 2025
1 parent 2b33a15 commit a88bf1d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions wazuh-agent-status/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,31 @@ func restartAgent() {
time.Sleep(5 * time.Second)
}

// updategent updates the Wazuh agent on macOS
// updateAgent updates the Wazuh agent on Windows
func updateAgent() {
log.Printf("[%s] Setting PowerShell Execution Policy...\n", time.Now().Format(time.RFC3339))

// Set the execution policy to RemoteSigned for the current user
setPolicyCmd := exec.Command("powershell", "-Command", "Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force")
err := setPolicyCmd.Run()
if err != nil {
log.Printf("[%s] Failed to set execution policy: %v\n", time.Now().Format(time.RFC3339), err)
return
}

log.Printf("[%s] Updating Wazuh agent...\n", time.Now().Format(time.RFC3339))

cmd := exec.Command("powershell", "-Command", "C:\\Program Files (x86)\\ossec-agent\\adorsys-update.ps1")
err := cmd.Run()
// Run the update script
cmd := exec.Command("powershell", "-Command", "& 'C:\\Program Files (x86)\\ossec-agent\\adorsys-update.ps1'")
err = cmd.Run()
if err != nil {
log.Printf("[%s] Failed to update Wazuh agent: %v\n", time.Now().Format(time.RFC3339), err)
} else {
log.Printf("[%s] Wazuh agent updated successfully\n", time.Now().Format(time.RFC3339))
}


// Restart the agent after updating
restartAgent()

}


Expand Down

0 comments on commit a88bf1d

Please sign in to comment.