-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and refactor SQL cumulative updates
- Loading branch information
Showing
4 changed files
with
84 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
# <meta name="description" content="Cumulative Update Package 16 for SQL Server 2022 - KB5048033"/> | ||
if ($response.Content -match "<meta name=`"description`" content=`"Cumulative Update Package (\d+) for SQL Server $MajorVersion - KB(\d+)`"\s*\/\>") { | ||
$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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
# <meta name="Description" content="Cumulative Update Package 7 for SQL Server 2017 - KB4229789" /> | ||
if ($response.Content -match "<meta name=`"Description`" content=`"Cumulative Update Package (\d+) for SQL Server 2017 - KB(\d+)`" \/\>") { | ||
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
# <meta name="Description" content="Cumulative Update Package 7 for SQL Server 2017 - KB4229789" /> | ||
if ($response.Content -match "<meta name=`"Description`" content=`"Cumulative Update Package (\d+) for SQL Server 2019 - KB(\d+)`" \/\>") { | ||
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
# <meta name="Description" content="Cumulative Update Package 7 for SQL Server 2017 - KB4229789" /> | ||
if ($response.Content -match "<meta name=`"Description`" content=`"Cumulative Update Package (\d+) for SQL Server 2022 - KB(\d+)`" \/\>") { | ||
$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 |