diff --git a/.gitignore b/.gitignore index 67ecc85d82..932c35449e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.log .DS_Store ._.DS_Store +.lock scoop.sublime-workspace test/installer/tmp/* test/tmp/* diff --git a/CHANGELOG.md b/CHANGELOG.md index c0c15ec326..e08a0dcff3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,51 @@ +## [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)) +- **core:** Add file lock to prevent concurrent executions ([#6557](https://github.com/ScoopInstaller/Scoop/issues/6557)) + +### 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)) +- **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)) + ## [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)) +- **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)) +- **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)) diff --git a/bin/checkver.ps1 b/bin/checkver.ps1 index 33a4449488..8d6f52df08 100644 --- a/bin/checkver.ps1 +++ b/bin/checkver.ps1 @@ -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,16 @@ 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) { + if ($url -and !$err) { $ms = New-Object System.IO.MemoryStream $ms.Write($result, 0, $result.Length) $ms.Seek(0, 0) | Out-Null @@ -300,6 +307,11 @@ while ($in_progress -gt 0) { $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 +370,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) { diff --git a/bin/scoop.ps1 b/bin/scoop.ps1 index fd2fd41fa7..f17de55ed7 100644 --- a/bin/scoop.ps1 +++ b/bin/scoop.ps1 @@ -6,48 +6,74 @@ Set-StrictMode -Off . "$PSScriptRoot\..\lib\commands.ps1" . "$PSScriptRoot\..\lib\help.ps1" -$subCommand = $Args[0] +$lock_file_path = "$PSScriptRoot\..\.lock" +$lock_stream = $null +$lock_show_waiting_message = $true -# for aliases where there's a local function, re-alias so the function takes precedence -$aliases = Get-Alias | Where-Object { $_.Options -notmatch 'ReadOnly|AllScope' } | ForEach-Object { $_.Name } -Get-ChildItem Function: | Where-Object -Property Name -In -Value $aliases | ForEach-Object { - Set-Alias -Name $_.Name -Value Local:$($_.Name) -Scope Script +while (-not $lock_stream) { + try { + $lock_stream = [System.IO.File]::Open($lock_file_path, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write) + } catch [System.IO.IOException] { + # Only deal with ERROR_SHARING_VIOLATION or ERROR_LOCK_VIOLATION. + $error_code = $_.Exception.HResult -band 0xFFFF + if ($error_code -notin 32, 33) { + throw + } + + if ($lock_show_waiting_message) { + Write-Host 'Waiting for exclusive access...' + $lock_show_waiting_message = $false + } + Start-Sleep -Seconds 1 + } } -switch ($subCommand) { - ({ $subCommand -in @($null, '-h', '--help', '/?') }) { - exec 'help' +try { + $subCommand = $Args[0] + + # for aliases where there's a local function, re-alias so the function takes precedence + $aliases = Get-Alias | Where-Object { $_.Options -notmatch 'ReadOnly|AllScope' } | ForEach-Object { $_.Name } + Get-ChildItem Function: | Where-Object -Property Name -In -Value $aliases | ForEach-Object { + Set-Alias -Name $_.Name -Value Local:$($_.Name) -Scope Script } - ({ $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') - } else { - $version = Select-String -Pattern '^## \[(v[\d.]+)\].*?([\d-]+)$' -Path "$PSScriptRoot\..\CHANGELOG.md" - Write-Host $version.Matches.Groups[1].Value -ForegroundColor Cyan -NoNewline - Write-Host " - Released at $($version.Matches.Groups[2].Value)" + + switch ($subCommand) { + ({ $subCommand -in @($null, '-h', '--help', '/?') }) { + exec 'help' } - Write-Host '' - - Get-LocalBucket | ForEach-Object { - $bucketLoc = Find-BucketDirectory $_ -Root - if (Test-GitAvailable -and (Test-Path "$bucketLoc\.git")) { - Write-Host "'$_' bucket:" - Invoke-Git -Path $bucketLoc -ArgumentList @('log', 'HEAD', '-1', '--oneline') - Write-Host '' + ({ $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 @('--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 + Write-Host " - Released at $($version.Matches.Groups[2].Value)" + } + Write-Host '' + + Get-LocalBucket | ForEach-Object { + $bucketLoc = Find-BucketDirectory $_ -Root + if ((Test-GitAvailable) -and (Test-Path "$bucketLoc\.git")) { + Write-Host "'$_' bucket:" + Invoke-Git -Path $bucketLoc -ArgumentList @('--no-pager', 'log', 'HEAD', '-1', '--oneline') + Write-Host '' + } } } - } - ({ $subCommand -in (commands) }) { - [string[]]$arguments = $Args | Select-Object -Skip 1 - if ($null -ne $arguments -and $arguments[0] -in @('-h', '--help', '/?')) { - exec 'help' @($subCommand) - } else { - exec $subCommand $arguments + ({ $subCommand -in (commands) }) { + [string[]]$arguments = $Args | Select-Object -Skip 1 + if ($null -ne $arguments -and $arguments[0] -in @('-h', '--help', '/?')) { + exec 'help' @($subCommand) + } else { + exec $subCommand $arguments + } + } + default { + warn "scoop: '$subCommand' isn't a scoop command. See 'scoop help'." + exit 1 } } - default { - warn "scoop: '$subCommand' isn't a scoop command. See 'scoop help'." - exit 1 - } +} finally { + $lock_stream.Dispose() } diff --git a/bin/uninstall.ps1 b/bin/uninstall.ps1 index 2e2dc36ea8..9302dd988a 100644 --- a/bin/uninstall.ps1 +++ b/bin/uninstall.ps1 @@ -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 diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index 711f2fd6e5..fbc3ebfdee 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -3,6 +3,8 @@ function format_hash([String] $hash) { $hash = $hash.toLower() + # Workaround for GitHub API: + # `"digest": "sha256:"` if ($hash -like 'sha256:*') { $hash = $hash.Substring(7) # Remove prefix 'sha256:' } @@ -209,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 @@ -297,7 +300,7 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u } '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 == '" + $url + "')].digest") + $hash = find_hash_in_json $hashfile_url $substitutions ("$..assets[?(@.browser_download_url == '" + $originurl + "')].digest") } } diff --git a/lib/buckets.ps1 b/lib/buckets.ps1 index 87bc02d287..a6035d7876 100644 --- a/lib/buckets.ps1 +++ b/lib/buckets.ps1 @@ -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 diff --git a/lib/core.ps1 b/lib/core.ps1 index 7ca7d121e2..d0ec3ccae4 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -90,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)" } } @@ -276,7 +276,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") } } @@ -353,7 +353,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' @@ -555,7 +555,7 @@ function app_status($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).FullName + $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) @@ -622,7 +622,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 } } @@ -743,7 +750,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 @@ -762,20 +769,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 } diff --git a/lib/database.ps1 b/lib/database.ps1 index 912db11c31..007abb90b4 100644 --- a/lib/database.ps1 +++ b/lib/database.ps1 @@ -25,12 +25,12 @@ function Get-SQLite { $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 + 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 + Write-Host 'Done.' -ForegroundColor DarkYellow return $true } catch { return $false diff --git a/lib/decompress.ps1 b/lib/decompress.ps1 index 3f174bf0c3..c25e46f5e3 100644 --- a/lib/decompress.ps1 +++ b/lib/decompress.ps1 @@ -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++ } } diff --git a/lib/download.ps1 b/lib/download.ps1 index 70641cca7f..ab74d92652 100644 --- a/lib/download.ps1 +++ b/lib/download.ps1 @@ -23,7 +23,8 @@ function Invoke-ScoopDownload ($app, $version, $manifest, $bucket, $architecture Invoke-CachedDownload $app $version $url "$dir\$fname" $cookies $use_cache } catch { Write-Host -ForegroundColor DarkRed $_ - abort "URL $url is not valid" + error "URL $url is not valid" + abort $(new_issue_msg $app $bucket 'download failed') } if ($check_hash) { @@ -390,9 +391,7 @@ function Invoke-CachedAria2Download ($app, $version, $manifest, $architecture, $ } 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) -ForegroundColor Cyan -NoNewline - Write-Host ' from 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 @@ -424,7 +423,7 @@ function Invoke-CachedAria2Download ($app, $version, $manifest, $architecture, $ $aria2 = "& '$(Get-HelperPath -Helper Aria2)' $($options -join ' ')" # handle aria2 console output - Write-Host 'Starting download with aria2 ...' + Write-Host 'Starting download with aria2...' # Set console output encoding to UTF8 for non-ASCII characters printing $oriConsoleEncoding = [Console]::OutputEncoding @@ -454,12 +453,18 @@ function Invoke-CachedAria2Download ($app, $version, $manifest, $architecture, $ 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 - warn $(new_issue_msg $app $bucket "download via aria2 failed") - Write-Host "Fallback to default downloader ..." + Write-Host 'Fallback to default downloader...' try { foreach ($url in $urls) { @@ -467,7 +472,8 @@ function Invoke-CachedAria2Download ($app, $version, $manifest, $architecture, $ } } catch { Write-Host $_ -ForegroundColor DarkRed - abort "URL $url is not valid" + error "URL $url is not valid" + abort $(new_issue_msg $app $bucket 'download failed') } } @@ -723,9 +729,7 @@ function check_hash($file, $hash, $app_name) { return $true, $null } - Write-Host 'Checking hash of ' -NoNewline - Write-Host $(url_remote_filename $url) -ForegroundColor Cyan -NoNewline - Write-Host ' ... ' -NoNewline + 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." @@ -747,7 +751,7 @@ function check_hash($file, $hash, $app_name) { } return $false, $msg } - Write-Host 'ok.' -f Green + Write-Host 'OK.' -f Green return $true, $null } diff --git a/lib/getopt.ps1 b/lib/getopt.ps1 index 2de3ac6c0a..0ba80965ea 100644 --- a/lib/getopt.ps1 +++ b/lib/getopt.ps1 @@ -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)] } diff --git a/lib/install.ps1 b/lib/install.ps1 index 56cfdac924..78acdd252b 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -165,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 } } @@ -285,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 } @@ -338,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 } @@ -348,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 } } @@ -359,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 '-----' } } @@ -419,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 } } } @@ -554,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 diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 29c898b6a7..59e2bd6019 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -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 } @@ -69,7 +69,7 @@ function Get-Manifest($app) { $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).FullName + $manifest = parse_json (Get-ChildItem $deprecated_dir -Filter "$(sanitary_path $app).json" -Recurse -ErrorAction Ignore).FullName } } } diff --git a/libexec/scoop-alias.ps1 b/libexec/scoop-alias.ps1 index 677b9337f7..2b0545abe4 100644 --- a/libexec/scoop-alias.ps1 +++ b/libexec/scoop-alias.ps1 @@ -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 diff --git a/libexec/scoop-bucket.ps1 b/libexec/scoop-bucket.ps1 index d3b7728559..39d8ccf8da 100644 --- a/libexec/scoop-bucket.ps1 +++ b/libexec/scoop-bucket.ps1 @@ -34,14 +34,14 @@ $usage_rm = 'usage: scoop bucket rm ' switch ($cmd) { 'add' { if (!$name) { - ' missing' + error ' missing' $usage_add exit 1 } if (!$repo) { $repo = known_bucket_repo $name if (!$repo) { - "Unknown bucket '$name'. Try specifying ." + error "Unknown bucket '$name'. Try specifying ." $usage_add exit 1 } @@ -51,7 +51,7 @@ switch ($cmd) { } 'rm' { if (!$name) { - ' missing' + error ' missing' $usage_rm exit 1 } @@ -73,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 } diff --git a/libexec/scoop-cache.ps1 b/libexec/scoop-cache.ps1 index 30e8354fca..e81a626db7 100644 --- a/libexec/scoop-cache.ps1 +++ b/libexec/scoop-cache.ps1 @@ -35,7 +35,7 @@ function cacheshow($app) { function cacheremove($app) { if (!$app) { - 'ERROR: missing' + error ' missing' my_usage exit 1 } elseif ($app -eq '*' -or $app -eq '-a' -or $app -eq '--all') { diff --git a/libexec/scoop-cleanup.ps1 b/libexec/scoop-cleanup.ps1 index 6ce40a211f..3ea5194d0f 100644 --- a/libexec/scoop-cleanup.ps1 +++ b/libexec/scoop-cleanup.ps1 @@ -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: missing'; my_usage; exit 1 } +if (!$apps -and !$all) { error ' 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) { diff --git a/libexec/scoop-config.ps1 b/libexec/scoop-config.ps1 index 6007bd6434..954b0b6a1c 100644 --- a/libexec/scoop-config.ps1 +++ b/libexec/scoop-config.ps1 @@ -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' diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index 996cb4e8e6..1deba8a808 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -25,6 +25,7 @@ . "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion' . "$PSScriptRoot\..\lib\manifest.ps1" # 'generate_user_manifest' 'Get-Manifest' . "$PSScriptRoot\..\lib\download.ps1" +. "$PSScriptRoot\..\lib\install.ps1" # 'nightly_version' if (get_config USE_SQLITE_CACHE) { . "$PSScriptRoot\..\lib\database.ps1" } @@ -108,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 } diff --git a/libexec/scoop-help.ps1 b/libexec/scoop-help.ps1 index 54ed8a9319..18a67fa9b1 100644 --- a/libexec/scoop-help.ps1 +++ b/libexec/scoop-help.ps1 @@ -27,17 +27,17 @@ function print_summaries { $commands = commands -if(!($cmd)) { +if (!($cmd)) { Write-Host "Usage: scoop [] Available commands are listed below. Type 'scoop help ' 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 } diff --git a/libexec/scoop-hold.ps1 b/libexec/scoop-hold.ps1 index 504f20a849..48f8304c9a 100644 --- a/libexec/scoop-hold.ps1 +++ b/libexec/scoop-hold.ps1 @@ -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 diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 1322e33a63..1c147e17c0 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -122,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 diff --git a/libexec/scoop-install.ps1 b/libexec/scoop-install.ps1 index 0fadcff09d..6af199a8b8 100644 --- a/libexec/scoop-install.ps1 +++ b/libexec/scoop-install.ps1 @@ -44,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') diff --git a/libexec/scoop-list.ps1 b/libexec/scoop-list.ps1 index f757146d47..aded1e5ee0 100644 --- a/libexec/scoop-list.ps1 +++ b/libexec/scoop-list.ps1 @@ -17,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 } @@ -48,7 +48,7 @@ $apps | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object { $item.Updated = $updated $info = @() - if ((app_status $app $global).deprecated) { $info += 'Deprecated package'} + 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' } diff --git a/libexec/scoop-reset.ps1 b/libexec/scoop-reset.ps1 index 512540e8e6..1dd000a373 100644 --- a/libexec/scoop-reset.ps1 +++ b/libexec/scoop-reset.ps1 @@ -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 ' missing'; my_usage; exit 1 } diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index d94b18660d..c38143e528 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -140,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 ')" + Write-Host "Results from other known buckets...`n(add them using 'scoop bucket add ')" } $remote_list = @() diff --git a/libexec/scoop-shim.ps1 b/libexec/scoop-shim.ps1 index 877b65b2e9..35314e069c 100644 --- a/libexec/scoop-shim.ps1 +++ b/libexec/scoop-shim.ps1 @@ -4,7 +4,7 @@ # # To add a custom shim, use the 'add' subcommand: # -# scoop shim add [...] +# scoop shim add [[--|--%] ...] # # 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 diff --git a/libexec/scoop-unhold.ps1 b/libexec/scoop-unhold.ps1 index 4e2413a340..88a859c81c 100644 --- a/libexec/scoop-unhold.ps1 +++ b/libexec/scoop-unhold.ps1 @@ -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 diff --git a/libexec/scoop-uninstall.ps1 b/libexec/scoop-uninstall.ps1 index 5bdd57e5d1..7beb0d260e 100644 --- a/libexec/scoop-uninstall.ps1 +++ b/libexec/scoop-uninstall.ps1 @@ -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 -Global $global -Uninstall + Invoke-Installer -Path $dir -Manifest $manifest -ProcessorArchitecture $architecture -Global:$global -Uninstall rm_shims $app $manifest $global $architecture rm_startmenu_shortcuts $manifest $global $architecture diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index 9d41906eca..bc590a13f6 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -30,7 +30,7 @@ if (get_config USE_SQLITE_CACHE) { } $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') @@ -136,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 @@ -341,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 @@ -400,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 = @() diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index 8fe63359cf..d56eb6e8b4 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -36,7 +36,7 @@ . "$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 diff --git a/schema.json b/schema.json index 6c24d4da20..9457c391e7 100644 --- a/schema.json +++ b/schema.json @@ -50,6 +50,7 @@ }, "mode": { "enum": [ + "github", "download", "extract", "json", diff --git a/test/Scoop-GetOpts.Tests.ps1 b/test/Scoop-GetOpts.Tests.ps1 index c55781ecbf..5608cb73ca 100644 --- a/test/Scoop-GetOpts.Tests.ps1 +++ b/test/Scoop-GetOpts.Tests.ps1 @@ -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') + } + }