forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoop-download.ps1
More file actions
144 lines (126 loc) · 5.14 KB
/
scoop-download.ps1
File metadata and controls
144 lines (126 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Usage: scoop download <app> [options]
# Summary: Download apps in the cache folder and verify hashes
# Help: e.g. The usual way to download an app, without installing it (uses your local 'buckets'):
# scoop download git
#
# To download a different version of the app
# (note that this will auto-generate the manifest using current version):
# scoop download gh@2.7.0
#
# To download an app from a manifest at a URL:
# scoop download https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/runat.json
#
# To download an app from a manifest on your computer
# scoop download path\to\app.json
#
# Options:
# -f, --force Force download (overwrite cache)
# -s, --skip-hash-check Skip hash verification (use with caution!)
# -u, --no-update-scoop Don't update Scoop before downloading if it's outdated
# -a, --arch <32bit|64bit|arm64> Use the specified architecture, if the app supports it
. "$PSScriptRoot\..\lib\getopt.ps1"
. "$PSScriptRoot\..\lib\json.ps1" # 'autoupdate.ps1' (indirectly)
. "$PSScriptRoot\..\lib\autoupdate.ps1" # 'generate_user_manifest' (indirectly)
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
. "$PSScriptRoot\..\lib\manifest.ps1" # 'generate_user_manifest' 'Get-Manifest'
. "$PSScriptRoot\..\lib\download.ps1"
. "$PSScriptRoot\..\lib\install.ps1" # 'nightly_version'
if (get_config USE_SQLITE_CACHE) {
. "$PSScriptRoot\..\lib\database.ps1"
}
$opt, $apps, $err = getopt $args 'fsua:' 'force', 'skip-hash-check', 'no-update-scoop', 'arch='
if ($err) { error "scoop download: $err"; exit 1 }
$check_hash = !($opt.s -or $opt.'skip-hash-check')
$use_cache = !($opt.f -or $opt.force)
$architecture = Get-DefaultArchitecture
try {
$architecture = Format-ArchitectureString ($opt.a + $opt.arch)
} catch {
abort "ERROR: $_"
}
if (!$apps) { error '<app> missing'; my_usage; exit 1 }
if (is_scoop_outdated) {
if ($opt.u -or $opt.'no-update-scoop') {
warn "Scoop is out of date."
} else {
& "$PSScriptRoot\scoop-update.ps1"
}
}
# we only want to show this warning once
if(!$use_cache) { warn "Cache is being ignored." }
foreach ($curr_app in $apps) {
# Prevent leaking variables from previous iteration
$bucket = $version = $app = $manifest = $url = $null
$app, $bucket, $version = parse_app $curr_app
$app, $manifest, $bucket, $url = Get-Manifest "$bucket/$app"
info "Downloading '$app'$(if ($version) { " ($version)" }) [$architecture]$(if ($bucket) { " from $bucket bucket" })"
# Generate manifest if there is different version in manifest
if (($null -ne $version) -and ($manifest.version -ne $version)) {
$generated = generate_user_manifest $app $bucket $version
if ($null -eq $generated) {
error 'Manifest cannot be generated with provided version'
continue
}
$manifest = parse_json($generated)
}
if(!$manifest) {
error "Couldn't find manifest for '$app'$(if($bucket) { " from '$bucket' bucket" } elseif($url) { " at '$url'" })."
continue
}
$version = $manifest.version
if(!$version) {
error "Manifest doesn't specify a version."
continue
}
if($version -match '[^\w\.\-\+_]') {
error "Manifest version has unsupported character '$($matches[0])'."
continue
}
$curr_check_hash = $check_hash
if ($version -eq 'nightly') {
$version = nightly_version
$curr_check_hash = $false
}
$architecture = Get-SupportedArchitecture $manifest $architecture
if ($null -eq $architecture) {
error "'$app' doesn't support current architecture!"
continue
}
if(Test-Aria2Enabled) {
Invoke-CachedAria2Download $app $version $manifest $architecture $cachedir $manifest.cookie $use_cache $curr_check_hash
} else {
foreach($url in script:url $manifest $architecture) {
try {
Invoke-CachedDownload $app $version $url $null $manifest.cookie $use_cache
} catch {
write-host -f darkred $_
error "URL $url is not valid"
$dl_failure = $true
continue
}
if($curr_check_hash) {
$manifest_hash = hash_for_url $manifest $url $architecture
$cached = cache_path $app $version $url
$ok, $err = check_hash $cached $manifest_hash (show_app $app $bucket)
if(!$ok) {
error $err
if(test-path $cached) {
# rm cached file
Remove-Item -force $cached
}
if ($url -like '*sourceforge.net*') {
warn 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'
}
error (new_issue_msg $app $bucket "hash check failed")
continue
}
} else {
info "Skipping hash verification."
}
}
}
if (!$dl_failure) {
success "'$app' ($version) was downloaded successfully!"
}
}
exit 0