diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 73cbecdfd..4b9412fb3 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -1,7 +1,7 @@ param ( - [Parameter(Mandatory)] + [Parameter()] $observe_collection_endpoint, - [Parameter(Mandatory)] + [Parameter()] $observe_token ) @@ -25,19 +25,30 @@ if((Get-Service ObserveAgent -ErrorAction SilentlyContinue)){ Expand-Archive -Force -LiteralPath $local_installer -DestinationPath "$temp_dir\observe-agent_Windows_x86_64" Copy-Item -Force -Path $temp_dir\observe-agent_Windows_x86_64\observe-agent.exe -Destination $observeagent_install_dir -Copy-Item -Force -Path $temp_dir\observe-agent_Windows_x86_64\observe-agent.yaml -Destination $observeagent_install_dir Copy-Item -Force -Path $temp_dir\observe-agent_Windows_x86_64\otel-collector.yaml -Destination $observeagent_install_dir\config\otel-collector.yaml Copy-Item -Force -Path $temp_dir\observe-agent_Windows_x86_64\connections\ -Destination $observeagent_install_dir\connections -Recurse -# Read the content of the config.yaml file -$configContent = Get-Content -Path $observeagent_install_dir\observe-agent.yaml -Raw +# If there's already an observe-agent.yaml we don't copy the template from the downloaded installation package and leave existing observe-agent.yaml alone +if (-Not (Test-Path "$observeagent_install_dir\observe-agent.yaml")) +{ + Copy-Item -Force -Path $temp_dir\observe-agent_Windows_x86_64\observe-agent.yaml -Destination $observeagent_install_dir -# Replace ${myhost} with the actual value -$configContent = $configContent -replace '\${OBSERVE_COLLECTION_ENDPOINT}', $observe_collection_endpoint -$configContent = $configContent -replace '\${OBSERVE_TOKEN}', $observe_token + # We can only insert param templates if there's no existing config and we're copying over the template observe-agent.yaml + $configContent = Get-Content -Path $observeagent_install_dir\observe-agent.yaml -Raw -# Write the modified content back to the config.yaml file -$configContent | Set-Content -Path $observeagent_install_dir\observe-agent.yaml + # Replace $OBSERVE_COLLECTION_ENDPOINT and $OBSERVE_TOKEN with param if provided + if($PSBoundParameters.ContainsKey('observe_collection_endpoint')) + { + $configContent = $configContent -replace '\${OBSERVE_COLLECTION_ENDPOINT}', $observe_collection_endpoint + } + if($PSBoundParameters.ContainsKey('observe_token')) + { + $configContent = $configContent -replace '\${OBSERVE_TOKEN}', $observe_token + } + + # Write the modified content back to the config.yaml file + $configContent | Set-Content -Path $observeagent_install_dir\observe-agent.yaml +} if(-not (Get-Service ObserveAgent -ErrorAction SilentlyContinue)){ $params = @{