mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2025-12-08 09:05:41 +00:00
Compare commits
48 Commits
rasa/sandb
...
scoop-diag
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08ff0f6ae0 | ||
|
|
148eed6a67 | ||
|
|
f8b11b1f03 | ||
|
|
164918a190 | ||
|
|
de2b42e38b | ||
|
|
a8c3582d79 | ||
|
|
631b71c581 | ||
|
|
98fd86e420 | ||
|
|
3a3f41c556 | ||
|
|
15f9bbec97 | ||
|
|
ab34b7fb61 | ||
|
|
863af42d4e | ||
|
|
b3c05e71fa | ||
|
|
acc271d115 | ||
|
|
6d79d62cc8 | ||
|
|
00c92b04d6 | ||
|
|
becc7a7b76 | ||
|
|
6898773a8d | ||
|
|
353137f0a9 | ||
|
|
43579714cc | ||
|
|
aa09601503 | ||
|
|
6a35a22b0b | ||
|
|
0b4919ca32 | ||
|
|
efdd6dd7ca | ||
|
|
3dfb4bfd97 | ||
|
|
053321c7b7 | ||
|
|
62f52d9afa | ||
|
|
dfbdb57ed9 | ||
|
|
1d140585a4 | ||
|
|
52059ca1ac | ||
|
|
cddc52e03b | ||
|
|
682a1e2c07 | ||
|
|
2accaae5d1 | ||
|
|
a20bb4f1a6 | ||
|
|
ad0f6178d0 | ||
|
|
41620bb169 | ||
|
|
559c6f9e64 | ||
|
|
7826d6fe2d | ||
|
|
8acfeeefcf | ||
|
|
c00dd42cae | ||
|
|
3f11454a3c | ||
|
|
0a39de86e2 | ||
|
|
c44e214743 | ||
|
|
7c6aeb240e | ||
|
|
32ca856f63 | ||
|
|
1d0bd434ab | ||
|
|
54e3613fca | ||
|
|
e2558ace75 |
8
.github/dependabot.yml
vendored
Normal file
8
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
# ~/.github/dependabot.yml
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/" # == /.github/workflows/
|
||||
schedule:
|
||||
interval: "daily"
|
||||
48
CHANGELOG.md
48
CHANGELOG.md
@@ -3,23 +3,66 @@
|
||||
### Features
|
||||
|
||||
- **scoop-update:** Add support for parallel syncing buckets in PowerShell 7 and improve output ([#5122](https://github.com/ScoopInstaller/Scoop/issues/5122))
|
||||
- **testing:** Add ability to test manifests inside a Windows sandbox ([#5349](https://github.com/(https://github.com/ScoopInstaller/Scoop/pulls/5349))
|
||||
- **bucket:** Switch nirsoft bucket to ScoopInstaller/Nirsoft ([#5328](https://github.com/ScoopInstaller/Scoop/issues/5328))
|
||||
- **config:** Support portable config file ([#5369](https://github.com/ScoopInstaller/Scoop/issues/5369))
|
||||
- **bucket:** Make official buckets higher priority ([#5398](https://github.com/ScoopInstaller/Scoop/issues/5398))
|
||||
- **core:** Add `-Quiet` switch for `Invoke-ExternalCommand` ([#5346](https://github.com/ScoopInstaller/Scoop/issues/5346))
|
||||
- **core:** Allow global install of PowerShell modules ([#5611](https://github.com/ScoopInstaller/Scoop/issues/5611))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **shim:** Remove console window for GUI applications ([#5559](https://github.com/ScoopInstaller/Scoop/issues/5559))
|
||||
- **decompress:** Exclude '*.nsis' that may cause error ([#5294](https://github.com/ScoopInstaller/Scoop/issues/5294))
|
||||
- **autoupdate:** Fix file hash extraction ([#5295](https://github.com/ScoopInstaller/Scoop/issues/5295))
|
||||
- **getopt:** Stop split arguments in `getopt()` and ensure array by explicit arguments type ([#5326](https://github.com/ScoopInstaller/Scoop/issues/5326))
|
||||
- **shortcuts:** Output correctly formatted path ([#5333](https://github.com/ScoopInstaller/Scoop/issues/5333))
|
||||
- **core:** Fix scripts' calling parameters ([#5365](https://github.com/ScoopInstaller/Scoop/issues/5365))
|
||||
- **core:** Fix `is_in_dir` under Unix ([#5391](https://github.com/ScoopInstaller/Scoop/issues/5391))
|
||||
- **core:** Rewrite config file when needed ([#5439](https://github.com/ScoopInstaller/Scoop/issues/5439))
|
||||
- **core:** Prevents leaking HTTP(S)_PROXY env vars to current sessions after Invoke-Git in parallel execution ([#5436](https://github.com/ScoopInstaller/Scoop/pull/5436))
|
||||
- **core:** Handle scoop aliases and broken(edited,copied) shim ([#5551](https://github.com/ScoopInstaller/Scoop/issues/5551))
|
||||
- **env:** Avoid automatic expansion of `%%` in env ([#5395](https://github.com/ScoopInstaller/Scoop/issues/5395), [#5452](https://github.com/ScoopInstaller/Scoop/pull/5452), [#5631](https://github.com/ScoopInstaller/Scoop/pull/5631))
|
||||
- **install:** Fix download from private GitHub repositories ([#5361](https://github.com/ScoopInstaller/Scoop/issues/5361))
|
||||
- **install:** Avoid error when unlinking non-existent junction/hardlink ([#5552](https://github.com/ScoopInstaller/Scoop/issues/5552))
|
||||
- **scoop-info:** Fix errors in file size collection when `--verbose` ([#5352](https://github.com/ScoopInstaller/Scoop/pull/5352))
|
||||
- **shim:** Use bash executable directly ([#5433](https://github.com/ScoopInstaller/Scoop/issues/5433))
|
||||
- **core:** Avoid error messages when deleting non-existent environment variable ([#5547](https://github.com/ScoopInstaller/Scoop/issues/5547))
|
||||
- **core:** Use relative path as fallback of `$scoopdir` ([#5544](https://github.com/ScoopInstaller/Scoop/issues/5544))
|
||||
- **core:** Fix detection of Git ([#5545](https://github.com/ScoopInstaller/Scoop/issues/5545))
|
||||
- **scoop-checkup:** Skip defender check in Windows Sandbox ([#5519](https://github.com/ScoopInstaller/Scoop/issues/5519))
|
||||
- **buckets:** Avoid error messages for unexpected dir ([#5549](https://github.com/ScoopInstaller/Scoop/issues/5549))
|
||||
- **scoop-virustotal:** Fix `scoop-virustotal` when `--all` has been passed without app ([#5593](https://github.com/ScoopInstaller/Scoop/pull/5593))
|
||||
- **scoop-checkup:** Change the message level of helpers from ERROR to WARN ([#5549](https://github.com/ScoopInstaller/Scoop/issues/5614))
|
||||
- **scoop-(un)hold:** Correct output the messages when manifest not found, (already|not) held ([#5519](https://github.com/ScoopInstaller/Scoop/issues/5519))
|
||||
- **scoop-update:** Change error message to a better instruction ([#5677](https://github.com/ScoopInstaller/Scoop/issues/5677))
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
- **decompress:** Disable progress bar to improve `Expand-Archive` performance ([#5410](https://github.com/ScoopInstaller/Scoop/issues/5410))
|
||||
- **scoop-search:** Improve performance for local search ([#5324](https://github.com/ScoopInstaller/Scoop/issues/5324))
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
- **git:** Use Invoke-Git() with direct path to git.exe to prevent spawning shim subprocesses ([#5122](https://github.com/ScoopInstaller/Scoop/issues/5122))
|
||||
- **git:** Use Invoke-Git() with direct path to git.exe to prevent spawning shim subprocesses ([#5122](https://github.com/ScoopInstaller/Scoop/issues/5122), [#5375](https://github.com/ScoopInstaller/Scoop/issues/5375))
|
||||
- **scoop-download:** Output more detailed manifest information ([#5277](https://github.com/ScoopInstaller/Scoop/issues/5277))
|
||||
|
||||
### Builds
|
||||
|
||||
- **checkver:** Read the private_host config variable ([#5381](https://github.com/ScoopInstaller/Scoop/issues/5381))
|
||||
|
||||
### Continuous Integration
|
||||
|
||||
- **dependabot:** Add dependabot.yml for GitHub Actions ([#5377](https://github.com/ScoopInstaller/Scoop/pull/5377))
|
||||
|
||||
### Tests
|
||||
|
||||
- **bucket:** Skip manifest validation if no manifest changes ([#5270](https://github.com/ScoopInstaller/Scoop/issues/5270))
|
||||
|
||||
### Documentation
|
||||
|
||||
- **scoop-info:** Fix help message([#5445](https://github.com/ScoopInstaller/Scoop/issues/5445))
|
||||
- **readme:** Improve documentation language ([#5638](https://github.com/ScoopInstaller/Scoop/issues/5638))
|
||||
|
||||
## [v0.3.1](https://github.com/ScoopInstaller/Scoop/compare/v0.3.0...v0.3.1) - 2022-11-15
|
||||
|
||||
### Features
|
||||
@@ -36,6 +79,7 @@
|
||||
- **shim:** Exit if shim creating failed 'cause no git ([#5225](https://github.com/ScoopInstaller/Scoop/issues/5225))
|
||||
- **scoop-import:** Add correct architecture argument ([#5210](https://github.com/ScoopInstaller/Scoop/issues/5210))
|
||||
- **scoop-config:** Output `[DateTime]` as `[String]` ([#5232](https://github.com/ScoopInstaller/Scoop/issues/5232))
|
||||
- **shim:** fixed shim add bug related to Resolve-Path ([#5492](https://github.com/ScoopInstaller/Scoop/issues/5492))
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
|
||||
103
README.md
103
README.md
@@ -1,17 +1,17 @@
|
||||
<p align="center">
|
||||
<h1 align="center">Scoop</h1>
|
||||
|
||||
<!--<img src="scoop.png" alt="Long live Scoop!"/>-->
|
||||
<h1 align="center">Scoop</h1>
|
||||
</p>
|
||||
<p align="center">
|
||||
<b><a href="https://github.com/ScoopInstaller/Scoop#what-does-scoop-do">Features</a></b>
|
||||
|
|
||||
<b><a href="https://github.com/ScoopInstaller/Scoop#installation">Installation</a></b>
|
||||
|
|
||||
<b><a href="https://github.com/ScoopInstaller/Scoop/wiki">Documentation</a></b>
|
||||
<a href="https://github.com/ScoopInstaller/Scoop#what-does-scoop-do">Features</a>
|
||||
|
|
||||
<a href="https://github.com/ScoopInstaller/Scoop#installation">Installation</a>
|
||||
|
|
||||
<a href="https://github.com/ScoopInstaller/Scoop/wiki">Documentation</a>
|
||||
</p>
|
||||
|
||||
- - -
|
||||
<p align="center" >
|
||||
---
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/ScoopInstaller/Scoop">
|
||||
<img src="https://img.shields.io/github/languages/code-size/ScoopInstaller/Scoop.svg" alt="Code Size" />
|
||||
</a>
|
||||
@@ -36,43 +36,48 @@ Scoop is a command-line installer for Windows.
|
||||
|
||||
## What does Scoop do?
|
||||
|
||||
Scoop installs programs from the command line with a minimal amount of friction. It:
|
||||
Scoop installs apps from the command line with a minimal amount of friction. It:
|
||||
|
||||
- Eliminates permission popup windows
|
||||
- Hides GUI wizard-style installers
|
||||
- Prevents PATH pollution from installing lots of programs
|
||||
- Avoids unexpected side-effects from installing and uninstalling programs
|
||||
- Finds and installs dependencies automatically
|
||||
- Performs all the extra setup steps itself to get a working program
|
||||
- Eliminates [User Account Control](https://learn.microsoft.com/windows/security/application-security/application-control/user-account-control/) (UAC) prompt notifications.
|
||||
- Hides the graphical user interface (GUI) of wizard-style installers.
|
||||
- Prevents polluting the `PATH` environment variable. Normally, this variable gets cluttered as different apps are installed on the device.
|
||||
- Avoids unexpected side effects from installing and uninstalling apps.
|
||||
- Resolves and installs dependencies automatically.
|
||||
- Performs all the necessary steps to get an app to a working state.
|
||||
|
||||
Scoop is very scriptable, so you can run repeatable setups to get your environment just the way you like, e.g.:
|
||||
Scoop is quite script-friendly. Your environment can become the way you like by using repeatable setups. For example:
|
||||
|
||||
```powershell
|
||||
```console
|
||||
scoop install sudo
|
||||
sudo scoop install 7zip git openssh --global
|
||||
scoop install aria2 curl grep sed less touch
|
||||
scoop install python ruby go perl
|
||||
```
|
||||
|
||||
If you've built software that you'd like others to use, Scoop is an alternative to building an installer (e.g. MSI or InnoSetup) — you just need to zip your program and provide a JSON manifest that describes how to install it.
|
||||
If you have built software that you would like others to use, Scoop is an alternative to building an installer (like MSI or InnoSetup). You just need to compress your app to a `.zip` file and provide a JSON manifest that describes how to install it.
|
||||
|
||||
## Installation
|
||||
|
||||
Run the following command from a **non-admin** PowerShell to install scoop to its default location `C:\Users\<YOUR USERNAME>\scoop`.
|
||||
Run the following commands from a regular (non-admin) PowerShell terminal to install Scoop:
|
||||
|
||||
```powershell
|
||||
iwr -useb get.scoop.sh | iex
|
||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
|
||||
```
|
||||
|
||||
Advanced installation instruction and full documentation of the installer are available in [ScoopInstaller/Install](https://github.com/ScoopInstaller/Install). Please create new issues there if you have questions about the installation.
|
||||
**Note**: The first command makes your device allow running the installation and management scripts. This is necessary because Windows 10 client devices restrict execution of any PowerShell scripts by default.
|
||||
|
||||
## [Documentation](https://github.com/ScoopInstaller/Scoop/wiki)
|
||||
It will install Scoop to its default location:
|
||||
|
||||
`C:\Users\<YOUR USERNAME>\scoop`
|
||||
|
||||
You can find the complete documentation about the installer, including advanced installation configurations, in [ScoopInstaller/Install](https://github.com/ScoopInstaller/Install). Please create new issues there if you have questions about the installation.
|
||||
|
||||
## Multi-connection downloads with `aria2`
|
||||
|
||||
Scoop can utilize [`aria2`](https://github.com/aria2/aria2) to use multi-connection downloads. Simply install `aria2` through Scoop and it will be used for all downloads afterward.
|
||||
|
||||
```powershell
|
||||
```console
|
||||
scoop install aria2
|
||||
```
|
||||
|
||||
@@ -90,54 +95,54 @@ You can tweak the following `aria2` settings with the `scoop config` command:
|
||||
|
||||
## Inspiration
|
||||
|
||||
- [Homebrew](http://mxcl.github.io/homebrew/)
|
||||
- [sub](https://github.com/37signals/sub#readme)
|
||||
- [Homebrew](https://brew.sh/)
|
||||
- [Sub](https://signalvnoise.com/posts/3264-automating-with-convention-introducing-sub)
|
||||
|
||||
## What sort of apps can Scoop install?
|
||||
|
||||
The apps that install best with Scoop are commonly called "portable" apps: i.e. compressed program files that run stand-alone when extracted and don't have side-effects like changing the registry or putting files outside the program directory.
|
||||
The apps that are most likely to get installed fine with Scoop are those referred to as "portable" apps. These apps are compressed files which can run standalone after being extracted. This type of apps does not produce side effects like changing the Windows Registry or placing files outside the app directory.
|
||||
|
||||
Since installers are common, Scoop supports them too (and their uninstallers).
|
||||
|
||||
Scoop is also great at handling single-file programs and Powershell scripts. These don't even need to be compressed. See the [runat](https://github.com/ScoopInstaller/Main/blob/master/bucket/runat.json) package for an example: it's really just a GitHub gist.
|
||||
Scoop also supports installer files and their uninstallation methods. Likewise, it can handle single-file apps and PowerShell scripts. These do not even need to be compressed. See the [runat](https://github.com/ScoopInstaller/Main/blob/master/bucket/runat.json) package for an example: it is simply a GitHub gist.
|
||||
|
||||
### Contribute to this project
|
||||
|
||||
If you'd like to improve Scoop by adding features or fixing bugs, please read our [Contributing Guide](https://github.com/ScoopInstaller/.github/blob/main/.github/CONTRIBUTING.md).
|
||||
If you would like to improve Scoop by adding features or fixing bugs, please read our [Contributing Guide](https://github.com/ScoopInstaller/.github/blob/main/.github/CONTRIBUTING.md).
|
||||
|
||||
### Support this project
|
||||
|
||||
If you find Scoop useful and would like to support ongoing development and maintenance, here's how:
|
||||
If you find Scoop useful and would like to support the ongoing development and maintenance of this project, you can donate here:
|
||||
|
||||
- [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DM2SUH9EUXSKJ) (one-time donation)
|
||||
- [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DM2SUH9EUXSKJ) (one-time donations)
|
||||
|
||||
## Known application buckets
|
||||
|
||||
The following buckets are known to scoop:
|
||||
The following buckets are known to Scoop:
|
||||
|
||||
- [main](https://github.com/ScoopInstaller/Main) - Default bucket for the most common (mostly CLI) apps
|
||||
- [extras](https://github.com/ScoopInstaller/Extras) - Apps that don't fit the main bucket's [criteria](https://github.com/ScoopInstaller/Scoop/wiki/Criteria-for-including-apps-in-the-main-bucket)
|
||||
- [games](https://github.com/Calinou/scoop-games) - Open source/freeware games and game-related tools
|
||||
- [nerd-fonts](https://github.com/matthewjberger/scoop-nerd-fonts) - Nerd Fonts
|
||||
- [nirsoft](https://github.com/kodybrown/scoop-nirsoft) - Almost all of the [250+](https://rasa.github.io/scoop-directory/by-apps#kodybrown_scoop-nirsoft) apps from [Nirsoft](https://nirsoft.net)
|
||||
- [sysinternals](https://github.com/niheaven/scoop-sysinternals) - Sysinternals Suite and all individual application from [Microsoft](https://learn.microsoft.com/sysinternals/)
|
||||
- [java](https://github.com/ScoopInstaller/Java) - A collection of Java development kits (JDKs), Java runtime engines (JREs), Java's virtual machine debugging tools and Java based runtime engines.
|
||||
- [nonportable](https://github.com/ScoopInstaller/Nonportable) - Non-portable apps (may require UAC)
|
||||
- [php](https://github.com/ScoopInstaller/PHP) - Installers for most versions of PHP
|
||||
- [versions](https://github.com/ScoopInstaller/Versions) - Alternative versions of apps found in other buckets
|
||||
- [main](https://github.com/ScoopInstaller/Main) - Default bucket which contains popular non-GUI apps.
|
||||
- [extras](https://github.com/ScoopInstaller/Extras) - Apps that do not fit the main bucket's [criteria](https://github.com/ScoopInstaller/Scoop/wiki/Criteria-for-including-apps-in-the-main-bucket).
|
||||
- [games](https://github.com/Calinou/scoop-games) - Open-source and freeware video games and game-related tools.
|
||||
- [nerd-fonts](https://github.com/matthewjberger/scoop-nerd-fonts) - Nerd Fonts.
|
||||
- [nirsoft](https://github.com/ScoopInstaller/Nirsoft) - A collection of over 250+ apps from [Nirsoft](https://nirsoft.net).
|
||||
- [sysinternals](https://github.com/niheaven/scoop-sysinternals) - The Sysinternals suite from [Microsoft](https://learn.microsoft.com/sysinternals/).
|
||||
- [java](https://github.com/ScoopInstaller/Java) - A collection of Java development kits (JDKs) and Java runtime engines (JREs), Java's virtual machine debugging tools and Java based runtime engines.
|
||||
- [nonportable](https://github.com/ScoopInstaller/Nonportable) - Non-portable apps (may trigger UAC prompts).
|
||||
- [php](https://github.com/ScoopInstaller/PHP) - Installers for most versions of PHP.
|
||||
- [versions](https://github.com/ScoopInstaller/Versions) - Alternative versions of apps found in other buckets.
|
||||
|
||||
The main bucket is installed by default. To add any of the other buckets, type:
|
||||
The `main` bucket is installed by default. You can make use of more buckets by typing:
|
||||
|
||||
```console
|
||||
scoop bucket add bucketname
|
||||
scoop bucket add <name>
|
||||
```
|
||||
|
||||
For example, to add the extras bucket, type:
|
||||
For example, to add the `extras` bucket, type:
|
||||
|
||||
```console
|
||||
scoop bucket add extras
|
||||
```
|
||||
|
||||
You would be able to install apps from the `extras` bucket now.
|
||||
|
||||
## Other application buckets
|
||||
|
||||
Many other application buckets hosted on Github can be found in the [Scoop Directory](https://rasa.github.io/scoop-directory/) or via [other search engines](https://rasa.github.io/scoop-directory/#other-search-engines).
|
||||
Many other application buckets hosted on GitHub can be found on [ScoopSearch](https://scoop.sh/) or via [other search engines](https://rasa.github.io/scoop-directory/#other-search-engines).
|
||||
|
||||
@@ -226,15 +226,21 @@ $Queue | ForEach-Object {
|
||||
$url = substitute $url $substitutions
|
||||
|
||||
$state = New-Object psobject @{
|
||||
app = $name;
|
||||
file = $file;
|
||||
url = $url;
|
||||
regex = $regex;
|
||||
json = $json;
|
||||
jsonpath = $jsonpath;
|
||||
xpath = $xpath;
|
||||
reverse = $reverse;
|
||||
replace = $replace;
|
||||
app = $name
|
||||
file = $file
|
||||
url = $url
|
||||
regex = $regex
|
||||
json = $json
|
||||
jsonpath = $jsonpath
|
||||
xpath = $xpath
|
||||
reverse = $reverse
|
||||
replace = $replace
|
||||
}
|
||||
|
||||
get_config PRIVATE_HOSTS | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object {
|
||||
(ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object {
|
||||
$wc.Headers[$_.Key] = $_.Value
|
||||
}
|
||||
}
|
||||
|
||||
$wc.Headers.Add('Referer', (strip_filename $url))
|
||||
|
||||
237
bin/sandbox.ps1
237
bin/sandbox.ps1
@@ -1,237 +0,0 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
# Portions Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
# Parse arguments
|
||||
|
||||
Param(
|
||||
[Parameter(Position = 0, HelpMessage = 'The Manifest to install in the Sandbox.')]
|
||||
[String] $Manifest,
|
||||
[Parameter(Position = 1, HelpMessage = 'Options to pass to scoop.')]
|
||||
[String] $Options,
|
||||
[Parameter(Position = 2, HelpMessage = 'The script to run in the Sandbox.')]
|
||||
[ScriptBlock] $Script,
|
||||
[Parameter(HelpMessage = 'The folder to map in the Sandbox.')]
|
||||
[String] $MapFolder = $pwd
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$mapFolder = (Resolve-Path -Path $MapFolder).Path
|
||||
|
||||
if (-Not (Test-Path -Path $mapFolder -PathType Container)) {
|
||||
Write-Error -Category InvalidArgument -Message 'The provided MapFolder is not a folder.'
|
||||
}
|
||||
|
||||
# Check if Windows Sandbox is enabled
|
||||
|
||||
if (-Not (Get-Command 'WindowsSandbox' -ErrorAction SilentlyContinue)) {
|
||||
Write-Error -Category NotInstalled -Message @'
|
||||
Windows Sandbox does not seem to be available. Check the following URL for prerequisites and further details:
|
||||
https://docs.microsoft.com/windows/security/threat-protection/windows-sandbox/windows-sandbox-overview
|
||||
|
||||
You can run the following command in an elevated PowerShell for enabling Windows Sandbox:
|
||||
$ Enable-WindowsOptionalFeature -Online -FeatureName 'Containers-DisposableClientVM'
|
||||
'@
|
||||
}
|
||||
|
||||
# Close Windows Sandbox
|
||||
|
||||
$sandbox = Get-Process 'WindowsSandboxClient' -ErrorAction SilentlyContinue
|
||||
if ($sandbox) {
|
||||
Write-Host '--> Closing Windows Sandbox'
|
||||
|
||||
$sandbox | Stop-Process
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
Write-Host
|
||||
}
|
||||
Remove-Variable sandbox
|
||||
|
||||
# Initialize Temp Folder
|
||||
|
||||
$tempFolderName = 'SandboxTest'
|
||||
$tempFolder = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath $tempFolderName
|
||||
|
||||
Remove-Item $tempFolder -Force -Recurse
|
||||
|
||||
New-Item $tempFolder -ItemType Directory | Out-Null
|
||||
|
||||
if (-Not [String]::IsNullOrWhiteSpace($Manifest)) {
|
||||
Copy-Item -Path $Manifest -Recurse -Destination $tempFolder
|
||||
}
|
||||
|
||||
if ($null -eq $env:SCOOP_HOME) { $env:SCOOP_HOME = "$env:USERPROFILE\scoop" }
|
||||
$scoopCache = $env:SCOOP_HOME + '\cache'
|
||||
|
||||
Write-Host "Copying $scoopCache to $tempFolder\cache"
|
||||
|
||||
Copy-Item -Path $scoopCache -Recurse -Destination $tempFolder | Out-Null
|
||||
|
||||
$userprofileInSandbox = 'C:\Users\WDAGUtilityAccount'
|
||||
$desktopInSandbox = $userprofileInSandbox + '\Desktop'
|
||||
$sandboxTestInSandbox = $desktopInSandbox + '\' + $tempFolderName
|
||||
$copiedCacheInSandbox = $sandboxTestInSandbox + "\cache"
|
||||
$scoopCacheInSandbox = $userprofileInSandbox + "\scoop\cache"
|
||||
|
||||
# Create Bootstrap script
|
||||
|
||||
# See: https://stackoverflow.com/a/22670892/12156188
|
||||
$bootstrapPs1Content = @'
|
||||
function Update-EnvironmentVariables {
|
||||
foreach($level in "Machine","User") {
|
||||
[Environment]::GetEnvironmentVariables($level).GetEnumerator() | % {
|
||||
# For Path variables, append the new values, if they're not already in there
|
||||
if($_.Name -match 'Path$') {
|
||||
$_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select -unique) -join ';'
|
||||
}
|
||||
$_
|
||||
} | Set-Content -Path { "Env:$($_.Name)" }
|
||||
}
|
||||
}
|
||||
|
||||
function Get-ARPTable {
|
||||
$registry_paths = @('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKCU:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*')
|
||||
return Get-ItemProperty $registry_paths -ErrorAction SilentlyContinue |
|
||||
Select-Object DisplayName, DisplayVersion, Publisher, @{N='ProductCode'; E={$_.PSChildName}} |
|
||||
Where-Object {$null -ne $_.DisplayName }
|
||||
}
|
||||
'@
|
||||
|
||||
$bootstrapPs1Content += @"
|
||||
Write-Host @'
|
||||
--> Installing Scoop, 7zip, git, innounp, dark and lessmsi
|
||||
'@
|
||||
`$ProgressPreference = 'SilentlyContinue'
|
||||
|
||||
irm get.scoop.sh -outfile 'install.ps1'
|
||||
.\install.ps1 -RunAsAdmin
|
||||
Update-EnvironmentVariables
|
||||
|
||||
xcopy /I /Q /Y $copiedCacheInSandbox\*.* $scoopCacheInSandbox\
|
||||
|
||||
scoop install --no-update-scoop main/7zip
|
||||
scoop install --no-update-scoop main/git
|
||||
scoop install --no-update-scoop main/innounp
|
||||
scoop install --no-update-scoop main/dark
|
||||
scoop install --no-update-scoop main/lessmsi
|
||||
|
||||
Write-Host @'
|
||||
Tip: you can type 'Update-EnvironmentVariables' to update your environment variables, such as after installing a new software.
|
||||
'@
|
||||
|
||||
|
||||
"@
|
||||
|
||||
if (-Not [String]::IsNullOrWhiteSpace($Manifest)) {
|
||||
$manifestFileName = Split-Path $Manifest -Leaf
|
||||
$manifestPathInSandbox = Join-Path -Path $desktopInSandbox -ChildPath (Join-Path -Path $tempFolderName -ChildPath $manifestFileName)
|
||||
|
||||
$bootstrapPs1Content += @"
|
||||
Write-Host @'
|
||||
|
||||
--> Saving current ARP entries
|
||||
'@
|
||||
`$originalARP = Get-ARPTable
|
||||
Write-Host @'
|
||||
|
||||
--> Running: scoop install $Options $Manifest
|
||||
|
||||
'@
|
||||
|
||||
scoop install $Options --no-update-scoop $manifestPathInSandbox
|
||||
|
||||
Write-Host @'
|
||||
|
||||
--> Refreshing environment variables
|
||||
'@
|
||||
Update-EnvironmentVariables
|
||||
|
||||
Write-Host @'
|
||||
|
||||
--> Comparing ARP entries
|
||||
'@
|
||||
(Compare-Object (Get-ARPTable) `$originalARP -Property DisplayName,DisplayVersion,Publisher,ProductCode)| Select-Object -Property * -ExcludeProperty SideIndicator | Format-Table
|
||||
|
||||
"@
|
||||
}
|
||||
|
||||
if (-Not [String]::IsNullOrWhiteSpace($Script)) {
|
||||
$bootstrapPs1Content += @"
|
||||
Write-Host @'
|
||||
|
||||
--> Running the following script:
|
||||
|
||||
{
|
||||
$Script
|
||||
}
|
||||
|
||||
'@
|
||||
|
||||
$Script
|
||||
|
||||
|
||||
"@
|
||||
}
|
||||
|
||||
$bootstrapPs1Content += @'
|
||||
Write-Host
|
||||
'@
|
||||
|
||||
$bootstrapPs1FileName = 'Bootstrap.ps1'
|
||||
$bootstrapPs1Content | Out-File (Join-Path -Path $tempFolder -ChildPath $bootstrapPs1FileName)
|
||||
|
||||
# Create Wsb file
|
||||
|
||||
$bootstrapPs1InSandbox = Join-Path -Path $desktopInSandbox -ChildPath (Join-Path -Path $tempFolderName -ChildPath $bootstrapPs1FileName)
|
||||
$mapFolderInSandbox = Join-Path -Path $desktopInSandbox -ChildPath (Split-Path -Path $mapFolder -Leaf)
|
||||
|
||||
$sandboxTestWsbContent = @"
|
||||
<Configuration>
|
||||
<MappedFolders>
|
||||
<MappedFolder>
|
||||
<HostFolder>$tempFolder</HostFolder>
|
||||
<ReadOnly>true</ReadOnly>
|
||||
</MappedFolder>
|
||||
<MappedFolder>
|
||||
<HostFolder>$mapFolder</HostFolder>
|
||||
</MappedFolder>
|
||||
</MappedFolders>
|
||||
<LogonCommand>
|
||||
<Command>PowerShell Start-Process PowerShell -WindowStyle Maximized -WorkingDirectory '$mapFolderInSandbox' -ArgumentList '-ExecutionPolicy Bypass -NoExit -NoLogo -File $bootstrapPs1InSandbox'</Command>
|
||||
</LogonCommand>
|
||||
</Configuration>
|
||||
"@
|
||||
|
||||
$sandboxTestWsbFileName = 'SandboxTest.wsb'
|
||||
$sandboxTestWsbFile = Join-Path -Path $tempFolder -ChildPath $sandboxTestWsbFileName
|
||||
$sandboxTestWsbContent | Out-File $sandboxTestWsbFile
|
||||
|
||||
Write-Host @"
|
||||
--> Starting Windows Sandbox, and:
|
||||
- Mounting the following directories:
|
||||
- $tempFolder as read-only
|
||||
- $mapFolder as read-and-write
|
||||
- Installing Scoop
|
||||
"@
|
||||
|
||||
if (-Not [String]::IsNullOrWhiteSpace($Manifest)) {
|
||||
Write-Host @"
|
||||
- Installing the Manifest $manifestFileName
|
||||
- Refreshing environment variables
|
||||
- Comparing ARP Entries
|
||||
"@
|
||||
}
|
||||
|
||||
if (-Not [String]::IsNullOrWhiteSpace($Script)) {
|
||||
Write-Host @"
|
||||
- Running the following script:
|
||||
|
||||
{
|
||||
$Script
|
||||
}
|
||||
"@
|
||||
}
|
||||
|
||||
Write-Host
|
||||
|
||||
WindowsSandbox $SandboxTestWsbFile
|
||||
@@ -17,7 +17,7 @@ param(
|
||||
. "$PSScriptRoot\..\lib\versions.ps1"
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1"
|
||||
|
||||
if ($global -and !(is_admin)) {
|
||||
if ($global -and !(Test-IsAdmin)) {
|
||||
error 'You need admin rights to uninstall globally.'
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"main": "https://github.com/ScoopInstaller/Main",
|
||||
"extras": "https://github.com/ScoopInstaller/Extras",
|
||||
"versions": "https://github.com/ScoopInstaller/Versions",
|
||||
"nirsoft": "https://github.com/kodybrown/scoop-nirsoft",
|
||||
"nirsoft": "https://github.com/ScoopInstaller/Nirsoft",
|
||||
"sysinternals": "https://github.com/niheaven/scoop-sysinternals",
|
||||
"php": "https://github.com/ScoopInstaller/PHP",
|
||||
"nerd-fonts": "https://github.com/matthewjberger/scoop-nerd-fonts",
|
||||
|
||||
@@ -58,10 +58,18 @@ function Get-LocalBucket {
|
||||
.SYNOPSIS
|
||||
List all local buckets.
|
||||
#>
|
||||
$bucketNames = (Get-ChildItem -Path $bucketsdir -Directory).Name
|
||||
$bucketNames = [System.Collections.Generic.List[String]](Get-ChildItem -Path $bucketsdir -Directory).Name
|
||||
if ($null -eq $bucketNames) {
|
||||
return @() # Return a zero-length list instead of $null.
|
||||
} else {
|
||||
$knownBuckets = known_buckets
|
||||
for ($i = $knownBuckets.Count - 1; $i -ge 0 ; $i--) {
|
||||
$name = $knownBuckets[$i]
|
||||
if ($bucketNames.Contains($name)) {
|
||||
[void]$bucketNames.Remove($name)
|
||||
$bucketNames.Insert(0, $name)
|
||||
}
|
||||
}
|
||||
return $bucketNames
|
||||
}
|
||||
}
|
||||
@@ -100,10 +108,10 @@ 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')
|
||||
$bucket.Updated = Invoke-Git -Path $path -ArgumentList @('log', '--format=%aD', '-n', '1') | Get-Date
|
||||
} else {
|
||||
$bucket.Source = friendly_path $path
|
||||
$bucket.Updated = (Get-Item "$path\bucket").LastWriteTime
|
||||
$bucket.Updated = (Get-Item "$path\bucket" -ErrorAction SilentlyContinue).LastWriteTime
|
||||
}
|
||||
$bucket.Manifests = Get-ChildItem "$path\bucket" -Force -Recurse -ErrorAction SilentlyContinue |
|
||||
Measure-Object | Select-Object -ExpandProperty Count
|
||||
|
||||
265
lib/core.ps1
265
lib/core.ps1
@@ -1,3 +1,56 @@
|
||||
# Returns the subsystem of the EXE
|
||||
function Get-Subsystem($filePath) {
|
||||
try {
|
||||
$fileStream = [System.IO.FileStream]::new($filePath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
|
||||
$binaryReader = [System.IO.BinaryReader]::new($fileStream)
|
||||
} catch {
|
||||
return -1 # leave the subsystem part silently
|
||||
}
|
||||
|
||||
try {
|
||||
$fileStream.Seek(0x3C, [System.IO.SeekOrigin]::Begin) | Out-Null
|
||||
$peOffset = $binaryReader.ReadInt32()
|
||||
|
||||
$fileStream.Seek($peOffset, [System.IO.SeekOrigin]::Begin) | Out-Null
|
||||
$fileHeaderOffset = $fileStream.Position
|
||||
|
||||
$fileStream.Seek(18, [System.IO.SeekOrigin]::Current) | Out-Null
|
||||
$fileStream.Seek($fileHeaderOffset + 0x5C, [System.IO.SeekOrigin]::Begin) | Out-Null
|
||||
|
||||
return $binaryReader.ReadInt16()
|
||||
} finally {
|
||||
$binaryReader.Close()
|
||||
$fileStream.Close()
|
||||
}
|
||||
}
|
||||
|
||||
function Change-Subsystem($filePath, $targetSubsystem) {
|
||||
try {
|
||||
$fileStream = [System.IO.FileStream]::new($filePath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite)
|
||||
$binaryReader = [System.IO.BinaryReader]::new($fileStream)
|
||||
$binaryWriter = [System.IO.BinaryWriter]::new($fileStream)
|
||||
} catch {
|
||||
Write-Output "Error opening File:'$filePath'"
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
$fileStream.Seek(0x3C, [System.IO.SeekOrigin]::Begin) | Out-Null
|
||||
$peOffset = $binaryReader.ReadInt32()
|
||||
|
||||
$fileStream.Seek($peOffset, [System.IO.SeekOrigin]::Begin) | Out-Null
|
||||
$fileHeaderOffset = $fileStream.Position
|
||||
|
||||
$fileStream.Seek(18, [System.IO.SeekOrigin]::Current) | Out-Null
|
||||
$fileStream.Seek($fileHeaderOffset + 0x5C, [System.IO.SeekOrigin]::Begin) | Out-Null
|
||||
|
||||
$binaryWriter.Write([System.Int16] $targetSubsystem)
|
||||
} finally {
|
||||
$binaryReader.Close()
|
||||
$fileStream.Close()
|
||||
}
|
||||
}
|
||||
|
||||
function Optimize-SecurityProtocol {
|
||||
# .NET Framework 4.7+ has a default security protocol called 'SystemDefault',
|
||||
# which allows the operating system to choose the best protocol to use.
|
||||
@@ -145,41 +198,31 @@ function Invoke-Git {
|
||||
|
||||
$proxy = get_config PROXY
|
||||
$git = Get-HelperPath -Helper Git
|
||||
$arguments = $ArgumentList -join ' '
|
||||
$cmd = "`"$git`" $arguments"
|
||||
|
||||
if ($WorkingDirectory) {
|
||||
$cmd = "`"$git`" -C `"$WorkingDirectory`" $arguments"
|
||||
$ArgumentList = @('-C', $WorkingDirectory) + $ArgumentList
|
||||
}
|
||||
$sb = [scriptblock]::Create("& $cmd")
|
||||
|
||||
if([String]::IsNullOrEmpty($proxy) -or $proxy -eq 'none') {
|
||||
return Invoke-Command $sb
|
||||
return & $git @ArgumentList
|
||||
}
|
||||
|
||||
if($arguments -Match '\b(clone|checkout|pull|fetch|ls-remote)\b') {
|
||||
$old_https = $env:HTTPS_PROXY
|
||||
$old_http = $env:HTTP_PROXY
|
||||
try {
|
||||
if($ArgumentList -Match '\b(clone|checkout|pull|fetch|ls-remote)\b') {
|
||||
$j = Start-Job -ScriptBlock {
|
||||
# convert proxy setting for git
|
||||
if ($proxy.StartsWith('currentuser@')) {
|
||||
$proxy = $using:proxy
|
||||
if ($proxy -and $proxy.StartsWith('currentuser@')) {
|
||||
$proxy = $proxy.Replace('currentuser@', ':@')
|
||||
}
|
||||
$env:HTTPS_PROXY = $proxy
|
||||
$env:HTTP_PROXY = $proxy
|
||||
return Invoke-Command $sb
|
||||
}
|
||||
catch {
|
||||
error $_
|
||||
return
|
||||
}
|
||||
finally {
|
||||
$env:HTTPS_PROXY = $old_https
|
||||
$env:HTTP_PROXY = $old_http
|
||||
& $using:git @using:ArgumentList
|
||||
}
|
||||
$o = $j | Receive-Job -Wait -AutoRemoveJob
|
||||
return $o
|
||||
}
|
||||
|
||||
return Invoke-Command $sb
|
||||
return & $git @ArgumentList
|
||||
}
|
||||
|
||||
function Invoke-GitLog {
|
||||
@@ -198,7 +241,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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,11 +253,16 @@ function format($str, $hash) {
|
||||
$executionContext.invokeCommand.expandString($str)
|
||||
}
|
||||
function is_admin {
|
||||
Show-DeprecatedWarning $MyInvocation 'Test-IsAdmin'
|
||||
$admin = [security.principal.windowsbuiltinrole]::administrator
|
||||
$id = [security.principal.windowsidentity]::getcurrent()
|
||||
([security.principal.windowsprincipal]($id)).isinrole($admin)
|
||||
}
|
||||
|
||||
function Test-IsAdmin {
|
||||
return ([System.Security.Principal.WindowsPrincipal] [System.Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
}
|
||||
|
||||
# messages
|
||||
function abort($msg, [int] $exit_code=1) { write-host $msg -f red; exit $exit_code }
|
||||
function error($msg) { write-host "ERROR $msg" -f darkred }
|
||||
@@ -274,6 +322,7 @@ function filesize($length) {
|
||||
function basedir($global) { if($global) { return $globaldir } $scoopdir }
|
||||
function appsdir($global) { "$(basedir $global)\apps" }
|
||||
function shimdir($global) { "$(basedir $global)\shims" }
|
||||
function modulesdir($global) { "$(basedir $global)\modules" }
|
||||
function appdir($app, $global) { "$(appsdir $global)\$app" }
|
||||
function versiondir($app, $version, $global) { "$(appdir $app $global)\$version" }
|
||||
|
||||
@@ -359,7 +408,7 @@ Function Test-CommandAvailable {
|
||||
}
|
||||
|
||||
Function Test-GitAvailable {
|
||||
Return [Boolean](Test-Path (Get-HelperPath -Helper Git) -ErrorAction Ignore)
|
||||
return [Boolean](Get-HelperPath -Helper Git)
|
||||
}
|
||||
|
||||
function Get-HelperPath {
|
||||
@@ -377,8 +426,8 @@ function Get-HelperPath {
|
||||
process {
|
||||
switch ($Helper) {
|
||||
'Git' {
|
||||
$internalgit = "$(versiondir 'git' 'current')\mingw64\bin\git.exe"
|
||||
if (Test-Path $internalgit) {
|
||||
$internalgit = (Get-AppFilePath 'git' 'mingw64\bin\git.exe'), (Get-AppFilePath 'git' 'mingw32\bin\git.exe') | Where-Object { $_ -ne $null }
|
||||
if ($internalgit) {
|
||||
$HelperPath = $internalgit
|
||||
} else {
|
||||
$HelperPath = (Get-Command git -ErrorAction Ignore).Source
|
||||
@@ -426,7 +475,10 @@ function Get-CommandPath {
|
||||
} catch {
|
||||
return $null
|
||||
}
|
||||
$commandPath = if ($comm.Path -like "$userShims*" -or $comm.Path -like "$globalShims*") {
|
||||
$commandPath = if ($comm.Path -like "$userShims\scoop-*.ps1") {
|
||||
# Scoop aliases
|
||||
$comm.Source
|
||||
} elseif ($comm.Path -like "$userShims*" -or $comm.Path -like "$globalShims*") {
|
||||
Get-ShimTarget ($comm.Path -replace '\.exe$', '.shim')
|
||||
} elseif ($comm.CommandType -eq 'Application') {
|
||||
$comm.Source
|
||||
@@ -571,6 +623,9 @@ function Invoke-ExternalCommand {
|
||||
[Parameter(ParameterSetName = "UseShellExecute")]
|
||||
[Switch]
|
||||
$RunAs,
|
||||
[Parameter(ParameterSetName = "UseShellExecute")]
|
||||
[Switch]
|
||||
$Quiet,
|
||||
[Alias("Msg")]
|
||||
[String]
|
||||
$Activity,
|
||||
@@ -600,29 +655,33 @@ function Invoke-ExternalCommand {
|
||||
if ($RunAs) {
|
||||
$Process.StartInfo.UseShellExecute = $true
|
||||
$Process.StartInfo.Verb = 'RunAs'
|
||||
} else {
|
||||
$Process.StartInfo.CreateNoWindow = $true
|
||||
}
|
||||
if ($FilePath -match '^((cmd|cscript|wscript|msiexec)(\.exe)?|.*\.(bat|cmd|js|vbs|wsf))$') {
|
||||
$Process.StartInfo.Arguments = $ArgumentList -join ' '
|
||||
} elseif ($Process.StartInfo.ArgumentList.Add) {
|
||||
# ArgumentList is supported in PowerShell 6.1 and later (built on .NET Core 2.1+)
|
||||
# ref-1: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0
|
||||
# ref-2: https://docs.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.2#net-framework-vs-net-core
|
||||
$ArgumentList | ForEach-Object { $Process.StartInfo.ArgumentList.Add($_) }
|
||||
} else {
|
||||
# escape arguments manually in lower versions, refer to https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=vs.85)
|
||||
$escapedArgs = $ArgumentList | ForEach-Object {
|
||||
# escape N consecutive backslash(es), which are followed by a double quote, to 2N consecutive ones
|
||||
$s = $_ -replace '(\\+)"', '$1$1"'
|
||||
# escape N consecutive backslash(es), which are at the end of the string, to 2N consecutive ones
|
||||
$s = $s -replace '(\\+)$', '$1$1'
|
||||
# escape double quotes
|
||||
$s = $s -replace '"', '\"'
|
||||
# quote the argument
|
||||
"`"$s`""
|
||||
if ($Quiet) {
|
||||
$Process.StartInfo.UseShellExecute = $true
|
||||
$Process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
|
||||
}
|
||||
if ($ArgumentList.Length -gt 0) {
|
||||
if ($FilePath -match '^((cmd|cscript|wscript|msiexec)(\.exe)?|.*\.(bat|cmd|js|vbs|wsf))$') {
|
||||
$Process.StartInfo.Arguments = $ArgumentList -join ' '
|
||||
} elseif ($Process.StartInfo.ArgumentList.Add) {
|
||||
# ArgumentList is supported in PowerShell 6.1 and later (built on .NET Core 2.1+)
|
||||
# ref-1: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0
|
||||
# ref-2: https://docs.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.2#net-framework-vs-net-core
|
||||
$ArgumentList | ForEach-Object { $Process.StartInfo.ArgumentList.Add($_) }
|
||||
} else {
|
||||
# escape arguments manually in lower versions, refer to https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=vs.85)
|
||||
$escapedArgs = $ArgumentList | ForEach-Object {
|
||||
# escape N consecutive backslash(es), which are followed by a double quote, to 2N consecutive ones
|
||||
$s = $_ -replace '(\\+)"', '$1$1"'
|
||||
# escape N consecutive backslash(es), which are at the end of the string, to 2N consecutive ones
|
||||
$s = $s -replace '(\\+)$', '$1$1'
|
||||
# escape double quotes
|
||||
$s = $s -replace '"', '\"'
|
||||
# quote the argument
|
||||
"`"$s`""
|
||||
}
|
||||
$Process.StartInfo.Arguments = $escapedArgs -join ' '
|
||||
}
|
||||
$Process.StartInfo.Arguments = $escapedArgs -join ' '
|
||||
}
|
||||
try {
|
||||
[void]$Process.Start()
|
||||
@@ -665,10 +724,55 @@ function Invoke-ExternalCommand {
|
||||
return $true
|
||||
}
|
||||
|
||||
function env($name,$global,$val='__get') {
|
||||
$target = 'User'; if($global) {$target = 'Machine'}
|
||||
if($val -eq '__get') { [environment]::getEnvironmentVariable($name,$target) }
|
||||
else { [environment]::setEnvironmentVariable($name,$val,$target) }
|
||||
function Publish-Env {
|
||||
if (-not ("Win32.NativeMethods" -as [Type])) {
|
||||
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SendMessageTimeout(
|
||||
IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam,
|
||||
uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
|
||||
"@
|
||||
}
|
||||
|
||||
$HWND_BROADCAST = [IntPtr] 0xffff;
|
||||
$WM_SETTINGCHANGE = 0x1a;
|
||||
$result = [UIntPtr]::Zero
|
||||
|
||||
[Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST,
|
||||
$WM_SETTINGCHANGE,
|
||||
[UIntPtr]::Zero,
|
||||
"Environment",
|
||||
2,
|
||||
5000,
|
||||
[ref] $result
|
||||
) | Out-Null
|
||||
}
|
||||
|
||||
function env($name, $global, $val = '__get') {
|
||||
$RegisterKey = if ($global) {
|
||||
Get-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager'
|
||||
} else {
|
||||
Get-Item -Path 'HKCU:'
|
||||
}
|
||||
$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment', $val -ne '__get')
|
||||
|
||||
if ($val -eq '__get') {
|
||||
$RegistryValueOption = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames
|
||||
$EnvRegisterKey.GetValue($name, $null, $RegistryValueOption)
|
||||
} elseif ($val -eq $null) {
|
||||
try { $EnvRegisterKey.DeleteValue($name) } catch { }
|
||||
Publish-Env
|
||||
} else {
|
||||
$RegistryValueKind = if ($val.Contains('%')) {
|
||||
[Microsoft.Win32.RegistryValueKind]::ExpandString
|
||||
} elseif ($EnvRegisterKey.GetValue($name)) {
|
||||
$EnvRegisterKey.GetValueKind($name)
|
||||
} else {
|
||||
[Microsoft.Win32.RegistryValueKind]::String
|
||||
}
|
||||
$EnvRegisterKey.SetValue($name, $val, $RegistryValueKind)
|
||||
Publish-Env
|
||||
}
|
||||
}
|
||||
|
||||
function isFileLocked([string]$path) {
|
||||
@@ -752,7 +856,7 @@ function Get-ShimTarget($ShimPath) {
|
||||
if (!$shimTarget) {
|
||||
$shimTarget = ((Select-String -Path $ShimPath -Pattern '[''"]([^@&]*?)[''"]' -AllMatches).Matches.Groups | Select-Object -Last 1).Value
|
||||
}
|
||||
$shimTarget | Convert-Path
|
||||
$shimTarget | Convert-Path -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,10 +888,10 @@ function shim($path, $global, $name, $arg) {
|
||||
$shim = "$abs_shimdir\$($name.tolower())"
|
||||
|
||||
# convert to relative path
|
||||
Push-Location $abs_shimdir
|
||||
$relative_path = Resolve-Path -Relative $path
|
||||
Pop-Location
|
||||
$resolved_path = Convert-Path $path
|
||||
Push-Location $abs_shimdir
|
||||
$relative_path = Resolve-Path -Relative $resolved_path
|
||||
Pop-Location
|
||||
|
||||
if ($path -match '\.(exe|com)$') {
|
||||
# for programs with no awareness of any shell
|
||||
@@ -797,6 +901,13 @@ function shim($path, $global, $name, $arg) {
|
||||
if ($arg) {
|
||||
Write-Output "args = $arg" | Out-UTF8File "$shim.shim" -Append
|
||||
}
|
||||
|
||||
$target_subsystem = Get-Subsystem $resolved_path
|
||||
|
||||
if (($target_subsystem -ne 3) -and ($target_subsystem -ge 0)) { # Subsystem -eq 3 means `Console`, -ge 0 to ignore
|
||||
Write-Output "Making $shim.exe a GUI binary."
|
||||
Change-Subsystem "$shim.exe" $target_subsystem
|
||||
}
|
||||
} elseif ($path -match '\.(bat|cmd)$') {
|
||||
# shim .bat, .cmd so they can be used by programs with no awareness of PSH
|
||||
warn_on_overwrite "$shim.cmd" $path
|
||||
@@ -882,19 +993,9 @@ function shim($path, $global, $name, $arg) {
|
||||
) -join "`n" | Out-UTF8File $shim -NoNewLine
|
||||
} else {
|
||||
warn_on_overwrite "$shim.cmd" $path
|
||||
# find path to Git's bash so that batch scripts can run bash scripts
|
||||
if (!(Get-CommandPath git)) {
|
||||
error "Can't shim '$shim': 'git' is needed but not installed."
|
||||
error "Please install git ('scoop install git') and try again."
|
||||
exit 1
|
||||
}
|
||||
$gitdir = (Get-Item (Get-CommandPath git) -ErrorAction:Stop).Directory.Parent
|
||||
if ($gitdir.FullName -imatch 'mingw') {
|
||||
$gitdir = $gitdir.Parent
|
||||
}
|
||||
@(
|
||||
"@rem $resolved_path",
|
||||
"@`"$(Join-Path (Join-Path $gitdir.FullName 'bin') 'bash.exe')`" `"$resolved_path`" $arg %*"
|
||||
"@bash `"$resolved_path`" $arg %*"
|
||||
) -join "`r`n" | Out-UTF8File "$shim.cmd"
|
||||
|
||||
warn_on_overwrite $shim $path
|
||||
@@ -1300,10 +1401,33 @@ Optimize-SecurityProtocol
|
||||
# Load Scoop config
|
||||
$configHome = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Select-Object -First 1
|
||||
$configFile = "$configHome\scoop\config.json"
|
||||
# Check if it's the expected install path for scoop: <root>/apps/scoop/current
|
||||
$coreRoot = Split-Path $PSScriptRoot
|
||||
$pathExpected = ($coreRoot -replace '\\','/') -like '*apps/scoop/current*'
|
||||
if ($pathExpected) {
|
||||
# Portable config is located in root directory:
|
||||
# .\current\scoop\apps\<root>\config.json <- a reversed path
|
||||
# Imagine `<root>/apps/scoop/current/` in a reversed format,
|
||||
# and the directory tree:
|
||||
#
|
||||
# ```
|
||||
# <root>:
|
||||
# ├─apps
|
||||
# ├─buckets
|
||||
# ├─cache
|
||||
# ├─persist
|
||||
# ├─shims
|
||||
# ├─config.json
|
||||
# ```
|
||||
$configPortablePath = fullpath "$coreRoot\..\..\..\config.json"
|
||||
if (Test-Path $configPortablePath) {
|
||||
$configFile = $configPortablePath
|
||||
}
|
||||
}
|
||||
$scoopConfig = load_cfg $configFile
|
||||
|
||||
# NOTE Scoop config file migration. Remove this after 2023/6/30
|
||||
if ($scoopConfig) {
|
||||
if ($scoopConfig -and $scoopConfig.PSObject.Properties.Name -contains 'lastUpdate') {
|
||||
$newConfigNames = @{
|
||||
'lastUpdate' = 'last_update'
|
||||
'SCOOP_REPO' = 'scoop_repo'
|
||||
@@ -1321,19 +1445,14 @@ if ($scoopConfig) {
|
||||
$value = $scoopConfig.$($_.Key)
|
||||
$scoopConfig.PSObject.Properties.Remove($_.Key)
|
||||
$scoopConfig | Add-Member -MemberType NoteProperty -Name $_.Value -Value $value
|
||||
if ($_.Key -eq 'lastUpdate') {
|
||||
$scoopConfigChg = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($scoopConfigChg) { # Only save config file if there was a change
|
||||
ConvertTo-Json $scoopConfig | Out-UTF8File -FilePath $configFile
|
||||
}
|
||||
ConvertTo-Json $scoopConfig | Out-UTF8File -FilePath $configFile
|
||||
}
|
||||
# END NOTE
|
||||
|
||||
# Scoop root directory
|
||||
$scoopdir = $env:SCOOP, (get_config ROOT_PATH), "$([System.Environment]::GetFolderPath('UserProfile'))\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
|
||||
$scoopdir = $env:SCOOP, (get_config ROOT_PATH), (Resolve-Path "$PSScriptRoot\..\..\..\.."), "$([System.Environment]::GetFolderPath('UserProfile'))\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
|
||||
|
||||
# Scoop global apps directory
|
||||
$globaldir = $env:SCOOP_GLOBAL, (get_config GLOBAL_PATH), "$([System.Environment]::GetFolderPath('CommonApplicationData'))\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
|
||||
|
||||
@@ -241,8 +241,14 @@ function Expand-ZipArchive {
|
||||
$OriDestinationPath = $DestinationPath
|
||||
$DestinationPath = "$DestinationPath\_tmp"
|
||||
}
|
||||
# Disable progress bar to gain performance
|
||||
$oldProgressPreference = $ProgressPreference
|
||||
$global:ProgressPreference = 'SilentlyContinue'
|
||||
|
||||
# Compatible with Pscx v3 (https://github.com/Pscx/Pscx) ('Microsoft.PowerShell.Archive' is not needed for Pscx v4)
|
||||
Microsoft.PowerShell.Archive\Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
|
||||
|
||||
$global:ProgressPreference = $oldProgressPreference
|
||||
if ($ExtractDir) {
|
||||
movedir "$DestinationPath\$ExtractDir" $OriDestinationPath | Out-Null
|
||||
Remove-Item $DestinationPath -Recurse -Force
|
||||
|
||||
@@ -3,7 +3,7 @@ Diagnostic tests.
|
||||
Return $true if the test passed, otherwise $false.
|
||||
Use 'warn' to highlight the issue, and follow up with the recommended actions to rectify.
|
||||
#>
|
||||
function check_windows_defender($global) {
|
||||
function Invoke-WindowsDefenderCheck($global) {
|
||||
$defender = Get-Service -Name WinDefend -ErrorAction SilentlyContinue
|
||||
if (Test-CommandAvailable Get-MpPreference) {
|
||||
if ((Get-MpPreference).DisableRealtimeMonitoring) { return $true }
|
||||
@@ -26,8 +26,12 @@ function check_windows_defender($global) {
|
||||
return $true
|
||||
}
|
||||
|
||||
function check_main_bucket {
|
||||
if ((Get-LocalBucket) -notcontains 'main') {
|
||||
function Test-MainBucketAvailable {
|
||||
return ((Get-LocalBucket) -contains 'main')
|
||||
}
|
||||
|
||||
function Invoke-MainBucketCheck {
|
||||
if (!(Test-MainBucketAvailable)) {
|
||||
warn 'Main bucket is not added.'
|
||||
Write-Host " run 'scoop bucket add main'"
|
||||
|
||||
@@ -37,13 +41,25 @@ function check_main_bucket {
|
||||
return $true
|
||||
}
|
||||
|
||||
function check_long_paths {
|
||||
if ([System.Environment]::OSVersion.Version.Major -lt 10 -or [System.Environment]::OSVersion.Version.Build -lt 1607) {
|
||||
function Test-WindowsLongPathsSupported {
|
||||
return !([System.Environment]::OSVersion.Version.Major -lt 10 -or [System.Environment]::OSVersion.Version.Build -lt 1607)
|
||||
}
|
||||
|
||||
function Test-WindowsLongPathsEnabled {
|
||||
return ((Get-ItemProperty `
|
||||
-Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' `
|
||||
-Name 'LongPathsEnabled' `
|
||||
-ErrorAction SilentlyContinue
|
||||
).LongPathsEnabled -eq 1)
|
||||
}
|
||||
|
||||
function Invoke-LongPathsCheck {
|
||||
if (!(Test-WindowsLongPathsSupported)) {
|
||||
warn 'This version of Windows does not support configuration of LongPaths.'
|
||||
return $false
|
||||
}
|
||||
$key = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -ErrorAction SilentlyContinue -Name 'LongPathsEnabled'
|
||||
if (!$key -or ($key.LongPathsEnabled -eq 0)) {
|
||||
|
||||
if (!(Test-WindowsLongPathsEnabled)) {
|
||||
warn 'LongPaths support is not enabled.'
|
||||
Write-Host " You can enable it by running:"
|
||||
Write-Host " sudo Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1"
|
||||
@@ -54,11 +70,15 @@ function check_long_paths {
|
||||
return $true
|
||||
}
|
||||
|
||||
function Get-WindowsDeveloperModeStatus {
|
||||
$DevModRegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
|
||||
if (!(Test-Path -Path $DevModRegistryPath) -or (Get-ItemProperty -Path `
|
||||
$DevModRegistryPath -Name AllowDevelopmentWithoutDevLicense -ErrorAction `
|
||||
SilentlyContinue).AllowDevelopmentWithoutDevLicense -ne 1) {
|
||||
function Test-WindowsDeveloperModeEnabled {
|
||||
return ((Get-ItemProperty `
|
||||
-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock' `
|
||||
-Name 'AllowDevelopmentWithoutDevLicense' `
|
||||
-ErrorAction SilentlyContinue).AllowDevelopmentWithoutDevLicense -eq 1)
|
||||
}
|
||||
|
||||
function Invoke-WindowsDeveloperModeCheck {
|
||||
if (!(Test-WindowsDeveloperModeEnabled)) {
|
||||
warn "Windows Developer Mode is not enabled. Operations relevant to symlinks may fail without proper rights."
|
||||
Write-Host " You may read more about the symlinks support here:"
|
||||
Write-Host " https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/"
|
||||
@@ -67,3 +87,156 @@ function Get-WindowsDeveloperModeStatus {
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
function Show-Value {
|
||||
[CmdletBinding()]
|
||||
[OutputType([String])]
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$Name,
|
||||
[String]
|
||||
$Value,
|
||||
[Switch]
|
||||
$Redacted,
|
||||
[Switch]
|
||||
$Color,
|
||||
[Int]
|
||||
$PadRight = 12
|
||||
)
|
||||
|
||||
if ([String]::IsNullOrEmpty($Value)) {
|
||||
return
|
||||
}
|
||||
|
||||
$Red = "`e[31m"
|
||||
$Green = "`e[32m"
|
||||
$Yellow = "`e[33m"
|
||||
$Cyan = "`e[36m"
|
||||
$End = "`e[0m"
|
||||
if (!$Color) {
|
||||
$Red, $Green, $Yellow, $Cyan, $End = '', '', '', '', ''
|
||||
}
|
||||
|
||||
if ($Redacted) {
|
||||
$Value = "$Red<redacted>$End"
|
||||
}
|
||||
|
||||
$Value = "$Value".Replace($env:USERPROFILE, "$Green`$env:USERPROFILE$End")
|
||||
$Value = "$Value".Replace($env:USERNAME, "$Green<username>$End")
|
||||
|
||||
$Name = $Name.PadRight($PadRight, ' ')
|
||||
|
||||
if ($Value -eq $True) {
|
||||
$Value = "$Green$Value$End"
|
||||
} elseif ($Value -eq $False) {
|
||||
$Value = "$Yellow$Value$End"
|
||||
}
|
||||
Write-Output "$Cyan$Name$End = $Value"
|
||||
}
|
||||
|
||||
function Show-Header {
|
||||
[CmdletBinding()]
|
||||
[OutputType([String])]
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$Value,
|
||||
[Switch]
|
||||
$Color
|
||||
)
|
||||
|
||||
if ($Color) {
|
||||
Write-Output "`e[35m[$Value]`e[0m"
|
||||
} else {
|
||||
Write-Output "[$Value]"
|
||||
}
|
||||
}
|
||||
|
||||
function Get-ParentProcess {
|
||||
$parent = [System.Diagnostics.Process]::GetCurrentProcess()
|
||||
while ($parent.MainModule.ModuleName -ieq 'pwsh.exe' -or $parent.MainModule.ModuleName -ieq 'powershell.exe') {
|
||||
$parent = $parent.Parent
|
||||
}
|
||||
return $parent.MainModule.ModuleName
|
||||
}
|
||||
|
||||
function Show-Diag {
|
||||
[CmdletBinding()]
|
||||
[OutputType([String])]
|
||||
param(
|
||||
[Switch]
|
||||
$Markdown,
|
||||
[Switch]
|
||||
$Color
|
||||
)
|
||||
|
||||
$redactedConfigValues = @(
|
||||
'virustotal_api_key'
|
||||
'private_hosts'
|
||||
'gh_token'
|
||||
'proxy'
|
||||
'analytics_id'
|
||||
'alias'
|
||||
)
|
||||
|
||||
if ($Markdown) {
|
||||
Write-Output "`n"
|
||||
Write-Output '```ini'
|
||||
}
|
||||
|
||||
Show-Header -Color:$Color -Value 'PowerShell'
|
||||
Show-Value -Color:$Color -Name 'Path' -Value ([System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName)
|
||||
Show-Value -Color:$Color -Name 'Version' -Value $PSversionTable.PSVersion.ToString()
|
||||
Show-Value -Color:$Color -Name 'Edition' -Value $PSversionTable.PSEdition
|
||||
Show-Value -Color:$Color -Name 'Architecture' -Value (Get-DefaultArchitecture)
|
||||
Show-Value -Color:$Color -Name 'RunAsAdmin' -Value (Test-IsAdmin)
|
||||
Show-Value -Color:$Color -Name 'Parent' -Value (Get-ParentProcess)
|
||||
|
||||
Show-Header -Color:$Color -Value 'Helpers'
|
||||
Show-Value -Color:$Color -Name 'GitPath' -Value (Get-HelperPath -Helper Git)
|
||||
Show-Value -Color:$Color -Name 'GitVersion' -Value (Invoke-Git -Path $PSScriptRoot -ArgumentList 'version')
|
||||
Show-Value -Color:$Color -Name 'Zip' -Value (Test-HelperInstalled -Helper '7zip')
|
||||
Show-Value -Color:$Color -Name 'Lessmsi' -Value (Test-HelperInstalled -Helper 'Lessmsi')
|
||||
Show-Value -Color:$Color -Name 'Innounp' -Value (Test-HelperInstalled -Helper 'Innounp')
|
||||
Show-Value -Color:$Color -Name 'Dark' -Value (Test-HelperInstalled -Helper 'Dark')
|
||||
Show-Value -Color:$Color -Name 'Aria2' -Value (Test-HelperInstalled -Helper 'Aria2')
|
||||
Show-Value -Color:$Color -Name 'Zstd' -Value (Test-HelperInstalled -Helper 'Zstd')
|
||||
|
||||
Show-Header -Color:$Color -Value 'Environment'
|
||||
Show-Value -Color:$Color -Name 'SCOOP' -Value $env:SCOOP
|
||||
Show-Value -Color:$Color -Name 'SCOOP_GLOBAL' -Value $env:SCOOP_GLOBAL
|
||||
Show-Value -Color:$Color -Name 'SCOOP_CACHE' -Value $env:SCOOP_CACHE
|
||||
Show-Value -Color:$Color -Name 'HTTPS_PROXY' -Value $env:HTTPS_PROXY -Redacted
|
||||
Show-Value -Color:$Color -Name 'HTTP_PROXY' -Value $env:HTTP_PROXY -Redacted
|
||||
|
||||
Show-Header -Color:$Color -Value 'Scoop'
|
||||
Show-Value -Color:$Color -Name 'Outdated' -Value (is_scoop_outdated)
|
||||
Show-Value -Color:$Color -Name 'OnHold' -Value (Test-ScoopCoreOnHold)
|
||||
Show-Value -Color:$Color -Name 'Config' -Value $configFile
|
||||
Show-Value -Color:$Color -Name 'CoreRoot' -Value $coreRoot
|
||||
Show-Value -Color:$Color -Name 'ScoopDir' -Value $scoopdir
|
||||
Show-Value -Color:$Color -Name 'CacheDir' -Value $cachedir
|
||||
Show-Value -Color:$Color -Name 'GlobalDir' -Value $globaldir
|
||||
|
||||
Show-Header -Color:$Color -Value 'Config'
|
||||
$pad = ($scoopConfig.PSObject.Properties.Name | Measure-Object -Maximum -Property Length).Maximum
|
||||
$scoopConfig.PSObject.Properties | ForEach-Object {
|
||||
Show-Value -Color:$Color -Name $_.Name -Value $_.Value -PadRight $pad -Redacted:($redactedConfigValues.Contains($_.Name))
|
||||
}
|
||||
|
||||
Show-Header -Color:$Color -Value 'Windows'
|
||||
$pad = 16
|
||||
Show-Value -Color:$Color -Name 'DeveloperMode' -PadRight $pad -Value (Test-WindowsDeveloperModeEnabled)
|
||||
Show-Value -Color:$Color -Name 'LongPathsEnabled' -PadRight $pad -Value (Test-WindowsLongPathsEnabled)
|
||||
Show-Value -Color:$Color -Name 'ScoopDirFormat' -PadRight $pad -Value ((New-Object System.IO.DriveInfo($scoopdir)).DriveFormat)
|
||||
Show-Value -Color:$Color -Name 'GlobalDirFormat' -PadRight $pad -Value ((New-Object System.IO.DriveInfo($globaldir)).DriveFormat)
|
||||
Show-Value -Color:$Color -Name 'WindowsDefender' -PadRight $pad -Value ((Get-Service -Name WinDefend -ErrorAction SilentlyContinue).Status)
|
||||
|
||||
if ($Markdown) {
|
||||
Write-Output '```'
|
||||
Write-Output "`n"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# 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)
|
||||
function getopt($argv, $shortopts, $longopts) {
|
||||
function getopt([String[]]$argv, [String]$shortopts, [String[]]$longopts) {
|
||||
$opts = @{}; $rem = @()
|
||||
|
||||
function err($msg) {
|
||||
@@ -24,10 +24,6 @@ function getopt($argv, $shortopts, $longopts) {
|
||||
return [Regex]::Escape($str)
|
||||
}
|
||||
|
||||
# ensure these are arrays
|
||||
$argv = @($argv -split ' ')
|
||||
$longopts = @($longopts)
|
||||
|
||||
for ($i = 0; $i -lt $argv.Length; $i++) {
|
||||
$arg = $argv[$i]
|
||||
if ($null -eq $arg) { continue }
|
||||
@@ -81,6 +77,5 @@ function getopt($argv, $shortopts, $longopts) {
|
||||
$rem += $arg
|
||||
}
|
||||
}
|
||||
|
||||
$opts, $rem
|
||||
}
|
||||
|
||||
@@ -365,7 +365,8 @@ function Invoke-Download ($url, $to, $cookies, $progress) {
|
||||
}
|
||||
if ($url -match 'api\.github\.com/repos') {
|
||||
$wreq.Accept = 'application/octet-stream'
|
||||
$wreq.Headers['Authorization'] = "token $(Get-GitHubToken)"
|
||||
$wreq.Headers['Authorization'] = "Bearer $(Get-GitHubToken)"
|
||||
$wreq.Headers['X-GitHub-Api-Version'] = "2022-11-28"
|
||||
}
|
||||
if ($cookies) {
|
||||
$wreq.Headers.Add('Cookie', (cookie_header $cookies))
|
||||
@@ -632,7 +633,7 @@ function cookie_header($cookies) {
|
||||
function is_in_dir($dir, $check) {
|
||||
$check = "$(fullpath $check)"
|
||||
$dir = "$(fullpath $dir)"
|
||||
$check -match "^$([regex]::escape("$dir"))(\\|`$)"
|
||||
$check -match "^$([regex]::Escape("$dir"))([/\\]|`$)"
|
||||
}
|
||||
|
||||
function ftp_file_size($url) {
|
||||
@@ -1066,13 +1067,18 @@ function ensure_none_failed($apps) {
|
||||
foreach ($app in $apps) {
|
||||
$app = ($app -split '/|\\')[-1] -replace '\.json$', ''
|
||||
foreach ($global in $true, $false) {
|
||||
if ($global) {
|
||||
$instArgs = @('--global')
|
||||
} else {
|
||||
$instArgs = @()
|
||||
}
|
||||
if (failed $app $global) {
|
||||
if (installed $app $global) {
|
||||
info "Repair previous failed installation of $app."
|
||||
& "$PSScriptRoot\..\libexec\scoop-reset.ps1" $app$(if ($global) { ' --global' })
|
||||
& "$PSScriptRoot\..\libexec\scoop-reset.ps1" $app @instArgs
|
||||
} else {
|
||||
warn "Purging previous failed installation of $app."
|
||||
& "$PSScriptRoot\..\libexec\scoop-uninstall.ps1" $app$(if ($global) { ' --global' })
|
||||
& "$PSScriptRoot\..\libexec\scoop-uninstall.ps1" $app @instArgs
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1179,7 +1185,7 @@ function unlink_persist_data($manifest, $dir) {
|
||||
if ($persist) {
|
||||
@($persist) | ForEach-Object {
|
||||
$source, $null = persist_def $_
|
||||
$source = Get-Item "$dir\$source"
|
||||
$source = Get-Item "$dir\$source" -ErrorAction SilentlyContinue
|
||||
if ($source.LinkType) {
|
||||
$source_path = $source.FullName
|
||||
# directory (junction)
|
||||
@@ -1199,7 +1205,7 @@ function unlink_persist_data($manifest, $dir) {
|
||||
|
||||
# check whether write permission for Users usergroup is set to global persist dir, if not then set
|
||||
function persist_permission($manifest, $global) {
|
||||
if($global -and $manifest.persist -and (is_admin)) {
|
||||
if($global -and $manifest.persist -and (Test-IsAdmin)) {
|
||||
$path = persistdir $null $global
|
||||
$user = New-Object System.Security.Principal.SecurityIdentifier 'S-1-5-32-545'
|
||||
$target_rule = New-Object System.Security.AccessControl.FileSystemAccessRule($user, 'Write', 'ObjectInherit', 'none', 'Allow')
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
$modulesdir = "$scoopdir\modules"
|
||||
|
||||
function install_psmodule($manifest, $dir, $global) {
|
||||
$psmodule = $manifest.psmodule
|
||||
if (!$psmodule) { return }
|
||||
|
||||
if ($global) {
|
||||
abort 'Installing PowerShell modules globally is not implemented!'
|
||||
}
|
||||
$targetdir = ensure (modulesdir $global)
|
||||
|
||||
$modulesdir = ensure $modulesdir
|
||||
ensure_in_psmodulepath $modulesdir $global
|
||||
ensure_in_psmodulepath $targetdir $global
|
||||
|
||||
$module_name = $psmodule.name
|
||||
if (!$module_name) {
|
||||
abort "Invalid manifest: The 'name' property is missing from 'psmodule'."
|
||||
}
|
||||
|
||||
$linkfrom = "$modulesdir\$module_name"
|
||||
$linkfrom = "$targetdir\$module_name"
|
||||
Write-Host "Installing PowerShell module '$module_name'"
|
||||
|
||||
Write-Host "Linking $(friendly_path $linkfrom) => $(friendly_path $dir)"
|
||||
@@ -36,7 +31,9 @@ function uninstall_psmodule($manifest, $dir, $global) {
|
||||
$module_name = $psmodule.name
|
||||
Write-Host "Uninstalling PowerShell module '$module_name'."
|
||||
|
||||
$linkfrom = "$modulesdir\$module_name"
|
||||
$targetdir = modulesdir $global
|
||||
|
||||
$linkfrom = "$targetdir\$module_name"
|
||||
if (Test-Path $linkfrom) {
|
||||
Write-Host "Removing $(friendly_path $linkfrom)"
|
||||
$linkfrom = Convert-Path $linkfrom
|
||||
|
||||
@@ -8,29 +8,28 @@
|
||||
$issues = 0
|
||||
$defenderIssues = 0
|
||||
|
||||
$adminPrivileges = ([System.Security.Principal.WindowsPrincipal] [System.Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
|
||||
if ($adminPrivileges) {
|
||||
$defenderIssues += !(check_windows_defender $false)
|
||||
$defenderIssues += !(check_windows_defender $true)
|
||||
if (Test-IsAdmin -and $env:USERNAME -ne 'WDAGUtilityAccount') {
|
||||
$defenderIssues += !(Invoke-WindowsDefenderCheck $false)
|
||||
$defenderIssues += !(Invoke-WindowsDefenderCheck $true)
|
||||
}
|
||||
|
||||
$issues += !(check_main_bucket)
|
||||
$issues += !(check_long_paths)
|
||||
$issues += !(Get-WindowsDeveloperModeStatus)
|
||||
$issues += !(Invoke-MainBucketCheck)
|
||||
$issues += !(Invoke-LongPathsCheck)
|
||||
$issues += !(Invoke-WindowsDeveloperModeCheck)
|
||||
|
||||
if (!(Test-HelperInstalled -Helper 7zip)) {
|
||||
error "'7-Zip' is not installed! It's required for unpacking most programs. Please Run 'scoop install 7zip' or 'scoop install 7zip-zstd'."
|
||||
warn "'7-Zip' is not installed! It's required for unpacking most programs. Please Run 'scoop install 7zip' or 'scoop install 7zip-zstd'."
|
||||
$issues++
|
||||
}
|
||||
|
||||
if (!(Test-HelperInstalled -Helper Innounp)) {
|
||||
error "'Inno Setup Unpacker' is not installed! It's required for unpacking InnoSetup files. Please run 'scoop install innounp'."
|
||||
warn "'Inno Setup Unpacker' is not installed! It's required for unpacking InnoSetup files. Please run 'scoop install innounp'."
|
||||
$issues++
|
||||
}
|
||||
|
||||
if (!(Test-HelperInstalled -Helper Dark)) {
|
||||
error "'dark' is not installed! It's required for unpacking installers created with the WiX Toolset. Please run 'scoop install dark' or 'scoop install wixtoolset'."
|
||||
warn "'dark' is not installed! It's required for unpacking installers created with the WiX Toolset. Please run 'scoop install dark' or 'scoop install wixtoolset'."
|
||||
$issues++
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ $all = $opt.a -or $opt.all
|
||||
|
||||
if (!$apps -and !$all) { 'ERROR: <app> missing'; my_usage; exit 1 }
|
||||
|
||||
if ($global -and !(is_admin)) {
|
||||
if ($global -and !(Test-IsAdmin)) {
|
||||
'ERROR: you need admin rights to cleanup global apps'; exit 1
|
||||
}
|
||||
|
||||
|
||||
8
libexec/scoop-diag.ps1
Normal file
8
libexec/scoop-diag.ps1
Normal file
@@ -0,0 +1,8 @@
|
||||
# Usage: scoop diag
|
||||
# Summary: Returns information about the Scoop environment that can be posted on a GitHub issue
|
||||
|
||||
. "$PSScriptRoot\..\lib\diagnostic.ps1"
|
||||
|
||||
Show-Diag -Markdown -Color
|
||||
|
||||
exit 0
|
||||
@@ -24,7 +24,7 @@ if (!$apps) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($global -and !(is_admin)) {
|
||||
if ($global -and !(Test-IsAdmin)) {
|
||||
error 'You need admin rights to hold a global app.'
|
||||
exit 1
|
||||
}
|
||||
@@ -47,15 +47,23 @@ $apps | ForEach-Object {
|
||||
return
|
||||
}
|
||||
|
||||
if (get_config NO_JUNCTION){
|
||||
if (get_config NO_JUNCTION) {
|
||||
$version = Select-CurrentVersion -App $app -Global:$global
|
||||
} else {
|
||||
$version = 'current'
|
||||
}
|
||||
$dir = versiondir $app $version $global
|
||||
$json = install_info $app $version $global
|
||||
if (!$json) {
|
||||
error "Failed to hold '$app'."
|
||||
continue
|
||||
}
|
||||
$install = @{}
|
||||
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name)) }
|
||||
if ($install.hold) {
|
||||
info "'$app' is already held."
|
||||
continue
|
||||
}
|
||||
$install.hold = $true
|
||||
save_install_info $install $dir
|
||||
success "$app is now held and can not be updated anymore."
|
||||
|
||||
@@ -34,20 +34,19 @@ foreach ($item in $import.buckets) {
|
||||
}
|
||||
|
||||
foreach ($item in $import.apps) {
|
||||
$instArgs = @()
|
||||
$holdArgs = @()
|
||||
$info = $item.Info -Split ', '
|
||||
$global = if ('Global install' -in $info) {
|
||||
' --global'
|
||||
} else {
|
||||
''
|
||||
if ('Global install' -in $info) {
|
||||
$instArgs += '--global'
|
||||
$holdArgs += '--global'
|
||||
}
|
||||
$arch = if ('64bit' -in $info -and '64bit' -ne $def_arch) {
|
||||
' --arch 64bit'
|
||||
if ('64bit' -in $info -and '64bit' -ne $def_arch) {
|
||||
$instArgs += '--arch', '64bit'
|
||||
} elseif ('32bit' -in $info -and '32bit' -ne $def_arch) {
|
||||
' --arch 32bit'
|
||||
$instArgs += '--arch', '32bit'
|
||||
} elseif ('arm64' -in $info -and 'arm64' -ne $def_arch) {
|
||||
' --arch arm64'
|
||||
} else {
|
||||
''
|
||||
$instArgs += '--arch', 'arm64'
|
||||
}
|
||||
|
||||
$app = if ($item.Source -in $bucket_names) {
|
||||
@@ -58,9 +57,9 @@ foreach ($item in $import.apps) {
|
||||
$item.Source
|
||||
}
|
||||
|
||||
& "$PSScriptRoot\scoop-install.ps1" $app$global$arch
|
||||
& "$PSScriptRoot\scoop-install.ps1" $app @instArgs
|
||||
|
||||
if ('Held package' -in $info) {
|
||||
& "$PSScriptRoot\scoop-hold.ps1" $($item.Name)$global
|
||||
& "$PSScriptRoot\scoop-hold.ps1" $item.Name @holdArgs
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Usage: scoop info <app> [--verbose]
|
||||
# Usage: scoop info <app> [options]
|
||||
# Summary: Display information about an app
|
||||
# Options:
|
||||
# -v, --verbose Show full paths and URLs
|
||||
# Help: Options:
|
||||
# -v, --verbose Show full paths and URLs
|
||||
|
||||
. "$PSScriptRoot\..\lib\getopt.ps1"
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
|
||||
@@ -84,7 +84,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=%aD#%an', $manifest_file) 2> $null) -Split '#'
|
||||
}
|
||||
if ($gitinfo) {
|
||||
$item.'Updated at' = $gitinfo[0] | Get-Date
|
||||
@@ -112,7 +112,7 @@ if ($status.installed) {
|
||||
|
||||
# Collect file list from each location
|
||||
$appFiles = Get-ChildItem $appsdir -Filter $app
|
||||
$currentFiles = Get-ChildItem $appFiles -Filter (Select-CurrentVersion $app $global)
|
||||
$currentFiles = Get-ChildItem $appFiles.FullName -Filter (Select-CurrentVersion $app $global)
|
||||
$persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data
|
||||
$cacheFiles = Get-ChildItem $cachedir -Filter "$app#*"
|
||||
|
||||
@@ -120,7 +120,7 @@ if ($status.installed) {
|
||||
$fileTotals = @()
|
||||
foreach ($fileType in ($appFiles, $currentFiles, $persistFiles, $cacheFiles)) {
|
||||
if ($null -ne $fileType) {
|
||||
$fileSum = (Get-ChildItem $fileType -Recurse | Measure-Object -Property Length -Sum).Sum
|
||||
$fileSum = (Get-ChildItem $fileType.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum
|
||||
$fileTotals += coalesce $fileSum 0
|
||||
} else {
|
||||
$fileTotals += 0
|
||||
|
||||
@@ -48,7 +48,7 @@ try {
|
||||
|
||||
if (!$apps) { error '<app> missing'; my_usage; exit 1 }
|
||||
|
||||
if ($global -and !(is_admin)) {
|
||||
if ($global -and !(Test-IsAdmin)) {
|
||||
abort 'ERROR: you need admin rights to install global apps'
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ $apps | ForEach-Object {
|
||||
return
|
||||
}
|
||||
|
||||
if($global -and !(is_admin)) {
|
||||
if($global -and !(Test-IsAdmin)) {
|
||||
warn "'$app' ($version) is a global app. You need admin rights to reset it. Skipping."
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ param($query)
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1" # 'manifest'
|
||||
. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-LatestVersion'
|
||||
|
||||
$list = @()
|
||||
$list = [System.Collections.Generic.List[PSCustomObject]]::new()
|
||||
|
||||
try {
|
||||
$query = New-Object Regex $query, 'IgnoreCase'
|
||||
@@ -32,24 +32,90 @@ function bin_match($manifest, $query) {
|
||||
if ((strip_ext $fname) -match $query) { $fname }
|
||||
elseif ($alias -match $query) { $alias }
|
||||
}
|
||||
|
||||
if ($bins) { return $bins }
|
||||
else { return $false }
|
||||
}
|
||||
|
||||
function bin_match_json($json, $query) {
|
||||
[System.Text.Json.JsonElement]$bin = [System.Text.Json.JsonElement]::new()
|
||||
if (!$json.RootElement.TryGetProperty("bin", [ref] $bin)) { return $false }
|
||||
$bins = @()
|
||||
if($bin.ValueKind -eq [System.Text.Json.JsonValueKind]::String -and [System.IO.Path]::GetFileNameWithoutExtension($bin) -match $query) {
|
||||
$bins += [System.IO.Path]::GetFileName($bin)
|
||||
} elseif ($bin.ValueKind -eq [System.Text.Json.JsonValueKind]::Array) {
|
||||
foreach($subbin in $bin.EnumerateArray()) {
|
||||
if($subbin.ValueKind -eq [System.Text.Json.JsonValueKind]::String -and [System.IO.Path]::GetFileNameWithoutExtension($subbin) -match $query) {
|
||||
$bins += [System.IO.Path]::GetFileName($subbin)
|
||||
} elseif ($subbin.ValueKind -eq [System.Text.Json.JsonValueKind]::Array) {
|
||||
if([System.IO.Path]::GetFileNameWithoutExtension($subbin[0]) -match $query) {
|
||||
$bins += [System.IO.Path]::GetFileName($subbin[0])
|
||||
} elseif ($subbin.GetArrayLength() -ge 2 -and $subbin[1] -match $query) {
|
||||
$bins += $subbin[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($bins) { return $bins }
|
||||
else { return $false }
|
||||
}
|
||||
|
||||
function search_bucket($bucket, $query) {
|
||||
$apps = apps_in_bucket (Find-BucketDirectory $bucket) | ForEach-Object { @{ name = $_ } }
|
||||
$apps = Get-ChildItem (Find-BucketDirectory $bucket) -Filter '*.json' -Recurse
|
||||
|
||||
if ($query) {
|
||||
$apps = $apps | Where-Object {
|
||||
if ($_.name -match $query) { return $true }
|
||||
$bin = bin_match (manifest $_.name $bucket) $query
|
||||
$apps | ForEach-Object {
|
||||
$json = [System.Text.Json.JsonDocument]::Parse([System.IO.File]::ReadAllText($_.FullName))
|
||||
$name = $_.BaseName
|
||||
|
||||
if ($name -match $query) {
|
||||
$list.Add([PSCustomObject]@{
|
||||
Name = $name
|
||||
Version = $json.RootElement.GetProperty("version")
|
||||
Source = $bucket
|
||||
Binaries = ""
|
||||
})
|
||||
} else {
|
||||
$bin = bin_match_json $json $query
|
||||
if ($bin) {
|
||||
$_.bin = $bin
|
||||
return $true
|
||||
$list.Add([PSCustomObject]@{
|
||||
Name = $name
|
||||
Version = $json.RootElement.GetProperty("version")
|
||||
Source = $bucket
|
||||
Binaries = $bin -join ' | '
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# fallback function for PowerShell 5
|
||||
function search_bucket_legacy($bucket, $query) {
|
||||
$apps = Get-ChildItem (Find-BucketDirectory $bucket) -Filter '*.json' -Recurse
|
||||
|
||||
$apps | ForEach-Object {
|
||||
$manifest = [System.IO.File]::ReadAllText($_.FullName) | ConvertFrom-Json -ErrorAction Continue
|
||||
$name = $_.BaseName
|
||||
|
||||
if ($name -match $query) {
|
||||
$list.Add([PSCustomObject]@{
|
||||
Name = $name
|
||||
Version = $manifest.Version
|
||||
Source = $bucket
|
||||
Binaries = ""
|
||||
})
|
||||
} else {
|
||||
$bin = bin_match $manifest $query
|
||||
if ($bin) {
|
||||
$list.Add([PSCustomObject]@{
|
||||
Name = $name
|
||||
Version = $manifest.Version
|
||||
Source = $bucket
|
||||
Binaries = $bin -join ' | '
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
$apps | ForEach-Object { $_.version = (Get-LatestVersion -AppName $_.name -Bucket $bucket); $_ }
|
||||
}
|
||||
|
||||
function download_json($url) {
|
||||
@@ -96,43 +162,35 @@ function search_remotes($query) {
|
||||
(add them using 'scoop bucket add <bucket name>')"
|
||||
}
|
||||
|
||||
$remote_list = @()
|
||||
$results | ForEach-Object {
|
||||
$name = $_.bucket
|
||||
$bucket = $_.bucket
|
||||
$_.results | ForEach-Object {
|
||||
$item = [ordered]@{}
|
||||
$item.Name = $_
|
||||
$item.Source = $name
|
||||
$list += [PSCustomObject]$item
|
||||
$item.Source = $bucket
|
||||
$remote_list += [PSCustomObject]$item
|
||||
}
|
||||
}
|
||||
|
||||
$list
|
||||
$remote_list
|
||||
}
|
||||
|
||||
$jsonTextAvailable = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-object { [System.IO.Path]::GetFileNameWithoutExtension($_.Location) -eq "System.Text.Json" }
|
||||
|
||||
Get-LocalBucket | ForEach-Object {
|
||||
$res = search_bucket $_ $query
|
||||
$local_results = $local_results -or $res
|
||||
if ($res) {
|
||||
$name = "$_"
|
||||
|
||||
$res | ForEach-Object {
|
||||
$item = [ordered]@{}
|
||||
$item.Name = $_.name
|
||||
$item.Version = $_.version
|
||||
$item.Source = $name
|
||||
$item.Binaries = ""
|
||||
if ($_.bin) { $item.Binaries = $_.bin -join ' | ' }
|
||||
$list += [PSCustomObject]$item
|
||||
}
|
||||
if ($jsonTextAvailable) {
|
||||
search_bucket $_ $query
|
||||
} else {
|
||||
search_bucket_legacy $_ $query
|
||||
}
|
||||
}
|
||||
|
||||
if ($list.Length -gt 0) {
|
||||
if ($list.Count -gt 0) {
|
||||
Write-Host "Results from local buckets..."
|
||||
$list
|
||||
}
|
||||
|
||||
if (!$local_results -and !(github_ratelimit_reached)) {
|
||||
if ($list.Count -eq 0 -and !(github_ratelimit_reached)) {
|
||||
$remote_results = search_remotes $query
|
||||
if (!$remote_results) {
|
||||
warn "No matches found."
|
||||
|
||||
@@ -24,7 +24,7 @@ if (!$apps) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($global -and !(is_admin)) {
|
||||
if ($global -and !(Test-IsAdmin)) {
|
||||
error 'You need admin rights to unhold a global app.'
|
||||
exit 1
|
||||
}
|
||||
@@ -53,8 +53,16 @@ $apps | ForEach-Object {
|
||||
}
|
||||
$dir = versiondir $app $version $global
|
||||
$json = install_info $app $version $global
|
||||
if (!$json) {
|
||||
error "Failed to unhold '$app'"
|
||||
continue
|
||||
}
|
||||
$install = @{}
|
||||
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name)) }
|
||||
if (!$install.hold) {
|
||||
info "'$app' is not held."
|
||||
continue
|
||||
}
|
||||
$install.hold = $null
|
||||
save_install_info $install $dir
|
||||
success "$app is no longer held and can be updated again."
|
||||
|
||||
@@ -30,7 +30,7 @@ if (!$apps) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($global -and !(is_admin)) {
|
||||
if ($global -and !(Test-IsAdmin)) {
|
||||
error 'You need admin rights to uninstall global apps.'
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ function Sync-Scoop {
|
||||
Rename-Item $newdir 'current' -ErrorAction Stop
|
||||
} catch {
|
||||
Write-Warning $_
|
||||
abort "Scoop update failed. Folder in use. Paste $newdir into $currentdir."
|
||||
abort "Scoop update failed. Folder in use. Please rename folders $currentdir to ``old`` and $newdir to ``current``."
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -346,7 +346,7 @@ if (-not ($apps -or $all)) {
|
||||
set_config LAST_UPDATE ([System.DateTime]::Now.ToString('o')) | Out-Null
|
||||
success 'Scoop was updated successfully!'
|
||||
} else {
|
||||
if ($global -and !(is_admin)) {
|
||||
if ($global -and !(Test-IsAdmin)) {
|
||||
'ERROR: You need admin rights to update global apps.'; exit 1
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
$opt, $apps, $err = getopt $args 'asnup' @('all', 'scan', 'no-depends', 'no-update-scoop', 'passthru')
|
||||
if ($err) { "scoop virustotal: $err"; exit 1 }
|
||||
if (!$apps) { my_usage; exit 1 }
|
||||
if (!$apps -and -$all) { my_usage; exit 1 }
|
||||
$architecture = Format-ArchitectureString
|
||||
|
||||
if (is_scoop_outdated) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
param($command)
|
||||
|
||||
if (!$command) {
|
||||
'ERROR: <command> missing'
|
||||
error '<command> missing'
|
||||
my_usage
|
||||
exit 1
|
||||
}
|
||||
@@ -12,7 +12,7 @@ if (!$command) {
|
||||
$path = Get-CommandPath $command
|
||||
|
||||
if ($null -eq $path) {
|
||||
Write-Host "'$command' not found / not a scoop shim."
|
||||
warn "'$command' not found, not a scoop shim, or a broken shim."
|
||||
exit 2
|
||||
} else {
|
||||
friendly_path $path
|
||||
|
||||
@@ -17,6 +17,12 @@ Describe 'getopt' -Tag 'Scoop' {
|
||||
$err | Should -Be 'Option --arb requires an argument.'
|
||||
}
|
||||
|
||||
It 'handle space in quote' {
|
||||
$opt, $rem, $err = getopt '-x', 'space arg' 'x:' ''
|
||||
$err | Should -BeNullOrEmpty
|
||||
$opt.x | Should -Be 'space arg'
|
||||
}
|
||||
|
||||
It 'handle unrecognized short option' {
|
||||
$null, $null, $err = getopt '-az' 'a' ''
|
||||
$err | Should -Be 'Option -z not recognized.'
|
||||
|
||||
Reference in New Issue
Block a user