Skip to content

MSI installer for PowerShell Gallery #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 25, 2015
Merged
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
19 changes: 12 additions & 7 deletions setup-powershellget/Setup/ShortcutStartup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@ Finalizing installation of Azure PowerShell.
Installing Azure Modules from PowerShell Gallery.
This may take some time...
"@
$env:PSModulePath = "$env:HOME\Documents\WindowsPowerShell\Modules;$env:ProgramFiles\WindowsPowerShell\Modules;$env:SystemRoot\system32\WindowsPowerShell\v1.0\Modules\"

Copy link
Member

Choose a reason for hiding this comment

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

nit: remove extra spaces

Import-Module PackageManagement
Get-PackageProvider -Name NuGet -ForceBootstrap

$result = Get-PackageProvider -Name NuGet -ForceBootstrap

Import-Module PowerShellGet

$NuGetPublishingSource = $env:NuGetPublishingSource
if ([string]::IsNullOrWhiteSpace($NuGetPublishingSource)) {
Install-Module AzureRM -Repository $NuGetPublishingSource
} else {
Install-Module AzureRM
}
Install-Module AzureRM
Write-Output "AzureRM $((Get-InstalledModule -Name AzureRM)[0].Version) installed..."
Update-AzureRM
} else {
cd c:\
$welcomeMessage = @"
For a list of all Azure cmdlets type 'help azure'.
For a list of Azure Pack cmdlets type 'Get-Command *wapack*'.

To use Azure Service Management cmdlets please execute the following cmdlet:
Install-Module Azure
"@
Write-Output $welcomeMessage

Expand Down
85 changes: 56 additions & 29 deletions tools/AzureRM/AzureRM.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
$AzureRMModules = @{
"Azure.Storage" = "0.9.8";
"AzureRM.ApiManagement" = "0.9.8";
"AzureRM.Automation" = "0.9.8";
"AzureRM.Backup" = "0.9.8";
"AzureRM.Batch" = "0.9.8";
"AzureRM.Compute" = "0.9.8";
"AzureRM.DataFactories" = "0.9.8";
"AzureRM.Dns" = "0.9.8";
"AzureRM.HDInsight" = "0.9.8";
"AzureRM.Insights" = "0.9.8";
"AzureRM.KeyVault" = "0.9.8";
"AzureRM.Network" = "0.9.8";
"AzureRM.OperationalInsights" = "0.9.8";
"AzureRM.Profile" = "0.9.8";
"AzureRM.RedisCache" = "0.9.8";
"AzureRM.Resources" = "0.9.8";
"AzureRM.SiteRecovery" = "0.9.8";
"AzureRM.Sql" = "0.9.8";
"AzureRM.Storage" = "0.9.8";
"AzureRM.StreamAnalytics" = "0.9.8";
"AzureRM.Tags" = "0.9.8";
"AzureRM.TrafficManager" = "0.9.8";
"AzureRM.UsageAggregates" = "0.9.8";
"AzureRM.Websites" = "0.9.8"
}

<#
.Synopsis
Install Azure Resource Manager cmdlet modules
Expand All @@ -13,36 +40,36 @@
#>
function Update-AzureRM
{
param(
[Parameter(Position=0, Mandatory = $false)]
[string]
$Repository,

[Parameter(Position=1, Mandatory = $false)]
[ValidateSet("CurrentUser","AllUsers")]
[string]
$Scope)
param(
[Parameter(Position=0; Mandatory = $false)]
[string]
$Repository;

if ([string]::IsNullOrWhiteSpace($Scope))
{
$Scope = "AllUsers"
}
[Parameter(Position=1; Mandatory = $false)]
[ValidateSet("CurrentUser";"AllUsers")]
[string]
$Scope)

Install-Module AzureRM.Profile -Repository $Repository
if ([string]::IsNullOrWhiteSpace($Repository))
{
$modules = Find-Module -Name AzureRM.* | Where-Object {$_.Name -ne "AzureRM" -and $_.Name -ne "AzureRM.Profile"}
} else {
$modules = Find-Module -Repository $Repository | Where-Object {$_.Name -like "AzureRM.*" -and $_.Name -ne "AzureRM" -and $_.Name -ne "AzureRM.Profile"}
}
if ([string]::IsNullOrWhiteSpace($Scope))
{
$Scope = "AllUsers"
}

Write-Output "Installing $($modules.Length) AzureRM modules. This may take a few minutes."
Write-Output "Installing AzureRM modules."

$result = $modules | ForEach {
Start-Job -Name $_.Name -ScriptBlock {
Install-Module -Name $args[0] -Repository $args[1] -Scope $args[2]
Write-Output "$($args[0]) installed..."
} -ArgumentList $_.Name, $Repository, $Scope }

$modules | ForEach {Get-Job -Name $_.Name | Wait-Job | Receive-Job }
}
$result = $AzureRMModules | ForEach {
Start-Job -Name $_ -ScriptBlock {
if ([string]::IsNullOrWhiteSpace($args[1]))
{
Install-Module -Name $args[0] -Scope $args[2]
Copy link
Member

Choose a reason for hiding this comment

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

Don't we want to use maxversion /minversion settings?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a current work in progress

} else {
Install-Module -Name $args[0] -Repository $args[1] -Scope $args[2]
}
$v = (Get-InstalledModule -Name $args[0])[0].Version.ToString()
Write-Output "$($args[0]) $v installed..."
} -ArgumentList $_; $Repository; $Scope }

$AzureRMModules | ForEach {Get-Job -Name $_ | Wait-Job | Receive-Job }
}
New-Alias -Name Install-AzureRM -Value Update-AzureRM
Export-ModuleMember -function * -Alias *
42 changes: 26 additions & 16 deletions tools/PublishModules.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,43 @@
param(
[Parameter(Mandatory = $false, Position = 0)]
[string] $buildConfig,
[Parameter(Mandatory = $false, Position = 1)]
[Parameter(Mandatory = $false, Position = 1)]
[string] $apiKey,
[Parameter(Mandatory = $false, Position = 2)]
[Parameter(Mandatory = $false, Position = 2)]
[string] $repositoryLocation
)

if ([string]::IsNullOrEmpty($buildConfig))
{
Write-Verbose "Setting build configuration to 'Release'"
$buildConfig = 'Release'
Write-Verbose "Setting build configuration to 'Release'"
$buildConfig = "Release"
}

if ([string]::IsNullOrEmpty($repositoryLocation))
{
Write-Verbose "Setting repository location to 'http://psget/PSGallery/api/v2/'"
$repositoryLocation = 'http://psget/PSGallery/api/v2/'
Write-Verbose "Setting repository location to 'https://dtlgalleryint.cloudapp.net/api/v2'"

$repositoryLocation = "https://dtlgalleryint.cloudapp.net/api/v2"
}


$packageFolder = "$PSScriptRoot\..\src\Package"

$repoName = $(New-Guid).ToString()
Register-PSRepository -Name $repoName -SourceLocation $repositoryLocation -PublishLocation $repositoryLocation -InstallationPolicy Trusted
$repo = Get-PSRepository | where { $_.SourceLocation -eq $repositoryLocation }
if ($repo -ne $null) {
$repoName = $repo.Name
} else {
$repoName = $(New-Guid).ToString()
Register-PSRepository -Name $repoName -SourceLocation $repositoryLocation -PublishLocation $repositoryLocation/package -InstallationPolicy Trusted
}
$modulePath = "$packageFolder\$buildConfig\ServiceManagement\Azure"
# Publish Azure module
Write-Host "Publishing Azure module from $modulePath"
Publish-Module -Path $modulePath -NuGetApiKey $apiKey -Repository $repoName
Publish-Module -Path $modulePath -NuGetApiKey $apiKey -Repository $repoName -Tags ("Azure", "AzureRM")
# Publish AzureRM module
$modulePath = "$PSScriptRoot\AzureRM"
Write-Host "Publishing AzureRM module from $modulePath"
Publish-Module -Path $modulePath -NuGetApiKey $apiKey -Repository $repoName -Tags ("Azure", "AzureRM")
Write-Host "Published Azure module"
# Publish AzureRM.Profile module
Write-Host "Publishing AzureRM.Profile module from $modulePath"
Expand All @@ -50,11 +61,10 @@ Write-Host "Published AzureRM.Profile module"
# Publish AzureRM modules
$resourceManagerModules = Get-ChildItem -Path "$packageFolder\$buildConfig\ResourceManager\AzureResourceManager" -Directory
foreach ($module in $resourceManagerModules) {
if ($module -ne "AzureRM.Profile") {
$modulePath = $module.FullName
Write-Host "Publishing $module module from $modulePath"
Publish-Module -Path $modulePath -NuGetApiKey $apiKey -Repository $repoName
Write-Host "Published $module module"
}
if ($module -ne "AzureRM.Profile") {
$modulePath = $module.FullName
Write-Host "Publishing $module module from $modulePath"
Publish-Module -Path $modulePath -NuGetApiKey $apiKey -Repository $repoName -Tags ("Azure", "AzureRM")
Write-Host "Published $module module"
}
}
Unregister-PSRepository -Name $repoName