Skip to content

Commit

Permalink
choco: handle custom env vars from registry (#5362)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyc-splunk authored Sep 16, 2024
1 parent c482b7f commit aec8fd2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/win-package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,20 @@ jobs:
if ($LASTEXITCODE -ne 0) {
throw "choco install failed!"
}
$env_vars = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\splunk-otel-collector" -Name "Environment"
$env_vars += "MY VAR WITH SPACES=my value"
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\splunk-otel-collector" -Name "Environment" -Value $env_vars -type MultiString
Start-Sleep 30
write-host "Upgrading $choco_file_name ..."
choco upgrade splunk-otel-collector -s=".\dist" -y
if ($LASTEXITCODE -ne 0) {
throw "choco upgrade failed!"
}
$env_vars = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\splunk-otel-collector" -Name "Environment"
if (!($env_vars -contains "MY VAR WITH SPACES=my value")) {
$env_vars
throw "'MY VAR WITH SPACES=my value' not found!"
}
}
Start-Sleep -s 30
& ${{ github.workspace }}\.github\workflows\scripts\win-test-services.ps1 -mode "${{ matrix.MODE }}" -access_token "${{ env.token }}" -realm "${{ env.realm }}" -memory "${{ env.memory }}" -with_fluentd "${{ matrix.WITH_FLUENTD }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $env_var_names = @(
"SPLUNK_BUNDLE_DIR",
"SPLUNK_LISTEN_INTERFACE"
)
$custom_entries = @()
$upgraded_from_version_with_machine_wide_env_vars = $false

Write-Host "Checking for previous installation..."
Expand Down Expand Up @@ -78,7 +79,11 @@ if (Test-Path $reg_path) {
Write-Host "Found previous environment variables for the $service_name service."
foreach ($entry in $previous_environment) {
$k, $v = $entry.Split("=", 2)
$env_vars[$k] = $v
if ($k -Match "^[0-9A-Za-z_]+$") {
$env_vars[$k] = $v
} else {
$custom_entries += $entry
}
}
}
}
Expand Down Expand Up @@ -159,7 +164,16 @@ if ($MODE) {
}
$packageArgs["silentArgs"] += $msi_properties_args

Install-ChocolateyInstallPackage @packageArgs
try {
Install-ChocolateyInstallPackage @packageArgs
} finally {
# Add any custom entries back to the reg key
if ($custom_entries) {
$custom_entries += (Get-ItemPropertyValue -Path $reg_path -Name "Environment")
$custom_entries = $custom_entries | Sort-Object -Unique
Set-ItemProperty -Path $reg_path -Name "Environment" -Value $custom_entries -Type MultiString
}
}

# Install and configure fluentd to forward log events to the collector.
if ($WITH_FLUENTD) {
Expand Down

0 comments on commit aec8fd2

Please sign in to comment.