From 9bb76d18347b47fd875f6f4255be2065b7694392 Mon Sep 17 00:00:00 2001 From: Dylane Bengono Date: Fri, 11 Oct 2024 11:46:07 +0100 Subject: [PATCH] Refactor setup-agent.ps1 to update Wazuh agent installation script URL, improve error handling, and add error handling to wazuh-cert-oauth2-client installation Add wazuh agent install on Windows #3 --- setup-agent.ps1 | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/setup-agent.ps1 b/setup-agent.ps1 index 6bf402e..4784764 100644 --- a/setup-agent.ps1 +++ b/setup-agent.ps1 @@ -93,24 +93,35 @@ function Install-WazuhAgent { } -# Step 2: Download and install wazuh-cert-oauth2-client +# Step 2: Download and install wazuh-cert-oauth2-client with error handling function Install-OAuth2Client { - Log-Info "Installing wazuh-cert-oauth2-client" - - $OAuth2Url = "https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-cert-oauth2/refs/heads/fix/scripts/install.ps1" #to be updated - $OAuth2Script = "$TEMP_DIR\wazuh-cert-oauth2-client-install.ps1" + try { + Write-Host "Downloading and executing wazuh-cert-oauth2-client script..." - # Download the wazuh-cert-oauth2-client - Invoke-WebRequest -Uri $OAuth2Url -OutFile $OAuth2Script + $OAuth2Url = "https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-cert-oauth2/refs/heads/fix/scripts/install.ps1" # Update the URL if needed + $OAuth2Script = "$env:TEMP\wazuh-cert-oauth2-client-install.ps1" - # Execute the downloaded executable with appropriate parameters - Start-Process -FilePath $OAuth2Script -ArgumentList "-LOG_LEVEL", $LOG_LEVEL, "-OSSEC_CONF_PATH", $OSSEC_CONF_PATH, "-APP_NAME", $APP_NAME, "-WOPS_VERSION", $WOPS_VERSION -Wait - Log-Info "wazuh-cert-oauth2-client installed successfully." + # Download the wazuh-cert-oauth2-client installer script + Invoke-WebRequest -Uri $OAuth2Url -OutFile $OAuth2Script -ErrorAction Stop + Write-Host "wazuh-cert-oauth2-client script downloaded successfully." - # Clean up the executable - Remove-Item $OAuth2Script + # Execute the downloaded script with required parameters + & powershell.exe -ExecutionPolicy Bypass -File $OAuth2Script -ArgumentList "-LOG_LEVEL", $LOG_LEVEL, "-OSSEC_CONF_PATH", $OSSEC_CONF_PATH, "-APP_NAME", $APP_NAME, "-WOPS_VERSION", $WOPS_VERSION -ErrorAction Stop + Write-Host "wazuh-cert-oauth2-client installed successfully." + } + catch { + Write-Host "Error during wazuh-cert-oauth2-client installation: $($_.Exception.Message)" -ForegroundColor Red + } + finally { + # Clean up the installer file if it exists + if (Test-Path $OAuth2Script) { + Remove-Item $OAuth2Script -Force + Write-Host "Installer file removed." + } + } } + # Step 3: Download and install YARA function Install-Yara { Log-Info "Installing YARA"