mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2025-11-28 04:13:30 +00:00
Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8468c8cc20 | ||
|
|
3a79532d5f | ||
|
|
aa499a140a | ||
|
|
03d831d9a0 | ||
|
|
874e8e6fa1 | ||
|
|
f2ee3f902f | ||
|
|
0e698ccbd5 | ||
|
|
7399945502 | ||
|
|
7e86336a42 | ||
|
|
f0cd3e1977 | ||
|
|
f9c6913d67 | ||
|
|
a8d4027a90 | ||
|
|
28c51e04b1 | ||
|
|
2120c28c22 | ||
|
|
79669717fe | ||
|
|
52a035b5cc | ||
|
|
20a178b1f3 | ||
|
|
ca0506cf3e | ||
|
|
2a637361cc | ||
|
|
4c55e7aebd | ||
|
|
db8d554f80 | ||
|
|
b592b38abd | ||
|
|
25d35007c6 | ||
|
|
04b7ce79c7 | ||
|
|
ff38652e01 | ||
|
|
c9f0728ff7 | ||
|
|
691c23330c | ||
|
|
b588a06e41 | ||
|
|
9246250808 | ||
|
|
8c51a50856 | ||
|
|
ebd8c036fa | ||
|
|
ed6101a2ab | ||
|
|
26a03e2404 | ||
|
|
f9c4f9e175 | ||
|
|
3321b969a4 | ||
|
|
22f1672fcb | ||
|
|
4e528e1655 | ||
|
|
ac6f1baaf4 | ||
|
|
dc9d198014 | ||
|
|
84e00fdb77 | ||
|
|
7a309a1b00 | ||
|
|
3577f91d82 | ||
|
|
e0c682de7c | ||
|
|
79cf33d0b7 | ||
|
|
7f99c499d7 |
67
CHANGELOG.md
67
CHANGELOG.md
@@ -1,3 +1,68 @@
|
||||
## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/v0.5.3...develop)
|
||||
|
||||
### Features
|
||||
|
||||
- **install:** Add output for the setting and removal of environment variables ([#6460](https://github.com/ScoopInstaller/Scoop/issues/6460))
|
||||
- **scoop-uninstall:** Allow access to `$bucket` in uninstall scripts ([#6380](https://github.com/ScoopInstaller/Scoop/issues/6380))
|
||||
- **install:** Add separator at the end of notes, highlight suggestions ([#6418](https://github.com/ScoopInstaller/Scoop/issues/6418))
|
||||
- **download|scoop-download:** Add GitHub issue prompt when the default downloader fails ([#6539](https://github.com/ScoopInstaller/Scoop/issues/6539))
|
||||
- **download|scoop-config:** Allow disabling automatic fallback to the default downloader when Aria2c download fails ([#6538](https://github.com/ScoopInstaller/Scoop/issues/6538))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **core:** Fix the grep parameter in the `Invoke-GitLog` function ([#6407](https://github.com/ScoopInstaller/Scoop/issues/6407))
|
||||
- **buckets:** Fix the filtering condition when retrieving the number of manifests ([#6509](https://github.com/ScoopInstaller/Scoop/issues/6509))
|
||||
- **scoop-download:** Fix function `nightly_version` not defined error ([#6386](https://github.com/ScoopInstaller/Scoop/issues/6386))
|
||||
- **scoop-uninstall:** Correct `-Global` Switch ([#6454](https://github.com/ScoopInstaller/Scoop/issues/6454))
|
||||
- **scoop-update:** Force sync tags w/ remote branch while scoop update ([#6439](https://github.com/ScoopInstaller/Scoop/issues/6439))
|
||||
- **autoupdate:** Use origin URL to handle URLs with fragment in GitHub mode ([#6455](https://github.com/ScoopInstaller/Scoop/issues/6455))
|
||||
- **buckets|scoop-info:** Switch git log date format to ISO 8601 to avoid locale issues ([#6446](https://github.com/ScoopInstaller/Scoop/issues/6446))
|
||||
- **scoop-version:** Fix logic error caused by missing brackets ([#6463](https://github.com/ScoopInstaller/Scoop/issues/6463))
|
||||
- **getopt:** Teach getopt to respect the `--%` token ([#6477](https://github.com/ScoopInstaller/Scoop/issues/6477))
|
||||
- **core|manifest:** Avoid error messages when searching non-existent 'deprecated' directory ([#6471](https://github.com/ScoopInstaller/Scoop/issues/6471))
|
||||
- **path:** Trim ending slash when initializing paths ([#6501](https://github.com/ScoopInstaller/Scoop/issues/6501))
|
||||
- **checkver:** Allow script to run when URL fetch fails but script exists ([#6490](https://github.com/ScoopInstaller/Scoop/issues/6490), [#6556](https://github.com/ScoopInstaller/Scoop/issues/6556))
|
||||
- **install:** Don't add to `$Error` when checking for service `cexecsvc` ([#6520](https://github.com/ScoopInstaller/Scoop/issues/6520))
|
||||
- **checkver:** Fix incorrect version returned when script fails without output ([#6547](https://github.com/ScoopInstaller/Scoop/issues/6547))
|
||||
- **uninstall:** Import `url_filename` from `download.ps1` ([#6530](https://github.com/ScoopInstaller/Scoop/issues/6530))
|
||||
- **schema:** Add missing `hash.mode` value `github` ([#6533](https://github.com/ScoopInstaller/Scoop/issues/6533))
|
||||
- **core:** Skip NO_JUNCTION logic when $app is 'scoop' in `currentdir` function ([#6541](https://github.com/ScoopInstaller/Scoop/issues/6541))
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
- **output:** Replace raw prints with functions for standardized output ([#6449](https://github.com/ScoopInstaller/Scoop/issues/6449))
|
||||
- **output:** Combine the separated outputs into a single output ([#6545](https://github.com/ScoopInstaller/Scoop/issues/6545))
|
||||
|
||||
### Builds
|
||||
|
||||
- **supporting:** Update System.Data.SQLite to 2.0.2 ([#6555](https://github.com/ScoopInstaller/Scoop/issues/6555), [#6560](https://github.com/ScoopInstaller/Scoop/issues/6560))
|
||||
|
||||
## [v0.5.3](https://github.com/ScoopInstaller/Scoop/compare/v0.5.2...v0.5.3) - 2025-08-11
|
||||
|
||||
### Features
|
||||
|
||||
- **autoupdate:** GitHub predefined hashes support ([#6416](https://github.com/ScoopInstaller/Scoop/issues/6416), [#6435](https://github.com/ScoopInstaller/Scoop/issues/6435))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **scoop-download|install|update:** Fallback to default downloader when aria2 fails ([#4292](https://github.com/ScoopInstaller/Scoop/issues/4292))
|
||||
- **decompress:** `Expand-7zipArchive` only delete temp dir / `$extractDir` if it is empty ([#6092](https://github.com/ScoopInstaller/Scoop/issues/6092))
|
||||
- **decompress:** Replace deprecated 7ZIPEXTRACT_USE_EXTERNAL config with USE_EXTERNAL_7ZIP ([#6327](https://github.com/ScoopInstaller/Scoop/issues/6327))
|
||||
- **commands:** Handling broken aliases ([#6141](https://github.com/ScoopInstaller/Scoop/issues/6141))
|
||||
- **shim:** Do not suppress `stderr`, properly check `wslpath`/`cygpath` command first ([#6114](https://github.com/ScoopInstaller/Scoop/issues/6114))
|
||||
- **scoop-bucket:** Add missing import for `no_junction` envs ([#6181](https://github.com/ScoopInstaller/Scoop/issues/6181))
|
||||
- **scoop-uninstall:** Fix uninstaller does not gain Global state ([#6430](https://github.com/ScoopInstaller/Scoop/issues/6430))
|
||||
- **scoop-depends-tests:** Mocking `USE_EXTERNAL_7ZIP` as $false to avoding error when it is $true ([#6431](https://github.com/ScoopInstaller/Scoop/issues/6431))
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
- **download:** Move download-related functions to 'download.ps1' ([#6095](https://github.com/ScoopInstaller/Scoop/issues/6095))
|
||||
- **Get-Manifest:** Select actual source for manifest ([#6142](https://github.com/ScoopInstaller/Scoop/issues/6142))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
- **shim:** Update kiennq-shim to v3.1.2 ([#6261](https://github.com/ScoopInstaller/Scoop/issues/6261))
|
||||
|
||||
## [v0.5.2](https://github.com/ScoopInstaller/Scoop/compare/v0.5.1...v0.5.2) - 2024-07-26
|
||||
|
||||
### Bug Fixes
|
||||
@@ -40,7 +105,7 @@
|
||||
- **checkver:** Correct error messages ([#6024](https://github.com/ScoopInstaller/Scoop/issues/6024))
|
||||
- **core:** Search for Git executable instead of any cmdlet ([#5998](https://github.com/ScoopInstaller/Scoop/issues/5998))
|
||||
- **core:** Use correct path in 'bash' ([#6006](https://github.com/ScoopInstaller/Scoop/issues/6006))
|
||||
- **core:** Limit the number of commands to get when search for git executable ([#6013](https://github.com/ScoopInstaller/Scoop/pull/6013))
|
||||
- **core:** Limit the number of commands to get when search for git executable ([#6013](https://github.com/ScoopInstaller/Scoop/issues/6013))
|
||||
- **decompress:** Match `extract_dir`/`extract_to` and archives ([#5983](https://github.com/ScoopInstaller/Scoop/issues/5983))
|
||||
- **json:** Serialize jsonpath return ([#5921](https://github.com/ScoopInstaller/Scoop/issues/5921))
|
||||
- **shim:** Restore original path for JAR cmd ([#6030](https://github.com/ScoopInstaller/Scoop/issues/6030))
|
||||
|
||||
@@ -46,7 +46,7 @@ param(
|
||||
. "$PSScriptRoot\..\lib\autoupdate.ps1"
|
||||
. "$PSScriptRoot\..\lib\json.ps1"
|
||||
. "$PSScriptRoot\..\lib\versions.ps1"
|
||||
. "$PSScriptRoot\..\lib\install.ps1"
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
|
||||
$Dir = Convert-Path $Dir
|
||||
if ($ForceUpdate) { $Update = $true }
|
||||
|
||||
@@ -28,7 +28,7 @@ param(
|
||||
|
||||
. "$PSScriptRoot\..\lib\core.ps1"
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1"
|
||||
. "$PSScriptRoot\..\lib\install.ps1"
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
|
||||
$Dir = Convert-Path $Dir
|
||||
$Queue = @()
|
||||
|
||||
@@ -73,7 +73,7 @@ param(
|
||||
. "$PSScriptRoot\..\lib\buckets.ps1"
|
||||
. "$PSScriptRoot\..\lib\json.ps1"
|
||||
. "$PSScriptRoot\..\lib\versions.ps1"
|
||||
. "$PSScriptRoot\..\lib\install.ps1" # needed for hash generation
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
|
||||
if ($App -ne '*' -and (Test-Path $App -PathType Leaf)) {
|
||||
$Dir = Split-Path $App
|
||||
@@ -274,6 +274,8 @@ while ($in_progress -gt 0) {
|
||||
$expected_ver = $json.version
|
||||
$ver = $Version
|
||||
|
||||
$matchesHashtable = @{}
|
||||
|
||||
if (!$ver) {
|
||||
if (!$regexp -and $replace) {
|
||||
next "'replace' requires 're' or 'regex'"
|
||||
@@ -281,11 +283,19 @@ while ($in_progress -gt 0) {
|
||||
}
|
||||
$err = $ev.SourceEventArgs.Error
|
||||
if ($err) {
|
||||
next "$($err.message)`r`nURL $url is not valid"
|
||||
continue
|
||||
if (!$script) {
|
||||
next "$($err.message)`r`nURL $url is not valid"
|
||||
continue
|
||||
} else {
|
||||
# Run script despite URL download failure
|
||||
Write-Host "$($err.message)`r`nURL $url is not valid. Falling back to checkver.script ..."
|
||||
}
|
||||
}
|
||||
|
||||
if ($url) {
|
||||
$page = $null
|
||||
$source = $url
|
||||
|
||||
if ($url -and !$err) {
|
||||
$ms = New-Object System.IO.MemoryStream
|
||||
$ms.Write($result, 0, $result.Length)
|
||||
$ms.Seek(0, 0) | Out-Null
|
||||
@@ -294,12 +304,17 @@ while ($in_progress -gt 0) {
|
||||
}
|
||||
$page = (New-Object System.IO.StreamReader($ms, (Get-Encoding $wc))).ReadToEnd()
|
||||
}
|
||||
$source = $url
|
||||
|
||||
if ($script) {
|
||||
$page = Invoke-Command ([scriptblock]::Create($script -join "`r`n"))
|
||||
$source = 'the output of script'
|
||||
}
|
||||
|
||||
if ($null -eq $page) {
|
||||
next "couldn't retrieve content from $source"
|
||||
continue
|
||||
}
|
||||
|
||||
if ($jsonpath) {
|
||||
# Return only a single value if regex is absent
|
||||
$noregex = [String]::IsNullOrEmpty($regexp)
|
||||
@@ -358,7 +373,6 @@ while ($in_progress -gt 0) {
|
||||
}
|
||||
|
||||
if ($match -and $match.Success) {
|
||||
$matchesHashtable = @{}
|
||||
$re.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) }
|
||||
$ver = $matchesHashtable['1']
|
||||
if ($replace) {
|
||||
|
||||
@@ -23,6 +23,7 @@ param(
|
||||
. "$PSScriptRoot\..\lib\core.ps1"
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1"
|
||||
. "$PSScriptRoot\..\lib\description.ps1"
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
|
||||
$Dir = Convert-Path $Dir
|
||||
$Queue = @()
|
||||
|
||||
@@ -20,8 +20,8 @@ switch ($subCommand) {
|
||||
}
|
||||
({ $subCommand -in @('-v', '--version') }) {
|
||||
Write-Host 'Current Scoop version:'
|
||||
if (Test-GitAvailable -and (Test-Path "$PSScriptRoot\..\.git") -and (get_config SCOOP_BRANCH 'master') -ne 'master') {
|
||||
Invoke-Git -Path "$PSScriptRoot\.." -ArgumentList @('log', 'HEAD', '-1', '--oneline')
|
||||
if ((Test-GitAvailable) -and (Test-Path "$PSScriptRoot\..\.git") -and ((get_config SCOOP_BRANCH 'master') -ne 'master')) {
|
||||
Invoke-Git -Path "$PSScriptRoot\.." -ArgumentList @('--no-pager', 'log', 'HEAD', '-1', '--oneline')
|
||||
} else {
|
||||
$version = Select-String -Pattern '^## \[(v[\d.]+)\].*?([\d-]+)$' -Path "$PSScriptRoot\..\CHANGELOG.md"
|
||||
Write-Host $version.Matches.Groups[1].Value -ForegroundColor Cyan -NoNewline
|
||||
@@ -31,9 +31,9 @@ switch ($subCommand) {
|
||||
|
||||
Get-LocalBucket | ForEach-Object {
|
||||
$bucketLoc = Find-BucketDirectory $_ -Root
|
||||
if (Test-GitAvailable -and (Test-Path "$bucketLoc\.git")) {
|
||||
if ((Test-GitAvailable) -and (Test-Path "$bucketLoc\.git")) {
|
||||
Write-Host "'$_' bucket:"
|
||||
Invoke-Git -Path $bucketLoc -ArgumentList @('log', 'HEAD', '-1', '--oneline')
|
||||
Invoke-Git -Path $bucketLoc -ArgumentList @('--no-pager', 'log', 'HEAD', '-1', '--oneline')
|
||||
Write-Host ''
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ function do_uninstall($app, $global) {
|
||||
$architecture = $install.architecture
|
||||
|
||||
Write-Output "Uninstalling '$app'"
|
||||
Invoke-Installer -Path $dir -Manifest $manifest -ProcessorArchitecture $architecture -Uninstall
|
||||
Invoke-Installer -Path $dir -Manifest $manifest -ProcessorArchitecture $architecture -Global:$global -Uninstall
|
||||
rm_shims $app $manifest $global $architecture
|
||||
|
||||
# If a junction was used during install, that will have been used
|
||||
|
||||
@@ -1,4 +1,24 @@
|
||||
# Must included with 'json.ps1'
|
||||
|
||||
function format_hash([String] $hash) {
|
||||
$hash = $hash.toLower()
|
||||
|
||||
# Workaround for GitHub API:
|
||||
# `"digest": "sha256:<SHA256_STRING>"`
|
||||
if ($hash -like 'sha256:*') {
|
||||
$hash = $hash.Substring(7) # Remove prefix 'sha256:'
|
||||
}
|
||||
|
||||
switch ($hash.Length) {
|
||||
32 { $hash = "md5:$hash" } # md5
|
||||
40 { $hash = "sha1:$hash" } # sha1
|
||||
64 { $hash = $hash } # sha256
|
||||
128 { $hash = "sha512:$hash" } # sha512
|
||||
default { $hash = $null }
|
||||
}
|
||||
return $hash
|
||||
}
|
||||
|
||||
function find_hash_in_rdf([String] $url, [String] $basename) {
|
||||
$xml = $null
|
||||
try {
|
||||
@@ -191,13 +211,14 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u
|
||||
$hash = $null
|
||||
|
||||
$hashmode = $config.mode
|
||||
$originurl = strip_fragment $url
|
||||
$basename = [System.Web.HttpUtility]::UrlDecode((url_remote_filename($url)))
|
||||
|
||||
$substitutions = $substitutions.Clone()
|
||||
$substitutions.Add('$url', (strip_fragment $url))
|
||||
$substitutions.Add('$baseurl', (strip_filename (strip_fragment $url)).TrimEnd('/'))
|
||||
$substitutions.Add('$url', $originurl)
|
||||
$substitutions.Add('$baseurl', (strip_filename $originurl).TrimEnd('/'))
|
||||
$substitutions.Add('$basename', $basename)
|
||||
$substitutions.Add('$urlNoExt', (strip_ext (strip_fragment $url)))
|
||||
$substitutions.Add('$urlNoExt', (strip_ext $originurl))
|
||||
$substitutions.Add('$basenameNoExt', (strip_ext $basename))
|
||||
|
||||
debug $substitutions
|
||||
@@ -246,6 +267,10 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u
|
||||
$hashmode = 'sourceforge'
|
||||
}
|
||||
|
||||
if (!$hashfile_url -and $url -match 'https:\/\/github\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/releases\/download\/[^\/]+\/[^\/]+') {
|
||||
$hashmode = 'github'
|
||||
}
|
||||
|
||||
switch ($hashmode) {
|
||||
'extract' {
|
||||
$hash = find_hash_in_textfile $hashfile_url $substitutions $regex
|
||||
@@ -273,6 +298,10 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u
|
||||
$hashfile_url = (strip_filename (strip_fragment "https://sourceforge.net/projects/$($matches['project'])/files/$($matches['file'])")).TrimEnd('/')
|
||||
$hash = find_hash_in_textfile $hashfile_url $substitutions '"$basename":.*?"sha1":\s*"([a-fA-F0-9]{40})"'
|
||||
}
|
||||
'github' {
|
||||
$hashfile_url = "https://api.github.com/repos/$($matches['owner'])/$($matches['repo'])/releases"
|
||||
$hash = find_hash_in_json $hashfile_url $substitutions ("$..assets[?(@.browser_download_url == '" + $originurl + "')].digest")
|
||||
}
|
||||
}
|
||||
|
||||
if ($hash) {
|
||||
|
||||
@@ -108,12 +108,12 @@ function list_buckets {
|
||||
$path = Find-BucketDirectory $_ -Root
|
||||
if ((Test-Path (Join-Path $path '.git')) -and (Get-Command git -ErrorAction SilentlyContinue)) {
|
||||
$bucket.Source = Invoke-Git -Path $path -ArgumentList @('config', 'remote.origin.url')
|
||||
$bucket.Updated = Invoke-Git -Path $path -ArgumentList @('log', '--format=%aD', '-n', '1') | Get-Date
|
||||
$bucket.Updated = Invoke-Git -Path $path -ArgumentList @('log', '--format=%aI', '-n', '1') | Get-Date
|
||||
} else {
|
||||
$bucket.Source = friendly_path $path
|
||||
$bucket.Updated = (Get-Item "$path\bucket" -ErrorAction SilentlyContinue).LastWriteTime
|
||||
}
|
||||
$bucket.Manifests = Get-ChildItem "$path\bucket" -Force -Recurse -ErrorAction SilentlyContinue |
|
||||
$bucket.Manifests = Get-ChildItem -Path "$path\bucket" -Filter "*.json" -File -Force -Recurse -ErrorAction SilentlyContinue |
|
||||
Measure-Object | Select-Object -ExpandProperty Count
|
||||
$buckets += [PSCustomObject]$bucket
|
||||
}
|
||||
@@ -160,7 +160,7 @@ function add_bucket($name, $repo) {
|
||||
Remove-Item $dir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
return 1
|
||||
}
|
||||
Write-Host 'OK'
|
||||
Write-Host 'OK.'
|
||||
if (get_config USE_SQLITE_CACHE) {
|
||||
info 'Updating cache...'
|
||||
Set-ScoopDB -Path (Get-ChildItem (Find-BucketDirectory $name) -Filter '*.json' -Recurse).FullName
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
function command_files {
|
||||
(Get-ChildItem "$PSScriptRoot\..\libexec") + (Get-ChildItem "$scoopdir\shims") |
|
||||
Where-Object 'scoop-.*?\.ps1$' -Property Name -Match
|
||||
Where-Object 'scoop-.*?\.ps1$' -Property Name -Match
|
||||
}
|
||||
|
||||
function commands {
|
||||
@@ -86,7 +86,9 @@ function rm_alias {
|
||||
}
|
||||
|
||||
info "Removing alias '$name'..."
|
||||
Remove-Item "$(shimdir $false)\scoop-$name.ps1"
|
||||
if (Test-Path "$(shimdir $false)\scoop-$name.ps1") {
|
||||
Remove-Item "$(shimdir $false)\scoop-$name.ps1"
|
||||
}
|
||||
$aliases.PSObject.Properties.Remove($name)
|
||||
set_config ALIAS $aliases | Out-Null
|
||||
}
|
||||
@@ -98,11 +100,19 @@ function list_aliases {
|
||||
|
||||
$aliases = get_config ALIAS ([PSCustomObject]@{})
|
||||
$alias_info = $aliases.PSObject.Properties.Name | Where-Object { $_ } | ForEach-Object {
|
||||
# Mark the alias as <BROKEN>, if the alias script file does NOT exist.
|
||||
if (!(Test-Path "$(shimdir $false)\scoop-$_.ps1")) {
|
||||
[PSCustomObject]@{
|
||||
Name = $_
|
||||
Command = '<BROKEN>'
|
||||
}
|
||||
return
|
||||
}
|
||||
$content = Get-Content (command_path $_)
|
||||
[PSCustomObject]@{
|
||||
Name = $_
|
||||
Summary = (summary $content).Trim()
|
||||
Command = ($content | Select-Object -Skip 1).Trim()
|
||||
Summary = (summary $content).Trim()
|
||||
}
|
||||
}
|
||||
if (!$alias_info) {
|
||||
|
||||
219
lib/core.ps1
219
lib/core.ps1
@@ -63,18 +63,6 @@ function Optimize-SecurityProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-Encoding($wc) {
|
||||
if ($null -ne $wc.ResponseHeaders -and $wc.ResponseHeaders['Content-Type'] -match 'charset=([^;]*)') {
|
||||
return [System.Text.Encoding]::GetEncoding($Matches[1])
|
||||
} else {
|
||||
return [System.Text.Encoding]::GetEncoding('utf-8')
|
||||
}
|
||||
}
|
||||
|
||||
function Get-UserAgent() {
|
||||
return "Scoop/1.0 (+http://scoop.sh/) PowerShell/$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) (Windows NT $([System.Environment]::OSVersion.Version.Major).$([System.Environment]::OSVersion.Version.Minor); $(if(${env:ProgramFiles(Arm)}){'ARM64; '}elseif($env:PROCESSOR_ARCHITECTURE -eq 'AMD64'){'Win64; x64; '})$(if($env:PROCESSOR_ARCHITEW6432 -in 'AMD64','ARM64'){'WOW64; '})$PSEdition)"
|
||||
}
|
||||
|
||||
function Show-DeprecatedWarning {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
@@ -102,7 +90,7 @@ function load_cfg($file) {
|
||||
$content = [System.IO.File]::ReadAllLines($file)
|
||||
return ($content | ConvertFrom-Json -ErrorAction Stop)
|
||||
} catch {
|
||||
Write-Host "ERROR loading $file`: $($_.exception.message)"
|
||||
error "loading $file`: $($_.exception.message)"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,9 +206,6 @@ function Complete-ConfigChange {
|
||||
}
|
||||
|
||||
if ($Name -eq 'use_sqlite_cache' -and $Value -eq $true) {
|
||||
if ((Get-DefaultArchitecture) -eq 'arm64') {
|
||||
abort 'SQLite cache is not supported on ARM64 platform.'
|
||||
}
|
||||
. "$PSScriptRoot\..\lib\database.ps1"
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1"
|
||||
info 'Initializing SQLite cache in progress... This may take a while, please wait.'
|
||||
@@ -228,35 +213,6 @@ function Complete-ConfigChange {
|
||||
}
|
||||
}
|
||||
|
||||
function setup_proxy() {
|
||||
# note: '@' and ':' in password must be escaped, e.g. 'p@ssword' -> p\@ssword'
|
||||
$proxy = get_config PROXY
|
||||
if(!$proxy) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
$credentials, $address = $proxy -split '(?<!\\)@'
|
||||
if(!$address) {
|
||||
$address, $credentials = $credentials, $null # no credentials supplied
|
||||
}
|
||||
|
||||
if($address -eq 'none') {
|
||||
[net.webrequest]::defaultwebproxy = $null
|
||||
} elseif($address -ne 'default') {
|
||||
[net.webrequest]::defaultwebproxy = new-object net.webproxy "http://$address"
|
||||
}
|
||||
|
||||
if($credentials -eq 'currentuser') {
|
||||
[net.webrequest]::defaultwebproxy.credentials = [net.credentialcache]::defaultcredentials
|
||||
} elseif($credentials) {
|
||||
$username, $password = $credentials -split '(?<!\\):' | ForEach-Object { $_ -replace '\\([@:])','$1' }
|
||||
[net.webrequest]::defaultwebproxy.credentials = new-object net.networkcredential($username, $password)
|
||||
}
|
||||
} catch {
|
||||
warn "Failed to use proxy '$proxy': $($_.exception.message)"
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-Git {
|
||||
[CmdletBinding()]
|
||||
[OutputType([String])]
|
||||
@@ -317,7 +273,7 @@ function Invoke-GitLog {
|
||||
}
|
||||
$Name = "%Cgreen$($Name.PadRight(12, ' ').Substring(0, 12))%Creset "
|
||||
}
|
||||
Invoke-Git -Path $Path -ArgumentList @('--no-pager', 'log', '--color', '--no-decorate', "--grep='^(chore)'", '--invert-grep', '--abbrev=12', "--format=tformat: * %C(yellow)%h%Creset %<|(72,trunc)%s $Name%C(cyan)%cr%Creset", "$CommitHash..HEAD")
|
||||
Invoke-Git -Path $Path -ArgumentList @('--no-pager', 'log', '--color', '--no-decorate', '--grep=^(chore)', '--invert-grep', '--abbrev=12', "--format=tformat: * %C(yellow)%h%Creset %<|(72,trunc)%s $Name%C(cyan)%cr%Creset", "$CommitHash..HEAD")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +350,7 @@ function appdir($app, $global) { "$(appsdir $global)\$app" }
|
||||
function versiondir($app, $version, $global) { "$(appdir $app $global)\$version" }
|
||||
|
||||
function currentdir($app, $global) {
|
||||
if (get_config NO_JUNCTION) {
|
||||
if ((get_config NO_JUNCTION) -and ($app -ne 'scoop')) {
|
||||
$version = Select-CurrentVersion -App $app -Global:$global
|
||||
} else {
|
||||
$version = 'current'
|
||||
@@ -584,10 +540,6 @@ function Test-HelperInstalled {
|
||||
return ![String]::IsNullOrWhiteSpace((Get-HelperPath -Helper $Helper))
|
||||
}
|
||||
|
||||
function Test-Aria2Enabled {
|
||||
return (Test-HelperInstalled -Helper Aria2) -and (get_config 'aria2-enabled' $true)
|
||||
}
|
||||
|
||||
function app_status($app, $global) {
|
||||
$status = @{}
|
||||
$status.installed = installed $app $global
|
||||
@@ -599,6 +551,9 @@ function app_status($app, $global) {
|
||||
$status.failed = failed $app $global
|
||||
$status.hold = ($install_info.hold -eq $true)
|
||||
|
||||
$deprecated_dir = (Find-BucketDirectory -Name $install_info.bucket -Root) + "\deprecated"
|
||||
$status.deprecated = (Get-ChildItem $deprecated_dir -Filter "$(sanitary_path $app).json" -Recurse -ErrorAction Ignore).FullName
|
||||
|
||||
$manifest = manifest $app $install_info.bucket $install_info.url
|
||||
$status.removed = (!$manifest)
|
||||
if ($manifest.version) {
|
||||
@@ -626,7 +581,6 @@ function app_status($app, $global) {
|
||||
if ($deps) {
|
||||
$status.missing_deps += , $deps
|
||||
}
|
||||
|
||||
return $status
|
||||
}
|
||||
|
||||
@@ -639,28 +593,6 @@ function fname($path) { split-path $path -leaf }
|
||||
function strip_ext($fname) { $fname -replace '\.[^\.]*$', '' }
|
||||
function strip_filename($path) { $path -replace [regex]::escape((fname $path)) }
|
||||
function strip_fragment($url) { $url -replace (new-object uri $url).fragment }
|
||||
|
||||
function url_filename($url) {
|
||||
(split-path $url -leaf).split('?') | Select-Object -First 1
|
||||
}
|
||||
# Unlike url_filename which can be tricked by appending a
|
||||
# URL fragment (e.g. #/dl.7z, useful for coercing a local filename),
|
||||
# this function extracts the original filename from the URL.
|
||||
function url_remote_filename($url) {
|
||||
$uri = (New-Object URI $url)
|
||||
$basename = Split-Path $uri.PathAndQuery -Leaf
|
||||
If ($basename -match ".*[?=]+([\w._-]+)") {
|
||||
$basename = $matches[1]
|
||||
}
|
||||
If (($basename -notlike "*.*") -or ($basename -match "^[v.\d]+$")) {
|
||||
$basename = Split-Path $uri.AbsolutePath -Leaf
|
||||
}
|
||||
If (($basename -notlike "*.*") -and ($uri.Fragment -ne "")) {
|
||||
$basename = $uri.Fragment.Trim('/', '#')
|
||||
}
|
||||
return $basename
|
||||
}
|
||||
|
||||
function ensure($dir) {
|
||||
if (!(Test-Path -Path $dir)) {
|
||||
New-Item -Path $dir -ItemType Directory | Out-Null
|
||||
@@ -687,7 +619,14 @@ function Get-AbsolutePath {
|
||||
$Path
|
||||
)
|
||||
process {
|
||||
return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
|
||||
$resolvedPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
|
||||
if ($resolvedPath -match '[\\/]$') {
|
||||
$root = [System.IO.Path]::GetPathRoot($resolvedPath)
|
||||
if ($resolvedPath -ine $root) {
|
||||
$resolvedPath = $resolvedPath.TrimEnd([char[]]@('\', '/'))
|
||||
}
|
||||
}
|
||||
return $resolvedPath
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,7 +747,7 @@ function Invoke-ExternalCommand {
|
||||
[void]$Process.Start()
|
||||
} catch {
|
||||
if ($Activity) {
|
||||
Write-Host "error." -ForegroundColor DarkRed
|
||||
Write-Host "Error." -ForegroundColor DarkRed
|
||||
}
|
||||
error $_.Exception.Message
|
||||
return $false
|
||||
@@ -827,20 +766,20 @@ function Invoke-ExternalCommand {
|
||||
if ($Process.ExitCode -ne 0) {
|
||||
if ($ContinueExitCodes -and ($ContinueExitCodes.ContainsKey($Process.ExitCode))) {
|
||||
if ($Activity) {
|
||||
Write-Host "done." -ForegroundColor DarkYellow
|
||||
Write-Host "Done." -ForegroundColor DarkYellow
|
||||
}
|
||||
warn $ContinueExitCodes[$Process.ExitCode]
|
||||
return $true
|
||||
} else {
|
||||
if ($Activity) {
|
||||
Write-Host "error." -ForegroundColor DarkRed
|
||||
Write-Host "Error." -ForegroundColor DarkRed
|
||||
}
|
||||
error "Exit code was $($Process.ExitCode)!"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
if ($Activity) {
|
||||
Write-Host "done." -ForegroundColor Green
|
||||
Write-Host "Done." -ForegroundColor Green
|
||||
}
|
||||
return $true
|
||||
}
|
||||
@@ -1070,11 +1009,18 @@ function shim($path, $global, $name, $arg) {
|
||||
) -join "`n" | Out-UTF8File $shim -NoNewLine
|
||||
} else {
|
||||
warn_on_overwrite "$shim.cmd" $path
|
||||
$quoted_arg = if ($arg.Count -gt 0) { $arg | ForEach-Object { "`"$_`"" } }
|
||||
@(
|
||||
"@rem $resolved_path",
|
||||
"@bash `"`$(wslpath -u '$resolved_path')`" $arg %* 2>nul",
|
||||
'@if %errorlevel% neq 0 (',
|
||||
" @bash `"`$(cygpath -u '$resolved_path')`" $arg %* 2>nul",
|
||||
'@echo off',
|
||||
'bash -c "command -v wslpath >/dev/null"',
|
||||
'if %errorlevel% equ 0 (',
|
||||
" bash `"`$(wslpath -u '$resolved_path')`" $quoted_arg %*",
|
||||
') else (',
|
||||
" set args=$quoted_arg %*",
|
||||
' setlocal enabledelayedexpansion',
|
||||
' if not "!args!"=="" set args=!args:"=""!',
|
||||
" bash -c `"`$(cygpath -u '$resolved_path') !args!`"",
|
||||
')'
|
||||
) -join "`r`n" | Out-UTF8File "$shim.cmd"
|
||||
|
||||
@@ -1282,112 +1228,6 @@ function substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) {
|
||||
return $newentity
|
||||
}
|
||||
|
||||
function format_hash([String] $hash) {
|
||||
$hash = $hash.toLower()
|
||||
switch ($hash.Length)
|
||||
{
|
||||
32 { $hash = "md5:$hash" } # md5
|
||||
40 { $hash = "sha1:$hash" } # sha1
|
||||
64 { $hash = $hash } # sha256
|
||||
128 { $hash = "sha512:$hash" } # sha512
|
||||
default { $hash = $null }
|
||||
}
|
||||
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 get_hash([String] $multihash) {
|
||||
$type, $hash = $multihash -split ':'
|
||||
if(!$hash) {
|
||||
# no type specified, assume sha256
|
||||
$type, $hash = 'sha256', $multihash
|
||||
}
|
||||
|
||||
if(@('md5','sha1','sha256', 'sha512') -notcontains $type) {
|
||||
return $null, "Hash type '$type' isn't supported."
|
||||
}
|
||||
|
||||
return $type, $hash.ToLower()
|
||||
}
|
||||
|
||||
function Get-GitHubToken {
|
||||
return $env:SCOOP_GH_TOKEN, (get_config GH_TOKEN) | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1
|
||||
}
|
||||
|
||||
function handle_special_urls($url)
|
||||
{
|
||||
# FossHub.com
|
||||
if ($url -match "^(?:.*fosshub.com\/)(?<name>.*)(?:\/|\?dwl=)(?<filename>.*)$") {
|
||||
$Body = @{
|
||||
projectUri = $Matches.name;
|
||||
fileName = $Matches.filename;
|
||||
source = 'CF';
|
||||
isLatestVersion = $true
|
||||
}
|
||||
if ((Invoke-RestMethod -Uri $url) -match '"p":"(?<pid>[a-f0-9]{24}).*?"r":"(?<rid>[a-f0-9]{24})') {
|
||||
$Body.Add("projectId", $Matches.pid)
|
||||
$Body.Add("releaseId", $Matches.rid)
|
||||
}
|
||||
$url = Invoke-RestMethod -Method Post -Uri "https://api.fosshub.com/download/" -ContentType "application/json" -Body (ConvertTo-Json $Body -Compress)
|
||||
if ($null -eq $url.error) {
|
||||
$url = $url.data.url
|
||||
}
|
||||
}
|
||||
|
||||
# Sourceforge.net
|
||||
if ($url -match "(?:downloads\.)?sourceforge.net\/projects?\/(?<project>[^\/]+)\/(?:files\/)?(?<file>.*?)(?:$|\/download|\?)") {
|
||||
# Reshapes the URL to avoid redirections
|
||||
$url = "https://downloads.sourceforge.net/project/$($matches['project'])/$($matches['file'])"
|
||||
}
|
||||
|
||||
# Github.com
|
||||
if ($url -match 'github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = Get-GitHubToken)) {
|
||||
$headers = @{ "Authorization" = "token $token" }
|
||||
$privateUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)"
|
||||
$assetUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)/releases/tags/$($Matches.tag)"
|
||||
|
||||
if ((Invoke-RestMethod -Uri $privateUrl -Headers $headers).Private) {
|
||||
$url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).Assets | Where-Object -Property Name -EQ -Value $Matches.file).Url, $Matches.filename -join ''
|
||||
}
|
||||
}
|
||||
|
||||
return $url
|
||||
}
|
||||
|
||||
function get_magic_bytes($file) {
|
||||
if(!(Test-Path $file)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if((Get-Command Get-Content).parameters.ContainsKey('AsByteStream')) {
|
||||
# PowerShell Core (6.0+) '-Encoding byte' is replaced by '-AsByteStream'
|
||||
return Get-Content $file -AsByteStream -TotalCount 8
|
||||
}
|
||||
else {
|
||||
return Get-Content $file -Encoding byte -TotalCount 8
|
||||
}
|
||||
}
|
||||
|
||||
function get_magic_bytes_pretty($file, $glue = ' ') {
|
||||
if(!(Test-Path $file)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return (get_magic_bytes $file | ForEach-Object { $_.ToString('x2') }) -join $glue
|
||||
}
|
||||
|
||||
function Out-UTF8File {
|
||||
param(
|
||||
[Parameter(Mandatory = $True, Position = 0)]
|
||||
@@ -1473,6 +1313,3 @@ $scoopPathEnvVar = switch (get_config USE_ISOLATED_PATH) {
|
||||
|
||||
# OS information
|
||||
$WindowsBuild = [System.Environment]::OSVersion.Version.Build
|
||||
|
||||
# Setup proxy globally
|
||||
setup_proxy
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
.SYNOPSIS
|
||||
Get SQLite .NET driver
|
||||
.DESCRIPTION
|
||||
Download and extract the SQLite .NET driver from NuGet.
|
||||
Download and extract the SQLite .NET driver and SQLite precompiled binaries.
|
||||
The SQLite version is automatically detected from the download page.
|
||||
.PARAMETER Version
|
||||
System.String
|
||||
The version of the SQLite .NET driver to download.
|
||||
The version of the System.Data.SQLite NuGet package to download. (require version 2.0.0 or higher)
|
||||
.INPUTS
|
||||
None
|
||||
.OUTPUTS
|
||||
@@ -16,21 +17,44 @@
|
||||
#>
|
||||
function Get-SQLite {
|
||||
param (
|
||||
[string]$Version = '1.0.118'
|
||||
[string]$Version = '2.0.2'
|
||||
)
|
||||
# Install SQLite
|
||||
try {
|
||||
Write-Host "Downloading SQLite $Version..." -ForegroundColor DarkYellow
|
||||
$sqlitePkgPath = "$env:TEMP\sqlite.zip"
|
||||
$sqliteNetPath = "$env:TEMP\sqlite.net.zip"
|
||||
$sqliteDllPath = "$env:TEMP\sqlite.dll.zip"
|
||||
$sqliteTempPath = "$env:TEMP\sqlite"
|
||||
$sqlitePath = "$PSScriptRoot\..\supporting\sqlite"
|
||||
Invoke-WebRequest -Uri "https://api.nuget.org/v3-flatcontainer/stub.system.data.sqlite.core.netframework/$version/stub.system.data.sqlite.core.netframework.$version.nupkg" -OutFile $sqlitePkgPath
|
||||
Write-Host "Extracting SQLite $Version..." -ForegroundColor DarkYellow -NoNewline
|
||||
Expand-Archive -Path $sqlitePkgPath -DestinationPath $sqliteTempPath -Force
|
||||
New-Item -Path $sqlitePath -ItemType Directory -Force | Out-Null
|
||||
Move-Item -Path "$sqliteTempPath\build\net451\*", "$sqliteTempPath\lib\net451\System.Data.SQLite.dll" -Destination $sqlitePath -Force
|
||||
Remove-Item -Path $sqlitePkgPath, $sqliteTempPath -Recurse -Force
|
||||
Write-Host ' Done' -ForegroundColor DarkYellow
|
||||
|
||||
$arch = switch (Get-DefaultArchitecture) {
|
||||
'32bit' { 'x86' }
|
||||
'64bit' { 'x64' }
|
||||
'arm64' { 'arm64' }
|
||||
default { Write-Warning "Unknown architecture, using x64 as fallback"; 'x64' }
|
||||
}
|
||||
|
||||
Write-Host "Downloading System.Data.SQLite $Version..." -ForegroundColor DarkYellow
|
||||
Invoke-WebRequest -Uri "https://globalcdn.nuget.org/packages/system.data.sqlite.$Version.nupkg" -OutFile $sqliteNetPath
|
||||
|
||||
$downloadPage = Invoke-WebRequest -Uri 'https://sqlite.org/download.html' -UseBasicParsing
|
||||
if ($downloadPage.Content -match '(?s)<!-- Download product data.*?(PRODUCT,.+?)-->') {
|
||||
$productData = $Matches[1] | ConvertFrom-Csv
|
||||
} else {
|
||||
throw "Failed to parse SQLite download page product data"
|
||||
}
|
||||
$matchRow = $productData | Where-Object { $_.'RELATIVE-URL' -match "sqlite-dll-win-$arch-" }
|
||||
if (-not $matchRow) {
|
||||
throw "SQLite DLL for architecture $arch not found"
|
||||
}
|
||||
Write-Host "Downloading SQLite DLL $($matchRow.VERSION)..." -ForegroundColor DarkYellow
|
||||
Invoke-WebRequest -Uri "https://sqlite.org/$($matchRow.'RELATIVE-URL')" -OutFile $sqliteDllPath
|
||||
|
||||
Write-Host "Extracting libraries... " -ForegroundColor DarkYellow -NoNewline
|
||||
$sqliteNetPath, $sqliteDllPath | Expand-Archive -DestinationPath $sqliteTempPath -Force
|
||||
$null = New-Item -Path "$sqlitePath\$arch" -ItemType Directory -Force
|
||||
Move-Item -Path "$sqliteTempPath\lib\netstandard2.0\System.Data.SQLite.dll" -Destination $sqlitePath -Force
|
||||
Move-Item -Path "$sqliteTempPath\sqlite3.dll" -Destination "$sqlitePath\$arch\e_sqlite3.dll" -Force
|
||||
Remove-Item -Path $sqliteNetPath, $sqliteDllPath, $sqliteTempPath -Recurse -Force
|
||||
Write-Host 'Done.' -ForegroundColor DarkYellow
|
||||
return $true
|
||||
} catch {
|
||||
return $false
|
||||
@@ -219,9 +243,9 @@ function Set-ScoopDB {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Select Scoop database item(s).
|
||||
Find Scoop database item(s).
|
||||
.DESCRIPTION
|
||||
Select item(s) from the Scoop SQLite database.
|
||||
Find item(s) from the Scoop SQLite database.
|
||||
The pattern is matched against the name, binaries, and shortcuts columns for apps.
|
||||
.PARAMETER Pattern
|
||||
System.String
|
||||
@@ -233,9 +257,9 @@ function Set-ScoopDB {
|
||||
System.String
|
||||
.OUTPUTS
|
||||
System.Data.DataTable
|
||||
The selected database item(s).
|
||||
The found database item(s).
|
||||
#>
|
||||
function Select-ScoopDBItem {
|
||||
function Find-ScoopDBItem {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
|
||||
@@ -264,6 +288,7 @@ function Select-ScoopDBItem {
|
||||
[void]$dbAdapter.Fill($result)
|
||||
}
|
||||
end {
|
||||
$dbCommand.Dispose()
|
||||
$dbAdapter.Dispose()
|
||||
$db.Dispose()
|
||||
return $result
|
||||
@@ -322,10 +347,13 @@ function Get-ScoopDBItem {
|
||||
process {
|
||||
$dbCommand.Parameters.AddWithValue('@Name', $Name) | Out-Null
|
||||
$dbCommand.Parameters.AddWithValue('@Bucket', $Bucket) | Out-Null
|
||||
$dbCommand.Parameters.AddWithValue('@Version', $Version) | Out-Null
|
||||
if ($Version) {
|
||||
$dbCommand.Parameters.AddWithValue('@Version', $Version) | Out-Null
|
||||
}
|
||||
[void]$dbAdapter.Fill($result)
|
||||
}
|
||||
end {
|
||||
$dbCommand.Dispose()
|
||||
$dbAdapter.Dispose()
|
||||
$db.Dispose()
|
||||
return $result
|
||||
|
||||
@@ -24,7 +24,7 @@ function Invoke-Extraction {
|
||||
$extractFn = $null
|
||||
switch -regex ($Name[$i]) {
|
||||
'\.zip$' {
|
||||
if ((Test-HelperInstalled -Helper 7zip) -or ((get_config 7ZIPEXTRACT_USE_EXTERNAL) -and (Test-CommandAvailable 7z))) {
|
||||
if ((Test-HelperInstalled -Helper 7zip) -or ((get_config USE_EXTERNAL_7ZIP) -and (Test-CommandAvailable 7z))) {
|
||||
$extractFn = 'Expand-7zipArchive'
|
||||
} else {
|
||||
$extractFn = 'Expand-ZipArchive'
|
||||
@@ -52,11 +52,9 @@ function Invoke-Extraction {
|
||||
DestinationPath = Join-Path $Path $extractTo[$extracted]
|
||||
ExtractDir = $extractDir[$extracted]
|
||||
}
|
||||
Write-Host 'Extracting ' -NoNewline
|
||||
Write-Host $(url_remote_filename $uri[$i]) -ForegroundColor Cyan -NoNewline
|
||||
Write-Host ' ... ' -NoNewline
|
||||
Write-Host "Extracting $([char]0x1b)[36m$(url_remote_filename $uri[$i])$([char]0x1b)[0m... " -NoNewline
|
||||
& $extractFn @fnArgs -Removal
|
||||
Write-Host 'done.' -ForegroundColor Green
|
||||
Write-Host 'Done.' -ForegroundColor Green
|
||||
$extracted++
|
||||
}
|
||||
}
|
||||
@@ -123,15 +121,18 @@ function Expand-7zipArchive {
|
||||
}
|
||||
if (!$IsTar -and $ExtractDir) {
|
||||
movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null
|
||||
# Remove temporary directory
|
||||
Remove-Item "$DestinationPath\$($ExtractDir -replace '[\\/].*')" -Recurse -Force -ErrorAction Ignore
|
||||
# Remove temporary directory if it is empty
|
||||
$ExtractDirTopPath = [string] "$DestinationPath\$($ExtractDir -replace '[\\/].*')"
|
||||
if ((Get-ChildItem -Path $ExtractDirTopPath -Force -ErrorAction Ignore).Count -eq 0) {
|
||||
Remove-Item -Path $ExtractDirTopPath -Recurse -Force -ErrorAction Ignore
|
||||
}
|
||||
}
|
||||
if (Test-Path $LogPath) {
|
||||
Remove-Item $LogPath -Force
|
||||
}
|
||||
if ($Removal) {
|
||||
if (($Path -replace '.*\.([^\.]*)$', '$1') -eq '001') {
|
||||
# Remove splited 7-zip archive parts
|
||||
# Remove splitted 7-zip archive parts
|
||||
Get-ChildItem "$($Path -replace '\.[^\.]*$', '').???" | Remove-Item -Force
|
||||
} elseif (($Path -replace '.*\.part(\d+)\.rar$', '$1')[-1] -eq '1') {
|
||||
# Remove splitted RAR archive parts
|
||||
|
||||
773
lib/download.ps1
Normal file
773
lib/download.ps1
Normal file
@@ -0,0 +1,773 @@
|
||||
# Description: Functions for downloading files
|
||||
|
||||
## Meta downloader
|
||||
|
||||
function Invoke-ScoopDownload ($app, $version, $manifest, $bucket, $architecture, $dir, $use_cache = $true, $check_hash = $true) {
|
||||
# we only want to show this warning once
|
||||
if (!$use_cache) { warn 'Cache is being ignored.' }
|
||||
|
||||
# can be multiple urls: if there are, then installer should go first to make 'installer.args' section work
|
||||
$urls = @(script:url $manifest $architecture)
|
||||
|
||||
# can be multiple cookies: they will be used for all HTTP requests.
|
||||
$cookies = $manifest.cookie
|
||||
|
||||
# download first
|
||||
if (Test-Aria2Enabled) {
|
||||
Invoke-CachedAria2Download $app $version $manifest $architecture $dir $cookies $use_cache $check_hash
|
||||
} else {
|
||||
foreach ($url in $urls) {
|
||||
$fname = url_filename $url
|
||||
|
||||
try {
|
||||
Invoke-CachedDownload $app $version $url "$dir\$fname" $cookies $use_cache
|
||||
} catch {
|
||||
Write-Host -ForegroundColor DarkRed $_
|
||||
error "URL $url is not valid"
|
||||
abort $(new_issue_msg $app $bucket 'download failed')
|
||||
}
|
||||
|
||||
if ($check_hash) {
|
||||
$manifest_hash = hash_for_url $manifest $url $architecture
|
||||
$ok, $err = check_hash "$dir\$fname" $manifest_hash $(show_app $app $bucket)
|
||||
if (!$ok) {
|
||||
error $err
|
||||
$cached = cache_path $app $version $url
|
||||
if (Test-Path $cached) {
|
||||
# rm cached file
|
||||
Remove-Item -Force $cached
|
||||
}
|
||||
if ($url.Contains('sourceforge.net')) {
|
||||
Write-Host -ForegroundColor Yellow 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'
|
||||
}
|
||||
abort $(new_issue_msg $app $bucket 'hash check failed')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $urls.ForEach({ url_filename $_ })
|
||||
}
|
||||
|
||||
## [System.Net] downloader
|
||||
|
||||
function Invoke-CachedDownload ($app, $version, $url, $to, $cookies = $null, $use_cache = $true) {
|
||||
$cached = cache_path $app $version $url
|
||||
|
||||
if (!(Test-Path $cached) -or !$use_cache) {
|
||||
ensure $cachedir | Out-Null
|
||||
Start-Download $url "$cached.download" $cookies
|
||||
Move-Item "$cached.download" $cached -Force
|
||||
} else { Write-Host "Loading $(url_remote_filename $url) from cache" }
|
||||
|
||||
if (!($null -eq $to)) {
|
||||
if ($use_cache) {
|
||||
Copy-Item $cached $to
|
||||
} else {
|
||||
Move-Item $cached $to -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Start-Download ($url, $to, $cookies) {
|
||||
$progress = [console]::isoutputredirected -eq $false -and
|
||||
$host.name -ne 'Windows PowerShell ISE Host'
|
||||
|
||||
try {
|
||||
$url = handle_special_urls $url
|
||||
Invoke-Download $url $to $cookies $progress
|
||||
} catch {
|
||||
$e = $_.exception
|
||||
if ($e.Response.StatusCode -eq 'Unauthorized') {
|
||||
warn 'Token might be misconfigured.'
|
||||
}
|
||||
if ($e.innerexception) { $e = $e.innerexception }
|
||||
throw $e
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-Download ($url, $to, $cookies, $progress) {
|
||||
# download with filesize and progress indicator
|
||||
$reqUrl = ($url -split '#')[0]
|
||||
$wreq = [Net.WebRequest]::Create($reqUrl)
|
||||
if ($wreq -is [Net.HttpWebRequest]) {
|
||||
$wreq.UserAgent = Get-UserAgent
|
||||
if (-not ($url -match 'sourceforge\.net' -or $url -match 'portableapps\.com')) {
|
||||
$wreq.Referer = strip_filename $url
|
||||
}
|
||||
if ($url -match 'api\.github\.com/repos') {
|
||||
$wreq.Accept = 'application/octet-stream'
|
||||
$wreq.Headers['Authorization'] = "Bearer $(Get-GitHubToken)"
|
||||
$wreq.Headers['X-GitHub-Api-Version'] = '2022-11-28'
|
||||
}
|
||||
if ($cookies) {
|
||||
$wreq.Headers.Add('Cookie', (cookie_header $cookies))
|
||||
}
|
||||
|
||||
get_config PRIVATE_HOSTS | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object {
|
||||
(ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object {
|
||||
$wreq.Headers[$_.Key] = $_.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$wres = $wreq.GetResponse()
|
||||
} catch [System.Net.WebException] {
|
||||
$exc = $_.Exception
|
||||
$handledCodes = @(
|
||||
[System.Net.HttpStatusCode]::MovedPermanently, # HTTP 301
|
||||
[System.Net.HttpStatusCode]::Found, # HTTP 302
|
||||
[System.Net.HttpStatusCode]::SeeOther, # HTTP 303
|
||||
[System.Net.HttpStatusCode]::TemporaryRedirect # HTTP 307
|
||||
)
|
||||
|
||||
# Only handle redirection codes
|
||||
$redirectRes = $exc.Response
|
||||
if ($handledCodes -notcontains $redirectRes.StatusCode) {
|
||||
throw $exc
|
||||
}
|
||||
|
||||
# Get the new location of the file
|
||||
if ((-not $redirectRes.Headers) -or ($redirectRes.Headers -notcontains 'Location')) {
|
||||
throw $exc
|
||||
}
|
||||
|
||||
$newUrl = $redirectRes.Headers['Location']
|
||||
info "Following redirect to $newUrl..."
|
||||
|
||||
# Handle manual file rename
|
||||
if ($url -like '*#/*') {
|
||||
$null, $postfix = $url -split '#/'
|
||||
$newUrl = "$newUrl`#/$postfix"
|
||||
}
|
||||
|
||||
Invoke-Download $newUrl $to $cookies $progress
|
||||
return
|
||||
}
|
||||
|
||||
$total = $wres.ContentLength
|
||||
if ($total -eq -1 -and $wreq -is [net.ftpwebrequest]) {
|
||||
$total = ftp_file_size($url)
|
||||
}
|
||||
|
||||
if ($progress -and ($total -gt 0)) {
|
||||
[console]::CursorVisible = $false
|
||||
function Trace-DownloadProgress ($read) {
|
||||
Write-DownloadProgress $read $total $url
|
||||
}
|
||||
} else {
|
||||
Write-Host "Downloading $url ($(filesize $total))..."
|
||||
function Trace-DownloadProgress {
|
||||
#no op
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$s = $wres.getresponsestream()
|
||||
$fs = [io.file]::openwrite($to)
|
||||
$buffer = New-Object byte[] 2048
|
||||
$totalRead = 0
|
||||
$sw = [diagnostics.stopwatch]::StartNew()
|
||||
|
||||
Trace-DownloadProgress $totalRead
|
||||
while (($read = $s.read($buffer, 0, $buffer.length)) -gt 0) {
|
||||
$fs.write($buffer, 0, $read)
|
||||
$totalRead += $read
|
||||
if ($sw.elapsedmilliseconds -gt 100) {
|
||||
$sw.restart()
|
||||
Trace-DownloadProgress $totalRead
|
||||
}
|
||||
}
|
||||
$sw.stop()
|
||||
Trace-DownloadProgress $totalRead
|
||||
} finally {
|
||||
if ($progress) {
|
||||
[console]::CursorVisible = $true
|
||||
Write-Host
|
||||
}
|
||||
if ($fs) {
|
||||
$fs.close()
|
||||
}
|
||||
if ($s) {
|
||||
$s.close()
|
||||
}
|
||||
$wres.close()
|
||||
}
|
||||
}
|
||||
|
||||
function Format-DownloadProgress ($url, $read, $total, $console) {
|
||||
$filename = url_remote_filename $url
|
||||
|
||||
# calculate current percentage done
|
||||
$p = [math]::Round($read / $total * 100, 0)
|
||||
|
||||
# pre-generate LHS and RHS of progress string
|
||||
# so we know how much space we have
|
||||
$left = "$filename ($(filesize $total))"
|
||||
$right = [string]::Format('{0,3}%', $p)
|
||||
|
||||
# calculate remaining width for progress bar
|
||||
$midwidth = $console.BufferSize.Width - ($left.Length + $right.Length + 8)
|
||||
|
||||
# calculate how many characters are completed
|
||||
$completed = [math]::Abs([math]::Round(($p / 100) * $midwidth, 0) - 1)
|
||||
|
||||
# generate dashes to symbolise completed
|
||||
if ($completed -gt 1) {
|
||||
$dashes = [string]::Join('', ((1..$completed) | ForEach-Object { '=' }))
|
||||
}
|
||||
|
||||
# this is why we calculate $completed - 1 above
|
||||
$dashes += switch ($p) {
|
||||
100 { '=' }
|
||||
default { '>' }
|
||||
}
|
||||
|
||||
# the remaining characters are filled with spaces
|
||||
$spaces = switch ($dashes.Length) {
|
||||
$midwidth { [string]::Empty }
|
||||
default {
|
||||
[string]::Join('', ((1..($midwidth - $dashes.Length)) | ForEach-Object { ' ' }))
|
||||
}
|
||||
}
|
||||
|
||||
"$left [$dashes$spaces] $right"
|
||||
}
|
||||
|
||||
function Write-DownloadProgress ($read, $total, $url) {
|
||||
$console = $Host.UI.RawUI
|
||||
$left = $console.CursorPosition.X
|
||||
$top = $console.CursorPosition.Y
|
||||
$width = $console.BufferSize.Width
|
||||
|
||||
if ($read -eq 0) {
|
||||
$maxOutputLength = $(Format-DownloadProgress $url 100 $total $console).Length
|
||||
if (($left + $maxOutputLength) -gt $width) {
|
||||
# not enough room to print progress on this line
|
||||
# print on new line
|
||||
Write-Host
|
||||
$left = 0
|
||||
$top = $top + 1
|
||||
if ($top -gt $console.CursorPosition.Y) { $top = $console.CursorPosition.Y }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host $(Format-DownloadProgress $url $read $total $console) -NoNewline
|
||||
[console]::SetCursorPosition($left, $top)
|
||||
}
|
||||
|
||||
## Aria2 downloader
|
||||
|
||||
function Test-Aria2Enabled {
|
||||
return (Test-HelperInstalled -Helper Aria2) -and (get_config 'aria2-enabled' $true)
|
||||
}
|
||||
|
||||
function aria_exit_code($exitcode) {
|
||||
$codes = @{
|
||||
0 = 'All downloads were successful'
|
||||
1 = 'An unknown error occurred'
|
||||
2 = 'Timeout'
|
||||
3 = 'Resource was not found'
|
||||
4 = 'Aria2 saw the specified number of "resource not found" error. See --max-file-not-found option'
|
||||
5 = 'Download aborted because download speed was too slow. See --lowest-speed-limit option'
|
||||
6 = 'Network problem occurred.'
|
||||
7 = 'There were unfinished downloads. This error is only reported if all finished downloads were successful and there were unfinished downloads in a queue when aria2 exited by pressing Ctrl-C by an user or sending TERM or INT signal'
|
||||
8 = 'Remote server did not support resume when resume was required to complete download'
|
||||
9 = 'There was not enough disk space available'
|
||||
10 = 'Piece length was different from one in .aria2 control file. See --allow-piece-length-change option'
|
||||
11 = 'Aria2 was downloading same file at that moment'
|
||||
12 = 'Aria2 was downloading same info hash torrent at that moment'
|
||||
13 = 'File already existed. See --allow-overwrite option'
|
||||
14 = 'Renaming file failed. See --auto-file-renaming option'
|
||||
15 = 'Aria2 could not open existing file'
|
||||
16 = 'Aria2 could not create new file or truncate existing file'
|
||||
17 = 'File I/O error occurred'
|
||||
18 = 'Aria2 could not create directory'
|
||||
19 = 'Name resolution failed'
|
||||
20 = 'Aria2 could not parse Metalink document'
|
||||
21 = 'FTP command failed'
|
||||
22 = 'HTTP response header was bad or unexpected'
|
||||
23 = 'Too many redirects occurred'
|
||||
24 = 'HTTP authorization failed'
|
||||
25 = 'Aria2 could not parse bencoded file (usually ".torrent" file)'
|
||||
26 = '".torrent" file was corrupted or missing information that aria2 needed'
|
||||
27 = 'Magnet URI was bad'
|
||||
28 = 'Bad/unrecognized option was given or unexpected option argument was given'
|
||||
29 = 'The remote server was unable to handle the request due to a temporary overloading or maintenance'
|
||||
30 = 'Aria2 could not parse JSON-RPC request'
|
||||
31 = 'Reserved. Not used'
|
||||
32 = 'Checksum validation failed'
|
||||
}
|
||||
if ($null -eq $codes[$exitcode]) {
|
||||
return 'An unknown error occurred'
|
||||
}
|
||||
return $codes[$exitcode]
|
||||
}
|
||||
|
||||
function get_filename_from_metalink($file) {
|
||||
$bytes = get_magic_bytes_pretty $file ''
|
||||
# check if file starts with '<?xml'
|
||||
if (!($bytes.StartsWith('3c3f786d6c'))) {
|
||||
return $null
|
||||
}
|
||||
|
||||
# Add System.Xml for reading metalink files
|
||||
Add-Type -AssemblyName 'System.Xml'
|
||||
$xr = [System.Xml.XmlReader]::Create($file)
|
||||
$filename = $null
|
||||
try {
|
||||
$xr.ReadStartElement('metalink')
|
||||
if ($xr.ReadToFollowing('file') -and $xr.MoveToFirstAttribute()) {
|
||||
$filename = $xr.Value
|
||||
}
|
||||
} catch [System.Xml.XmlException] {
|
||||
return $null
|
||||
} finally {
|
||||
$xr.Close()
|
||||
}
|
||||
|
||||
return $filename
|
||||
}
|
||||
|
||||
function Invoke-CachedAria2Download ($app, $version, $manifest, $architecture, $dir, $cookies = $null, $use_cache = $true, $check_hash = $true) {
|
||||
$data = @{}
|
||||
$urls = @(script:url $manifest $architecture)
|
||||
|
||||
# aria2 input file
|
||||
$urlstxt = Join-Path $cachedir "$app.txt"
|
||||
$urlstxt_content = ''
|
||||
$download_finished = $true
|
||||
|
||||
# aria2 options
|
||||
$options = @(
|
||||
"--input-file='$urlstxt'"
|
||||
"--user-agent='$(Get-UserAgent)'"
|
||||
'--allow-overwrite=true'
|
||||
'--auto-file-renaming=false'
|
||||
"--retry-wait=$(get_config 'aria2-retry-wait' 2)"
|
||||
"--split=$(get_config 'aria2-split' 5)"
|
||||
"--max-connection-per-server=$(get_config 'aria2-max-connection-per-server' 5)"
|
||||
"--min-split-size=$(get_config 'aria2-min-split-size' '5M')"
|
||||
'--console-log-level=warn'
|
||||
'--enable-color=false'
|
||||
'--no-conf=true'
|
||||
'--follow-metalink=true'
|
||||
'--metalink-preferred-protocol=https'
|
||||
'--min-tls-version=TLSv1.2'
|
||||
"--stop-with-process=$PID"
|
||||
'--continue'
|
||||
'--summary-interval=0'
|
||||
'--auto-save-interval=1'
|
||||
)
|
||||
|
||||
if ($cookies) {
|
||||
$options += "--header='Cookie: $(cookie_header $cookies)'"
|
||||
}
|
||||
|
||||
$proxy = get_config PROXY
|
||||
if ($proxy -ne 'none') {
|
||||
if ([Net.Webrequest]::DefaultWebProxy.Address) {
|
||||
$options += "--all-proxy='$([Net.Webrequest]::DefaultWebProxy.Address.Authority)'"
|
||||
}
|
||||
if ([Net.Webrequest]::DefaultWebProxy.Credentials.UserName) {
|
||||
$options += "--all-proxy-user='$([Net.Webrequest]::DefaultWebProxy.Credentials.UserName)'"
|
||||
}
|
||||
if ([Net.Webrequest]::DefaultWebProxy.Credentials.Password) {
|
||||
$options += "--all-proxy-passwd='$([Net.Webrequest]::DefaultWebProxy.Credentials.Password)'"
|
||||
}
|
||||
}
|
||||
|
||||
$more_options = get_config 'aria2-options'
|
||||
if ($more_options) {
|
||||
$options += $more_options
|
||||
}
|
||||
|
||||
foreach ($url in $urls) {
|
||||
$data.$url = @{
|
||||
'target' = Join-Path $dir (url_filename $url)
|
||||
'cachename' = fname (cache_path $app $version $url)
|
||||
'source' = cache_path $app $version $url
|
||||
}
|
||||
|
||||
if ((Test-Path $data.$url.source) -and -not((Test-Path "$($data.$url.source).aria2") -or (Test-Path $urlstxt)) -and $use_cache) {
|
||||
Write-Host "Loading $([char]0x1b)[36m$(url_remote_filename $url)$([char]0x1b)[0m from cache."
|
||||
} else {
|
||||
$download_finished = $false
|
||||
# create aria2 input file content
|
||||
try {
|
||||
$try_url = handle_special_urls $url
|
||||
} catch {
|
||||
if ($_.Exception.Response.StatusCode -eq 'Unauthorized') {
|
||||
warn 'Token might be misconfigured.'
|
||||
}
|
||||
}
|
||||
$urlstxt_content += "$try_url`n"
|
||||
if (!$url.Contains('sourceforge.net')) {
|
||||
$urlstxt_content += " referer=$(strip_filename $url)`n"
|
||||
}
|
||||
$urlstxt_content += " dir=$cachedir`n"
|
||||
$urlstxt_content += " out=$($data.$url.cachename)`n"
|
||||
}
|
||||
}
|
||||
|
||||
if (-not($download_finished)) {
|
||||
# write aria2 input file
|
||||
if ($urlstxt_content -ne '') {
|
||||
ensure $cachedir | Out-Null
|
||||
# Write aria2 input-file with UTF8NoBOM encoding
|
||||
$urlstxt_content | Out-UTF8File -FilePath $urlstxt
|
||||
}
|
||||
|
||||
# build aria2 command
|
||||
$aria2 = "& '$(Get-HelperPath -Helper Aria2)' $($options -join ' ')"
|
||||
|
||||
# handle aria2 console output
|
||||
Write-Host 'Starting download with aria2...'
|
||||
|
||||
# Set console output encoding to UTF8 for non-ASCII characters printing
|
||||
$oriConsoleEncoding = [Console]::OutputEncoding
|
||||
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding
|
||||
|
||||
Invoke-Command ([scriptblock]::Create($aria2)) | ForEach-Object {
|
||||
# Skip blank lines
|
||||
if ([String]::IsNullOrWhiteSpace($_)) { return }
|
||||
|
||||
# Prevent potential overlaping of text when one line is shorter
|
||||
$len = $Host.UI.RawUI.WindowSize.Width - $_.Length - 20
|
||||
$blank = if ($len -gt 0) { ' ' * $len } else { '' }
|
||||
$color = 'Gray'
|
||||
|
||||
if ($_.StartsWith('(OK):')) {
|
||||
$noNewLine = $true
|
||||
$color = 'Green'
|
||||
} elseif ($_.StartsWith('[') -and $_.EndsWith(']')) {
|
||||
$noNewLine = $true
|
||||
$color = 'Cyan'
|
||||
} elseif ($_.StartsWith('Download Results:')) {
|
||||
$noNewLine = $false
|
||||
}
|
||||
|
||||
Write-Host "`rDownload: $_$blank" -ForegroundColor $color -NoNewline:$noNewLine
|
||||
}
|
||||
Write-Host ''
|
||||
|
||||
if ($lastexitcode -gt 0) {
|
||||
if (get_config ARIA2-FALLBACK-DISABLED) {
|
||||
error "Download failed! (Error $lastexitcode) $(aria_exit_code $lastexitcode)"
|
||||
error $urlstxt_content
|
||||
error $aria2
|
||||
abort $(new_issue_msg $app $bucket 'download via aria2 failed')
|
||||
}
|
||||
|
||||
warn "Download failed! (Error $lastexitcode) $(aria_exit_code $lastexitcode)"
|
||||
warn $urlstxt_content
|
||||
warn $aria2
|
||||
|
||||
Write-Host 'Fallback to default downloader...'
|
||||
|
||||
try {
|
||||
foreach ($url in $urls) {
|
||||
Invoke-CachedDownload $app $version $url "$($data.$url.target)" $cookies $use_cache
|
||||
}
|
||||
} catch {
|
||||
Write-Host $_ -ForegroundColor DarkRed
|
||||
error "URL $url is not valid"
|
||||
abort $(new_issue_msg $app $bucket 'download failed')
|
||||
}
|
||||
}
|
||||
|
||||
# remove aria2 input file when done
|
||||
if (Test-Path $urlstxt, "$($data.$url.source).aria2*") {
|
||||
Remove-Item $urlstxt -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item "$($data.$url.source).aria2*" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# Revert console encoding
|
||||
[Console]::OutputEncoding = $oriConsoleEncoding
|
||||
}
|
||||
|
||||
foreach ($url in $urls) {
|
||||
|
||||
$metalink_filename = get_filename_from_metalink $data.$url.source
|
||||
if ($metalink_filename) {
|
||||
Remove-Item $data.$url.source -Force
|
||||
Rename-Item -Force (Join-Path -Path $cachedir -ChildPath $metalink_filename) $data.$url.source
|
||||
}
|
||||
|
||||
# run hash checks
|
||||
if ($check_hash) {
|
||||
$manifest_hash = hash_for_url $manifest $url $architecture
|
||||
$ok, $err = check_hash $data.$url.source $manifest_hash $(show_app $app $bucket)
|
||||
if (!$ok) {
|
||||
error $err
|
||||
if (Test-Path $data.$url.source) {
|
||||
# rm cached file
|
||||
Remove-Item $data.$url.source -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item "$($data.$url.source).aria2*" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
if ($url.Contains('sourceforge.net')) {
|
||||
Write-Host -f yellow 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'
|
||||
}
|
||||
abort $(new_issue_msg $app $bucket 'hash check failed')
|
||||
}
|
||||
}
|
||||
|
||||
# copy or move file to target location
|
||||
if (!(Test-Path $data.$url.source) ) {
|
||||
abort $(new_issue_msg $app $bucket 'cached file not found')
|
||||
}
|
||||
|
||||
if (!($dir -eq $cachedir)) {
|
||||
if ($use_cache) {
|
||||
Copy-Item $data.$url.source $data.$url.target
|
||||
} else {
|
||||
Move-Item $data.$url.source $data.$url.target -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
## Helper functions
|
||||
|
||||
### Downloader parameters
|
||||
|
||||
function cookie_header($cookies) {
|
||||
if (!$cookies) { return }
|
||||
|
||||
$vals = $cookies.psobject.properties | ForEach-Object {
|
||||
"$($_.name)=$($_.value)"
|
||||
}
|
||||
|
||||
[string]::join(';', $vals)
|
||||
}
|
||||
|
||||
function Get-Encoding($wc) {
|
||||
if ($null -ne $wc.ResponseHeaders -and $wc.ResponseHeaders['Content-Type'] -match 'charset=([^;]*)') {
|
||||
return [System.Text.Encoding]::GetEncoding($Matches[1])
|
||||
} else {
|
||||
return [System.Text.Encoding]::GetEncoding('utf-8')
|
||||
}
|
||||
}
|
||||
|
||||
function Get-UserAgent() {
|
||||
return "Scoop/1.0 (+http://scoop.sh/) PowerShell/$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) (Windows NT $([System.Environment]::OSVersion.Version.Major).$([System.Environment]::OSVersion.Version.Minor); $(if(${env:ProgramFiles(Arm)}){'ARM64; '}elseif($env:PROCESSOR_ARCHITECTURE -eq 'AMD64'){'Win64; x64; '})$(if($env:PROCESSOR_ARCHITEW6432 -in 'AMD64','ARM64'){'WOW64; '})$PSEdition)"
|
||||
}
|
||||
|
||||
function setup_proxy() {
|
||||
# note: '@' and ':' in password must be escaped, e.g. 'p@ssword' -> p\@ssword'
|
||||
$proxy = get_config PROXY
|
||||
if (!$proxy) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
$credentials, $address = $proxy -split '(?<!\\)@'
|
||||
if (!$address) {
|
||||
$address, $credentials = $credentials, $null # no credentials supplied
|
||||
}
|
||||
|
||||
if ($address -eq 'none') {
|
||||
[net.webrequest]::defaultwebproxy = $null
|
||||
} elseif ($address -ne 'default') {
|
||||
[net.webrequest]::defaultwebproxy = New-Object net.webproxy "http://$address"
|
||||
}
|
||||
|
||||
if ($credentials -eq 'currentuser') {
|
||||
[net.webrequest]::defaultwebproxy.credentials = [net.credentialcache]::defaultcredentials
|
||||
} elseif ($credentials) {
|
||||
$username, $password = $credentials -split '(?<!\\):' | ForEach-Object { $_ -replace '\\([@:])', '$1' }
|
||||
[net.webrequest]::defaultwebproxy.credentials = New-Object net.networkcredential($username, $password)
|
||||
}
|
||||
} catch {
|
||||
warn "Failed to use proxy '$proxy': $($_.exception.message)"
|
||||
}
|
||||
}
|
||||
|
||||
function Get-GitHubToken {
|
||||
return $env:SCOOP_GH_TOKEN, (get_config GH_TOKEN) | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1
|
||||
}
|
||||
|
||||
function github_ratelimit_reached {
|
||||
$api_link = 'https://api.github.com/rate_limit'
|
||||
$ret = (download_json $api_link).rate.remaining -eq 0
|
||||
if ($ret) {
|
||||
Write-Host "GitHub API rate limit reached.`r`nPlease try again later or configure your API token using 'scoop config gh_token <your token>'."
|
||||
}
|
||||
$ret
|
||||
}
|
||||
|
||||
### URL handling
|
||||
|
||||
function handle_special_urls($url) {
|
||||
# FossHub.com
|
||||
if ($url -match '^(?:.*fosshub.com\/)(?<name>.*)(?:\/|\?dwl=)(?<filename>.*)$') {
|
||||
$Body = @{
|
||||
projectUri = $Matches.name
|
||||
fileName = $Matches.filename
|
||||
source = 'CF'
|
||||
isLatestVersion = $true
|
||||
}
|
||||
if ((Invoke-RestMethod -Uri $url) -match '"p":"(?<pid>[a-f0-9]{24}).*?"r":"(?<rid>[a-f0-9]{24})') {
|
||||
$Body.Add('projectId', $Matches.pid)
|
||||
$Body.Add('releaseId', $Matches.rid)
|
||||
}
|
||||
$url = Invoke-RestMethod -Method Post -Uri 'https://api.fosshub.com/download/' -ContentType 'application/json' -Body (ConvertTo-Json $Body -Compress)
|
||||
if ($null -eq $url.error) {
|
||||
$url = $url.data.url
|
||||
}
|
||||
}
|
||||
|
||||
# Sourceforge.net
|
||||
if ($url -match '(?:downloads\.)?sourceforge.net\/projects?\/(?<project>[^\/]+)\/(?:files\/)?(?<file>.*?)(?:$|\/download|\?)') {
|
||||
# Reshapes the URL to avoid redirections
|
||||
$url = "https://downloads.sourceforge.net/project/$($matches['project'])/$($matches['file'])"
|
||||
}
|
||||
|
||||
# Github.com
|
||||
if ($url -match 'github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = Get-GitHubToken)) {
|
||||
$headers = @{ 'Authorization' = "token $token" }
|
||||
$privateUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)"
|
||||
$assetUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)/releases/tags/$($Matches.tag)"
|
||||
|
||||
if ((Invoke-RestMethod -Uri $privateUrl -Headers $headers).Private) {
|
||||
$url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).Assets | Where-Object -Property Name -EQ -Value $Matches.file).Url, $Matches.filename -join ''
|
||||
}
|
||||
}
|
||||
|
||||
return $url
|
||||
}
|
||||
|
||||
### Remote file information
|
||||
|
||||
function download_json($url) {
|
||||
$githubtoken = Get-GitHubToken
|
||||
$authheader = @{}
|
||||
if ($githubtoken) {
|
||||
$authheader = @{'Authorization' = "token $githubtoken" }
|
||||
}
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
$result = Invoke-WebRequest $url -UseBasicParsing -Headers $authheader | Select-Object -ExpandProperty content | ConvertFrom-Json
|
||||
$ProgressPreference = 'Continue'
|
||||
$result
|
||||
}
|
||||
|
||||
function get_magic_bytes($file) {
|
||||
if (!(Test-Path $file)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if ((Get-Command Get-Content).parameters.ContainsKey('AsByteStream')) {
|
||||
# PowerShell Core (6.0+) '-Encoding byte' is replaced by '-AsByteStream'
|
||||
return Get-Content $file -AsByteStream -TotalCount 8
|
||||
} else {
|
||||
return Get-Content $file -Encoding byte -TotalCount 8
|
||||
}
|
||||
}
|
||||
|
||||
function get_magic_bytes_pretty($file, $glue = ' ') {
|
||||
if (!(Test-Path $file)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return (get_magic_bytes $file | ForEach-Object { $_.ToString('x2') }) -join $glue
|
||||
}
|
||||
|
||||
Function Get-RemoteFileSize ($Uri) {
|
||||
$response = Invoke-WebRequest -Uri $Uri -Method HEAD -UseBasicParsing
|
||||
if (!$response.Headers.StatusCode) {
|
||||
$response.Headers.'Content-Length' | ForEach-Object { [int]$_ }
|
||||
}
|
||||
}
|
||||
|
||||
function ftp_file_size($url) {
|
||||
$request = [net.ftpwebrequest]::create($url)
|
||||
$request.method = [net.webrequestmethods+ftp]::getfilesize
|
||||
$request.getresponse().contentlength
|
||||
}
|
||||
|
||||
function url_filename($url) {
|
||||
(Split-Path $url -Leaf).split('?') | Select-Object -First 1
|
||||
}
|
||||
|
||||
function url_remote_filename($url) {
|
||||
# Unlike url_filename which can be tricked by appending a
|
||||
# URL fragment (e.g. #/dl.7z, useful for coercing a local filename),
|
||||
# this function extracts the original filename from the URL.
|
||||
$uri = (New-Object URI $url)
|
||||
$basename = Split-Path $uri.PathAndQuery -Leaf
|
||||
If ($basename -match '.*[?=]+([\w._-]+)') {
|
||||
$basename = $matches[1]
|
||||
}
|
||||
If (($basename -notlike '*.*') -or ($basename -match '^[v.\d]+$')) {
|
||||
$basename = Split-Path $uri.AbsolutePath -Leaf
|
||||
}
|
||||
If (($basename -notlike '*.*') -and ($uri.Fragment -ne '')) {
|
||||
$basename = $uri.Fragment.Trim('/', '#')
|
||||
}
|
||||
return $basename
|
||||
}
|
||||
|
||||
### Hash-related functions
|
||||
|
||||
function hash_for_url($manifest, $url, $arch) {
|
||||
$hashes = @(hash $manifest $arch) | Where-Object { $_ -ne $null }
|
||||
|
||||
if ($hashes.length -eq 0) { return $null }
|
||||
|
||||
$urls = @(script:url $manifest $arch)
|
||||
|
||||
$index = [array]::IndexOf($urls, $url)
|
||||
if ($index -eq -1) { abort "Couldn't find hash in manifest for '$url'." }
|
||||
|
||||
@($hashes)[$index]
|
||||
}
|
||||
|
||||
function check_hash($file, $hash, $app_name) {
|
||||
# returns (ok, err)
|
||||
if (!$hash) {
|
||||
warn "Warning: No hash in manifest. SHA256 for '$(fname $file)' is:`n $((Get-FileHash -Path $file -Algorithm SHA256).Hash.ToLower())"
|
||||
return $true, $null
|
||||
}
|
||||
|
||||
Write-Host "Checking hash of $([char]0x1b)[36m$(url_remote_filename $url)$([char]0x1b)[0m... " -NoNewline
|
||||
$algorithm, $expected = get_hash $hash
|
||||
if ($null -eq $algorithm) {
|
||||
return $false, "Hash type '$algorithm' isn't supported."
|
||||
}
|
||||
|
||||
$actual = (Get-FileHash -Path $file -Algorithm $algorithm).Hash.ToLower()
|
||||
$expected = $expected.ToLower()
|
||||
|
||||
if ($actual -ne $expected) {
|
||||
$msg = "Hash check failed!`n"
|
||||
$msg += "App: $app_name`n"
|
||||
$msg += "URL: $url`n"
|
||||
if (Test-Path $file) {
|
||||
$msg += "First bytes: $((get_magic_bytes_pretty $file ' ').ToUpper())`n"
|
||||
}
|
||||
if ($expected -or $actual) {
|
||||
$msg += "Expected: $expected`n"
|
||||
$msg += "Actual: $actual"
|
||||
}
|
||||
return $false, $msg
|
||||
}
|
||||
Write-Host 'OK.' -f Green
|
||||
return $true, $null
|
||||
}
|
||||
|
||||
function get_hash([String] $multihash) {
|
||||
$type, $hash = $multihash -split ':'
|
||||
if (!$hash) {
|
||||
# no type specified, assume sha256
|
||||
$type, $hash = 'sha256', $multihash
|
||||
}
|
||||
|
||||
if (@('md5', 'sha1', 'sha256', 'sha512') -notcontains $type) {
|
||||
return $null, "Hash type '$type' isn't supported."
|
||||
}
|
||||
|
||||
return $type, $hash.ToLower()
|
||||
}
|
||||
|
||||
# Setup proxy globally
|
||||
setup_proxy
|
||||
@@ -9,10 +9,10 @@
|
||||
# a parameter should end with '='
|
||||
# returns @(opts hash, remaining_args array, error string)
|
||||
# NOTES:
|
||||
# The first "--" in $argv, if any, will terminate all options; any
|
||||
# following arguments are treated as non-option arguments, even if
|
||||
# they begin with a hyphen. The "--" itself will not be included in
|
||||
# the returned $opts. (POSIX-compatible)
|
||||
# The first "--" or "--%" in $argv, if any, will terminate all options; any
|
||||
# following arguments are treated as non-option arguments, even if
|
||||
# they begin with a hyphen. The terminator token itself ("--" or "--%")
|
||||
# will not be included. (POSIX-compatible)
|
||||
function getopt([String[]]$argv, [String]$shortopts, [String[]]$longopts) {
|
||||
$opts = @{}; $rem = @()
|
||||
|
||||
@@ -32,7 +32,7 @@ function getopt([String[]]$argv, [String]$shortopts, [String[]]$longopts) {
|
||||
if ($arg -is [Int]) { $rem += $arg; continue }
|
||||
if ($arg -is [Decimal]) { $rem += $arg; continue }
|
||||
|
||||
if ($arg -eq '--') {
|
||||
if ($arg -eq '--' -or $arg -eq '--%') {
|
||||
if ($i -lt $argv.Length - 1) {
|
||||
$rem += $argv[($i + 1)..($argv.Length - 1)]
|
||||
}
|
||||
|
||||
579
lib/install.ps1
579
lib/install.ps1
@@ -81,576 +81,10 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru
|
||||
show_notes $manifest $dir $original_dir $persist_dir
|
||||
}
|
||||
|
||||
function Invoke-CachedDownload ($app, $version, $url, $to, $cookies = $null, $use_cache = $true) {
|
||||
$cached = cache_path $app $version $url
|
||||
|
||||
if (!(Test-Path $cached) -or !$use_cache) {
|
||||
ensure $cachedir | Out-Null
|
||||
Start-Download $url "$cached.download" $cookies
|
||||
Move-Item "$cached.download" $cached -Force
|
||||
} else { Write-Host "Loading $(url_remote_filename $url) from cache" }
|
||||
|
||||
if (!($null -eq $to)) {
|
||||
if ($use_cache) {
|
||||
Copy-Item $cached $to
|
||||
} else {
|
||||
Move-Item $cached $to -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Start-Download ($url, $to, $cookies) {
|
||||
$progress = [console]::isoutputredirected -eq $false -and
|
||||
$host.name -ne 'Windows PowerShell ISE Host'
|
||||
|
||||
try {
|
||||
$url = handle_special_urls $url
|
||||
Invoke-Download $url $to $cookies $progress
|
||||
} catch {
|
||||
$e = $_.exception
|
||||
if ($e.Response.StatusCode -eq 'Unauthorized') {
|
||||
warn 'Token might be misconfigured.'
|
||||
}
|
||||
if ($e.innerexception) { $e = $e.innerexception }
|
||||
throw $e
|
||||
}
|
||||
}
|
||||
|
||||
function aria_exit_code($exitcode) {
|
||||
$codes = @{
|
||||
0 = 'All downloads were successful'
|
||||
1 = 'An unknown error occurred'
|
||||
2 = 'Timeout'
|
||||
3 = 'Resource was not found'
|
||||
4 = 'Aria2 saw the specified number of "resource not found" error. See --max-file-not-found option'
|
||||
5 = 'Download aborted because download speed was too slow. See --lowest-speed-limit option'
|
||||
6 = 'Network problem occurred.'
|
||||
7 = 'There were unfinished downloads. This error is only reported if all finished downloads were successful and there were unfinished downloads in a queue when aria2 exited by pressing Ctrl-C by an user or sending TERM or INT signal'
|
||||
8 = 'Remote server did not support resume when resume was required to complete download'
|
||||
9 = 'There was not enough disk space available'
|
||||
10 = 'Piece length was different from one in .aria2 control file. See --allow-piece-length-change option'
|
||||
11 = 'Aria2 was downloading same file at that moment'
|
||||
12 = 'Aria2 was downloading same info hash torrent at that moment'
|
||||
13 = 'File already existed. See --allow-overwrite option'
|
||||
14 = 'Renaming file failed. See --auto-file-renaming option'
|
||||
15 = 'Aria2 could not open existing file'
|
||||
16 = 'Aria2 could not create new file or truncate existing file'
|
||||
17 = 'File I/O error occurred'
|
||||
18 = 'Aria2 could not create directory'
|
||||
19 = 'Name resolution failed'
|
||||
20 = 'Aria2 could not parse Metalink document'
|
||||
21 = 'FTP command failed'
|
||||
22 = 'HTTP response header was bad or unexpected'
|
||||
23 = 'Too many redirects occurred'
|
||||
24 = 'HTTP authorization failed'
|
||||
25 = 'Aria2 could not parse bencoded file (usually ".torrent" file)'
|
||||
26 = '".torrent" file was corrupted or missing information that aria2 needed'
|
||||
27 = 'Magnet URI was bad'
|
||||
28 = 'Bad/unrecognized option was given or unexpected option argument was given'
|
||||
29 = 'The remote server was unable to handle the request due to a temporary overloading or maintenance'
|
||||
30 = 'Aria2 could not parse JSON-RPC request'
|
||||
31 = 'Reserved. Not used'
|
||||
32 = 'Checksum validation failed'
|
||||
}
|
||||
if ($null -eq $codes[$exitcode]) {
|
||||
return 'An unknown error occurred'
|
||||
}
|
||||
return $codes[$exitcode]
|
||||
}
|
||||
|
||||
function get_filename_from_metalink($file) {
|
||||
$bytes = get_magic_bytes_pretty $file ''
|
||||
# check if file starts with '<?xml'
|
||||
if (!($bytes.StartsWith('3c3f786d6c'))) {
|
||||
return $null
|
||||
}
|
||||
|
||||
# Add System.Xml for reading metalink files
|
||||
Add-Type -AssemblyName 'System.Xml'
|
||||
$xr = [System.Xml.XmlReader]::Create($file)
|
||||
$filename = $null
|
||||
try {
|
||||
$xr.ReadStartElement('metalink')
|
||||
if ($xr.ReadToFollowing('file') -and $xr.MoveToFirstAttribute()) {
|
||||
$filename = $xr.Value
|
||||
}
|
||||
} catch [System.Xml.XmlException] {
|
||||
return $null
|
||||
} finally {
|
||||
$xr.Close()
|
||||
}
|
||||
|
||||
return $filename
|
||||
}
|
||||
|
||||
function Invoke-CachedAria2Download ($app, $version, $manifest, $architecture, $dir, $cookies = $null, $use_cache = $true, $check_hash = $true) {
|
||||
$data = @{}
|
||||
$urls = @(script:url $manifest $architecture)
|
||||
|
||||
# aria2 input file
|
||||
$urlstxt = Join-Path $cachedir "$app.txt"
|
||||
$urlstxt_content = ''
|
||||
$download_finished = $true
|
||||
|
||||
# aria2 options
|
||||
$options = @(
|
||||
"--input-file='$urlstxt'"
|
||||
"--user-agent='$(Get-UserAgent)'"
|
||||
'--allow-overwrite=true'
|
||||
'--auto-file-renaming=false'
|
||||
"--retry-wait=$(get_config 'aria2-retry-wait' 2)"
|
||||
"--split=$(get_config 'aria2-split' 5)"
|
||||
"--max-connection-per-server=$(get_config 'aria2-max-connection-per-server' 5)"
|
||||
"--min-split-size=$(get_config 'aria2-min-split-size' '5M')"
|
||||
'--console-log-level=warn'
|
||||
'--enable-color=false'
|
||||
'--no-conf=true'
|
||||
'--follow-metalink=true'
|
||||
'--metalink-preferred-protocol=https'
|
||||
'--min-tls-version=TLSv1.2'
|
||||
"--stop-with-process=$PID"
|
||||
'--continue'
|
||||
'--summary-interval=0'
|
||||
'--auto-save-interval=1'
|
||||
)
|
||||
|
||||
if ($cookies) {
|
||||
$options += "--header='Cookie: $(cookie_header $cookies)'"
|
||||
}
|
||||
|
||||
$proxy = get_config PROXY
|
||||
if ($proxy -ne 'none') {
|
||||
if ([Net.Webrequest]::DefaultWebProxy.Address) {
|
||||
$options += "--all-proxy='$([Net.Webrequest]::DefaultWebProxy.Address.Authority)'"
|
||||
}
|
||||
if ([Net.Webrequest]::DefaultWebProxy.Credentials.UserName) {
|
||||
$options += "--all-proxy-user='$([Net.Webrequest]::DefaultWebProxy.Credentials.UserName)'"
|
||||
}
|
||||
if ([Net.Webrequest]::DefaultWebProxy.Credentials.Password) {
|
||||
$options += "--all-proxy-passwd='$([Net.Webrequest]::DefaultWebProxy.Credentials.Password)'"
|
||||
}
|
||||
}
|
||||
|
||||
$more_options = get_config 'aria2-options'
|
||||
if ($more_options) {
|
||||
$options += $more_options
|
||||
}
|
||||
|
||||
foreach ($url in $urls) {
|
||||
$data.$url = @{
|
||||
'target' = Join-Path $dir (url_filename $url)
|
||||
'cachename' = fname (cache_path $app $version $url)
|
||||
'source' = cache_path $app $version $url
|
||||
}
|
||||
|
||||
if ((Test-Path $data.$url.source) -and -not((Test-Path "$($data.$url.source).aria2") -or (Test-Path $urlstxt)) -and $use_cache) {
|
||||
Write-Host 'Loading ' -NoNewline
|
||||
Write-Host $(url_remote_filename $url) -f Cyan -NoNewline
|
||||
Write-Host ' from cache.'
|
||||
} else {
|
||||
$download_finished = $false
|
||||
# create aria2 input file content
|
||||
try {
|
||||
$try_url = handle_special_urls $url
|
||||
} catch {
|
||||
if ($_.Exception.Response.StatusCode -eq 'Unauthorized') {
|
||||
warn 'Token might be misconfigured.'
|
||||
}
|
||||
}
|
||||
$urlstxt_content += "$try_url`n"
|
||||
if (!$url.Contains('sourceforge.net')) {
|
||||
$urlstxt_content += " referer=$(strip_filename $url)`n"
|
||||
}
|
||||
$urlstxt_content += " dir=$cachedir`n"
|
||||
$urlstxt_content += " out=$($data.$url.cachename)`n"
|
||||
}
|
||||
}
|
||||
|
||||
if (-not($download_finished)) {
|
||||
# write aria2 input file
|
||||
if ($urlstxt_content -ne '') {
|
||||
ensure $cachedir | Out-Null
|
||||
# Write aria2 input-file with UTF8NoBOM encoding
|
||||
$urlstxt_content | Out-UTF8File -FilePath $urlstxt
|
||||
}
|
||||
|
||||
# build aria2 command
|
||||
$aria2 = "& '$(Get-HelperPath -Helper Aria2)' $($options -join ' ')"
|
||||
|
||||
# handle aria2 console output
|
||||
Write-Host 'Starting download with aria2 ...'
|
||||
|
||||
# Set console output encoding to UTF8 for non-ASCII characters printing
|
||||
$oriConsoleEncoding = [Console]::OutputEncoding
|
||||
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding
|
||||
|
||||
Invoke-Command ([scriptblock]::Create($aria2)) | ForEach-Object {
|
||||
# Skip blank lines
|
||||
if ([String]::IsNullOrWhiteSpace($_)) { return }
|
||||
|
||||
# Prevent potential overlaping of text when one line is shorter
|
||||
$len = $Host.UI.RawUI.WindowSize.Width - $_.Length - 20
|
||||
$blank = if ($len -gt 0) { ' ' * $len } else { '' }
|
||||
$color = 'Gray'
|
||||
|
||||
if ($_.StartsWith('(OK):')) {
|
||||
$noNewLine = $true
|
||||
$color = 'Green'
|
||||
} elseif ($_.StartsWith('[') -and $_.EndsWith(']')) {
|
||||
$noNewLine = $true
|
||||
$color = 'Cyan'
|
||||
} elseif ($_.StartsWith('Download Results:')) {
|
||||
$noNewLine = $false
|
||||
}
|
||||
|
||||
Write-Host "`rDownload: $_$blank" -ForegroundColor $color -NoNewline:$noNewLine
|
||||
}
|
||||
Write-Host ''
|
||||
|
||||
if ($lastexitcode -gt 0) {
|
||||
error "Download failed! (Error $lastexitcode) $(aria_exit_code $lastexitcode)"
|
||||
error $urlstxt_content
|
||||
error $aria2
|
||||
abort $(new_issue_msg $app $bucket 'download via aria2 failed')
|
||||
}
|
||||
|
||||
# remove aria2 input file when done
|
||||
if (Test-Path $urlstxt, "$($data.$url.source).aria2*") {
|
||||
Remove-Item $urlstxt -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item "$($data.$url.source).aria2*" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# Revert console encoding
|
||||
[Console]::OutputEncoding = $oriConsoleEncoding
|
||||
}
|
||||
|
||||
foreach ($url in $urls) {
|
||||
|
||||
$metalink_filename = get_filename_from_metalink $data.$url.source
|
||||
if ($metalink_filename) {
|
||||
Remove-Item $data.$url.source -Force
|
||||
Rename-Item -Force (Join-Path -Path $cachedir -ChildPath $metalink_filename) $data.$url.source
|
||||
}
|
||||
|
||||
# run hash checks
|
||||
if ($check_hash) {
|
||||
$manifest_hash = hash_for_url $manifest $url $architecture
|
||||
$ok, $err = check_hash $data.$url.source $manifest_hash $(show_app $app $bucket)
|
||||
if (!$ok) {
|
||||
error $err
|
||||
if (Test-Path $data.$url.source) {
|
||||
# rm cached file
|
||||
Remove-Item $data.$url.source -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item "$($data.$url.source).aria2*" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
if ($url.Contains('sourceforge.net')) {
|
||||
Write-Host -f yellow 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'
|
||||
}
|
||||
abort $(new_issue_msg $app $bucket 'hash check failed')
|
||||
}
|
||||
}
|
||||
|
||||
# copy or move file to target location
|
||||
if (!(Test-Path $data.$url.source) ) {
|
||||
abort $(new_issue_msg $app $bucket 'cached file not found')
|
||||
}
|
||||
|
||||
if (!($dir -eq $cachedir)) {
|
||||
if ($use_cache) {
|
||||
Copy-Item $data.$url.source $data.$url.target
|
||||
} else {
|
||||
Move-Item $data.$url.source $data.$url.target -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# download with filesize and progress indicator
|
||||
function Invoke-Download ($url, $to, $cookies, $progress) {
|
||||
$reqUrl = ($url -split '#')[0]
|
||||
$wreq = [Net.WebRequest]::Create($reqUrl)
|
||||
if ($wreq -is [Net.HttpWebRequest]) {
|
||||
$wreq.UserAgent = Get-UserAgent
|
||||
if (-not ($url -match 'sourceforge\.net' -or $url -match 'portableapps\.com')) {
|
||||
$wreq.Referer = strip_filename $url
|
||||
}
|
||||
if ($url -match 'api\.github\.com/repos') {
|
||||
$wreq.Accept = 'application/octet-stream'
|
||||
$wreq.Headers['Authorization'] = "Bearer $(Get-GitHubToken)"
|
||||
$wreq.Headers['X-GitHub-Api-Version'] = '2022-11-28'
|
||||
}
|
||||
if ($cookies) {
|
||||
$wreq.Headers.Add('Cookie', (cookie_header $cookies))
|
||||
}
|
||||
|
||||
get_config PRIVATE_HOSTS | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object {
|
||||
(ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object {
|
||||
$wreq.Headers[$_.Key] = $_.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$wres = $wreq.GetResponse()
|
||||
} catch [System.Net.WebException] {
|
||||
$exc = $_.Exception
|
||||
$handledCodes = @(
|
||||
[System.Net.HttpStatusCode]::MovedPermanently, # HTTP 301
|
||||
[System.Net.HttpStatusCode]::Found, # HTTP 302
|
||||
[System.Net.HttpStatusCode]::SeeOther, # HTTP 303
|
||||
[System.Net.HttpStatusCode]::TemporaryRedirect # HTTP 307
|
||||
)
|
||||
|
||||
# Only handle redirection codes
|
||||
$redirectRes = $exc.Response
|
||||
if ($handledCodes -notcontains $redirectRes.StatusCode) {
|
||||
throw $exc
|
||||
}
|
||||
|
||||
# Get the new location of the file
|
||||
if ((-not $redirectRes.Headers) -or ($redirectRes.Headers -notcontains 'Location')) {
|
||||
throw $exc
|
||||
}
|
||||
|
||||
$newUrl = $redirectRes.Headers['Location']
|
||||
info "Following redirect to $newUrl..."
|
||||
|
||||
# Handle manual file rename
|
||||
if ($url -like '*#/*') {
|
||||
$null, $postfix = $url -split '#/'
|
||||
$newUrl = "$newUrl#/$postfix"
|
||||
}
|
||||
|
||||
Invoke-Download $newUrl $to $cookies $progress
|
||||
return
|
||||
}
|
||||
|
||||
$total = $wres.ContentLength
|
||||
if ($total -eq -1 -and $wreq -is [net.ftpwebrequest]) {
|
||||
$total = ftp_file_size($url)
|
||||
}
|
||||
|
||||
if ($progress -and ($total -gt 0)) {
|
||||
[console]::CursorVisible = $false
|
||||
function Trace-DownloadProgress ($read) {
|
||||
Write-DownloadProgress $read $total $url
|
||||
}
|
||||
} else {
|
||||
Write-Host "Downloading $url ($(filesize $total))..."
|
||||
function Trace-DownloadProgress {
|
||||
#no op
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$s = $wres.getresponsestream()
|
||||
$fs = [io.file]::openwrite($to)
|
||||
$buffer = New-Object byte[] 2048
|
||||
$totalRead = 0
|
||||
$sw = [diagnostics.stopwatch]::StartNew()
|
||||
|
||||
Trace-DownloadProgress $totalRead
|
||||
while (($read = $s.read($buffer, 0, $buffer.length)) -gt 0) {
|
||||
$fs.write($buffer, 0, $read)
|
||||
$totalRead += $read
|
||||
if ($sw.elapsedmilliseconds -gt 100) {
|
||||
$sw.restart()
|
||||
Trace-DownloadProgress $totalRead
|
||||
}
|
||||
}
|
||||
$sw.stop()
|
||||
Trace-DownloadProgress $totalRead
|
||||
} finally {
|
||||
if ($progress) {
|
||||
[console]::CursorVisible = $true
|
||||
Write-Host
|
||||
}
|
||||
if ($fs) {
|
||||
$fs.close()
|
||||
}
|
||||
if ($s) {
|
||||
$s.close()
|
||||
}
|
||||
$wres.close()
|
||||
}
|
||||
}
|
||||
|
||||
function Format-DownloadProgress ($url, $read, $total, $console) {
|
||||
$filename = url_remote_filename $url
|
||||
|
||||
# calculate current percentage done
|
||||
$p = [math]::Round($read / $total * 100, 0)
|
||||
|
||||
# pre-generate LHS and RHS of progress string
|
||||
# so we know how much space we have
|
||||
$left = "$filename ($(filesize $total))"
|
||||
$right = [string]::Format('{0,3}%', $p)
|
||||
|
||||
# calculate remaining width for progress bar
|
||||
$midwidth = $console.BufferSize.Width - ($left.Length + $right.Length + 8)
|
||||
|
||||
# calculate how many characters are completed
|
||||
$completed = [math]::Abs([math]::Round(($p / 100) * $midwidth, 0) - 1)
|
||||
|
||||
# generate dashes to symbolise completed
|
||||
if ($completed -gt 1) {
|
||||
$dashes = [string]::Join('', ((1..$completed) | ForEach-Object { '=' }))
|
||||
}
|
||||
|
||||
# this is why we calculate $completed - 1 above
|
||||
$dashes += switch ($p) {
|
||||
100 { '=' }
|
||||
default { '>' }
|
||||
}
|
||||
|
||||
# the remaining characters are filled with spaces
|
||||
$spaces = switch ($dashes.Length) {
|
||||
$midwidth { [string]::Empty }
|
||||
default {
|
||||
[string]::Join('', ((1..($midwidth - $dashes.Length)) | ForEach-Object { ' ' }))
|
||||
}
|
||||
}
|
||||
|
||||
"$left [$dashes$spaces] $right"
|
||||
}
|
||||
|
||||
function Write-DownloadProgress ($read, $total, $url) {
|
||||
$console = $host.UI.RawUI
|
||||
$left = $console.CursorPosition.X
|
||||
$top = $console.CursorPosition.Y
|
||||
$width = $console.BufferSize.Width
|
||||
|
||||
if ($read -eq 0) {
|
||||
$maxOutputLength = $(Format-DownloadProgress $url 100 $total $console).length
|
||||
if (($left + $maxOutputLength) -gt $width) {
|
||||
# not enough room to print progress on this line
|
||||
# print on new line
|
||||
Write-Host
|
||||
$left = 0
|
||||
$top = $top + 1
|
||||
if ($top -gt $console.CursorPosition.Y) { $top = $console.CursorPosition.Y }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host $(Format-DownloadProgress $url $read $total $console) -NoNewline
|
||||
[console]::SetCursorPosition($left, $top)
|
||||
}
|
||||
|
||||
function Invoke-ScoopDownload ($app, $version, $manifest, $bucket, $architecture, $dir, $use_cache = $true, $check_hash = $true) {
|
||||
# we only want to show this warning once
|
||||
if (!$use_cache) { warn 'Cache is being ignored.' }
|
||||
|
||||
# can be multiple urls: if there are, then installer should go first to make 'installer.args' section work
|
||||
$urls = @(script:url $manifest $architecture)
|
||||
|
||||
# can be multiple cookies: they will be used for all HTTP requests.
|
||||
$cookies = $manifest.cookie
|
||||
|
||||
# download first
|
||||
if (Test-Aria2Enabled) {
|
||||
Invoke-CachedAria2Download $app $version $manifest $architecture $dir $cookies $use_cache $check_hash
|
||||
} else {
|
||||
foreach ($url in $urls) {
|
||||
$fname = url_filename $url
|
||||
|
||||
try {
|
||||
Invoke-CachedDownload $app $version $url "$dir\$fname" $cookies $use_cache
|
||||
} catch {
|
||||
Write-Host -f darkred $_
|
||||
abort "URL $url is not valid"
|
||||
}
|
||||
|
||||
if ($check_hash) {
|
||||
$manifest_hash = hash_for_url $manifest $url $architecture
|
||||
$ok, $err = check_hash "$dir\$fname" $manifest_hash $(show_app $app $bucket)
|
||||
if (!$ok) {
|
||||
error $err
|
||||
$cached = cache_path $app $version $url
|
||||
if (Test-Path $cached) {
|
||||
# rm cached file
|
||||
Remove-Item -Force $cached
|
||||
}
|
||||
if ($url.Contains('sourceforge.net')) {
|
||||
Write-Host -f yellow 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'
|
||||
}
|
||||
abort $(new_issue_msg $app $bucket 'hash check failed')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $urls.ForEach({ url_filename $_ })
|
||||
}
|
||||
|
||||
function cookie_header($cookies) {
|
||||
if (!$cookies) { return }
|
||||
|
||||
$vals = $cookies.psobject.properties | ForEach-Object {
|
||||
"$($_.name)=$($_.value)"
|
||||
}
|
||||
|
||||
[string]::join(';', $vals)
|
||||
}
|
||||
|
||||
function is_in_dir($dir, $check) {
|
||||
$check -match "^$([regex]::Escape("$dir"))([/\\]|$)"
|
||||
}
|
||||
|
||||
function ftp_file_size($url) {
|
||||
$request = [net.ftpwebrequest]::create($url)
|
||||
$request.method = [net.webrequestmethods+ftp]::getfilesize
|
||||
$request.getresponse().contentlength
|
||||
}
|
||||
|
||||
# hashes
|
||||
function hash_for_url($manifest, $url, $arch) {
|
||||
$hashes = @(hash $manifest $arch) | Where-Object { $_ -ne $null }
|
||||
|
||||
if ($hashes.length -eq 0) { return $null }
|
||||
|
||||
$urls = @(script:url $manifest $arch)
|
||||
|
||||
$index = [array]::indexof($urls, $url)
|
||||
if ($index -eq -1) { abort "Couldn't find hash in manifest for '$url'." }
|
||||
|
||||
@($hashes)[$index]
|
||||
}
|
||||
|
||||
# returns (ok, err)
|
||||
function check_hash($file, $hash, $app_name) {
|
||||
if (!$hash) {
|
||||
warn "Warning: No hash in manifest. SHA256 for '$(fname $file)' is:`n $((Get-FileHash -Path $file -Algorithm SHA256).Hash.ToLower())"
|
||||
return $true, $null
|
||||
}
|
||||
|
||||
Write-Host 'Checking hash of ' -NoNewline
|
||||
Write-Host $(url_remote_filename $url) -f Cyan -NoNewline
|
||||
Write-Host ' ... ' -NoNewline
|
||||
$algorithm, $expected = get_hash $hash
|
||||
if ($null -eq $algorithm) {
|
||||
return $false, "Hash type '$algorithm' isn't supported."
|
||||
}
|
||||
|
||||
$actual = (Get-FileHash -Path $file -Algorithm $algorithm).Hash.ToLower()
|
||||
$expected = $expected.ToLower()
|
||||
|
||||
if ($actual -ne $expected) {
|
||||
$msg = "Hash check failed!`n"
|
||||
$msg += "App: $app_name`n"
|
||||
$msg += "URL: $url`n"
|
||||
if (Test-Path $file) {
|
||||
$msg += "First bytes: $((get_magic_bytes_pretty $file ' ').ToUpper())`n"
|
||||
}
|
||||
if ($expected -or $actual) {
|
||||
$msg += "Expected: $expected`n"
|
||||
$msg += "Actual: $actual"
|
||||
}
|
||||
return $false, $msg
|
||||
}
|
||||
Write-Host 'ok.' -f Green
|
||||
return $true, $null
|
||||
}
|
||||
|
||||
function Invoke-Installer {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
@@ -731,9 +165,9 @@ function Invoke-HookScript {
|
||||
$script = $script.script
|
||||
}
|
||||
if ($script) {
|
||||
Write-Host "Running $HookType script..." -NoNewline
|
||||
Write-Host "Running $HookType script... " -NoNewline
|
||||
Invoke-Command ([scriptblock]::Create($script -join "`r`n"))
|
||||
Write-Host 'done.' -ForegroundColor Green
|
||||
Write-Host 'Done.' -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
@@ -851,7 +285,7 @@ function ensure_install_dir_not_in_path($dir, $global) {
|
||||
|
||||
$fixed, $removed = find_dir_or_subdir $path "$dir"
|
||||
if ($removed) {
|
||||
$removed | ForEach-Object { "Installer added '$(friendly_path $_)' to path. Removing." }
|
||||
$removed | ForEach-Object { Write-Output "Installer added '$(friendly_path $_)' to path. Removing." }
|
||||
Set-EnvVar -Name 'PATH' -Value $fixed -Global:$global
|
||||
}
|
||||
|
||||
@@ -904,6 +338,7 @@ function env_set($manifest, $global, $arch) {
|
||||
$env_set | Get-Member -MemberType NoteProperty | ForEach-Object {
|
||||
$name = $_.Name
|
||||
$val = $ExecutionContext.InvokeCommand.ExpandString($env_set.$($name))
|
||||
Write-Output "Setting $(if ($global) {'system'} else {'user'}) environment variable: $([char]0x1b)[34m$name$([char]0x1b)[0m = $([char]0x1b)[35m$val$([char]0x1b)[0m"
|
||||
Set-EnvVar -Name $name -Value $val -Global:$global
|
||||
Set-Content env:\$name $val
|
||||
}
|
||||
@@ -914,6 +349,7 @@ function env_rm($manifest, $global, $arch) {
|
||||
if ($env_set) {
|
||||
$env_set | Get-Member -MemberType NoteProperty | ForEach-Object {
|
||||
$name = $_.Name
|
||||
Write-Output "Removing $(if ($global) {'system'} else {'user'}) environment variable: $([char]0x1b)[34m$name$([char]0x1b)[0m"
|
||||
Set-EnvVar -Name $name -Value $null -Global:$global
|
||||
if (Test-Path env:\$name) { Remove-Item env:\$name }
|
||||
}
|
||||
@@ -925,6 +361,7 @@ function show_notes($manifest, $dir, $original_dir, $persist_dir) {
|
||||
Write-Output 'Notes'
|
||||
Write-Output '-----'
|
||||
Write-Output (wraptext (substitute $manifest.notes @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir }))
|
||||
Write-Output '-----'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,7 +422,7 @@ function show_suggestions($suggested) {
|
||||
}
|
||||
|
||||
if (!$fulfilled) {
|
||||
Write-Host "'$app' suggests installing '$([string]::join("' or '", $feature_suggestions))'."
|
||||
Write-Host "'$app' suggests installing '$([string]::join("' or '", $feature_suggestions))'." -ForegroundColor DarkYellow
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1120,7 +557,7 @@ function test_running_process($app, $global) {
|
||||
# Required to handle docker/for-win#12240
|
||||
function New-DirectoryJunction($source, $target) {
|
||||
# test if this script is being executed inside a docker container
|
||||
if (Get-Service -Name cexecsvc -ErrorAction SilentlyContinue) {
|
||||
if (Get-Service -Name cexecsvc -ErrorAction Ignore) {
|
||||
cmd.exe /d /c "mklink /j `"$source`" `"$target`""
|
||||
} else {
|
||||
New-Item -Path $source -ItemType Junction -Value $target
|
||||
|
||||
@@ -18,8 +18,8 @@ function url_manifest($url) {
|
||||
$wc.Headers.Add('User-Agent', (Get-UserAgent))
|
||||
$data = $wc.DownloadData($url)
|
||||
$str = (Get-Encoding($wc)).GetString($data)
|
||||
} catch [system.management.automation.methodinvocationexception] {
|
||||
warn "error: $($_.exception.innerexception.message)"
|
||||
} catch [System.Management.Automation.MethodInvocationException] {
|
||||
error $_.Exception.InnerException.Message
|
||||
} catch {
|
||||
throw
|
||||
}
|
||||
@@ -40,30 +40,74 @@ function Get-Manifest($app) {
|
||||
$app = appname_from_url $url
|
||||
$manifest = url_manifest $url
|
||||
} else {
|
||||
$app, $bucket, $version = parse_app $app
|
||||
if ($bucket) {
|
||||
$manifest = manifest $app $bucket
|
||||
# Check if the manifest is already installed
|
||||
if (installed $app) {
|
||||
$global = installed $app $true
|
||||
$ver = Select-CurrentVersion -AppName $app -Global:$global
|
||||
if (!$ver) {
|
||||
$app, $bucket, $ver = parse_app $app
|
||||
$ver = Select-CurrentVersion -AppName $app -Global:$global
|
||||
}
|
||||
$install_info_path = "$(versiondir $app $ver $global)\install.json"
|
||||
if (Test-Path $install_info_path) {
|
||||
$install_info = parse_json $install_info_path
|
||||
$bucket = $install_info.bucket
|
||||
if (!$bucket) {
|
||||
$url = $install_info.url
|
||||
if ($url -match '^(ht|f)tps?://|\\\\') {
|
||||
$manifest = url_manifest $url
|
||||
}
|
||||
if (!$manifest) {
|
||||
if (Test-Path $url) {
|
||||
$manifest = parse_json $url
|
||||
} else {
|
||||
# Fallback to installed manifest
|
||||
$manifest = installed_manifest $app $ver $global
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$manifest = manifest $app $bucket
|
||||
if (!$manifest) {
|
||||
$deprecated_dir = (Find-BucketDirectory -Name $bucket -Root) + '\deprecated'
|
||||
$manifest = parse_json (Get-ChildItem $deprecated_dir -Filter "$(sanitary_path $app).json" -Recurse -ErrorAction Ignore).FullName
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($tekcub in Get-LocalBucket) {
|
||||
$manifest = manifest $app $tekcub
|
||||
if ($manifest) {
|
||||
$bucket = $tekcub
|
||||
break
|
||||
$app, $bucket, $version = parse_app $app
|
||||
if ($bucket) {
|
||||
$manifest = manifest $app $bucket
|
||||
} else {
|
||||
$matched_buckets = @()
|
||||
foreach ($tekcub in Get-LocalBucket) {
|
||||
$current_manifest = manifest $app $tekcub
|
||||
if (!$manifest -and $current_manifest) {
|
||||
$manifest = $current_manifest
|
||||
$bucket = $tekcub
|
||||
}
|
||||
if ($current_manifest) {
|
||||
$matched_buckets += $tekcub
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$manifest) {
|
||||
# couldn't find app in buckets: check if it's a local path
|
||||
if (Test-Path $app) {
|
||||
$url = Convert-Path $app
|
||||
$app = appname_from_url $url
|
||||
$manifest = parse_json $url
|
||||
} else {
|
||||
if (($app -match '\\/') -or $app.EndsWith('.json')) { $url = $app }
|
||||
$app = appname_from_url $app
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$manifest) {
|
||||
# couldn't find app in buckets: check if it's a local path
|
||||
if (Test-Path $app) {
|
||||
$url = Convert-Path $app
|
||||
$app = appname_from_url $url
|
||||
$manifest = url_manifest $url
|
||||
} else {
|
||||
if (($app -match '\\/') -or $app.EndsWith('.json')) { $url = $app }
|
||||
$app = appname_from_url $app
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($matched_buckets.Length -gt 1) {
|
||||
warn "Multiple buckets contain manifest '$app', the current selection is '$bucket/$app'."
|
||||
}
|
||||
|
||||
return $app, $manifest, $bucket, $url
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ if ($SubCommand -notin $SubCommands) {
|
||||
}
|
||||
|
||||
$opt, $other, $err = getopt $Args 'v' 'verbose'
|
||||
if ($err) { "scoop alias: $err"; exit 1 }
|
||||
if ($err) { error "scoop alias: $err"; exit 1 }
|
||||
|
||||
$name, $command, $description = $other
|
||||
$verbose = $opt.v -or $opt.verbose
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
# scoop bucket known
|
||||
param($cmd, $name, $repo)
|
||||
|
||||
if (get_config NO_JUNCTION) {
|
||||
. "$PSScriptRoot\..\lib\versions.ps1"
|
||||
}
|
||||
|
||||
if (get_config USE_SQLITE_CACHE) {
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1"
|
||||
. "$PSScriptRoot\..\lib\database.ps1"
|
||||
@@ -30,14 +34,14 @@ $usage_rm = 'usage: scoop bucket rm <name>'
|
||||
switch ($cmd) {
|
||||
'add' {
|
||||
if (!$name) {
|
||||
'<name> missing'
|
||||
error '<name> missing'
|
||||
$usage_add
|
||||
exit 1
|
||||
}
|
||||
if (!$repo) {
|
||||
$repo = known_bucket_repo $name
|
||||
if (!$repo) {
|
||||
"Unknown bucket '$name'. Try specifying <repo>."
|
||||
error "Unknown bucket '$name'. Try specifying <repo>."
|
||||
$usage_add
|
||||
exit 1
|
||||
}
|
||||
@@ -47,7 +51,7 @@ switch ($cmd) {
|
||||
}
|
||||
'rm' {
|
||||
if (!$name) {
|
||||
'<name> missing'
|
||||
error '<name> missing'
|
||||
$usage_rm
|
||||
exit 1
|
||||
}
|
||||
@@ -69,7 +73,7 @@ switch ($cmd) {
|
||||
exit 0
|
||||
}
|
||||
default {
|
||||
"scoop bucket: cmd '$cmd' not supported"
|
||||
error "scoop bucket: cmd '$cmd' not supported"
|
||||
my_usage
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ function cacheshow($app) {
|
||||
|
||||
function cacheremove($app) {
|
||||
if (!$app) {
|
||||
'ERROR: <app(s)> missing'
|
||||
error '<app(s)> missing'
|
||||
my_usage
|
||||
exit 1
|
||||
} elseif ($app -eq '*' -or $app -eq '-a' -or $app -eq '--all') {
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
param($app)
|
||||
|
||||
. "$PSScriptRoot\..\lib\json.ps1" # 'ConvertToPrettyJson'
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
|
||||
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
|
||||
|
||||
if (!$app) { error '<app> missing'; my_usage; exit 1 }
|
||||
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
. "$PSScriptRoot\..\lib\install.ps1" # persist related
|
||||
|
||||
$opt, $apps, $err = getopt $args 'agk' 'all', 'global', 'cache'
|
||||
if ($err) { "scoop cleanup: $err"; exit 1 }
|
||||
if ($err) { error "scoop cleanup: $err"; exit 1 }
|
||||
$global = $opt.g -or $opt.global
|
||||
$cache = $opt.k -or $opt.cache
|
||||
$all = $opt.a -or $opt.all
|
||||
|
||||
if (!$apps -and !$all) { 'ERROR: <app> missing'; my_usage; exit 1 }
|
||||
if (!$apps -and !$all) { error '<app> missing'; my_usage; exit 1 }
|
||||
|
||||
if ($global -and !(is_admin)) {
|
||||
'ERROR: you need admin rights to cleanup global apps'; exit 1
|
||||
error 'you need admin rights to cleanup global apps'; exit 1
|
||||
}
|
||||
|
||||
function cleanup($app, $global, $verbose, $cache) {
|
||||
|
||||
@@ -132,6 +132,9 @@
|
||||
# aria2-warning-enabled: $true|$false
|
||||
# Disable Aria2c warning which is shown while downloading.
|
||||
#
|
||||
# aria2-fallback-disabled: $true|$false
|
||||
# Disable automatic fallback to the default downloader when Aria2c download fails.
|
||||
#
|
||||
# aria2-retry-wait: 2
|
||||
# Number of seconds to wait between retries.
|
||||
# See: 'https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-retry-wait'
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
|
||||
. "$PSScriptRoot\..\lib\getopt.ps1"
|
||||
. "$PSScriptRoot\..\lib\depends.ps1" # 'Get-Dependency'
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest' (indirectly)
|
||||
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
|
||||
|
||||
$opt, $apps, $err = getopt $args 'a:' 'arch='
|
||||
$app = $apps[0]
|
||||
@@ -20,7 +22,14 @@ try {
|
||||
$deps = @()
|
||||
Get-Dependency $app $architecture | ForEach-Object {
|
||||
$dep = [ordered]@{}
|
||||
$dep.Source, $dep.Name = $_ -split '/'
|
||||
|
||||
$app, $null, $bucket, $url = Get-Manifest $_
|
||||
if (!$url) {
|
||||
$bucket, $app = $_ -split '/'
|
||||
}
|
||||
$dep.Source = if ($url) { $url } else { $bucket }
|
||||
$dep.Name = $app
|
||||
|
||||
$deps += [PSCustomObject]$dep
|
||||
}
|
||||
$deps
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
. "$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\install.ps1"
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
. "$PSScriptRoot\..\lib\install.ps1" # 'nightly_version'
|
||||
if (get_config USE_SQLITE_CACHE) {
|
||||
. "$PSScriptRoot\..\lib\database.ps1"
|
||||
}
|
||||
@@ -107,6 +109,7 @@ foreach ($curr_app in $apps) {
|
||||
} catch {
|
||||
write-host -f darkred $_
|
||||
error "URL $url is not valid"
|
||||
error $(new_issue_msg $app $bucket 'download failed')
|
||||
$dl_failure = $true
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -27,17 +27,17 @@ function print_summaries {
|
||||
|
||||
$commands = commands
|
||||
|
||||
if(!($cmd)) {
|
||||
if (!($cmd)) {
|
||||
Write-Host "Usage: scoop <command> [<args>]
|
||||
|
||||
Available commands are listed below.
|
||||
|
||||
Type 'scoop help <command>' to get more help for a specific command."
|
||||
print_summaries
|
||||
} elseif($commands -contains $cmd) {
|
||||
} elseif ($commands -contains $cmd) {
|
||||
print_help $cmd
|
||||
} else {
|
||||
warn "scoop help: no such command '$cmd'"
|
||||
error "scoop help: no such command '$cmd'"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
|
||||
$opt, $apps, $err = getopt $args 'g' 'global'
|
||||
if ($err) { "scoop hold: $err"; exit 1 }
|
||||
if ($err) { error "scoop hold: $err"; exit 1 }
|
||||
|
||||
$global = $opt.g -or $opt.global
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
# Summary: Opens the app homepage
|
||||
param($app)
|
||||
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
|
||||
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
|
||||
|
||||
if ($app) {
|
||||
$null, $manifest, $bucket, $null = Get-Manifest $app
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
. "$PSScriptRoot\..\lib\getopt.ps1"
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-InstalledVersion'
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-InstalledVersion', 'Select-CurrentVersion'
|
||||
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-RemoteFileSize'
|
||||
|
||||
$opt, $app, $err = getopt $args 'v' 'verbose'
|
||||
$original_app = $app
|
||||
if ($err) { error "scoop info: $err"; exit 1 }
|
||||
$verbose = $opt.v -or $opt.verbose
|
||||
|
||||
@@ -22,7 +24,7 @@ if (!$manifest) {
|
||||
$global = installed $app $true
|
||||
$status = app_status $app $global
|
||||
$install = install_info $app $status.version $global
|
||||
$status.installed = $bucket -and $install.bucket -eq $bucket
|
||||
$status.installed = ($bucket -and $install.bucket -eq $bucket) -or (installed $app)
|
||||
$version_output = $manifest.version
|
||||
$manifest_file = if ($bucket) {
|
||||
manifest_path $app $bucket
|
||||
@@ -30,12 +32,30 @@ $manifest_file = if ($bucket) {
|
||||
$url
|
||||
}
|
||||
|
||||
# Standalone and Source detection
|
||||
if ((Test-Path $original_app) -or ($original_app -match '^(ht|f)tps?://|\\\\')) {
|
||||
$standalone = $true
|
||||
if (Test-Path $original_app) {
|
||||
$original_app = (Get-AbsolutePath "$original_app")
|
||||
}
|
||||
if ($install.url) {
|
||||
if (Test-Path $install.url) {
|
||||
$install_url = (Get-AbsolutePath $install.url)
|
||||
} else {
|
||||
$install_url = $install.url
|
||||
}
|
||||
}
|
||||
if ($original_app -eq $install_url) {
|
||||
$same_source = $true
|
||||
}
|
||||
}
|
||||
|
||||
if ($verbose) {
|
||||
$dir = currentdir $app $global
|
||||
$original_dir = versiondir $app $manifest.version $global
|
||||
$persist_dir = persistdir $app $global
|
||||
} else {
|
||||
$dir, $original_dir, $persist_dir = "<root>", "<root>", "<root>"
|
||||
$dir, $original_dir, $persist_dir = '<root>', '<root>', '<root>'
|
||||
}
|
||||
|
||||
if ($status.installed) {
|
||||
@@ -43,21 +63,39 @@ if ($status.installed) {
|
||||
if ($install.url) {
|
||||
$manifest_file = $install.url
|
||||
}
|
||||
if ($status.version -eq $manifest.version) {
|
||||
if ($status.deprecated) {
|
||||
$manifest_file = $status.deprecated
|
||||
} elseif ($standalone -and !$same_source) {
|
||||
$version_output = $manifest.version
|
||||
} elseif ($status.version -eq $manifest.version) {
|
||||
$version_output = $status.version
|
||||
} else {
|
||||
$version_output = "$($status.version) (Update to $($manifest.version) available)"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$item = [ordered]@{ Name = $app }
|
||||
if ($status.deprecated) {
|
||||
$item.Name += ' (DEPRECATED)'
|
||||
}
|
||||
if ($manifest.description) {
|
||||
$item.Description = $manifest.description
|
||||
}
|
||||
$item.Version = $version_output
|
||||
if ($bucket) {
|
||||
$item.Bucket = $bucket
|
||||
|
||||
$item.Source = if ($standalone) {
|
||||
$original_app
|
||||
} else {
|
||||
if ($install.bucket) {
|
||||
$install.bucket
|
||||
} elseif ($install.url) {
|
||||
$install.url
|
||||
} else {
|
||||
$bucket
|
||||
}
|
||||
}
|
||||
|
||||
if ($manifest.homepage) {
|
||||
$item.Website = $manifest.homepage.TrimEnd('/')
|
||||
}
|
||||
@@ -69,7 +107,7 @@ if ($manifest.license) {
|
||||
$manifest.license
|
||||
} elseif ($manifest.license -match '[|,]') {
|
||||
if ($verbose) {
|
||||
"$($manifest.license) ($(($manifest.license -Split "\||," | ForEach-Object { "https://spdx.org/licenses/$_.html" }) -join ', '))"
|
||||
"$($manifest.license) ($(($manifest.license -Split '\||,' | ForEach-Object { "https://spdx.org/licenses/$_.html" }) -join ', '))"
|
||||
} else {
|
||||
$manifest.license
|
||||
}
|
||||
@@ -84,7 +122,7 @@ if ($manifest.depends) {
|
||||
|
||||
if (Test-Path $manifest_file) {
|
||||
if (Get-Command git -ErrorAction Ignore) {
|
||||
$gitinfo = (Invoke-Git -Path (Split-Path $manifest_file) -ArgumentList @('log', '-1', '-s', '--format=%aD#%an', $manifest_file) 2> $null) -Split '#'
|
||||
$gitinfo = (Invoke-Git -Path (Split-Path $manifest_file) -ArgumentList @('log', '-1', '-s', '--format=%aI#%an', $manifest_file) 2> $null) -Split '#'
|
||||
}
|
||||
if ($gitinfo) {
|
||||
$item.'Updated at' = $gitinfo[0] | Get-Date
|
||||
@@ -100,11 +138,13 @@ if ($verbose) { $item.Manifest = $manifest_file }
|
||||
|
||||
if ($status.installed) {
|
||||
# Show installed versions
|
||||
$installed_output = @()
|
||||
Get-InstalledVersion -AppName $app -Global:$global | ForEach-Object {
|
||||
$installed_output += if ($verbose) { versiondir $app $_ $global } else { "$_$(if ($global) { " *global*" })" }
|
||||
if (!$standalone -or $same_source) {
|
||||
$installed_output = @()
|
||||
Get-InstalledVersion -AppName $app -Global:$global | ForEach-Object {
|
||||
$installed_output += if ($verbose) { versiondir $app $_ $global } else { "$_$(if ($global) { ' *global*' })" }
|
||||
}
|
||||
$item.Installed = $installed_output -join "`n"
|
||||
}
|
||||
$item.Installed = $installed_output -join "`n"
|
||||
|
||||
if ($verbose) {
|
||||
# Show size of installation
|
||||
@@ -161,12 +201,12 @@ if ($status.installed) {
|
||||
foreach ($url in @(url $manifest (Get-DefaultArchitecture))) {
|
||||
try {
|
||||
if (Test-Path (cache_path $app $manifest.version $url)) {
|
||||
$cached = " (latest version is cached)"
|
||||
$cached = ' (latest version is cached)'
|
||||
} else {
|
||||
$cached = $null
|
||||
}
|
||||
|
||||
$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length' | ForEach-Object { [int]$_ }
|
||||
$urlLength = Get-RemoteFileSize $url
|
||||
$totalPackage += $urlLength
|
||||
} catch [System.Management.Automation.RuntimeException] {
|
||||
$totalPackage = 0
|
||||
@@ -196,7 +236,7 @@ if ($binaries) {
|
||||
$binary_output += $_
|
||||
}
|
||||
}
|
||||
$item.Binaries = $binary_output -join " | "
|
||||
$item.Binaries = $binary_output -join ' | '
|
||||
}
|
||||
$shortcuts = @(arch_specific 'shortcuts' $manifest $install.architecture)
|
||||
if ($shortcuts) {
|
||||
@@ -204,7 +244,7 @@ if ($shortcuts) {
|
||||
$shortcuts | ForEach-Object {
|
||||
$shortcut_output += $_[1]
|
||||
}
|
||||
$item.Shortcuts = $shortcut_output -join " | "
|
||||
$item.Shortcuts = $shortcut_output -join ' | '
|
||||
}
|
||||
$env_set = arch_specific 'env_set' $manifest $install.architecture
|
||||
if ($env_set) {
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'generate_user_manifest' 'Get-Manifest' 'Select-CurrentVersion' (indirectly)
|
||||
. "$PSScriptRoot\..\lib\system.ps1"
|
||||
. "$PSScriptRoot\..\lib\install.ps1"
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
. "$PSScriptRoot\..\lib\decompress.ps1"
|
||||
. "$PSScriptRoot\..\lib\shortcuts.ps1"
|
||||
. "$PSScriptRoot\..\lib\psmodules.ps1"
|
||||
@@ -43,7 +44,7 @@ if (get_config USE_SQLITE_CACHE) {
|
||||
}
|
||||
|
||||
$opt, $apps, $err = getopt $args 'giksua:' 'global', 'independent', 'no-cache', 'skip-hash-check', 'no-update-scoop', 'arch='
|
||||
if ($err) { "scoop install: $err"; exit 1 }
|
||||
if ($err) { error "scoop install: $err"; exit 1 }
|
||||
|
||||
$global = $opt.g -or $opt.global
|
||||
$check_hash = !($opt.s -or $opt.'skip-hash-check')
|
||||
|
||||
@@ -5,8 +5,9 @@ param($query)
|
||||
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'parse_json' 'Select-CurrentVersion' (indirectly)
|
||||
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
|
||||
|
||||
$def_arch = Get-DefaultArchitecture
|
||||
$defaultArchitecture = Get-DefaultArchitecture
|
||||
if (-not (Get-FormatData ScoopApps)) {
|
||||
Update-FormatData "$PSScriptRoot\..\supporting\formats\ScoopTypes.Format.ps1xml"
|
||||
}
|
||||
@@ -16,7 +17,7 @@ $global = installed_apps $true | ForEach-Object { @{ name = $_; global = $true }
|
||||
|
||||
$apps = @($local) + @($global)
|
||||
if (-not $apps) {
|
||||
Write-Host "There aren't any apps installed."
|
||||
warn "There aren't any apps installed."
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -47,10 +48,11 @@ $apps | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
|
||||
$item.Updated = $updated
|
||||
|
||||
$info = @()
|
||||
if ((app_status $app $global).deprecated) { $info += 'Deprecated package' }
|
||||
if ($global) { $info += 'Global install' }
|
||||
if (failed $app $global) { $info += 'Install failed' }
|
||||
if ($install_info.hold) { $info += 'Held package' }
|
||||
if ($install_info.architecture -and $def_arch -ne $install_info.architecture) {
|
||||
if ($install_info.architecture -and $defaultArchitecture -ne $install_info.architecture) {
|
||||
$info += $install_info.architecture
|
||||
}
|
||||
$item.Info = $info -join ', '
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
. "$PSScriptRoot\..\lib\shortcuts.ps1"
|
||||
|
||||
$opt, $apps, $err = getopt $args 'a' 'all'
|
||||
if($err) { "scoop reset: $err"; exit 1 }
|
||||
if($err) { error "scoop reset: $err"; exit 1 }
|
||||
$all = $opt.a -or $opt.all
|
||||
|
||||
if(!$apps -and !$all) { error '<app> missing'; my_usage; exit 1 }
|
||||
|
||||
@@ -10,15 +10,10 @@ param($query)
|
||||
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'manifest'
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-LatestVersion'
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
|
||||
$list = [System.Collections.Generic.List[PSCustomObject]]::new()
|
||||
|
||||
$githubtoken = Get-GitHubToken
|
||||
$authheader = @{}
|
||||
if ($githubtoken) {
|
||||
$authheader = @{'Authorization' = "token $githubtoken" }
|
||||
}
|
||||
|
||||
function bin_match($manifest, $query) {
|
||||
if (!$manifest.bin) { return $false }
|
||||
$bins = foreach ($bin in $manifest.bin) {
|
||||
@@ -122,23 +117,6 @@ function search_bucket_legacy($bucket, $query) {
|
||||
}
|
||||
}
|
||||
|
||||
function download_json($url) {
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
$result = Invoke-WebRequest $url -UseBasicParsing -Headers $authheader | Select-Object -ExpandProperty content | ConvertFrom-Json
|
||||
$ProgressPreference = 'Continue'
|
||||
$result
|
||||
}
|
||||
|
||||
function github_ratelimit_reached {
|
||||
$api_link = 'https://api.github.com/rate_limit'
|
||||
$ret = (download_json $api_link).rate.remaining -eq 0
|
||||
if ($ret) {
|
||||
Write-Host "GitHub API rate limit reached.
|
||||
Please try again later or configure your API token using 'scoop config gh_token <your token>'."
|
||||
}
|
||||
$ret
|
||||
}
|
||||
|
||||
function search_remote($bucket, $query) {
|
||||
$uri = [System.Uri](known_bucket_repo $bucket)
|
||||
if ($uri.AbsolutePath -match '/([a-zA-Z0-9]*)/([a-zA-Z0-9-]*)(?:.git|/)?') {
|
||||
@@ -162,8 +140,7 @@ function search_remotes($query) {
|
||||
} | Where-Object { $_.results }
|
||||
|
||||
if ($results.count -gt 0) {
|
||||
Write-Host "Results from other known buckets...
|
||||
(add them using 'scoop bucket add <bucket name>')"
|
||||
Write-Host "Results from other known buckets...`n(add them using 'scoop bucket add <bucket name>')"
|
||||
}
|
||||
|
||||
$remote_list = @()
|
||||
@@ -181,7 +158,7 @@ function search_remotes($query) {
|
||||
|
||||
if (get_config USE_SQLITE_CACHE) {
|
||||
. "$PSScriptRoot\..\lib\database.ps1"
|
||||
Select-ScoopDBItem $query -From @('name', 'binary', 'shortcut') |
|
||||
Find-ScoopDBItem $query -From @('name', 'binary', 'shortcut') |
|
||||
Select-Object -Property name, version, bucket, binary |
|
||||
ForEach-Object {
|
||||
$list.Add([PSCustomObject]@{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#
|
||||
# To add a custom shim, use the 'add' subcommand:
|
||||
#
|
||||
# scoop shim add <shim_name> <command_path> [<args>...]
|
||||
# scoop shim add <shim_name> <command_path> [[--|--%] <args>...]
|
||||
#
|
||||
# To remove shims, use the 'rm' subcommand: (CAUTION: this could remove shims added by an app manifest)
|
||||
#
|
||||
@@ -25,11 +25,15 @@
|
||||
# Options:
|
||||
# -g, --global Manipulate global shim(s)
|
||||
#
|
||||
# HINT: The FIRST double-hyphen '--', if any, will be treated as the POSIX-style command option terminator
|
||||
# and will NOT be included in arguments, so if you want to pass arguments like '-g' or '--global' to
|
||||
# the shim, put them after a '--'. Note that in PowerShell, you must use a QUOTED '--', e.g.,
|
||||
#
|
||||
# scoop shim add myapp 'D:\path\myapp.exe' '--' myapp_args --global
|
||||
# HINT: The FIRST terminator token ('--' or PowerShell '--%'), if any, is treated as the option
|
||||
# terminator and will NOT be included; everything after it is passed to the shim.
|
||||
# So if you want to pass arguments like '-g' or '--global' to the shim, put them after a '--' or '--%'.
|
||||
# Examples:
|
||||
# POSIX-style: scoop shim add myapp 'D:\path\myapp.exe' '--' myapp_args --global
|
||||
# PowerShell: scoop shim add myapp D:\path\myapp.exe --% myapp_args --global
|
||||
# Notes:
|
||||
# - In PowerShell, '--' should be quoted to avoid parsing.
|
||||
# - '--%' disables PowerShell parsing of the remainder; pass literals as needed.
|
||||
|
||||
param($SubCommand)
|
||||
|
||||
@@ -48,7 +52,7 @@ if ($SubCommand -notin @('add', 'rm', 'list', 'info', 'alter')) {
|
||||
}
|
||||
|
||||
$opt, $other, $err = getopt $Args 'g' 'global'
|
||||
if ($err) { "scoop shim: $err"; exit 1 }
|
||||
if ($err) { error "scoop shim: $err"; exit 1 }
|
||||
|
||||
$global = $opt.g -or $opt.global
|
||||
|
||||
@@ -112,13 +116,10 @@ switch ($SubCommand) {
|
||||
}
|
||||
}
|
||||
if ($commandPath -and (Test-Path $commandPath)) {
|
||||
Write-Host "Adding $(if ($global) { 'global' } else { 'local' }) shim " -NoNewline
|
||||
Write-Host $shimName -ForegroundColor Cyan -NoNewline
|
||||
Write-Host '...'
|
||||
Write-Host "Adding $(if ($global) { 'global' } else { 'local' }) shim $([char]0x1b)[36m$shimName$([char]0x1b)[0m..."
|
||||
shim $commandPath $global $shimName $commandArgs
|
||||
} else {
|
||||
Write-Host "ERROR: Command path does not exist: " -ForegroundColor Red -NoNewline
|
||||
Write-Host $($other[1]) -ForegroundColor Cyan
|
||||
error "Command path does not exist: $([char]0x1b)[36m$($other[1])$([char]0x1b)[31m"
|
||||
exit 3
|
||||
}
|
||||
}
|
||||
@@ -133,8 +134,7 @@ switch ($SubCommand) {
|
||||
}
|
||||
if ($failed) {
|
||||
$failed | ForEach-Object {
|
||||
Write-Host "ERROR: $(if ($global) { 'Global' } else {'Local' }) shim not found: " -ForegroundColor Red -NoNewline
|
||||
Write-Host $_ -ForegroundColor Cyan
|
||||
error "$(if ($global) { 'Global' } else { 'Local' }) shim not found: $([char]0x1b)[36m$_$([char]0x1b)[31m"
|
||||
}
|
||||
exit 3
|
||||
}
|
||||
@@ -147,8 +147,7 @@ switch ($SubCommand) {
|
||||
$pattern = $_
|
||||
[void][Regex]::New($pattern)
|
||||
} catch {
|
||||
Write-Host "ERROR: Invalid pattern: " -ForegroundColor Red -NoNewline
|
||||
Write-Host $pattern -ForegroundColor Magenta
|
||||
error "Invalid pattern: $([char]0x1b)[35m$pattern$([char]0x1b)[31m"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
@@ -172,11 +171,9 @@ switch ($SubCommand) {
|
||||
if ($shimPath) {
|
||||
Get-ShimInfo $shimPath
|
||||
} else {
|
||||
Write-Host "ERROR: $(if ($global) { 'Global' } else { 'Local' }) shim not found: " -ForegroundColor Red -NoNewline
|
||||
Write-Host $shimName -ForegroundColor Cyan
|
||||
error "$(if ($global) { 'Global' } else { 'Local' }) shim not found: $([char]0x1b)[36m$shimName$([char]0x1b)[31m"
|
||||
if (Get-ShimPath $shimName (!$global)) {
|
||||
Write-Host "But a $(if ($global) { 'local' } else {'global' }) shim exists, " -NoNewline
|
||||
Write-Host "run 'scoop shim info $shimName$(if (!$global) { ' --global' })' to show its info"
|
||||
Write-Host "But a $(if ($global) { 'local' } else { 'global' }) shim exists, run 'scoop shim info $shimName$(if (!$global) { ' --global' })' to show its info."
|
||||
exit 2
|
||||
}
|
||||
exit 3
|
||||
@@ -188,9 +185,7 @@ switch ($SubCommand) {
|
||||
if ($shimPath) {
|
||||
$shimInfo = Get-ShimInfo $shimPath
|
||||
if ($null -eq $shimInfo.Alternatives) {
|
||||
Write-Host 'ERROR: No alternatives of ' -ForegroundColor Red -NoNewline
|
||||
Write-Host $shimName -ForegroundColor Cyan -NoNewline
|
||||
Write-Host ' found.' -ForegroundColor Red
|
||||
error "No alternatives of $([char]0x1b)[36m$shimName$([char]0x1b)[31m found."
|
||||
exit 2
|
||||
}
|
||||
$shimInfo.Alternatives = $shimInfo.Alternatives.Split(' ')
|
||||
@@ -199,18 +194,10 @@ switch ($SubCommand) {
|
||||
}
|
||||
$selected = $Host.UI.PromptForChoice("Alternatives of '$shimName' command", "Please choose one that provides '$shimName' as default:", $altApps, 0)
|
||||
if ($selected -eq 0) {
|
||||
Write-Host 'INFO: ' -ForegroundColor Blue -NoNewline
|
||||
Write-Host $shimName -ForegroundColor Cyan -NoNewline
|
||||
Write-Host ' is already from ' -NoNewline
|
||||
Write-Host $shimInfo.Source -ForegroundColor DarkYellow -NoNewline
|
||||
Write-Host ', nothing changed.'
|
||||
Write-Host "$([char]0x1b)[36m$shimName$([char]0x1b)[0m is already from $([char]0x1b)[33m$($shimInfo.Source)$([char]0x1b)[0m, nothing changed."
|
||||
} else {
|
||||
$newApp = $shimInfo.Alternatives[$selected]
|
||||
Write-Host 'Use ' -NoNewline
|
||||
Write-Host $shimName -ForegroundColor Cyan -NoNewline
|
||||
Write-Host ' from ' -NoNewline
|
||||
Write-Host $newApp -ForegroundColor DarkYellow -NoNewline
|
||||
Write-Host ' as default...' -NoNewline
|
||||
Write-Host "Use $([char]0x1b)[36m$shimName$([char]0x1b)[0m from $([char]0x1b)[33m$newApp$([char]0x1b)[0m as default... " -NoNewline
|
||||
$pathNoExt = strip_ext $shimPath
|
||||
'', '.shim', '.cmd', '.ps1' | ForEach-Object {
|
||||
$oldShimPath = "$pathNoExt$_"
|
||||
@@ -222,14 +209,12 @@ switch ($SubCommand) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Host 'done.'
|
||||
Write-Host 'Done.'
|
||||
}
|
||||
} else {
|
||||
Write-Host "ERROR: $(if ($global) { 'Global' } else { 'Local' }) shim not found: " -ForegroundColor Red -NoNewline
|
||||
Write-Host $shimName -ForegroundColor Cyan
|
||||
error "$(if ($global) { 'Global' } else { 'Local' }) shim not found: $([char]0x1b)[36m$shimName$([char]0x1b)[31m"
|
||||
if (Get-ShimPath $shimName (!$global)) {
|
||||
Write-Host "But a $(if ($global) { 'local' } else {'global' }) shim exists, " -NoNewline
|
||||
Write-Host "run 'scoop shim alter $shimName$(if (!$global) { ' --global' })' to alternate its source"
|
||||
Write-Host "But a $(if ($global) { 'local' } else { 'global' }) shim exists, run 'scoop shim alter $shimName$(if (!$global) { ' --global' })' to alternate its source."
|
||||
exit 2
|
||||
}
|
||||
exit 3
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'manifest' 'parse_json' "install_info"
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
|
||||
|
||||
# check if scoop needs updating
|
||||
$currentdir = versiondir 'scoop' 'current'
|
||||
@@ -58,7 +59,7 @@ $true, $false | ForEach-Object { # local and global apps
|
||||
Get-ChildItem $dir | Where-Object name -NE 'scoop' | ForEach-Object {
|
||||
$app = $_.name
|
||||
$status = app_status $app $global
|
||||
if (!$status.outdated -and !$status.failed -and !$status.removed -and !$status.missing_deps) { return }
|
||||
if (!$status.outdated -and !$status.failed -and !$status.deprecated -and !$status.removed -and !$status.missing_deps) { return }
|
||||
|
||||
$item = [ordered]@{}
|
||||
$item.Name = $app
|
||||
@@ -66,9 +67,10 @@ $true, $false | ForEach-Object { # local and global apps
|
||||
$item.'Latest Version' = if ($status.outdated) { $status.latest_version } else { "" }
|
||||
$item.'Missing Dependencies' = $status.missing_deps -Split ' ' -Join ' | '
|
||||
$info = @()
|
||||
if ($status.failed) { $info += 'Install failed' }
|
||||
if ($status.hold) { $info += 'Held package' }
|
||||
if ($status.removed) { $info += 'Manifest removed' }
|
||||
if ($status.failed) { $info += 'Install failed' }
|
||||
if ($status.hold) { $info += 'Held package' }
|
||||
if ($status.deprecated) { $info += 'Deprecated' }
|
||||
if ($status.removed) { $info += 'Manifest removed' }
|
||||
$item.Info = $info -join ', '
|
||||
$list += [PSCustomObject]$item
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
|
||||
$opt, $apps, $err = getopt $args 'g' 'global'
|
||||
if ($err) { "scoop unhold: $err"; exit 1 }
|
||||
if ($err) { error "scoop unhold: $err"; exit 1 }
|
||||
|
||||
$global = $opt.g -or $opt.global
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest' 'Select-CurrentVersion' (indirectly)
|
||||
. "$PSScriptRoot\..\lib\system.ps1"
|
||||
. "$PSScriptRoot\..\lib\install.ps1"
|
||||
. "$PSScriptRoot\..\lib\download.ps1" # url_filename
|
||||
. "$PSScriptRoot\..\lib\shortcuts.ps1"
|
||||
. "$PSScriptRoot\..\lib\psmodules.ps1"
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
@@ -58,6 +59,7 @@ if (!$apps) { exit 0 }
|
||||
$manifest = installed_manifest $app $version $global
|
||||
$install = install_info $app $version $global
|
||||
$architecture = $install.architecture
|
||||
$bucket = $install.bucket
|
||||
|
||||
Invoke-HookScript -HookType 'pre_uninstall' -Manifest $manifest -Arch $architecture
|
||||
|
||||
@@ -74,7 +76,7 @@ if (!$apps) { exit 0 }
|
||||
continue
|
||||
}
|
||||
|
||||
Invoke-Installer -Path $dir -Manifest $manifest -ProcessorArchitecture $architecture -Uninstall
|
||||
Invoke-Installer -Path $dir -Manifest $manifest -ProcessorArchitecture $architecture -Global:$global -Uninstall
|
||||
rm_shims $app $manifest $global $architecture
|
||||
rm_startmenu_shortcuts $manifest $global $architecture
|
||||
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
. "$PSScriptRoot\..\lib\versions.ps1"
|
||||
. "$PSScriptRoot\..\lib\depends.ps1"
|
||||
. "$PSScriptRoot\..\lib\install.ps1"
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
if (get_config USE_SQLITE_CACHE) {
|
||||
. "$PSScriptRoot\..\lib\database.ps1"
|
||||
}
|
||||
|
||||
$opt, $apps, $err = getopt $args 'gfiksqa' 'global', 'force', 'independent', 'no-cache', 'skip-hash-check', 'quiet', 'all'
|
||||
if ($err) { "scoop update: $err"; exit 1 }
|
||||
if ($err) { error "scoop update: $err"; exit 1 }
|
||||
$global = $opt.g -or $opt.global
|
||||
$force = $opt.f -or $opt.force
|
||||
$check_hash = !($opt.s -or $opt.'skip-hash-check')
|
||||
@@ -135,7 +136,7 @@ function Sync-Scoop {
|
||||
# reset branch HEAD
|
||||
Invoke-Git -Path $currentdir -ArgumentList @('reset', '--hard', "origin/$configBranch", '-q')
|
||||
} else {
|
||||
Invoke-Git -Path $currentdir -ArgumentList @('pull', '-q')
|
||||
Invoke-Git -Path $currentdir -ArgumentList @('pull', '--tags', '--force', '-q')
|
||||
}
|
||||
|
||||
$res = $lastexitcode
|
||||
@@ -340,7 +341,7 @@ function update($app, $global, $quiet = $false, $independent, $suggested, $use_c
|
||||
Invoke-HookScript -HookType 'pre_uninstall' -Manifest $old_manifest -Arch $architecture
|
||||
|
||||
Write-Host "Uninstalling '$app' ($old_version)"
|
||||
Invoke-Installer -Path $dir -Manifest $old_manifest -ProcessorArchitecture $architecture -Uninstall
|
||||
Invoke-Installer -Path $dir -Manifest $old_manifest -ProcessorArchitecture $architecture -Global:$global -Uninstall
|
||||
rm_shims $app $old_manifest $global $architecture
|
||||
|
||||
# If a junction was used during install, that will have been used
|
||||
@@ -399,7 +400,7 @@ if (-not ($apps -or $all)) {
|
||||
success 'Scoop was updated successfully!'
|
||||
} else {
|
||||
if ($global -and !(is_admin)) {
|
||||
'ERROR: You need admin rights to update global apps.'; exit 1
|
||||
error 'You need admin rights to update global apps.'; exit 1
|
||||
}
|
||||
|
||||
$outdated = @()
|
||||
|
||||
@@ -29,13 +29,14 @@
|
||||
# -p, --passthru Return reports as objects
|
||||
|
||||
. "$PSScriptRoot\..\lib\getopt.ps1"
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
|
||||
. "$PSScriptRoot\..\lib\json.ps1" # 'json_path'
|
||||
. "$PSScriptRoot\..\lib\install.ps1" # 'hash_for_url'
|
||||
. "$PSScriptRoot\..\lib\download.ps1" # 'hash_for_url'
|
||||
. "$PSScriptRoot\..\lib\depends.ps1" # 'Get-Dependency'
|
||||
|
||||
$opt, $apps, $err = getopt $args 'asnup' @('all', 'scan', 'no-depends', 'no-update-scoop', 'passthru')
|
||||
if ($err) { "scoop virustotal: $err"; exit 1 }
|
||||
if ($err) { error "scoop virustotal: $err"; exit 1 }
|
||||
$all = $apps -eq '*' -or $opt.a -or $opt.all
|
||||
if (!$apps -and !$all) { my_usage; exit 1 }
|
||||
$architecture = Get-DefaultArchitecture
|
||||
@@ -86,11 +87,6 @@ Function ConvertTo-VirusTotalUrlId ($url) {
|
||||
$url_id
|
||||
}
|
||||
|
||||
Function Get-RemoteFileSize ($url) {
|
||||
$response = Invoke-WebRequest -Uri $url -Method HEAD -UseBasicParsing
|
||||
$response.Headers.'Content-Length' | ForEach-Object { [System.Convert]::ToInt32($_) }
|
||||
}
|
||||
|
||||
Function Get-VirusTotalResultByHash ($hash, $url, $app) {
|
||||
$hash = $hash.ToLower()
|
||||
$api_url = "https://www.virustotal.com/api/v3/files/$hash"
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
},
|
||||
"mode": {
|
||||
"enum": [
|
||||
"github",
|
||||
"download",
|
||||
"extract",
|
||||
"json",
|
||||
|
||||
@@ -1 +1 @@
|
||||
410f84fe347cf55f92861ea3899d30b2d84a8bbc56bb3451d74697a4a0610b25 *shim.exe
|
||||
140e3801d8adeda639a21b14e62b93a4c7d26b7a758421f43c82be59753be49b *shim.exe
|
||||
|
||||
@@ -1 +1 @@
|
||||
9ce94adf48f7a31ab5773465582728c39db6f11a560fc43316fe6c1ad0a7b69a76aa3f9b52bb6b2e3be8043e4920985c8ca0bf157be9bf1e4a5a4d7c4ed195ba *shim.exe
|
||||
59d9da9f9714003b915bcafbe1b41f53b121dde206ecc23984f62273e957766eece8d64ffc53011c328d3a2ad627aa0f4f7c39bbec8e7b64d0d2ee7b7e771423 *shim.exe
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
v3.1.1
|
||||
v3.1.2
|
||||
|
||||
@@ -73,28 +73,6 @@ Describe 'Test-HelperInstalled' -Tag 'Scoop' {
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Test-Aria2Enabled' -Tag 'Scoop' {
|
||||
It 'should return true if aria2 is installed' {
|
||||
Mock Test-HelperInstalled { $true }
|
||||
Mock get_config { $true }
|
||||
Test-Aria2Enabled | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'should return false if aria2 is not installed' {
|
||||
Mock Test-HelperInstalled { $false }
|
||||
Mock get_config { $false }
|
||||
Test-Aria2Enabled | Should -BeFalse
|
||||
|
||||
Mock Test-HelperInstalled { $false }
|
||||
Mock get_config { $true }
|
||||
Test-Aria2Enabled | Should -BeFalse
|
||||
|
||||
Mock Test-HelperInstalled { $true }
|
||||
Mock get_config { $false }
|
||||
Test-Aria2Enabled | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Test-CommandAvailable' -Tag 'Scoop' {
|
||||
It 'should return true if command exists' {
|
||||
Test-CommandAvailable 'Write-Host' | Should -BeTrue
|
||||
|
||||
@@ -25,7 +25,7 @@ Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
|
||||
}
|
||||
It 'Test cases should exist and hash should match' {
|
||||
$testcases | Should -Exist
|
||||
(Get-FileHash -Path $testcases -Algorithm SHA256).Hash.ToLower() | Should -Be 'afb86b0552187b8d630ce25d02835fb809af81c584f07e54cb049fb74ca134b6'
|
||||
(Get-FileHash -Path $testcases -Algorithm SHA256).Hash.ToLower() | Should -Be '591072faabd419b77932b7023e5899b4e05c0bf8e6859ad367398e6bfe1eb203'
|
||||
}
|
||||
It 'Test cases should be extracted correctly' {
|
||||
{ Microsoft.PowerShell.Archive\Expand-Archive -Path $testcases -DestinationPath $working_dir } | Should -Not -Throw
|
||||
@@ -61,7 +61,7 @@ Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
|
||||
$to = test_extract 'Expand-7zipArchive' $test1
|
||||
$to | Should -Exist
|
||||
"$to\empty" | Should -Exist
|
||||
(Get-ChildItem $to).Count | Should -Be 3
|
||||
(Get-ChildItem $to).Count | Should -Be 4
|
||||
}
|
||||
|
||||
It 'extract "extract_dir" correctly' {
|
||||
@@ -78,6 +78,14 @@ Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
|
||||
(Get-ChildItem $to).Count | Should -Be 1
|
||||
}
|
||||
|
||||
It 'extract "extract_dir" with nested folder with same name' {
|
||||
$to = test_extract 'Expand-7zipArchive' $test1 $false 'keep\sub'
|
||||
$to | Should -Exist
|
||||
"$to\keep\empty" | Should -Exist
|
||||
(Get-ChildItem $to).Count | Should -Be 1
|
||||
(Get-ChildItem "$to\keep").Count | Should -Be 1
|
||||
}
|
||||
|
||||
It 'extract nested compressed file' {
|
||||
# file ext: tgz
|
||||
$to = test_extract 'Expand-7zipArchive' $test2
|
||||
|
||||
@@ -65,6 +65,7 @@ Describe 'Package Dependencies' -Tag 'Scoop' {
|
||||
BeforeAll {
|
||||
Mock Test-HelperInstalled { $false }
|
||||
Mock get_config { $true } -ParameterFilter { $name -eq 'USE_LESSMSI' }
|
||||
Mock get_config { $false } -ParameterFilter { $name -eq 'USE_EXTERNAL_7ZIP' }
|
||||
Mock Get-Manifest { 'lessmsi', @{}, $null, $null } -ParameterFilter { $app -eq 'lessmsi' }
|
||||
Mock Get-Manifest { '7zip', @{ url = 'test.msi' }, $null, $null } -ParameterFilter { $app -eq '7zip' }
|
||||
Mock Get-Manifest { 'innounp', @{}, $null, $null } -ParameterFilter { $app -eq 'innounp' }
|
||||
|
||||
49
test/Scoop-Download.Tests.ps1
Normal file
49
test/Scoop-Download.Tests.ps1
Normal file
@@ -0,0 +1,49 @@
|
||||
BeforeAll {
|
||||
. "$PSScriptRoot\Scoop-TestLib.ps1"
|
||||
. "$PSScriptRoot\..\lib\core.ps1"
|
||||
. "$PSScriptRoot\..\lib\download.ps1"
|
||||
}
|
||||
|
||||
Describe 'Test-Aria2Enabled' -Tag 'Scoop' {
|
||||
It 'should return true if aria2 is installed' {
|
||||
Mock Test-HelperInstalled { $true }
|
||||
Mock get_config { $true }
|
||||
Test-Aria2Enabled | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'should return false if aria2 is not installed' {
|
||||
Mock Test-HelperInstalled { $false }
|
||||
Mock get_config { $false }
|
||||
Test-Aria2Enabled | Should -BeFalse
|
||||
|
||||
Mock Test-HelperInstalled { $false }
|
||||
Mock get_config { $true }
|
||||
Test-Aria2Enabled | Should -BeFalse
|
||||
|
||||
Mock Test-HelperInstalled { $true }
|
||||
Mock get_config { $false }
|
||||
Test-Aria2Enabled | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'url_filename' -Tag 'Scoop' {
|
||||
It 'should extract the real filename from an url' {
|
||||
url_filename 'http://example.org/foo.txt' | Should -Be 'foo.txt'
|
||||
url_filename 'http://example.org/foo.txt?var=123' | Should -Be 'foo.txt'
|
||||
}
|
||||
|
||||
It 'can be tricked with a hash to override the real filename' {
|
||||
url_filename 'http://example.org/foo-v2.zip#/foo.zip' | Should -Be 'foo.zip'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'url_remote_filename' -Tag 'Scoop' {
|
||||
It 'should extract the real filename from an url' {
|
||||
url_remote_filename 'http://example.org/foo.txt' | Should -Be 'foo.txt'
|
||||
url_remote_filename 'http://example.org/foo.txt?var=123' | Should -Be 'foo.txt'
|
||||
}
|
||||
|
||||
It 'can not be tricked with a hash to override the real filename' {
|
||||
url_remote_filename 'http://example.org/foo-v2.zip#/foo.zip' | Should -Be 'foo-v2.zip'
|
||||
}
|
||||
}
|
||||
@@ -81,13 +81,32 @@ Describe 'getopt' -Tag 'Scoop' {
|
||||
$opt, $rem, $err = getopt '--long-arg', '--' '' 'long-arg'
|
||||
$err | Should -BeNullOrEmpty
|
||||
$opt.'long-arg' | Should -BeTrue
|
||||
$rem[0] | Should -BeNullOrEmpty
|
||||
$rem | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'handles remainder args after the option terminator' {
|
||||
$opt, $rem, $err = getopt '--long-arg', '--', '-x', '-y' 'xy' 'long-arg'
|
||||
$err | Should -BeNullOrEmpty
|
||||
$opt.'long-arg' | Should -BeTrue
|
||||
$opt.'x' | Should -BeNullOrEmpty
|
||||
$opt.'y' | Should -BeNullOrEmpty
|
||||
$opt.Keys | Should -Not -Contain 'x'
|
||||
$opt.Keys | Should -Not -Contain 'y'
|
||||
$rem[0] | Should -Be '-x'
|
||||
$rem[1] | Should -Be '-y'
|
||||
}
|
||||
|
||||
It 'handles PowerShell stop-parsing token' {
|
||||
$opt, $rem, $err = getopt '--long-arg', '--%' '' 'long-arg'
|
||||
$err | Should -BeNullOrEmpty
|
||||
$opt.'long-arg' | Should -BeTrue
|
||||
$rem | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'handles remainder args after PowerShell stop-parsing token' {
|
||||
$opt, $rem, $err = getopt @('--long-arg', '--%', '--from', 'there', '--to', 'here') '' 'long-arg'
|
||||
$err | Should -BeNullOrEmpty
|
||||
$opt.Keys | Should -Not -Contain 'from'
|
||||
$opt.Keys | Should -Not -Contain 'to'
|
||||
$rem | Should -Be @('--from', 'there', '--to', 'here')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,28 +12,6 @@ Describe 'appname_from_url' -Tag 'Scoop' {
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'url_filename' -Tag 'Scoop' {
|
||||
It 'should extract the real filename from an url' {
|
||||
url_filename 'http://example.org/foo.txt' | Should -Be 'foo.txt'
|
||||
url_filename 'http://example.org/foo.txt?var=123' | Should -Be 'foo.txt'
|
||||
}
|
||||
|
||||
It 'can be tricked with a hash to override the real filename' {
|
||||
url_filename 'http://example.org/foo-v2.zip#/foo.zip' | Should -Be 'foo.zip'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'url_remote_filename' -Tag 'Scoop' {
|
||||
It 'should extract the real filename from an url' {
|
||||
url_remote_filename 'http://example.org/foo.txt' | Should -Be 'foo.txt'
|
||||
url_remote_filename 'http://example.org/foo.txt?var=123' | Should -Be 'foo.txt'
|
||||
}
|
||||
|
||||
It 'can not be tricked with a hash to override the real filename' {
|
||||
url_remote_filename 'http://example.org/foo-v2.zip#/foo.zip' | Should -Be 'foo-v2.zip'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'is_in_dir' -Tag 'Scoop', 'Windows' {
|
||||
It 'should work correctly' {
|
||||
is_in_dir 'C:\test' 'C:\foo' | Should -BeFalse
|
||||
|
||||
BIN
test/fixtures/decompress/TestCases.zip
vendored
BIN
test/fixtures/decompress/TestCases.zip
vendored
Binary file not shown.
Reference in New Issue
Block a user