Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tasks/check.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"openvox_bootstrap/lib/openvox_bootstrap/task.rb",
"openvox_bootstrap/tasks/check.rb"
]
},
{
"name": "check_windows.ps1",
"requirements": ["powershell"]
}
]
}
16 changes: 16 additions & 0 deletions tasks/check_windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$rootPath = 'HKLM:\SOFTWARE\Puppet Labs\Puppet'

$reg = Get-ItemProperty -Path $rootPath -ErrorAction SilentlyContinue
if ($null -ne $reg) {
if ($null -ne $reg.RememberedInstallDir64) {
$loc = $reg.RememberedInstallDir64+'VERSION'
} elseif ($null -ne $reg.RememberedInstallDir) {
$loc = $reg.RememberedInstallDir+'VERSION'
}
}

if ( ($null -ne $loc) -and (Test-Path -Path $loc) ) {
Write-Output "{`"version`":`"$(Get-Content -Path $loc -ErrorAction Stop)`",`"source`":`"$($loc.replace('\', '/'))`"}"
} else {
Write-Output '{"version":null,"source":null}'
}
4 changes: 4 additions & 0 deletions tasks/install.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"facts/tasks/bash.sh",
"openvox_bootstrap/files/common.sh"
]
},
{
"name": "install_windows.ps1",
"requirements": ["powershell"]
}
]
}
106 changes: 106 additions & 0 deletions tasks/install_windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[string]$package = "openvox-agent",

[Parameter(Mandatory = $false)]
[string]$version = "latest",

[Parameter(Mandatory = $false)]
[string]$collection = "openvox8",

[Parameter(Mandatory = $false)]
[string]$apt_source = "https://apt.voxpupuli.org",

[Parameter(Mandatory = $false)]
[string]$yum_source = "https://yum.voxpupuli.org",

[Parameter(Mandatory = $false)]
[bool]$stop_service = $false
)

$agent_package = "openvox-agent"

$ErrorActionPreference = "Stop"

function Write-Result($status, $message, $extra = @{}) {
$output = @{
status = $status
message = $message
} + $extra
$output | ConvertTo-Json -Compress
if ($status -eq "failure") { exit 1 } else { exit 0 }
}

# Exit if anything other than the agent is requested
if ($package -ne $agent_package) {
Write-Result "failure" "Unsupported package name '$package'. This task only supports '$agent_package'."
}

try {
# Detect if already installed
$installed = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Where-Object { $_.DisplayName -like "$agent_package*" } |
Select-Object -First 1

if ($installed) {
$installedVersion = $installed.DisplayVersion
if ($installedVersion -eq $version) {
Write-Result "skipped" "$agent_package $version is already installed." @{ version = $installedVersion }
}
}

# Service handling
$serviceName = "Puppet Agent"
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue

if ($service) {
if ($service.Status -eq "Running") {
if ($stop_service) {
Write-Verbose "Stopping $serviceName service as requested."
Stop-Service -Name $serviceName -Force -ErrorAction Stop
} else {
Write-Result "failure" "The $serviceName service is running. Use stop_service=true to allow upgrade."
}
}
}

# Resolve "latest" version if requested
if ($version -eq "latest") {
$version = '8.23.1'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack to get around that there's no latest versioned msi to download.

If the downloads site had a symlinked openvox-agent-latest-x64.msi this would be unnecessary

}

# Build download URL
$baseUrl = "https://artifacts.voxpupuli.org/downloads/windows/$collection"
$installer = "$($agent_package)-$($version)-x64.msi"
$url = "$baseUrl/$installer"
$installerPath = Join-Path $env:TEMP $installer
$installLog = Join-Path $env:TEMP "$($agent_package)-install.log"

# Download installer
Write-Verbose "Downloading from $url"
Invoke-WebRequest -Uri $url -OutFile $installerPath

# Install package silently
Start-Process "msiexec.exe" -ArgumentList "/i `"$installerPath`" /qn /norestart /log `"$installLog`"" -Wait

# Cleanup downloaded artifacts
Remove-Item -Path $installerPath -ErrorAction SilentlyContinue
Remove-Item -Path $installLog -ErrorAction SilentlyContinue

# Restart service if previously running
if ($service -and $stop_service) {
Write-Verbose "Restarting $serviceName service."
Start-Service -Name $serviceName -ErrorAction SilentlyContinue
}

# Return success result
Write-Result "success" "$agent_package $version installed successfully." @{
package = $agent_package
version = $newInstall.DisplayVersion
source = $url
}

} catch {
Write-Result "failure" $_.Exception.Message
}