Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(core): Prefer SHOVEL* environment variables over SCOOP* #290

Draft
wants to merge 3 commits into
base: NEW
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5)

- **Core**: Prefer `SHOVEL*` environment variables over `SCOOP*`
- Configuration path `~/.config/Shovel` is prefered over `~/.config/scoop/`
- **Schema**:
- Better properties descriptions
- More strict object validation
Expand Down
84 changes: 57 additions & 27 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1030,38 +1030,75 @@ if (!$env:ProgramData) {
$env:ProgramData = $apD
}

if (!$env:SCOOP -and !$env:USERPROFILE) {
Stop-ScoopExecution -Message "'SCOOP', 'USERPROFILE' or 'HOME' environment is not configured."
if ((!$env:SHOVEL -or !$env:SCOOP) -and !$env:USERPROFILE) {
Stop-ScoopExecution -Message "'SHOVEL', 'SCOOP', 'USERPROFILE' or 'HOME' environment is not configured."
}

# TODO: Shovel installed globally
# Path gluing has to remain in these global variables to not fail in case user do not have some environment configured (most likely linux case)
# Scoop root directory
$SCOOP_ROOT_DIRECTORY = $env:SCOOP, [System.IO.Path]::Combine($env:USERPROFILE, 'scoop') | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
# Shovel root directory
$SHOVEL_ROOT_DIRECTORY = $env:SHOVEL
if (!$SHOVEL_ROOT_DIRECTORY) {
# TODO: $env:USERPROFILE\Shovel
# Scoop root directory (fallback)
$SHOVEL_ROOT_DIRECTORY = $env:SCOOP, [System.IO.Path]::Combine($env:USERPROFILE, 'scoop') | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1

# Scoop global apps directory
$SCOOP_GLOBAL_ROOT_DIRECTORY = $env:SCOOP_GLOBAL, [System.IO.Path]::Combine($env:ProgramData, 'scoop') | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
}

# Shovel global applications directory
$SHOVEL_GLOBAL_ROOT_DIRECTORY = $env:SHOVEL_GLOBAL
if (!$SHOVEL_GLOBAL_ROOT_DIRECTORY) {
# Scoop global apps directory (fallback)
$SHOVEL_GLOBAL_ROOT_DIRECTORY = $env:SCOOP_GLOBAL, [System.IO.Path]::Combine($env:ProgramData, 'scoop') | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
}

# Directory for local buckets
$SCOOP_BUCKETS_DIRECTORY = Join-Path $SCOOP_ROOT_DIRECTORY 'buckets'
# TODO: Global buckets concept
# Shovel local buckets directory
$SHOVEL_BUCKETS_DIRECTORY = Join-Path $SHOVEL_ROOT_DIRECTORY 'buckets'

# Scoop cache directory
# Shovel cache directory
$SHOVEL_CACHE_DIRECTORY = $env:SHOVEL_CACHE
# Note: Setting the SCOOP_CACHE environment variable to use a shared directory
# is experimental and untested. There may be concurrency issues when
# multiple users write and access cached files at the same time.
# Use at your own risk.
$SCOOP_CACHE_DIRECTORY = $env:SCOOP_CACHE, [System.IO.Path]::Combine($SCOOP_ROOT_DIRECTORY, 'cache') | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
if (!$SHOVEL_CACHE_DIRECTORY) {
$SHOVEL_CACHE_DIRECTORY = $env:SCOOP_CACHE, [System.IO.Path]::Combine($SHOVEL_ROOT_DIRECTORY, 'cache') | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
}

# Scoop directory for powershell modules installtation
$SCOOP_MODULE_DIRECTORY = Join-Path $SCOOP_ROOT_DIRECTORY 'modules'
$SCOOP_GLOBAL_MODULE_DIRECTORY = Join-Path $SCOOP_GLOBAL_ROOT_DIRECTORY 'modules'
# Shovel PowerShell modules directory
$SHOVEL_MODULE_DIRECTORY = Join-Path $SHOVEL_ROOT_DIRECTORY 'modules'
$SHOVEL_GLOBAL_MODULE_DIRECTORY = Join-Path $SHOVEL_GLOBAL_ROOT_DIRECTORY 'modules'

# Directory for downloaded manifests (mainly)
$SHOVEL_GENERAL_MANIFESTS_DIRECTORY = Join-Path $SCOOP_ROOT_DIRECTORY 'manifests'
$SHOVEL_GENERAL_MANIFESTS_DIRECTORY = Join-Path $SHOVEL_ROOT_DIRECTORY 'manifests'

# Shovel configuration files
$configHome = $env:XDG_CONFIG_HOME, [System.IO.Path]::Combine($env:USERPROFILE, '.config') | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
$SHOVEL_CONFIGURATION_DIRECTORY = Join-Path $configHome 'Shovel'
$SHOVEL_CONFIGURATION_FILE = Join-Path $SHOVEL_CONFIGURATION_DIRECTORY 'config.json'
if (!(Test-Path -LiteralPath $SHOVEL_CONFIGURATION_DIRECTORY -PathType 'Container')) {
$SHOVEL_CONFIGURATION_FILE = Join-Path $configHome 'scoop\config.json'
}

# Load Scoop config
$configHome = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
$SCOOP_CONFIGURATION_FILE = Join-Path $configHome 'scoop\config.json'
$SCOOP_CONFIGURATION = load_cfg $SCOOP_CONFIGURATION_FILE
$SHOVEL_CONFIGURATION = load_cfg $SHOVEL_CONFIGURATION_FILE

# TODO: Remove deprecated variables
$scoopdir = $SHOVEL_ROOT_DIRECTORY
$globaldir = $SHOVEL_GLOBAL_ROOT_DIRECTORY
$cachedir = $SHOVEL_CACHE_DIRECTORY
$scoopConfig = $SHOVEL_CONFIGURATION
$configFile = $SHOVEL_CONFIGURATION_FILE
$modulesdir = $SHOVEL_MODULE_DIRECTORY
$bucketsdir = $SHOVEL_BUCKETS_DIRECTORY
$SCOOP_ROOT_DIRECTORY = $SHOVEL_ROOT_DIRECTORY
$SCOOP_GLOBAL_ROOT_DIRECTORY = $SHOVEL_GLOBAL_ROOT_DIRECTORY
$SCOOP_CACHE_DIRECTORY = $SHOVEL_CACHE_DIRECTORY
$SCOOP_MODULE_DIRECTORY = $SHOVEL_MODULE_DIRECTORY
$SCOOP_GLOBAL_MODULE_DIRECTORY = $SHOVEL_GLOBAL_MODULE_DIRECTORY
$SCOOP_CONFIGURATION_FILE = $SHOVEL_CONFIGURATION_FILE
$SCOOP_CONFIGURATION = load_cfg $SHOVEL_CONFIGURATION_FILE
$SCOOP_BUCKETS_DIRECTORY = $SHOVEL_BUCKETS_DIRECTORY

# General variables
$SHOVEL_DEBUG_ENABLED = Test-ScoopDebugEnabled
Expand All @@ -1073,18 +1110,11 @@ $SHOVEL_USERAGENT = Get-UserAgent
# All supported architectures
$SHOVEL_SUPPORTED_ARCHITECTURES = @('64bit', '32bit', 'arm64')

# TODO: Remove deprecated variables
$scoopdir = $SCOOP_ROOT_DIRECTORY
$globaldir = $SCOOP_GLOBAL_ROOT_DIRECTORY
$cachedir = $SCOOP_CACHE_DIRECTORY
$scoopConfig = $SCOOP_CONFIGURATION
$configFile = $SCOOP_CONFIGURATION_FILE
$modulesdir = $SCOOP_MODULE_DIRECTORY
$bucketsdir = $SCOOP_BUCKETS_DIRECTORY

# Do not use the new native command parsing PowerShell/PowerShell#15239, Ash258/Scoop-Core#142
$PSNativeCommandArgumentPassing = 'Legacy'

# TODO: Warning about change of defaults

# Setup proxy globally
setup_proxy
#endregion Main
Expand Down