|
15 | 15 | Useful for hash updates. |
16 | 16 | .PARAMETER SkipUpdated |
17 | 17 | Updated manifests will not be shown. |
| 18 | +.PARAMETER Version |
| 19 | + Update manifest to specific version. |
18 | 20 | .EXAMPLE |
19 | 21 | PS BUCKETROOT > .\bin\checkver.ps1 |
20 | 22 | Check all manifest inside default directory. |
@@ -76,6 +78,11 @@ $Dir = Resolve-Path $Dir |
76 | 78 | $Search = $App |
77 | 79 | $GitHubToken = $env:SCOOP_CHECKVER_TOKEN, (get_config 'checkver-token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1 |
78 | 80 |
|
| 81 | +# don't use $Version with $App = '*' |
| 82 | +if ($App -eq '*' -and $Version -ne '') { |
| 83 | + throw "Don't use '-Version' with '-App *'!" |
| 84 | +} |
| 85 | + |
79 | 86 | # get apps to check |
80 | 87 | $Queue = @() |
81 | 88 | $json = '' |
@@ -205,95 +212,97 @@ while ($in_progress -gt 0) { |
205 | 212 | $reverse = $state.reverse |
206 | 213 | $replace = $state.replace |
207 | 214 | $expected_ver = $json.version |
208 | | - $ver = '' |
209 | | - |
210 | | - $page = $ev.SourceEventArgs.Result |
211 | | - $err = $ev.SourceEventArgs.Error |
212 | | - if ($json.checkver.script) { |
213 | | - $page = $json.checkver.script -join "`r`n" | Invoke-Expression |
214 | | - } |
| 215 | + $ver = $Version |
215 | 216 |
|
216 | | - if ($err) { |
217 | | - next "$($err.message)`r`nURL $url is not valid" |
218 | | - continue |
219 | | - } |
220 | | - |
221 | | - if (!$regex -and $replace) { |
222 | | - next "'replace' requires 're' or 'regex'" |
223 | | - continue |
224 | | - } |
225 | | - |
226 | | - if ($jsonpath) { |
227 | | - # Return only a single value if regex is absent |
228 | | - $noregex = [String]::IsNullOrEmpty($regex) |
229 | | - # If reverse is ON and regex is ON, |
230 | | - # Then reverse would have no effect because regex handles reverse |
231 | | - # on its own |
232 | | - # So in this case we have to disable reverse |
233 | | - $ver = json_path $page $jsonpath $null ($reverse -and $noregex) $noregex |
234 | | - if (!$ver) { |
235 | | - $ver = json_path_legacy $page $jsonpath |
| 217 | + if (!$ver) { |
| 218 | + $page = $ev.SourceEventArgs.Result |
| 219 | + $err = $ev.SourceEventArgs.Error |
| 220 | + if ($json.checkver.script) { |
| 221 | + $page = $json.checkver.script -join "`r`n" | Invoke-Expression |
236 | 222 | } |
237 | | - if (!$ver) { |
238 | | - next "couldn't find '$jsonpath' in $url" |
| 223 | + |
| 224 | + if ($err) { |
| 225 | + next "$($err.message)`r`nURL $url is not valid" |
239 | 226 | continue |
240 | 227 | } |
241 | | - } |
242 | 228 |
|
243 | | - if ($xpath) { |
244 | | - $xml = [xml]$page |
245 | | - # Find all `significant namespace declarations` from the XML file |
246 | | - $nsList = $xml.SelectNodes("//namespace::*[not(. = ../../namespace::*)]") |
247 | | - # Then add them into the NamespaceManager |
248 | | - $nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable) |
249 | | - $nsList | ForEach-Object { |
250 | | - $nsmgr.AddNamespace($_.LocalName, $_.Value) |
251 | | - } |
252 | | - # Getting version from XML, using XPath |
253 | | - $ver = $xml.SelectSingleNode($xpath, $nsmgr).'#text' |
254 | | - if (!$ver) { |
255 | | - next "couldn't find '$xpath' in $url" |
| 229 | + if (!$regex -and $replace) { |
| 230 | + next "'replace' requires 're' or 'regex'" |
256 | 231 | continue |
257 | 232 | } |
258 | | - } |
259 | 233 |
|
260 | | - if ($jsonpath -and $regexp) { |
261 | | - $page = $ver |
262 | | - $ver = '' |
263 | | - } |
| 234 | + if ($jsonpath) { |
| 235 | + # Return only a single value if regex is absent |
| 236 | + $noregex = [String]::IsNullOrEmpty($regex) |
| 237 | + # If reverse is ON and regex is ON, |
| 238 | + # Then reverse would have no effect because regex handles reverse |
| 239 | + # on its own |
| 240 | + # So in this case we have to disable reverse |
| 241 | + $ver = json_path $page $jsonpath $null ($reverse -and $noregex) $noregex |
| 242 | + if (!$ver) { |
| 243 | + $ver = json_path_legacy $page $jsonpath |
| 244 | + } |
| 245 | + if (!$ver) { |
| 246 | + next "couldn't find '$jsonpath' in $url" |
| 247 | + continue |
| 248 | + } |
| 249 | + } |
264 | 250 |
|
265 | | - if ($xpath -and $regexp) { |
266 | | - $page = $ver |
267 | | - $ver = '' |
268 | | - } |
| 251 | + if ($xpath) { |
| 252 | + $xml = [xml]$page |
| 253 | + # Find all `significant namespace declarations` from the XML file |
| 254 | + $nsList = $xml.SelectNodes("//namespace::*[not(. = ../../namespace::*)]") |
| 255 | + # Then add them into the NamespaceManager |
| 256 | + $nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable) |
| 257 | + $nsList | ForEach-Object { |
| 258 | + $nsmgr.AddNamespace($_.LocalName, $_.Value) |
| 259 | + } |
| 260 | + # Getting version from XML, using XPath |
| 261 | + $ver = $xml.SelectSingleNode($xpath, $nsmgr).'#text' |
| 262 | + if (!$ver) { |
| 263 | + next "couldn't find '$xpath' in $url" |
| 264 | + continue |
| 265 | + } |
| 266 | + } |
269 | 267 |
|
270 | | - if ($regexp) { |
271 | | - $regex = New-Object System.Text.RegularExpressions.Regex($regexp) |
272 | | - if ($reverse) { |
273 | | - $match = $regex.Matches($page) | Select-Object -Last 1 |
274 | | - } else { |
275 | | - $match = $regex.Matches($page) | Select-Object -First 1 |
| 268 | + if ($jsonpath -and $regexp) { |
| 269 | + $page = $ver |
| 270 | + $ver = '' |
276 | 271 | } |
277 | 272 |
|
278 | | - if ($match -and $match.Success) { |
279 | | - $matchesHashtable = @{} |
280 | | - $regex.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) } |
281 | | - $ver = $matchesHashtable['1'] |
282 | | - if ($replace) { |
283 | | - $ver = $regex.Replace($match.Value, $replace) |
| 273 | + if ($xpath -and $regexp) { |
| 274 | + $page = $ver |
| 275 | + $ver = '' |
| 276 | + } |
| 277 | + |
| 278 | + if ($regexp) { |
| 279 | + $regex = New-Object System.Text.RegularExpressions.Regex($regexp) |
| 280 | + if ($reverse) { |
| 281 | + $match = $regex.Matches($page) | Select-Object -Last 1 |
| 282 | + } else { |
| 283 | + $match = $regex.Matches($page) | Select-Object -First 1 |
284 | 284 | } |
285 | | - if (!$ver) { |
286 | | - $ver = $matchesHashtable['version'] |
| 285 | + |
| 286 | + if ($match -and $match.Success) { |
| 287 | + $matchesHashtable = @{} |
| 288 | + $regex.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) } |
| 289 | + $ver = $matchesHashtable['1'] |
| 290 | + if ($replace) { |
| 291 | + $ver = $regex.Replace($match.Value, $replace) |
| 292 | + } |
| 293 | + if (!$ver) { |
| 294 | + $ver = $matchesHashtable['version'] |
| 295 | + } |
| 296 | + } else { |
| 297 | + next "couldn't match '$regexp' in $url" |
| 298 | + continue |
287 | 299 | } |
288 | | - } else { |
289 | | - next "couldn't match '$regexp' in $url" |
290 | | - continue |
291 | 300 | } |
292 | | - } |
293 | 301 |
|
294 | | - if (!$ver) { |
295 | | - next "couldn't find new version in $url" |
296 | | - continue |
| 302 | + if (!$ver) { |
| 303 | + next "couldn't find new version in $url" |
| 304 | + continue |
| 305 | + } |
297 | 306 | } |
298 | 307 |
|
299 | 308 | # Skip actual only if versions are same and there is no -f |
@@ -325,9 +334,6 @@ while ($in_progress -gt 0) { |
325 | 334 | Write-Host 'Forcing autoupdate!' -ForegroundColor DarkMagenta |
326 | 335 | } |
327 | 336 | try { |
328 | | - if ($Version -ne "") { |
329 | | - $ver = $Version |
330 | | - } |
331 | 337 | Invoke-AutoUpdate $App $Dir $json $ver $matchesHashtable |
332 | 338 | } catch { |
333 | 339 | error $_.Exception.Message |
|
0 commit comments