Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Builds

- **checkver:** Fix output with '-Version' ([#3774](https://github.com/ScoopInstaller/Scoop/issues/3774))
- **schema:** Add '$schema' property ([#4623](https://github.com/ScoopInstaller/Scoop/issues/4623))

### Styles
Expand Down
158 changes: 82 additions & 76 deletions bin/checkver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
Useful for hash updates.
.PARAMETER SkipUpdated
Updated manifests will not be shown.
.PARAMETER Version
Update manifest to specific version.
.EXAMPLE
PS BUCKETROOT > .\bin\checkver.ps1
Check all manifest inside default directory.
Expand Down Expand Up @@ -76,6 +78,11 @@ $Dir = Resolve-Path $Dir
$Search = $App
$GitHubToken = $env:SCOOP_CHECKVER_TOKEN, (get_config 'checkver-token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1

# don't use $Version with $App = '*'
if ($App -eq '*' -and $Version -ne '') {
throw "Don't use '-Version' with '-App *'!"
}

# get apps to check
$Queue = @()
$json = ''
Expand Down Expand Up @@ -205,95 +212,97 @@ while ($in_progress -gt 0) {
$reverse = $state.reverse
$replace = $state.replace
$expected_ver = $json.version
$ver = ''

$page = $ev.SourceEventArgs.Result
$err = $ev.SourceEventArgs.Error
if ($json.checkver.script) {
$page = $json.checkver.script -join "`r`n" | Invoke-Expression
}
$ver = $Version

if ($err) {
next "$($err.message)`r`nURL $url is not valid"
continue
}

if (!$regex -and $replace) {
next "'replace' requires 're' or 'regex'"
continue
}

if ($jsonpath) {
# Return only a single value if regex is absent
$noregex = [String]::IsNullOrEmpty($regex)
# If reverse is ON and regex is ON,
# Then reverse would have no effect because regex handles reverse
# on its own
# So in this case we have to disable reverse
$ver = json_path $page $jsonpath $null ($reverse -and $noregex) $noregex
if (!$ver) {
$ver = json_path_legacy $page $jsonpath
if (!$ver) {
$page = $ev.SourceEventArgs.Result
$err = $ev.SourceEventArgs.Error
if ($json.checkver.script) {
$page = $json.checkver.script -join "`r`n" | Invoke-Expression
}
if (!$ver) {
next "couldn't find '$jsonpath' in $url"

if ($err) {
next "$($err.message)`r`nURL $url is not valid"
continue
}
}

if ($xpath) {
$xml = [xml]$page
# Find all `significant namespace declarations` from the XML file
$nsList = $xml.SelectNodes("//namespace::*[not(. = ../../namespace::*)]")
# Then add them into the NamespaceManager
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$nsList | ForEach-Object {
$nsmgr.AddNamespace($_.LocalName, $_.Value)
}
# Getting version from XML, using XPath
$ver = $xml.SelectSingleNode($xpath, $nsmgr).'#text'
if (!$ver) {
next "couldn't find '$xpath' in $url"
if (!$regex -and $replace) {
next "'replace' requires 're' or 'regex'"
continue
}
}

if ($jsonpath -and $regexp) {
$page = $ver
$ver = ''
}
if ($jsonpath) {
# Return only a single value if regex is absent
$noregex = [String]::IsNullOrEmpty($regex)
# If reverse is ON and regex is ON,
# Then reverse would have no effect because regex handles reverse
# on its own
# So in this case we have to disable reverse
$ver = json_path $page $jsonpath $null ($reverse -and $noregex) $noregex
if (!$ver) {
$ver = json_path_legacy $page $jsonpath
}
if (!$ver) {
next "couldn't find '$jsonpath' in $url"
continue
}
}

if ($xpath -and $regexp) {
$page = $ver
$ver = ''
}
if ($xpath) {
$xml = [xml]$page
# Find all `significant namespace declarations` from the XML file
$nsList = $xml.SelectNodes("//namespace::*[not(. = ../../namespace::*)]")
# Then add them into the NamespaceManager
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$nsList | ForEach-Object {
$nsmgr.AddNamespace($_.LocalName, $_.Value)
}
# Getting version from XML, using XPath
$ver = $xml.SelectSingleNode($xpath, $nsmgr).'#text'
if (!$ver) {
next "couldn't find '$xpath' in $url"
continue
}
}

if ($regexp) {
$regex = New-Object System.Text.RegularExpressions.Regex($regexp)
if ($reverse) {
$match = $regex.Matches($page) | Select-Object -Last 1
} else {
$match = $regex.Matches($page) | Select-Object -First 1
if ($jsonpath -and $regexp) {
$page = $ver
$ver = ''
}

if ($match -and $match.Success) {
$matchesHashtable = @{}
$regex.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) }
$ver = $matchesHashtable['1']
if ($replace) {
$ver = $regex.Replace($match.Value, $replace)
if ($xpath -and $regexp) {
$page = $ver
$ver = ''
}

if ($regexp) {
$regex = New-Object System.Text.RegularExpressions.Regex($regexp)
if ($reverse) {
$match = $regex.Matches($page) | Select-Object -Last 1
} else {
$match = $regex.Matches($page) | Select-Object -First 1
}
if (!$ver) {
$ver = $matchesHashtable['version']

if ($match -and $match.Success) {
$matchesHashtable = @{}
$regex.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) }
$ver = $matchesHashtable['1']
if ($replace) {
$ver = $regex.Replace($match.Value, $replace)
}
if (!$ver) {
$ver = $matchesHashtable['version']
}
} else {
next "couldn't match '$regexp' in $url"
continue
}
} else {
next "couldn't match '$regexp' in $url"
continue
}
}

if (!$ver) {
next "couldn't find new version in $url"
continue
if (!$ver) {
next "couldn't find new version in $url"
continue
}
}

# Skip actual only if versions are same and there is no -f
Expand Down Expand Up @@ -325,9 +334,6 @@ while ($in_progress -gt 0) {
Write-Host 'Forcing autoupdate!' -ForegroundColor DarkMagenta
}
try {
if ($Version -ne "") {
$ver = $Version
}
Invoke-AutoUpdate $App $Dir $json $ver $matchesHashtable
} catch {
error $_.Exception.Message
Expand Down