Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multi-connection downloads via aria2c #2312

Merged
merged 19 commits into from
Aug 7, 2018
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
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,28 @@ Scoop is very scriptable, so you can run repeatable setups to get your environme
```powershell
scoop install sudo
sudo scoop install 7zip git openssh --global
scoop install curl grep sed less touch
scoop install aria2 curl grep sed less touch
scoop install python ruby go perl
```

If you've built software that you'd like others to use, Scoop is an alternative to building an installer (e.g. MSI or InnoSetup)—you just need to zip your program and provide a JSON manifest that describes how to install it.

## [Documentation](https://github.com/lukesampson/scoop/wiki)

## Multi-connection downloads with `aria2`
Scoop can utilize [`aria2`](https://github.com/aria2/aria2) to use multi-connection downloads. Simply install `aria2` through Scoop and it will be used for all downloads afterward.
```powershell
scoop install aria2
```

You can tweak the following `aria2` settings with the `scoop config` command:

- aria2-enabled (default: true)
- [aria2-retry-wait](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-retry-wait) (default: 2)
- [aria2-split](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-s) (default: 5)
- [aria2-max-connection-per-server](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-x) (default: 5)
- [aria2-min-split-size](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-k) (default: 5M)

### Inspiration

* [Homebrew](http://mxcl.github.io/homebrew/)
Expand Down
5 changes: 4 additions & 1 deletion lib/config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function load_cfg {
}
}

function get_config($name) {
function get_config($name, $default) {
if($null -eq $cfg.$name -and $null -ne $default) {
return $default
}
return $cfg.$name
}

Expand Down
44 changes: 44 additions & 0 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ function installed_apps($global) {
}
}

function aria2_path() {
# normal path to executable
$aria2 = "$(versiondir 'aria2' 'current' $false)\aria2c.exe"
if(Test-Path($aria2)) {
return $aria2
}

# global path to executable
$aria2 = "$(versiondir 'aria2' 'current' $true)\aria2c.exe"
if(Test-Path($aria2)) {
return $aria2
}

# not found
return $null
}

function aria2_installed() {
return ![String]::IsNullOrWhiteSpace("$(aria2_path)")
}

function aria2_enabled() {
return (aria2_installed) -and (get_config 'aria2-enabled' $true)
}

function app_status($app, $global) {
$status = @{}
$status.installed = (installed $app $global)
Expand Down Expand Up @@ -579,6 +604,19 @@ function format_hash([String] $hash) {
return $hash
}

function format_hash_aria2([String] $hash) {
$hash = $hash -split ':' | Select-Object -Last 1
switch ($hash.Length)
{
32 { $hash = "md5=$hash" } # md5
40 { $hash = "sha-1=$hash" } # sha1
64 { $hash = "sha-256=$hash" } # sha256
128 { $hash = "sha-512=$hash" } # sha512
default { $hash = $null }
}
return $hash
}

function handle_special_urls($url)
{
# FossHub.com
Expand All @@ -590,5 +628,11 @@ function handle_special_urls($url)
$url = "https://www.fosshub.com/gensLink/$name/$filename/2053434f4f5053434f4f5020"
$url = (Invoke-WebRequest -Uri $url | Select-Object -ExpandProperty Content)
}

# Sourceforge.net
if ($url -match "(?:downloads\.)?sourceforge.net\/projects?\/(?<project>[^\/]+)\/(?:files\/)?(?<file>.*)") {
# Reshapes the URL to avoid redirections
$url = "https://downloads.sourceforge.net/project/$($matches['project'])/$($matches['file'])?r=&ts="
}
return $url
}
Loading