mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 08:58:35 +00:00
Compare commits
3 Commits
a890f7e6eb
...
6f47e81610
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f47e81610 | |||
| d49b271e6a | |||
| f17e4c6642 |
13
dcrup.cmd
13
dcrup.cmd
@@ -1,13 +0,0 @@
|
||||
@echo off
|
||||
setlocal
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
if exist "%SCRIPT_DIR%dcrup.ps1" (
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%dcrup.ps1" %*
|
||||
exit /b %ERRORLEVEL%
|
||||
)
|
||||
if exist "%USERPROFILE%\.dcr\bin\dcrup.ps1" (
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%USERPROFILE%\.dcr\bin\dcrup.ps1" %*
|
||||
exit /b %ERRORLEVEL%
|
||||
)
|
||||
echo [error] dcrup.ps1 not found near dcrup.cmd >&2
|
||||
exit /b 1
|
||||
45
dcrup.ps1
45
dcrup.ps1
@@ -1,4 +1,4 @@
|
||||
#Requires -Version 5.1
|
||||
#Requires -Version 5.1
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$DcrupHome = if ($env:DCRUP_HOME) { $env:DCRUP_HOME } else { Join-Path $env:USERPROFILE '.dcr' }
|
||||
@@ -6,6 +6,7 @@ $DcrupBin = if ($env:DCRUP_BIN) { $env:DCRUP_BIN } else { Join-Path $DcrupHom
|
||||
$DcrupTc = Join-Path $DcrupHome 'toolchains'
|
||||
$DcrupMeta = Join-Path $DcrupHome 'meta'
|
||||
$RepoUrl = if ($env:DCRUP_REPO) { $env:DCRUP_REPO } else { 'https://github.com/dexoron/dcr' }
|
||||
$InstallUrl = if ($env:DCRUP_INSTALL_URL) { $env:DCRUP_INSTALL_URL } else { 'https://ps1.dcr-tool.ru' }
|
||||
$DcrupMirror = if ($env:DCRUP_MIRROR) { $env:DCRUP_MIRROR } else { 'auto' }
|
||||
$ApiLatest = 'https://api.github.com/repos/dexoron/dcr/releases/latest'
|
||||
$ApiAll = 'https://api.github.com/repos/dexoron/dcr/releases'
|
||||
@@ -133,6 +134,18 @@ function Link-Default([string]$id) {
|
||||
Ok "default → $id ($dst)"
|
||||
}
|
||||
|
||||
function Resolve-InstalledId([string]$spec) {
|
||||
Parse-Spec $spec
|
||||
if ($script:SpecChannel -eq 'night' -or $script:SpecFloating) {
|
||||
$item = Get-ChildItem $DcrupTc -Directory -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.Name -like "$($script:SpecChannel)-*" } |
|
||||
Sort-Object Name | Select-Object -Last 1
|
||||
if ($item) { return $item.Name }
|
||||
return $null
|
||||
}
|
||||
return (Toolchain-Id)
|
||||
}
|
||||
|
||||
function Set-Mirror([string]$value) {
|
||||
if ($value -notin @('auto', 'cf', 'gh', 'sf', 'ya')) {
|
||||
Die "invalid --mirror: $value (use auto|cf|gh|sf|ya)"
|
||||
@@ -379,7 +392,19 @@ function Cmd-Show {
|
||||
|
||||
function Cmd-SelfInstall {
|
||||
Ensure-Dirs
|
||||
Copy-Item $PSCommandPath (Join-Path $DcrupBin 'dcrup.ps1') -Force
|
||||
if ([string]::IsNullOrWhiteSpace($PSCommandPath) -or -not (Test-Path $PSCommandPath)) {
|
||||
# With `irm URL | iex`, PowerShell evaluates text and there is no
|
||||
# source path. Download the canonical installer for self-install.
|
||||
$tmp = Join-Path $env:TEMP ("dcrup-" + [guid]::NewGuid().ToString('N') + '.ps1')
|
||||
try {
|
||||
Invoke-WebRequest -Uri $InstallUrl -OutFile $tmp -UseBasicParsing -UserAgent 'dcrup'
|
||||
Copy-Item $tmp (Join-Path $DcrupBin 'dcrup.ps1') -Force
|
||||
} finally {
|
||||
Remove-Item $tmp -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
} else {
|
||||
Copy-Item $PSCommandPath (Join-Path $DcrupBin 'dcrup.ps1') -Force
|
||||
}
|
||||
Install-CmdShim
|
||||
Ensure-UserPath
|
||||
Ok "dcrup installed to $DcrupBin (use: dcrup …)"
|
||||
@@ -417,7 +442,7 @@ switch ($cmd) {
|
||||
if ($a -like 'night-*') { Cmd-Install @('night', '--build', '--force') }
|
||||
elseif ($a -like 'stable-*') { Cmd-Install @('stable', '--force') }
|
||||
elseif ($a -like 'dev-*') { Cmd-Install @('dev', '--force') }
|
||||
else { Ok "pinned $a — install a newer version explicitly" }
|
||||
else { Ok "pinned $a - install a newer version explicitly" }
|
||||
}
|
||||
'uninstall' {
|
||||
if ($rest -contains '--all') {
|
||||
@@ -426,9 +451,21 @@ switch ($cmd) {
|
||||
Remove-Item (Active-Path) -ErrorAction SilentlyContinue
|
||||
Ok 'removed all'
|
||||
} else {
|
||||
Die 'use: dcrup uninstall --all (or install a replacement first)'
|
||||
if ($rest.Count -ne 1) { Die 'usage: dcrup uninstall <spec>|--all' }
|
||||
$id = Resolve-InstalledId $rest[0]
|
||||
if (-not $id) { Die "not installed: $($rest[0])" }
|
||||
$dir = Join-Path $DcrupTc $id
|
||||
if (-not (Test-Path $dir)) { Die "not installed: $($rest[0])" }
|
||||
Remove-Item -Recurse -Force $dir
|
||||
if ((Read-Active) -eq $id) {
|
||||
Remove-Item (Join-Path $DcrupBin 'dcr.exe') -ErrorAction SilentlyContinue
|
||||
Remove-Item (Active-Path) -ErrorAction SilentlyContinue
|
||||
Warn 'removed active toolchain; install or select another default'
|
||||
}
|
||||
Ok "removed $id"
|
||||
}
|
||||
}
|
||||
'self-install' { Cmd-SelfInstall }
|
||||
default { Die "unknown command: $cmd" }
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ Install and switch DCR versions (stable / dev / night, pin `0.8.2`, optional bui
|
||||
### Linux / macOS / BSD / Windows (bash)
|
||||
|
||||
```sh
|
||||
curl -fsSL https://sh.dcr-tool.ru | sh -s -- self-install
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.dcr-tool.ru | sh -s -- self-install
|
||||
export PATH="$HOME/.dcr/bin:$PATH"
|
||||
dcrup install stable
|
||||
```
|
||||
@@ -19,28 +19,19 @@ dcrup install stable
|
||||
Non-interactive install of DCR in one shot:
|
||||
|
||||
```sh
|
||||
curl -fsSL https://sh.dcr-tool.ru | sh -s -- install stable
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.dcr-tool.ru | sh -s -- install stable
|
||||
export PATH="$HOME/.dcr/bin:$PATH"
|
||||
```
|
||||
|
||||
### Windows (PowerShell)
|
||||
|
||||
```powershell
|
||||
irm https://ps1.dcr-tool.ru | iex
|
||||
# or download then run:
|
||||
# irm https://ps1.dcr-tool.ru -OutFile dcrup.ps1
|
||||
# powershell -File .\dcrup.ps1 self-install
|
||||
& ([scriptblock]::Create((irm https://ps1.dcr-tool.ru))) self-install
|
||||
# $env:Path += ";$env:USERPROFILE\.dcr\bin"
|
||||
dcrup install stable
|
||||
```
|
||||
|
||||
Optional cmd bootstrap (if you prefer `curl` of the cmd shim):
|
||||
|
||||
```bat
|
||||
curl -fsSL -o dcrup.cmd https://cmd.dcr-tool.ru
|
||||
```
|
||||
|
||||
After `self-install`, the command is **`dcrup`** (no `.sh` / `.ps1`): shims live in `~/.dcr/bin` (Unix) or `%USERPROFILE%\.dcr\bin` (Windows `dcrup.cmd`).
|
||||
After `self-install`, the command is **`dcrup`** (no `.sh` / `.ps1`) and is installed in `~/.dcr/bin` (Unix) or `%USERPROFILE%\.dcr\bin` (Windows).
|
||||
|
||||
### Common dcrup commands
|
||||
|
||||
@@ -58,6 +49,8 @@ dcrup update
|
||||
dcrup list
|
||||
dcrup show
|
||||
dcrup which
|
||||
dcrup uninstall 0.8.2 # remove one installed version
|
||||
dcrup uninstall --all # remove all installed versions
|
||||
```
|
||||
|
||||
Layout: `~/.dcr/toolchains/<id>/dcr` and `~/.dcr/bin/dcr` → active version.
|
||||
|
||||
Reference in New Issue
Block a user