diff --git a/_scripts/SqlServerCumulativeUpdates.ps1 b/_scripts/SqlServerCumulativeUpdates.ps1
new file mode 100644
index 00000000..e7381c52
--- /dev/null
+++ b/_scripts/SqlServerCumulativeUpdates.ps1
@@ -0,0 +1,72 @@
+. ..\_scripts\Submit-VirusTotal.ps1
+
+
+function SearchReplace($MajorVersion, $Latest) {
+ @{
+ # softwareName = 'Hotfix 3026 for Microsoft SQL Server*(KB4229789)*'
+ 'tools\chocolateyInstall.ps1' = @{
+ "(^[$]url\s*=\s*)('.*')" = "`$1'$($Latest.URL64)'"
+ "(^[$]checksum\s*=\s*)('.*')" = "`$1'$($Latest.Checksum64)'"
+ "(^[$]softwareName\s*=\s*)('.*')" = "`$1'Hotfix $($Latest.Build) for SQL Server $MajorVersion*(KB$($Latest.KB))*'"
+ }
+ }
+}
+
+function GetLatest($downloadId, $MajorVersion) {
+ $response = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/details.aspx?id=$downloadId" -ErrorAction Ignore
+
+ $url = $response.Content |
+ Select-String -AllMatches -Pattern "(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?" |
+ ForEach-Object { $_.Matches.Value } |
+ Select-string "\.exe$" |
+ Select-Object -First 1 -ExpandProperty Line
+
+ #
+ if ($response.Content -match "") {
+ $cu = $Matches[1]
+ $kb = $Matches[2]
+ } else {
+ return @{}
+ }
+
+ # Find full version number
+ if ($response.Content -match "\d+\.\d+\.\d+\.\d+") {
+ $version = $Matches[0]
+ } else {
+ return @{}
+ }
+
+ $v = [Version] $version
+ $Latest = @{
+ URL64 = $url
+ Version = $version
+ KB = $kb
+ CU = $cu
+ Build = $v.Build
+ }
+
+ # Check for a partial page update (has happened in the past) where the download URL doesn't change.
+ # We can't do this from global:au_BeforeUpdate, because the checksum stuff has already been run (and updated the chocolateyinstall.ps1 script)
+ $toolsContent = Get-Content .\tools\chocolateyinstall.ps1 -Encoding utf8
+
+ $matched = ($toolsContent -match "(^[$]url\s*=\s*)('.*')") | Select-Object -First 1
+
+ if ($matched -match "(^[$]url\s*=\s*)'(.*)'") {
+ $script:previousUrl = $Matches[2]
+ }
+ return $Latest
+}
+
+function AfterUpdate ($Package, $Latest, $MajorVersion) {
+
+ if (($Package.RemoteVersion -ne $Package.NuspecVersion) -and ($script:previousUrl -eq $Latest.URL64)) {
+ # URL didn't change, game over!
+ throw "New version $($Package.NuspecVersion) but URL ($($script:previousUrl)) didn't change"
+ }
+
+ $Package.NuspecXml.package.metadata.releaseNotes = "https://support.microsoft.com/help/$($Latest.KB)"
+ $Package.NuspecXml.package.metadata.title = "Microsoft SQL Server $MajorVersion Cumulative Update $($Latest.CU)"
+ $Package.SaveNuspec()
+
+ VirusTotal_AfterUpdate $Package
+}
\ No newline at end of file
diff --git a/sql-server-2017-cumulative-update/update.ps1 b/sql-server-2017-cumulative-update/update.ps1
index 0f412414..b8342d82 100644
--- a/sql-server-2017-cumulative-update/update.ps1
+++ b/sql-server-2017-cumulative-update/update.ps1
@@ -1,76 +1,18 @@
Import-Module chocolatey-au
-. ..\_scripts\Submit-VirusTotal.ps1
+. ..\_scripts\SqlServerCumulativeUpdates.ps1
function global:au_SearchReplace {
- @{
- # softwareName = 'Hotfix 3026 for Microsoft SQL Server*(KB4229789)*'
- 'tools\chocolateyInstall.ps1' = @{
- "(^[$]url\s*=\s*)('.*')" = "`$1'$($Latest.URL64)'"
- "(^[$]checksum\s*=\s*)('.*')" = "`$1'$($Latest.Checksum64)'"
- "(^[$]softwareName\s*=\s*)('.*')" = "`$1'Hotfix $($Latest.Build) for SQL Server 2017*(KB$($Latest.KB))*'"
- }
- }
+ return SearchReplace 2022 $Latest
}
function global:au_GetLatest {
- $downloadId = "56128"
- $response = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/confirmation.aspx?id=$downloadId" -ErrorAction Ignore
-
- $url = $response.Content |
- Select-String -AllMatches -Pattern "(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?" |
- ForEach-Object { $_.Matches.Value } |
- Select-string "\.exe$" |
- Select-Object -First 1 -ExpandProperty Line
-
- #
- if ($response.Content -match "") {
- $cu = $Matches[1]
- $kb = $Matches[2]
- } else {
- return @{}
- }
-
- $response = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/details.aspx?id=$downloadId"
-
- if ($response.Content -match "\d+\.\d+\.\d+\.\d+") {
- $version = $Matches[0]
- } else {
- return @{}
- }
-
- $v = [Version] $version
- $Latest = @{
- URL64 = $url
- Version = $version
- KB = $kb
- CU = $cu
- Build = $v.Build
- }
-
- # We can't do this from global:au_BeforeUpdate, because the checksum stuff has already been run (and updated the chocolateyinstall.ps1 script)
- $toolsContent = Get-Content .\tools\chocolateyinstall.ps1 -Encoding utf8
-
- $matched = ($toolsContent -match "(^[$]url\s*=\s*)('.*')") | Select-Object -First 1
-
- if ($matched -match "(^[$]url\s*=\s*)'(.*)'") {
- $script:previousUrl = $Matches[2]
- }
- return $Latest
+ return GetLatest 56128 2017
}
function global:au_AfterUpdate ($Package) {
- if (($Package.RemoteVersion -ne $Package.NuspecVersion) -and ($script:previousUrl -eq $Latest.URL64)) {
- # URL didn't change, game over!
- throw "New version $($Package.NuspecVersion) but URL ($($script:previousUrl)) didn't change"
- }
-
- $Package.NuspecXml.package.metadata.releaseNotes = "https://support.microsoft.com/help/$($Latest.KB)"
- $Package.NuspecXml.package.metadata.title = "Microsoft SQL Server 2017 Cumulative Update $($Latest.CU)"
- $Package.SaveNuspec()
-
- VirusTotal_AfterUpdate $Package
+ AfterUpdate $Package $Latest 2017
}
update -ChecksumFor 64
diff --git a/sql-server-2019-cumulative-update/update.ps1 b/sql-server-2019-cumulative-update/update.ps1
index dd29be8a..ef45413e 100644
--- a/sql-server-2019-cumulative-update/update.ps1
+++ b/sql-server-2019-cumulative-update/update.ps1
@@ -1,76 +1,18 @@
Import-Module chocolatey-au
-. ..\_scripts\Submit-VirusTotal.ps1
+. ..\_scripts\SqlServerCumulativeUpdates.ps1
function global:au_SearchReplace {
- @{
- # softwareName = 'Hotfix 3026 for Microsoft SQL Server*(KB4229789)*'
- 'tools\chocolateyInstall.ps1' = @{
- "(^[$]url\s*=\s*)('.*')" = "`$1'$($Latest.URL64)'"
- "(^[$]checksum\s*=\s*)('.*')" = "`$1'$($Latest.Checksum64)'"
- "(^[$]softwareName\s*=\s*)('.*')" = "`$1'Hotfix $($Latest.Build) for SQL Server 2019*(KB$($Latest.KB))*'"
- }
- }
+ return SearchReplace 2022 $Latest
}
function global:au_GetLatest {
- $downloadId = "100809"
- $response = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/confirmation.aspx?id=$downloadId" -ErrorAction Ignore
-
- $url = $response.Content |
- Select-String -AllMatches -Pattern "(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?" |
- ForEach-Object { $_.Matches.Value } |
- Select-string "\.exe$" |
- Select-Object -First 1 -ExpandProperty Line
-
- #
- if ($response.Content -match "") {
- $cu = $Matches[1]
- $kb = $Matches[2]
- } else {
- return @{}
- }
-
- $response = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/details.aspx?id=$downloadId"
-
- if ($response.Content -match "\d+\.\d+\.\d+\.\d+") {
- $version = $Matches[0]
- } else {
- return @{}
- }
-
- $v = [Version] $version
- $Latest = @{
- URL64 = $url
- Version = $version
- KB = $kb
- CU = $cu
- Build = $v.Build
- }
-
- # We can't do this from global:au_BeforeUpdate, because the checksum stuff has already been run (and updated the chocolateyinstall.ps1 script)
- $toolsContent = Get-Content .\tools\chocolateyinstall.ps1 -Encoding utf8
-
- $matched = ($toolsContent -match "(^[$]url\s*=\s*)('.*')") | Select-Object -First 1
-
- if ($matched -match "(^[$]url\s*=\s*)'(.*)'") {
- $script:previousUrl = $Matches[2]
- }
- return $Latest
+ return GetLatest 100809 2019
}
function global:au_AfterUpdate ($Package) {
- if (($Package.RemoteVersion -ne $Package.NuspecVersion) -and ($script:previousUrl -eq $Latest.URL64)) {
- # URL didn't change, game over!
- throw "New version $($Package.NuspecVersion) but URL ($($script:previousUrl)) didn't change"
- }
-
- $Package.NuspecXml.package.metadata.releaseNotes = "https://support.microsoft.com/help/$($Latest.KB)"
- $Package.NuspecXml.package.metadata.title = "Microsoft SQL Server 2019 Cumulative Update $($Latest.CU)"
- $Package.SaveNuspec()
-
- VirusTotal_AfterUpdate $Package
+ AfterUpdate $Package $Latest 2019
}
update -ChecksumFor 64
diff --git a/sql-server-2022-cumulative-update/update.ps1 b/sql-server-2022-cumulative-update/update.ps1
index df53b517..ef26c026 100644
--- a/sql-server-2022-cumulative-update/update.ps1
+++ b/sql-server-2022-cumulative-update/update.ps1
@@ -1,76 +1,18 @@
Import-Module chocolatey-au
-. ..\_scripts\Submit-VirusTotal.ps1
+. ..\_scripts\SqlServerCumulativeUpdates.ps1
function global:au_SearchReplace {
- @{
- # softwareName = 'Hotfix 3026 for Microsoft SQL Server*(KB4229789)*'
- 'tools\chocolateyInstall.ps1' = @{
- "(^[$]url\s*=\s*)('.*')" = "`$1'$($Latest.URL64)'"
- "(^[$]checksum\s*=\s*)('.*')" = "`$1'$($Latest.Checksum64)'"
- "(^[$]softwareName\s*=\s*)('.*')" = "`$1'Hotfix $($Latest.Build) for SQL Server 2022*(KB$($Latest.KB))*'"
- }
- }
+ return SearchReplace 2022 $Latest
}
function global:au_GetLatest {
- $downloadId = "105013"
- $response = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/confirmation.aspx?id=$downloadId" -ErrorAction Ignore
-
- $url = $response.Content |
- Select-String -AllMatches -Pattern "(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?" |
- ForEach-Object { $_.Matches.Value } |
- Select-string "\.exe$" |
- Select-Object -First 1 -ExpandProperty Line
-
- #
- if ($response.Content -match "") {
- $cu = $Matches[1]
- $kb = $Matches[2]
- } else {
- return @{}
- }
-
- $response = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/details.aspx?id=$downloadId"
-
- if ($response.Content -match "\d+\.\d+\.\d+\.\d+") {
- $version = $Matches[0]
- } else {
- return @{}
- }
-
- $v = [Version] $version
- $Latest = @{
- URL64 = $url
- Version = $version
- KB = $kb
- CU = $cu
- Build = $v.Build
- }
-
- # We can't do this from global:au_BeforeUpdate, because the checksum stuff has already been run (and updated the chocolateyinstall.ps1 script)
- $toolsContent = Get-Content .\tools\chocolateyinstall.ps1 -Encoding utf8
-
- $matched = ($toolsContent -match "(^[$]url\s*=\s*)('.*')") | Select-Object -First 1
-
- if ($matched -match "(^[$]url\s*=\s*)'(.*)'") {
- $script:previousUrl = $Matches[2]
- }
- return $Latest
+ return GetLatest 105013 2022
}
function global:au_AfterUpdate ($Package) {
- if (($Package.RemoteVersion -ne $Package.NuspecVersion) -and ($script:previousUrl -eq $Latest.URL64)) {
- # URL didn't change, game over!
- throw "New version $($Package.NuspecVersion) but URL ($($script:previousUrl)) didn't change"
- }
-
- $Package.NuspecXml.package.metadata.releaseNotes = "https://support.microsoft.com/help/$($Latest.KB)"
- $Package.NuspecXml.package.metadata.title = "Microsoft SQL Server 2022 Cumulative Update $($Latest.CU)"
- $Package.SaveNuspec()
-
- VirusTotal_AfterUpdate $Package
+ AfterUpdate $Package $Latest 2022
}
update -ChecksumFor 64