From 6164543b68b97972e6f34d3a0a0902d76e4b9443 Mon Sep 17 00:00:00 2001 From: James Ruskin Date: Thu, 2 Nov 2023 18:34:55 +0000 Subject: [PATCH 1/3] (dbatools-library.powershell) Adds dbatools-library.powershell Package This package is required by >2.0 versions of dbatools. We discussed packaging the library into the dbatools package, but as it is on a separate update cadence (and published as a separate module) it made most sense to create a new package. --- .../dbatools-library.powershell/README.md | 9 +++ .../dbatools-library.powershell.nuspec | 75 +++++++++++++++++++ .../tools/.skipAutoUninstaller | 0 .../tools/LICENSE.txt | 25 +++++++ .../tools/VERIFICATION.txt | 14 ++++ .../tools/chocolateyBeforeModify.ps1 | 21 ++++++ .../tools/chocolateyInstall.ps1 | 38 ++++++++++ .../tools/chocolateyUninstall.ps1 | 17 +++++ .../dbatools-library.powershell/update.ps1 | 46 ++++++++++++ 9 files changed, 245 insertions(+) create mode 100644 automatic/dbatools-library.powershell/README.md create mode 100644 automatic/dbatools-library.powershell/dbatools-library.powershell.nuspec create mode 100644 automatic/dbatools-library.powershell/tools/.skipAutoUninstaller create mode 100644 automatic/dbatools-library.powershell/tools/LICENSE.txt create mode 100644 automatic/dbatools-library.powershell/tools/VERIFICATION.txt create mode 100644 automatic/dbatools-library.powershell/tools/chocolateyBeforeModify.ps1 create mode 100644 automatic/dbatools-library.powershell/tools/chocolateyInstall.ps1 create mode 100644 automatic/dbatools-library.powershell/tools/chocolateyUninstall.ps1 create mode 100644 automatic/dbatools-library.powershell/update.ps1 diff --git a/automatic/dbatools-library.powershell/README.md b/automatic/dbatools-library.powershell/README.md new file mode 100644 index 00000000..d052f8e0 --- /dev/null +++ b/automatic/dbatools-library.powershell/README.md @@ -0,0 +1,9 @@ +# ![dbatools Logo](https://cdn.jsdelivr.net/gh/pauby/ChocoPackages@306a1af5/icons/dbatools.png "dbatools")[dbatools](https://chocolatey.org/packages/dbatools-library.powershell) + +dbatools is sort of like a command-line SQL Server Management Studio. The project initially started out as Start-SqlMigration.ps1, but has now grown into a collection of over 600 commands that help automate SQL Server tasks and encourage best practices. + +This module is the library enabling cross-platform usage of the dbatools module. + +_**NOTE: This module requires a minimum of PowerShell v3.**_ + +**NOTE**: This is an automatically updated package. If you find it is out of date by more than a week, please contact the maintainer(s) and let them know the package is no longer updating correctly. \ No newline at end of file diff --git a/automatic/dbatools-library.powershell/dbatools-library.powershell.nuspec b/automatic/dbatools-library.powershell/dbatools-library.powershell.nuspec new file mode 100644 index 00000000..65ce8d99 --- /dev/null +++ b/automatic/dbatools-library.powershell/dbatools-library.powershell.nuspec @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + dbatools-library.powershell + 2023.9.21 + https://github.com/pauby/ChocoPackages/tree/master/automatic/dbatools-library.powershell + + pauby jpruskin + + + + dbatools.library (PowerShell Module) + the dbatools team + + https://dbatools.io + https://cdn.jsdelivr.net/gh/pauby/ChocoPackages@306a1af5/icons/dbatools.png + 2022 Data Platform Community + + https://github.com/dataplat/dbatools/blob/master/license + false + https://github.com/dataplat/dbatools.library + https://docs.dbatools.io/ + + https://github.com/dataplat/dbatools.library/issues + admin powershell module template dba sqlserver migrations sql dba databases mac linux core smo + The library that powers dbatools, the community module for SQL Server Pros. + dbatools is sort of like a command-line SQL Server Management Studio. The project initially started out as Start-SqlMigration.ps1, but has now grown into a collection of over 600 commands that help automate SQL Server tasks and encourage best practices. + +This module is the library enabling cross-platform usage of the dbatools module. + +_**NOTE: This module requires a minimum of PowerShell v3.**_ + +**NOTE**: This is an automatically updated package. If you find it is out of date by more than a week, please contact the maintainer(s) and let them know the package is no longer updating correctly. + + https://github.com/dataplat/dbatools.library/releases + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/automatic/dbatools-library.powershell/tools/.skipAutoUninstaller b/automatic/dbatools-library.powershell/tools/.skipAutoUninstaller new file mode 100644 index 00000000..e69de29b diff --git a/automatic/dbatools-library.powershell/tools/LICENSE.txt b/automatic/dbatools-library.powershell/tools/LICENSE.txt new file mode 100644 index 00000000..f2911680 --- /dev/null +++ b/automatic/dbatools-library.powershell/tools/LICENSE.txt @@ -0,0 +1,25 @@ +From: https://raw.githubusercontent.com/dataplat/dbatools.library/main/LICENSE + +LICENSE + +MIT License + +Copyright (c) 2022 Data Platform Community + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/automatic/dbatools-library.powershell/tools/VERIFICATION.txt b/automatic/dbatools-library.powershell/tools/VERIFICATION.txt new file mode 100644 index 00000000..39d9d98a --- /dev/null +++ b/automatic/dbatools-library.powershell/tools/VERIFICATION.txt @@ -0,0 +1,14 @@ +VERIFICATION +Verification is intended to assist the Chocolatey moderators and community in verifying that this package's contents are trustworthy. + +To verify the files using the project source: + +1. Please go to the project source location (https://github.com/dataplat/dbatools.library) and download the source files; +2. Build the source to create the binary files to verify; +3. Use Get-FileHash -Path to get the file hash value from both the built file (from step 1 above) and the file from the dbatools.zip within the package and compare them; + +Alternatively you can download the module from the PowerShell Gallery ... + + Save-Module -Name dbatools -Path + +... and compare the files from the package against those in the installed module. Again use Get-FileHash -Path to retrieve those hash values. \ No newline at end of file diff --git a/automatic/dbatools-library.powershell/tools/chocolateyBeforeModify.ps1 b/automatic/dbatools-library.powershell/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 00000000..851f437b --- /dev/null +++ b/automatic/dbatools-library.powershell/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1,21 @@ +$ErrorActionPreference = 'Stop' + +$moduleName = 'dbatools.library' # this could be different from package name + +$module = Get-Module -Name $moduleName +if ($module) { + Write-Verbose "Module '$moduleName' is imported into the session. Removing it." + Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue + + if ($lib = [appdomain]::CurrentDomain.GetAssemblies() | Where-Object FullName -like "dbatools, *") { + Write-Verbose "Found locked DLL files for module '$moduleName'." + $moduleDir = Split-Path $module.Path -Parent + if ($lib.Location -like "$moduleDir\*") { + Write-Warning @" +We have detected dbatools to be already imported from '$moduleDir' and the dll files have been locked and cannot be updated. +Please close all consoles that have dbatools imported (Remove-Module dbatools is NOT enough). +"@ + throw + } + } +} \ No newline at end of file diff --git a/automatic/dbatools-library.powershell/tools/chocolateyInstall.ps1 b/automatic/dbatools-library.powershell/tools/chocolateyInstall.ps1 new file mode 100644 index 00000000..f873a852 --- /dev/null +++ b/automatic/dbatools-library.powershell/tools/chocolateyInstall.ps1 @@ -0,0 +1,38 @@ +$ErrorActionPreference = 'Stop' + +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$moduleName = 'dbatools.library' # this may be different from the package name and different case + +if ($PSVersionTable.PSVersion.Major -lt 3) { + throw "$moduleName) module requires a minimum of PowerShell v3." +} + +# module may already be installed outside of Chocolatey +Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue + +$sourcePath = Join-Path -Path $toolsDir -ChildPath "$modulename.zip" +$destPath = Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell\Modules\$moduleName" + +if ($PSVersionTable.PSVersion.Major -ge 5) +{ + $destPath = Join-Path -Path $destPath -ChildPath $env:ChocolateyPackageVersion +} + +Write-Verbose "Creating destination directory '$destPath' for module." +New-Item -Path $destPath -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null + +Write-Verbose "Extracting '$moduleName' files from '$sourcePath' to '$destPath'." +Get-ChocolateyUnzip -FileFullPath $sourcePath -Destination $destPath + +if ($PSVersionTable.PSVersion.Major -lt 4) +{ + $modulePaths = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') -split ';' + if ($modulePaths -notcontains $destPath) + { + Write-Verbose "Adding '$destPath' to PSModulePath." + $newModulePath = @($destPath, $modulePaths) -join ';' + + [Environment]::SetEnvironmentVariable('PSModulePath', $newModulePath, 'Machine') + $env:PSModulePath = $newModulePath + } +} diff --git a/automatic/dbatools-library.powershell/tools/chocolateyUninstall.ps1 b/automatic/dbatools-library.powershell/tools/chocolateyUninstall.ps1 new file mode 100644 index 00000000..cd6a9694 --- /dev/null +++ b/automatic/dbatools-library.powershell/tools/chocolateyUninstall.ps1 @@ -0,0 +1,17 @@ +$ErrorActionPreference = 'Stop' + +$moduleName = 'dbatools.library' +$sourcePath = Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell\Modules\$moduleName" + +Write-Verbose "Removing all version of '$moduleName' from '$sourcePath'." +Remove-Item -Path $sourcePath -Recurse -Force -ErrorAction SilentlyContinue + +if ($PSVersionTable.PSVersion.Major -lt 4) { + $modulePaths = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') -split ';' + + Write-Verbose "Removing '$sourcePath' from PSModulePath." + $newModulePath = $modulePaths | Where-Object { $_ -ne $sourcePath } + + [Environment]::SetEnvironmentVariable('PSModulePath', $newModulePath, 'Machine') + $env:PSModulePath = $newModulePath +} \ No newline at end of file diff --git a/automatic/dbatools-library.powershell/update.ps1 b/automatic/dbatools-library.powershell/update.ps1 new file mode 100644 index 00000000..fc51a807 --- /dev/null +++ b/automatic/dbatools-library.powershell/update.ps1 @@ -0,0 +1,46 @@ +#import-module au + +. $PSScriptRoot\..\..\scripts\all.ps1 + +$moduleName = 'dbatools.library' + +function global:au_SearchReplace { + @{ + } +} + +function global:au_BeforeUpdate() { + do { + $tempPath = Join-Path -Path $env:TEMP -ChildPath ([GUID]::NewGuid()).ToString() + } + while (Test-Path $tempPath) + + New-Item -Path $tempPath -ItemType Directory | Out-Null + Save-Module -Name $moduleName -RequiredVersion $Latest.ModuleVersion -Path $tempPath + $modulePath = Join-Path -Path $tempPath -ChildPath "\$ModuleName\$($Latest.ModuleVersion)\" + + $zipPath = Join-Path -Path $tempPath -ChildPath "$moduleName.zip" + Compress-Archive -Path (Join-Path -Path $modulePath -ChildPath "*") -DestinationPath $zipPath -CompressionLevel Optimal + + $params = @{ + Path = $zipPath + Destination = "tools\" + Force = $true + } + Move-Item @params +} + +function global:au_AfterUpdate { + Set-DescriptionFromReadme -SkipFirst 2 +} + +function global:au_GetLatest { + $version = (Find-Module -Name $moduleName).Version.ToString() + + return @{ + Version = $version + ModuleVersion = $version + } +} + +update -ChecksumFor none \ No newline at end of file From b77f1ea4090037c429f958af82c8965ed0bd3cd6 Mon Sep 17 00:00:00 2001 From: James Ruskin Date: Thu, 2 Nov 2023 18:35:05 +0000 Subject: [PATCH 2/3] (dbatools) Updates dbatools to use dependency on dbatools.library Dbatools now has a library it is dependent on. This was not reflected in the package. This update to the package and update logic adds a dependency on the dbatools-library.powershell package, and ensures that on a new version of the dbatools package it should be pointing at the right new version of that package. --- automatic/dbatools/README.md | 2 +- automatic/dbatools/dbatools.nuspec | 33 +++++++++++++++--------------- automatic/dbatools/update.ps1 | 7 ++++++- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/automatic/dbatools/README.md b/automatic/dbatools/README.md index ebfe99c2..a7a10788 100644 --- a/automatic/dbatools/README.md +++ b/automatic/dbatools/README.md @@ -1,6 +1,6 @@ # ![dbatools Logo](https://cdn.jsdelivr.net/gh/pauby/ChocoPackages@306a1af5/icons/dbatools.png "dbatools")[dbatools](https://chocolatey.org/packages/dbatools) -dbatools is sort of like a command-line SQL Server Management Studio. The project initially started out as Start-SqlMigration.ps1, but has now grown into a collection of over 300 commands that help automate SQL Server tasks and encourage best practices. +dbatools is sort of like a command-line SQL Server Management Studio. The project initially started out as Start-SqlMigration.ps1, but has now grown into a collection of over 600 commands that help automate SQL Server tasks and encourage best practices. _**NOTE: This module requires a minimum of PowerShell v3.**_ diff --git a/automatic/dbatools/dbatools.nuspec b/automatic/dbatools/dbatools.nuspec index 1e79b12f..7c382cf4 100644 --- a/automatic/dbatools/dbatools.nuspec +++ b/automatic/dbatools/dbatools.nuspec @@ -3,11 +3,12 @@ @@ -20,10 +21,7 @@ This is a nuspec. It mostly adheres to https://docs.nuget.org/create/Nuspec-Refe dbatools - - - - 0.9.362 + 2.0.4 https://github.com/pauby/ChocoPackages/tree/master/automatic/dbatools pauby @@ -44,8 +42,8 @@ This is a nuspec. It mostly adheres to https://docs.nuget.org/create/Nuspec-Refe https://github.com/sqlcollaborative/dbatools/issues admin powershell module template dba sqlserver sql tools database - dbatools is sort of like a command-line SQL Server Management Studio. - dbatools logo dbatools is sort of like a command-line SQL Server Management Studio. The project initially started out as Start-SqlMigration.ps1, but has now grown into a collection of over 300 commands that help automate SQL Server tasks and encourage best practices. + dbatools is sort of like a command-line SQL Server Management Studio. + dbatools is sort of like a command-line SQL Server Management Studio. The project initially started out as Start-SqlMigration.ps1, but has now grown into a collection of over 600 commands that help automate SQL Server tasks and encourage best practices. _**NOTE: This module requires a minimum of PowerShell v3.**_ @@ -54,17 +52,20 @@ _**NOTE: This module requires a minimum of PowerShell v3.**_ https://github.com/sqlcollaborative/dbatools/releases - - - - - - - + + + + + + + + + + diff --git a/automatic/dbatools/update.ps1 b/automatic/dbatools/update.ps1 index d33409c3..b6a5b7fc 100644 --- a/automatic/dbatools/update.ps1 +++ b/automatic/dbatools/update.ps1 @@ -6,6 +6,9 @@ $moduleName = 'dbatools' function global:au_SearchReplace { @{ + "dbatools.nuspec" = @{ + '(\s+' = "`$1`"$($Latest.LibVersion)`" />" + } } } @@ -37,11 +40,13 @@ function global:au_AfterUpdate { } function global:au_GetLatest { - $version = (Find-Module -Name $moduleName).Version.ToString() + $module = Find-Module -Name $moduleName + $version = $module.Version.ToString() return @{ Version = $version ModuleVersion = $version + LibVersion = $module.Dependencies.Where{$_.Name -eq 'dbatools.library'}.MinimumVersion } } From 56e42b8d97a8e3a601fa654a2bdc66af2a272c16 Mon Sep 17 00:00:00 2001 From: James Ruskin Date: Fri, 30 Jun 2023 09:42:10 +0100 Subject: [PATCH 3/3] (dbatools, dbatools-library.powershell) Fixes Install Script Handling of Patchfix When testing the packages, forced patchfix versions failed to import due to the module version not matching the module folder path. This should fix that. --- .../tools/chocolateyInstall.ps1 | 3 ++- automatic/dbatools-library.powershell/update.ps1 | 12 ++++++++++++ automatic/dbatools/tools/chocolateyInstall.ps1 | 3 ++- automatic/dbatools/update.ps1 | 12 ++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/automatic/dbatools-library.powershell/tools/chocolateyInstall.ps1 b/automatic/dbatools-library.powershell/tools/chocolateyInstall.ps1 index f873a852..74063ab4 100644 --- a/automatic/dbatools-library.powershell/tools/chocolateyInstall.ps1 +++ b/automatic/dbatools-library.powershell/tools/chocolateyInstall.ps1 @@ -2,6 +2,7 @@ $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" $moduleName = 'dbatools.library' # this may be different from the package name and different case +$moduleVersion = $env:ChocolateyPackageVersion if ($PSVersionTable.PSVersion.Major -lt 3) { throw "$moduleName) module requires a minimum of PowerShell v3." @@ -15,7 +16,7 @@ $destPath = Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell\Mo if ($PSVersionTable.PSVersion.Major -ge 5) { - $destPath = Join-Path -Path $destPath -ChildPath $env:ChocolateyPackageVersion + $destPath = Join-Path -Path $destPath -ChildPath $moduleVersion } Write-Verbose "Creating destination directory '$destPath' for module." diff --git a/automatic/dbatools-library.powershell/update.ps1 b/automatic/dbatools-library.powershell/update.ps1 index fc51a807..40a37217 100644 --- a/automatic/dbatools-library.powershell/update.ps1 +++ b/automatic/dbatools-library.powershell/update.ps1 @@ -6,6 +6,18 @@ $moduleName = 'dbatools.library' function global:au_SearchReplace { @{ + "tools\chocolateyInstall.ps1" = @{ + # We use ChocolateyPackageVersion to minimise changes to the package code - + # If using a patchfix version, use the moduleversion instead of the packageversion. + '(\s*\$moduleVersion\s*=\s*)(\$env:ChocolateyPackageVersion|(["'']?).+["'']?)' = "`${1}$( + if ($Latest.ModuleVersion -ne $Latest.Version) { + $Quote = if ($Matches.'3') {'${3}'} else {"'"} + $Quote + $Latest.ModuleVersion + $Quote + } else { + '$env:ChocolateyPackageVersion' + } + )" + } } } diff --git a/automatic/dbatools/tools/chocolateyInstall.ps1 b/automatic/dbatools/tools/chocolateyInstall.ps1 index 85ca79ef..1d14a5d6 100644 --- a/automatic/dbatools/tools/chocolateyInstall.ps1 +++ b/automatic/dbatools/tools/chocolateyInstall.ps1 @@ -2,6 +2,7 @@ $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" $moduleName = 'dbatools' # this may be different from the package name and different case +$moduleVersion = $env:ChocolateyPackageVersion if ($PSVersionTable.PSVersion.Major -lt 3) { throw "$moduleName) module requires a minimum of PowerShell v3." @@ -15,7 +16,7 @@ $destPath = Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell\Mo if ($PSVersionTable.PSVersion.Major -ge 5) { - $destPath = Join-Path -Path $destPath -ChildPath $env:ChocolateyPackageVersion + $destPath = Join-Path -Path $destPath -ChildPath $moduleVersion } Write-Verbose "Creating destination directory '$destPath' for module." diff --git a/automatic/dbatools/update.ps1 b/automatic/dbatools/update.ps1 index b6a5b7fc..2a98b15e 100644 --- a/automatic/dbatools/update.ps1 +++ b/automatic/dbatools/update.ps1 @@ -9,6 +9,18 @@ function global:au_SearchReplace { "dbatools.nuspec" = @{ '(\s+' = "`$1`"$($Latest.LibVersion)`" />" } + "tools\chocolateyInstall.ps1" = @{ + # We use ChocolateyPackageVersion to minimise changes to the package code - + # If using a patchfix version, use the moduleversion instead of the packageversion. + '(\s*\$moduleVersion\s*=\s*)(\$env:ChocolateyPackageVersion|(["'']?).+["'']?)' = "`${1}$( + if ($Latest.ModuleVersion -ne $Latest.Version) { + $Quote = if ($Matches.'3') {'${3}'} else {"'"} + $Quote + $Latest.ModuleVersion + $Quote + } else { + '$env:ChocolateyPackageVersion' + } + )" + } } }