Skip to content

Commit

Permalink
Refactor setup-agent.ps1 to update Wazuh agent installation script UR…
Browse files Browse the repository at this point in the history
…L, improve error handling, and add error handling to wazuh-cert-oauth2-client installation Add wazuh agent install on Windows #3
  • Loading branch information
bengo237 committed Oct 11, 2024
1 parent 63bd5bd commit 9bb76d1
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions setup-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9bb76d1

Please sign in to comment.