From e7a8e6a597779e21fb24f5032fa2645285f9ec1a Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Mon, 14 Sep 2020 16:25:33 +0300 Subject: [PATCH] install powershell modules --- .../SoftwareReport.Databases.psm1 | 4 +-- .../installers/Install-PowerShellModules.ps1 | 31 +++++++++++++++++++ images/linux/toolsets/toolset-1604.json | 4 +++ images/linux/toolsets/toolset-1804.json | 4 +++ images/linux/toolsets/toolset-2004.json | 4 +++ images/linux/ubuntu1604.json | 12 ++++++- images/linux/ubuntu1804.json | 12 ++++++- images/linux/ubuntu2004.json | 12 ++++++- 8 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 images/linux/scripts/installers/Install-PowerShellModules.ps1 diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Databases.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Databases.psm1 index 7c1605cc..47f04de2 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Databases.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Databases.psm1 @@ -14,8 +14,8 @@ function Get-SqliteVersion { } function Get-MySQLVersion { - $mySqlVersion = (mysql --version).Split("/usr/bin/")[1] - return "MySQL ($mySqlVersion)" + $mySQLVersion = mysqld --version | Take-OutputPart -Part 2 | Take-OutputPart -Part 0 -Delimiter "-" + return "MySQL ($mySQLVersion)" } function Build-MySQLSection { diff --git a/images/linux/scripts/installers/Install-PowerShellModules.ps1 b/images/linux/scripts/installers/Install-PowerShellModules.ps1 new file mode 100644 index 00000000..ed100e3c --- /dev/null +++ b/images/linux/scripts/installers/Install-PowerShellModules.ps1 @@ -0,0 +1,31 @@ +$ErrorActionPreference = "Stop" + +function Get-ToolsetContent +{ + $toolset = Join-Path $env:INSTALLER_SCRIPT_FOLDER "toolset.json" + Get-Content $toolset -Raw | ConvertFrom-Json +} + +# Specifies the installation policy +Set-PSRepository -InstallationPolicy Trusted -Name PSGallery + +# Install PowerShell modules +$modules = (Get-ToolsetContent).powershellModules + +foreach($module in $modules) +{ + $moduleName = $module.name + Write-Host "Installing ${moduleName} module" + + if ($module.versions) + { + foreach ($version in $module.versions) + { + Write-Host " - $version" + Install-Module -Name $moduleName -RequiredVersion $version -Scope AllUsers -SkipPublisherCheck -Force + } + continue + } + + Install-Module -Name $moduleName -Scope AllUsers -SkipPublisherCheck -Force +} diff --git a/images/linux/toolsets/toolset-1604.json b/images/linux/toolsets/toolset-1604.json index 1204f2a8..c8b2b151 100644 --- a/images/linux/toolsets/toolset-1604.json +++ b/images/linux/toolsets/toolset-1604.json @@ -91,6 +91,10 @@ "platform-tools" ] }, + "powershellModules": [ + {"name": "MarkdownPS"}, + {"name": "Pester"} + ], "azureModules": [ { "name": "az", diff --git a/images/linux/toolsets/toolset-1804.json b/images/linux/toolsets/toolset-1804.json index 2c399c8f..6311cc1a 100644 --- a/images/linux/toolsets/toolset-1804.json +++ b/images/linux/toolsets/toolset-1804.json @@ -87,6 +87,10 @@ "platform-tools" ] }, + "powershellModules": [ + {"name": "MarkdownPS"}, + {"name": "Pester"} + ], "azureModules": [ { "name": "az", diff --git a/images/linux/toolsets/toolset-2004.json b/images/linux/toolsets/toolset-2004.json index 1162b713..5ac23025 100644 --- a/images/linux/toolsets/toolset-2004.json +++ b/images/linux/toolsets/toolset-2004.json @@ -68,6 +68,10 @@ "platform-tools" ] }, + "powershellModules": [ + {"name": "MarkdownPS"}, + {"name": "Pester"} + ], "apt": { "common_packages": [ "dbus", diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 7d180a0a..27cc6b0b 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -292,10 +292,20 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts":[ + "{{template_dir}}/scripts/installers/Install-PowerShellModules.ps1" + ], + "environment_vars": [ + "INSTALLER_SCRIPT_FOLDER={{user `installer_script_folder`}}" + ], + "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" + }, { "type": "shell", "inline": [ - "sudo pwsh -File {{user `image_folder`}}/SoftwareReport/SoftwareReport.Generator.ps1 -OutputDirectory {{user `image_folder`}}" + "pwsh -File {{user `image_folder`}}/SoftwareReport/SoftwareReport.Generator.ps1 -OutputDirectory {{user `image_folder`}}" ], "environment_vars":[ "IMAGE_VERSION={{user `image_version`}}", diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index c5265b9f..05f4a269 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -296,10 +296,20 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts":[ + "{{template_dir}}/scripts/installers/Install-PowerShellModules.ps1" + ], + "environment_vars": [ + "INSTALLER_SCRIPT_FOLDER={{user `installer_script_folder`}}" + ], + "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" + }, { "type": "shell", "inline": [ - "sudo pwsh -File {{user `image_folder`}}/SoftwareReport/SoftwareReport.Generator.ps1 -OutputDirectory {{user `image_folder`}}" + "pwsh -File {{user `image_folder`}}/SoftwareReport/SoftwareReport.Generator.ps1 -OutputDirectory {{user `image_folder`}}" ], "environment_vars":[ "IMAGE_VERSION={{user `image_version`}}", diff --git a/images/linux/ubuntu2004.json b/images/linux/ubuntu2004.json index eccace5f..4a4ff5c5 100644 --- a/images/linux/ubuntu2004.json +++ b/images/linux/ubuntu2004.json @@ -298,10 +298,20 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts":[ + "{{template_dir}}/scripts/installers/Install-PowerShellModules.ps1" + ], + "environment_vars": [ + "INSTALLER_SCRIPT_FOLDER={{user `installer_script_folder`}}" + ], + "execute_command": "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" + }, { "type": "shell", "inline": [ - "sudo pwsh -File {{user `image_folder`}}/SoftwareReport/SoftwareReport.Generator.ps1 -OutputDirectory {{user `image_folder`}}" + "pwsh -File {{user `image_folder`}}/SoftwareReport/SoftwareReport.Generator.ps1 -OutputDirectory {{user `image_folder`}}" ], "environment_vars":[ "IMAGE_VERSION={{user `image_version`}}",