Skip to content

Commit 9142703

Browse files
authored
feat(download): Allow downloading without installing (#4621)
* feat(download): Allow downloading without installing * update changelog * rename 'skip' -> 'no-hash-check' * add --no-update-scoop flag
1 parent 00adc0d commit 9142703

2 files changed

Lines changed: 136 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<a name="unreleased"></a>
22
## [Unreleased]
33

4+
### Features
5+
6+
- **scoop-download:** Add `scoop download` command ([#4621](https://github.com/ScoopInstaller/Scoop/issues/4621))
7+
48
### Bug Fixes
59

610
- **autoupdate:** Allow checksum file that contains whitespaces ([#4619](https://github.com/ScoopInstaller/Scoop/issues/4619))

libexec/scoop-download.ps1

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

0 commit comments

Comments
 (0)