Skip to content

Commit 44a2194

Browse files
Ash258rasa
authored andcommitted
[checkurls] Add SkipValid Parameter (#2845)
* Format first * Add SkipValid parameter * Remove junk comment
1 parent 30311d6 commit 44a2194

File tree

1 file changed

+90
-72
lines changed

1 file changed

+90
-72
lines changed

bin/checkurls.ps1

+90-72
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,134 @@
1-
# list manifests which do not specify a checkver regex
1+
<#
2+
.SYNOPSIS
3+
List manifests which do not have valid URLs.
4+
.PARAMETER App
5+
Manifest name to search.
6+
Placeholder is supported.
7+
.PARAMETER Dir
8+
Where to search for manifest(s).
9+
.PARAMETER Timeout
10+
How long (seconds) the request can be pending before it times out.
11+
.PARAMETER SkipValid
12+
Manifests will all valid URLs will not be shown.
13+
#>
214
param(
3-
[String]$app,
4-
[String]$dir,
5-
[Int]$timeout = 5
15+
[String] $App = '*',
16+
[ValidateScript( {
17+
if (!(Test-Path $_ -Type Container)) {
18+
throw "$_ is not a directory!"
19+
} else {
20+
$true
21+
}
22+
})]
23+
[String] $Dir = "$PSScriptRoot\\..\bucket",
24+
[Int] $Timeout = 5,
25+
[Switch] $SkipValid
626
)
727

8-
if(!$dir) { $dir = "$psscriptroot\..\bucket" }
9-
$dir = resolve-path $dir
10-
11-
$search = "*"
12-
if($app) { $search = $app }
28+
. "$PSScriptRoot\..\lib\core.ps1"
29+
. "$PSScriptRoot\..\lib\manifest.ps1"
30+
. "$PSScriptRoot\..\lib\config.ps1"
31+
. "$PSScriptRoot\..\lib\install.ps1"
1332

14-
. "$psscriptroot\..\lib\core.ps1"
15-
. "$psscriptroot\..\lib\manifest.ps1"
16-
. "$psscriptroot\..\lib\config.ps1"
17-
. "$psscriptroot\..\lib\install.ps1"
33+
$Dir = Resolve-Path $Dir
34+
$Queue = @()
1835

19-
if(!$dir) { $dir = "$psscriptroot\..\bucket" }
20-
$dir = resolve-path $dir
21-
22-
# get apps to check
23-
$queue = @()
24-
Get-ChildItem $dir "$search.json" | ForEach-Object {
25-
$manifest = parse_json "$dir\$($_.Name)"
26-
$queue += ,@($_.Name, $manifest)
36+
Get-ChildItem $Dir "$App.json" | ForEach-Object {
37+
$manifest = parse_json "$Dir\$($_.Name)"
38+
$Queue += , @($_.Name, $manifest)
2739
}
2840

2941
$original = use_any_https_protocol
3042

31-
write-host "[" -nonewline
32-
write-host -f cyan "U" -nonewline
33-
write-host "]RLs"
34-
write-host " | [" -nonewline
35-
write-host -f green "O" -nonewline
36-
write-host "]kay"
37-
write-host " | | [" -nonewline
38-
write-host -f red "F" -nonewline
39-
write-host "]ailed"
40-
write-host " | | |"
41-
42-
function test_dl($url, $cookies) {
43-
$wreq = [net.webrequest]::create($url)
44-
$wreq.timeout = $timeout * 1000
45-
if($wreq -is [net.httpwebrequest]) {
46-
$wreq.useragent = Get-UserAgent
47-
$wreq.referer = strip_filename $url
48-
if($cookies) {
49-
$wreq.headers.add('Cookie', (cookie_header $cookies))
43+
Write-Host '[' -NoNewLine
44+
Write-Host 'U' -NoNewLine -ForegroundColor Cyan
45+
Write-Host ']RLs'
46+
Write-Host ' | [' -NoNewLine
47+
Write-Host 'O' -NoNewLine -ForegroundColor Green
48+
Write-Host ']kay'
49+
Write-Host ' | | [' -NoNewLine
50+
Write-Host 'F' -NoNewLine -ForegroundColor Red
51+
Write-Host ']ailed'
52+
Write-Host ' | | |'
53+
54+
function test_dl([String] $url, $cookies) {
55+
$wreq = [Net.WebRequest]::Create($url)
56+
$wreq.Timeout = $Timeout * 1000
57+
if ($wreq -is [Net.HttpWebRequest]) {
58+
$wreq.UserAgent = Get-UserAgent
59+
$wreq.Referer = strip_filename $url
60+
if ($cookies) {
61+
$wreq.Headers.Add('Cookie', (cookie_header $cookies))
5062
}
5163
}
5264
$wres = $null
5365
try {
54-
$wres = $wreq.getresponse()
55-
return $url, $wres.statuscode, $null
66+
$wres = $wreq.GetResponse()
67+
68+
return $url, $wres.StatusCode, $null
5669
} catch {
57-
$e = $_.exception
58-
if($e.innerexception) { $e = $e.innerexception }
59-
return $url, "Error", $e.message
70+
$e = $_.Exception
71+
if ($e.InnerException) { $e = $e.InnerException }
72+
73+
return $url, 'Error', $e.Message
6074
} finally {
61-
if($null -ne $wres -and $wres -isnot [net.ftpwebresponse]) {
62-
$wres.close()
75+
if ($null -ne $wres -and $wres -isnot [Net.FtpWebResponse]) {
76+
$wres.Close()
6377
}
6478
}
6579
}
6680

67-
$queue | ForEach-Object {
68-
$name, $manifest = $_
81+
foreach ($man in $Queue) {
82+
$name, $manifest = $man
6983
$urls = @()
7084
$ok = 0
7185
$failed = 0
7286
$errors = @()
7387

74-
if($manifest.url) {
88+
if ($manifest.url) {
7589
$manifest.url | ForEach-Object { $urls += $_ }
7690
} else {
77-
url $manifest "64bit" | ForEach-Object { $urls += $_ }
78-
url $manifest "32bit" | ForEach-Object { $urls += $_ }
91+
url $manifest '64bit' | ForEach-Object { $urls += $_ }
92+
url $manifest '32bit' | ForEach-Object { $urls += $_ }
7993
}
8094

8195
$urls | ForEach-Object {
8296
$url, $status, $msg = test_dl $_ $manifest.cookie
83-
if($msg) { $errors += "$msg ($url)" }
84-
if($status -eq "OK" -or $status -eq "OpeningData") { $ok += 1 } else { $failed += 1 }
97+
if ($msg) { $errors += "$msg ($url)" }
98+
if ($status -eq 'OK' -or $status -eq 'OpeningData') { $ok += 1 } else { $failed += 1 }
8599
}
86100

87-
write-host "[" -nonewline
88-
write-host -f cyan -nonewline $urls.length
89-
write-host "]" -nonewline
101+
if (($ok -eq $urls.Length) -and $SkipValid) { continue }
102+
103+
# URLS
104+
Write-Host '[' -NoNewLine
105+
Write-Host $urls.Length -NoNewLine -ForegroundColor Cyan
106+
Write-Host ']' -NoNewLine
90107

91-
write-host "[" -nonewline
92-
if($ok -eq $urls.length) {
93-
write-host -f green -nonewline $ok
94-
} elseif($ok -eq 0) {
95-
write-host -f red -nonewline $ok
108+
# Okay
109+
Write-Host '[' -NoNewLine
110+
if ($ok -eq $urls.Length) {
111+
Write-Host $ok -NoNewLine -ForegroundColor Green
112+
} elseif ($ok -eq 0) {
113+
Write-Host $ok -NoNewLine -ForegroundColor Red
96114
} else {
97-
write-host -f yellow -nonewline $ok
115+
Write-Host $ok -NoNewLine -ForegroundColor Yellow
98116
}
99-
write-host "]" -nonewline
117+
Write-Host ']' -NoNewLine
100118

101-
write-host "[" -nonewline
102-
if($failed -eq 0) {
103-
write-host -f green -nonewline $failed
119+
# Failed
120+
Write-Host '[' -NoNewLine
121+
if ($failed -eq 0) {
122+
Write-Host $failed -NoNewLine -ForegroundColor Green
104123
} else {
105-
write-host -f red -nonewline $failed
124+
Write-Host $failed -NoNewLine -ForegroundColor Red
106125
}
107-
write-host "] " -nonewline
108-
write-host (strip_ext $name)
126+
Write-Host '] ' -NoNewLine
127+
Write-Host (strip_ext $name)
109128

110129
$errors | ForEach-Object {
111-
write-host -f darkred " > $_"
130+
Write-Host " > $_" -ForegroundColor DarkRed
112131
}
113132
}
114133

115-
116134
set_https_protocols $original

0 commit comments

Comments
 (0)