1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
function Get-ProjectMetadata {
<#
.SYNOPSIS
Get metadata for a Chef Software, Inc. project
.DESCRIPTION
Get metadata for project
.EXAMPLE
iex (new-object net.webclient).downloadstring('<%= base_url %>/install.ps1'); Get-ProjectMetadata -project chef -channel stable
Gets the download url and SHA256 checksum for the latest stable release of Chef.
.EXAMPLE
iex (irm '<%= base_url %>/install.ps1'); Get-ProjectMetadata -project chefdk -channel stable -version 0.8.0
Gets the download url and SHA256 checksum for ChefDK 0.8.0.
#>
[cmdletbinding()]
param (
# Base url to retrieve metadata from.
[uri]$base_server_uri = '<%= base_url %>',
[string]
# Project to install
[string]
$project = 'chef',
# Version of the application to install
# This parameter is optional, if not supplied it will provide the latest version,
# and if an iteration number is not specified, it will grab the latest available iteration.
# Partial version numbers are also acceptable (using v=11
# will grab the latest 11.x client which matches the other flags).
[string]
$version,
# Release channel to install from
[validateset('current', 'stable', 'unstable')]
[string]
$channel = 'stable',
# The following legacy switches are just aliases for the current channel
[switch]
$prerelease,
[switch]
$nightlies,
[validateset('auto', 'i386', 'x86_64')]
[string]
$architecture = 'auto'
)
# The following legacy switches are just aliases for the current channel
if (($prerelease -eq $true)) { $channel = 'current'}
if (($nightlies -eq $true)) { $channel = 'current'}
# PowerShell is only on Windows ATM
$platform = 'windows'
Write-Verbose "Platform: $platform"
$platform_version = Get-PlatformVersion
Write-Verbose "Platform Version: $platform_version"
if ($architecture -eq 'auto') {
$architecture = Get-PlatformArchitecture
}
Write-Verbose "Architecture: $architecture"
Write-Verbose "Project: $project"
$metadata_base_url = "/$($channel)/$($project)/metadata"
$metadata_array = ("?v=$($version)",
"p=$platform",
"pv=$platform_version",
"m=$architecture")
$metadata_base_url += [string]::join('&', $metadata_array)
$metadata_url = new-uri $base_server_uri $metadata_base_url
Write-Verbose "Downloading $project details from $metadata_url"
$package_metadata = (Get-WebContent $metadata_url).trim() -split '\n' |
foreach { $hash = @{} } {$key, $value = $_ -split '\s+'; $hash.Add($key, $value)} {$hash}
Write-Verbose "Project details: "
foreach ($key in $package_metadata.keys) {
Write-Verbose "`t$key = $($package_metadata[$key])"
}
$package_metadata
}
|