mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 19:29:30 +00:00
Compare commits
3 Commits
a890f7e6eb
...
dev
| 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
|
|
||||||
43
dcrup.ps1
43
dcrup.ps1
@@ -1,4 +1,4 @@
|
|||||||
#Requires -Version 5.1
|
#Requires -Version 5.1
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
$DcrupHome = if ($env:DCRUP_HOME) { $env:DCRUP_HOME } else { Join-Path $env:USERPROFILE '.dcr' }
|
$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'
|
$DcrupTc = Join-Path $DcrupHome 'toolchains'
|
||||||
$DcrupMeta = Join-Path $DcrupHome 'meta'
|
$DcrupMeta = Join-Path $DcrupHome 'meta'
|
||||||
$RepoUrl = if ($env:DCRUP_REPO) { $env:DCRUP_REPO } else { 'https://github.com/dexoron/dcr' }
|
$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' }
|
$DcrupMirror = if ($env:DCRUP_MIRROR) { $env:DCRUP_MIRROR } else { 'auto' }
|
||||||
$ApiLatest = 'https://api.github.com/repos/dexoron/dcr/releases/latest'
|
$ApiLatest = 'https://api.github.com/repos/dexoron/dcr/releases/latest'
|
||||||
$ApiAll = 'https://api.github.com/repos/dexoron/dcr/releases'
|
$ApiAll = 'https://api.github.com/repos/dexoron/dcr/releases'
|
||||||
@@ -133,6 +134,18 @@ function Link-Default([string]$id) {
|
|||||||
Ok "default → $id ($dst)"
|
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) {
|
function Set-Mirror([string]$value) {
|
||||||
if ($value -notin @('auto', 'cf', 'gh', 'sf', 'ya')) {
|
if ($value -notin @('auto', 'cf', 'gh', 'sf', 'ya')) {
|
||||||
Die "invalid --mirror: $value (use 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 {
|
function Cmd-SelfInstall {
|
||||||
Ensure-Dirs
|
Ensure-Dirs
|
||||||
|
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
|
Copy-Item $PSCommandPath (Join-Path $DcrupBin 'dcrup.ps1') -Force
|
||||||
|
}
|
||||||
Install-CmdShim
|
Install-CmdShim
|
||||||
Ensure-UserPath
|
Ensure-UserPath
|
||||||
Ok "dcrup installed to $DcrupBin (use: dcrup …)"
|
Ok "dcrup installed to $DcrupBin (use: dcrup …)"
|
||||||
@@ -417,7 +442,7 @@ switch ($cmd) {
|
|||||||
if ($a -like 'night-*') { Cmd-Install @('night', '--build', '--force') }
|
if ($a -like 'night-*') { Cmd-Install @('night', '--build', '--force') }
|
||||||
elseif ($a -like 'stable-*') { Cmd-Install @('stable', '--force') }
|
elseif ($a -like 'stable-*') { Cmd-Install @('stable', '--force') }
|
||||||
elseif ($a -like 'dev-*') { Cmd-Install @('dev', '--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' {
|
'uninstall' {
|
||||||
if ($rest -contains '--all') {
|
if ($rest -contains '--all') {
|
||||||
@@ -426,9 +451,21 @@ switch ($cmd) {
|
|||||||
Remove-Item (Active-Path) -ErrorAction SilentlyContinue
|
Remove-Item (Active-Path) -ErrorAction SilentlyContinue
|
||||||
Ok 'removed all'
|
Ok 'removed all'
|
||||||
} else {
|
} 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 }
|
'self-install' { Cmd-SelfInstall }
|
||||||
default { Die "unknown command: $cmd" }
|
default { Die "unknown command: $cmd" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
104
dcrup.sh
Executable file → Normal file
104
dcrup.sh
Executable file → Normal file
@@ -6,6 +6,7 @@ DCRUP_BIN="${DCRUP_BIN:-$DCRUP_HOME/bin}"
|
|||||||
DCRUP_TC="${DCRUP_HOME}/toolchains"
|
DCRUP_TC="${DCRUP_HOME}/toolchains"
|
||||||
DCRUP_META="${DCRUP_HOME}/meta"
|
DCRUP_META="${DCRUP_HOME}/meta"
|
||||||
REPO_URL="${DCRUP_REPO:-https://github.com/dexoron/dcr}"
|
REPO_URL="${DCRUP_REPO:-https://github.com/dexoron/dcr}"
|
||||||
|
DCRUP_INSTALL_URL="${DCRUP_INSTALL_URL:-https://sh.dcr-tool.ru}"
|
||||||
DCRUP_MIRROR="${DCRUP_MIRROR:-auto}"
|
DCRUP_MIRROR="${DCRUP_MIRROR:-auto}"
|
||||||
API_LATEST="https://api.github.com/repos/dexoron/dcr/releases/latest"
|
API_LATEST="https://api.github.com/repos/dexoron/dcr/releases/latest"
|
||||||
API_ALL="https://api.github.com/repos/dexoron/dcr/releases"
|
API_ALL="https://api.github.com/repos/dexoron/dcr/releases"
|
||||||
@@ -20,7 +21,10 @@ NC='\033[0m'
|
|||||||
log() { printf "${CYAN}[dcrup]${NC} %s\n" "$*"; }
|
log() { printf "${CYAN}[dcrup]${NC} %s\n" "$*"; }
|
||||||
ok() { printf "${GREEN}[ok]${NC} %s\n" "$*"; }
|
ok() { printf "${GREEN}[ok]${NC} %s\n" "$*"; }
|
||||||
warn() { printf "${YELLOW}[warn]${NC} %s\n" "$*"; }
|
warn() { printf "${YELLOW}[warn]${NC} %s\n" "$*"; }
|
||||||
die() { printf "${RED}[error]${NC} %s\n" "$*" >&2; exit 1; }
|
die() {
|
||||||
|
printf "${RED}[error]${NC} %s\n" "$*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@ -79,7 +83,7 @@ need_cmd() {
|
|||||||
detect_linux_libc() {
|
detect_linux_libc() {
|
||||||
local pref="${DCRUP_LIBC:-gnu}"
|
local pref="${DCRUP_LIBC:-gnu}"
|
||||||
case "$pref" in
|
case "$pref" in
|
||||||
gnu|glibc) echo "gnu" ;;
|
gnu | glibc) echo "gnu" ;;
|
||||||
musl) echo "musl" ;;
|
musl) echo "musl" ;;
|
||||||
auto)
|
auto)
|
||||||
if command -v ldd >/dev/null 2>&1; then
|
if command -v ldd >/dev/null 2>&1; then
|
||||||
@@ -115,7 +119,7 @@ detect_triple() {
|
|||||||
echo "x86_64-unknown-linux-gnu"
|
echo "x86_64-unknown-linux-gnu"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Linux:aarch64|Linux:arm64)
|
Linux:aarch64 | Linux:arm64)
|
||||||
libc="$(detect_linux_libc)"
|
libc="$(detect_linux_libc)"
|
||||||
if [[ "$libc" == "musl" ]]; then
|
if [[ "$libc" == "musl" ]]; then
|
||||||
echo "aarch64-unknown-linux-musl"
|
echo "aarch64-unknown-linux-musl"
|
||||||
@@ -123,7 +127,7 @@ detect_triple() {
|
|||||||
echo "aarch64-unknown-linux-gnu"
|
echo "aarch64-unknown-linux-gnu"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Linux:i686|Linux:i386)
|
Linux:i686 | Linux:i386)
|
||||||
libc="$(detect_linux_libc)"
|
libc="$(detect_linux_libc)"
|
||||||
if [[ "$libc" == "musl" ]]; then
|
if [[ "$libc" == "musl" ]]; then
|
||||||
echo "i686-unknown-linux-musl"
|
echo "i686-unknown-linux-musl"
|
||||||
@@ -131,7 +135,7 @@ detect_triple() {
|
|||||||
echo "i686-unknown-linux-gnu"
|
echo "i686-unknown-linux-gnu"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Linux:armv7l|Linux:armv7)
|
Linux:armv7l | Linux:armv7)
|
||||||
libc="$(detect_linux_libc)"
|
libc="$(detect_linux_libc)"
|
||||||
if [[ "$libc" == "musl" ]]; then
|
if [[ "$libc" == "musl" ]]; then
|
||||||
echo "armv7-unknown-linux-musleabihf"
|
echo "armv7-unknown-linux-musleabihf"
|
||||||
@@ -148,16 +152,16 @@ detect_triple() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Darwin:x86_64) echo "x86_64-apple-darwin" ;;
|
Darwin:x86_64) echo "x86_64-apple-darwin" ;;
|
||||||
Darwin:arm64|Darwin:aarch64) echo "aarch64-apple-darwin" ;;
|
Darwin:arm64 | Darwin:aarch64) echo "aarch64-apple-darwin" ;;
|
||||||
FreeBSD:x86_64|FreeBSD:amd64) echo "x86_64-unknown-freebsd" ;;
|
FreeBSD:x86_64 | FreeBSD:amd64) echo "x86_64-unknown-freebsd" ;;
|
||||||
FreeBSD:aarch64|FreeBSD:arm64) echo "aarch64-unknown-freebsd" ;;
|
FreeBSD:aarch64 | FreeBSD:arm64) echo "aarch64-unknown-freebsd" ;;
|
||||||
OpenBSD:x86_64|OpenBSD:amd64) echo "x86_64-unknown-openbsd" ;;
|
OpenBSD:x86_64 | OpenBSD:amd64) echo "x86_64-unknown-openbsd" ;;
|
||||||
NetBSD:x86_64|NetBSD:amd64) echo "x86_64-unknown-netbsd" ;;
|
NetBSD:x86_64 | NetBSD:amd64) echo "x86_64-unknown-netbsd" ;;
|
||||||
MINGW*|MSYS*|CYGWIN*)
|
MINGW* | MSYS* | CYGWIN*)
|
||||||
case "$arch" in
|
case "$arch" in
|
||||||
x86_64|amd64) echo "x86_64-pc-windows-gnu" ;;
|
x86_64 | amd64) echo "x86_64-pc-windows-gnu" ;;
|
||||||
aarch64|arm64) echo "aarch64-pc-windows-gnullvm" ;;
|
aarch64 | arm64) echo "aarch64-pc-windows-gnullvm" ;;
|
||||||
i686|i386) echo "i686-pc-windows-gnu" ;;
|
i686 | i386) echo "i686-pc-windows-gnu" ;;
|
||||||
*) die "unsupported Windows arch under MSYS: $arch" ;;
|
*) die "unsupported Windows arch under MSYS: $arch" ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
@@ -180,7 +184,7 @@ parse_spec() {
|
|||||||
|
|
||||||
case "$raw" in
|
case "$raw" in
|
||||||
"") die "missing version/channel spec" ;;
|
"") die "missing version/channel spec" ;;
|
||||||
stable|dev|night)
|
stable | dev | night)
|
||||||
SPEC_CHANNEL="$raw"
|
SPEC_CHANNEL="$raw"
|
||||||
SPEC_VERSION=""
|
SPEC_VERSION=""
|
||||||
SPEC_FLOATING=1
|
SPEC_FLOATING=1
|
||||||
@@ -189,7 +193,7 @@ parse_spec() {
|
|||||||
SPEC_VERSION="$(normalize_version "${raw%@*}")"
|
SPEC_VERSION="$(normalize_version "${raw%@*}")"
|
||||||
SPEC_CHANNEL="${raw#*@}"
|
SPEC_CHANNEL="${raw#*@}"
|
||||||
case "$SPEC_CHANNEL" in
|
case "$SPEC_CHANNEL" in
|
||||||
stable|dev) ;;
|
stable | dev) ;;
|
||||||
night) die "cannot pin a version on night (use: dcrup install night)" ;;
|
night) die "cannot pin a version on night (use: dcrup install night)" ;;
|
||||||
*) die "unknown channel in spec: $SPEC_CHANNEL (use stable|dev)" ;;
|
*) die "unknown channel in spec: $SPEC_CHANNEL (use stable|dev)" ;;
|
||||||
esac
|
esac
|
||||||
@@ -235,6 +239,8 @@ link_default() {
|
|||||||
local id="$1"
|
local id="$1"
|
||||||
local src="$DCRUP_TC/$id/dcr"
|
local src="$DCRUP_TC/$id/dcr"
|
||||||
[[ -x "$src" ]] || die "toolchain not installed: $id"
|
[[ -x "$src" ]] || die "toolchain not installed: $id"
|
||||||
|
# Resolve the source so a relative DCRUP_HOME cannot create a broken link.
|
||||||
|
src="$(cd "$(dirname "$src")" && pwd)/$(basename "$src")"
|
||||||
ln -sfn "$src" "$DCRUP_BIN/dcr"
|
ln -sfn "$src" "$DCRUP_BIN/dcr"
|
||||||
write_active "$id"
|
write_active "$id"
|
||||||
ok "default → $id ($DCRUP_BIN/dcr)"
|
ok "default → $id ($DCRUP_BIN/dcr)"
|
||||||
@@ -251,7 +257,7 @@ json_tag() {
|
|||||||
|
|
||||||
set_mirror() {
|
set_mirror() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
auto|cf|gh|sf|ya) DCRUP_MIRROR="$1" ;;
|
auto | cf | gh | sf | ya) DCRUP_MIRROR="$1" ;;
|
||||||
*) die "invalid --mirror: $1 (use auto|cf|gh|sf|ya)" ;;
|
*) die "invalid --mirror: $1 (use auto|cf|gh|sf|ya)" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -272,7 +278,7 @@ mirror_chain() { echo "cf gh sf ya"; }
|
|||||||
mirrors_to_try() {
|
mirrors_to_try() {
|
||||||
case "$DCRUP_MIRROR" in
|
case "$DCRUP_MIRROR" in
|
||||||
auto) mirror_chain ;;
|
auto) mirror_chain ;;
|
||||||
cf|gh|sf|ya) echo "$DCRUP_MIRROR" ;;
|
cf | gh | sf | ya) echo "$DCRUP_MIRROR" ;;
|
||||||
*) die "invalid mirror: $DCRUP_MIRROR (use auto|cf|gh|sf|ya)" ;;
|
*) die "invalid mirror: $DCRUP_MIRROR (use auto|cf|gh|sf|ya)" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -361,8 +367,8 @@ install_prebuilt() {
|
|||||||
|
|
||||||
mkdir -p "$dest"
|
mkdir -p "$dest"
|
||||||
log "downloading $asset (mirror=$DCRUP_MIRROR) …"
|
log "downloading $asset (mirror=$DCRUP_MIRROR) …"
|
||||||
download_from_mirrors "$tag" "$asset" "$dest" \
|
download_from_mirrors "$tag" "$asset" "$dest" ||
|
||||||
|| die "no mirror reachable for $asset (try: --mirror cf|gh|sf|ya)"
|
die "no mirror reachable for $asset (try: --mirror cf|gh|sf|ya)"
|
||||||
mirror="$USED_MIRROR"
|
mirror="$USED_MIRROR"
|
||||||
log "mirror → $mirror"
|
log "mirror → $mirror"
|
||||||
chmod +x "$dest/dcr"
|
chmod +x "$dest/dcr"
|
||||||
@@ -390,8 +396,8 @@ install_build() {
|
|||||||
|
|
||||||
if [[ "$SPEC_CHANNEL" == "night" ]]; then
|
if [[ "$SPEC_CHANNEL" == "night" ]]; then
|
||||||
log "cloning $REPO_URL (branch dev) for night …"
|
log "cloning $REPO_URL (branch dev) for night …"
|
||||||
git clone --depth 1 --branch dev "$REPO_URL" "$tmp/src" 2>/dev/null \
|
git clone --depth 1 --branch dev "$REPO_URL" "$tmp/src" 2>/dev/null ||
|
||||||
|| git clone --depth 1 "$REPO_URL" "$tmp/src"
|
git clone --depth 1 "$REPO_URL" "$tmp/src"
|
||||||
sha="$(git -C "$tmp/src" rev-parse --short HEAD)"
|
sha="$(git -C "$tmp/src" rev-parse --short HEAD)"
|
||||||
version="night"
|
version="night"
|
||||||
id="$(toolchain_id "$sha")"
|
id="$(toolchain_id "$sha")"
|
||||||
@@ -403,8 +409,8 @@ install_build() {
|
|||||||
version="$(normalize_version "$tag")"
|
version="$(normalize_version "$tag")"
|
||||||
id="$(toolchain_id "$version")"
|
id="$(toolchain_id "$version")"
|
||||||
log "cloning $REPO_URL @ $tag …"
|
log "cloning $REPO_URL @ $tag …"
|
||||||
git clone --depth 1 --branch "$tag" "$REPO_URL" "$tmp/src" 2>/dev/null \
|
git clone --depth 1 --branch "$tag" "$REPO_URL" "$tmp/src" 2>/dev/null ||
|
||||||
|| {
|
{
|
||||||
git clone --depth 1 "$REPO_URL" "$tmp/src"
|
git clone --depth 1 "$REPO_URL" "$tmp/src"
|
||||||
git -C "$tmp/src" fetch --depth 1 origin "refs/tags/${tag}:refs/tags/${tag}"
|
git -C "$tmp/src" fetch --depth 1 origin "refs/tags/${tag}:refs/tags/${tag}"
|
||||||
git -C "$tmp/src" checkout "$tag"
|
git -C "$tmp/src" checkout "$tag"
|
||||||
@@ -415,8 +421,8 @@ install_build() {
|
|||||||
id="$(toolchain_id)"
|
id="$(toolchain_id)"
|
||||||
local tag="v${SPEC_VERSION}"
|
local tag="v${SPEC_VERSION}"
|
||||||
log "cloning $REPO_URL @ $tag …"
|
log "cloning $REPO_URL @ $tag …"
|
||||||
git clone --depth 1 --branch "$tag" "$REPO_URL" "$tmp/src" 2>/dev/null \
|
git clone --depth 1 --branch "$tag" "$REPO_URL" "$tmp/src" 2>/dev/null ||
|
||||||
|| {
|
{
|
||||||
git clone --depth 1 "$REPO_URL" "$tmp/src"
|
git clone --depth 1 "$REPO_URL" "$tmp/src"
|
||||||
git -C "$tmp/src" fetch --depth 1 origin "refs/tags/${tag}:refs/tags/${tag}"
|
git -C "$tmp/src" fetch --depth 1 origin "refs/tags/${tag}:refs/tags/${tag}"
|
||||||
git -C "$tmp/src" checkout "$tag"
|
git -C "$tmp/src" checkout "$tag"
|
||||||
@@ -453,9 +459,18 @@ cmd_install() {
|
|||||||
local libc_cli=""
|
local libc_cli=""
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--build) mode="build"; shift ;;
|
--build)
|
||||||
--release) mode="release"; shift ;;
|
mode="build"
|
||||||
--force) FORCE=1; shift ;;
|
shift
|
||||||
|
;;
|
||||||
|
--release)
|
||||||
|
mode="release"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--force)
|
||||||
|
FORCE=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--libc)
|
--libc)
|
||||||
[[ $# -ge 2 ]] || die "--libc needs gnu|musl|auto"
|
[[ $# -ge 2 ]] || die "--libc needs gnu|musl|auto"
|
||||||
libc_cli="$2"
|
libc_cli="$2"
|
||||||
@@ -474,7 +489,10 @@ cmd_install() {
|
|||||||
set_mirror "${1#--mirror=}"
|
set_mirror "${1#--mirror=}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-h|--help) usage; exit 0 ;;
|
-h | --help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
-*) die "unknown flag: $1" ;;
|
-*) die "unknown flag: $1" ;;
|
||||||
*)
|
*)
|
||||||
[[ -z "$spec" ]] || die "unexpected argument: $1"
|
[[ -z "$spec" ]] || die "unexpected argument: $1"
|
||||||
@@ -489,7 +507,7 @@ cmd_install() {
|
|||||||
|
|
||||||
if [[ -n "$libc_cli" ]]; then
|
if [[ -n "$libc_cli" ]]; then
|
||||||
case "$libc_cli" in
|
case "$libc_cli" in
|
||||||
gnu|glibc|musl|auto) DCRUP_LIBC="$libc_cli" ;;
|
gnu | glibc | musl | auto) DCRUP_LIBC="$libc_cli" ;;
|
||||||
*) die "invalid --libc: $libc_cli (use gnu|musl|auto)" ;;
|
*) die "invalid --libc: $libc_cli (use gnu|musl|auto)" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
@@ -534,12 +552,12 @@ cmd_update() {
|
|||||||
log "updating night (rebuild HEAD) …"
|
log "updating night (rebuild HEAD) …"
|
||||||
FORCE=1 cmd_install night --build --force
|
FORCE=1 cmd_install night --build --force
|
||||||
;;
|
;;
|
||||||
stable-*|dev-*)
|
stable-* | dev-*)
|
||||||
local ch="${active%%-*}"
|
local ch="${active%%-*}"
|
||||||
log "updating floating channel $ch …"
|
log "updating floating channel $ch …"
|
||||||
FORCE=1 cmd_install "$ch" --force
|
FORCE=1 cmd_install "$ch" --force
|
||||||
;;
|
;;
|
||||||
*-stable|*-dev)
|
*-stable | *-dev)
|
||||||
ok "pinned toolchain $active — not floating; install a newer version explicitly"
|
ok "pinned toolchain $active — not floating; install a newer version explicitly"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@@ -633,14 +651,28 @@ cmd_self_install() {
|
|||||||
local dest="$DCRUP_BIN"
|
local dest="$DCRUP_BIN"
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--to) dest="$2"; shift 2 ;;
|
--to)
|
||||||
|
dest="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
*) die "usage: dcrup self-install [--to DIR]" ;;
|
*) die "usage: dcrup self-install [--to DIR]" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
ensure_dirs
|
ensure_dirs
|
||||||
mkdir -p "$dest"
|
mkdir -p "$dest"
|
||||||
local self
|
local self
|
||||||
self="$(readlink -f "$0" 2>/dev/null || realpath "$0" 2>/dev/null || echo "$0")"
|
self="$(readlink -f "$0" 2>/dev/null || realpath "$0" 2>/dev/null || true)"
|
||||||
|
if [[ -z "$self" || ! -f "$self" ]]; then
|
||||||
|
# When invoked as `curl ... | sh`, the shell has no script file to copy.
|
||||||
|
# Fetch the same trusted installer URL and install that exact script.
|
||||||
|
need_cmd curl
|
||||||
|
self="$(mktemp "${TMPDIR:-/tmp}/dcrup.XXXXXX")"
|
||||||
|
curl -fsSL --proto '=https' --tlsv1.2 "$DCRUP_INSTALL_URL" -o "$self" || {
|
||||||
|
rm -f "$self"
|
||||||
|
die "unable to download installer for self-install"
|
||||||
|
}
|
||||||
|
trap 'rm -f "$self"' EXIT
|
||||||
|
fi
|
||||||
cp "$self" "$dest/dcrup"
|
cp "$self" "$dest/dcrup"
|
||||||
chmod +x "$dest/dcrup"
|
chmod +x "$dest/dcrup"
|
||||||
ok "dcrup installed to $dest/dcrup"
|
ok "dcrup installed to $dest/dcrup"
|
||||||
@@ -652,7 +684,7 @@ main() {
|
|||||||
local cmd="${1:-}"
|
local cmd="${1:-}"
|
||||||
shift || true
|
shift || true
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
""|-h|--help|help) usage ;;
|
"" | -h | --help | help) usage ;;
|
||||||
install) cmd_install "$@" ;;
|
install) cmd_install "$@" ;;
|
||||||
default) cmd_default "$@" ;;
|
default) cmd_default "$@" ;;
|
||||||
update) cmd_update "$@" ;;
|
update) cmd_update "$@" ;;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Install and switch DCR versions (stable / dev / night, pin `0.8.2`, optional bui
|
|||||||
### Linux / macOS / BSD / Windows (bash)
|
### Linux / macOS / BSD / Windows (bash)
|
||||||
|
|
||||||
```sh
|
```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"
|
export PATH="$HOME/.dcr/bin:$PATH"
|
||||||
dcrup install stable
|
dcrup install stable
|
||||||
```
|
```
|
||||||
@@ -19,28 +19,19 @@ dcrup install stable
|
|||||||
Non-interactive install of DCR in one shot:
|
Non-interactive install of DCR in one shot:
|
||||||
|
|
||||||
```sh
|
```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"
|
export PATH="$HOME/.dcr/bin:$PATH"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Windows (PowerShell)
|
### Windows (PowerShell)
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
irm https://ps1.dcr-tool.ru | iex
|
& ([scriptblock]::Create((irm https://ps1.dcr-tool.ru))) self-install
|
||||||
# or download then run:
|
|
||||||
# irm https://ps1.dcr-tool.ru -OutFile dcrup.ps1
|
|
||||||
# powershell -File .\dcrup.ps1 self-install
|
|
||||||
# $env:Path += ";$env:USERPROFILE\.dcr\bin"
|
# $env:Path += ";$env:USERPROFILE\.dcr\bin"
|
||||||
dcrup install stable
|
dcrup install stable
|
||||||
```
|
```
|
||||||
|
|
||||||
Optional cmd bootstrap (if you prefer `curl` of the cmd shim):
|
After `self-install`, the command is **`dcrup`** (no `.sh` / `.ps1`) and is installed in `~/.dcr/bin` (Unix) or `%USERPROFILE%\.dcr\bin` (Windows).
|
||||||
|
|
||||||
```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`).
|
|
||||||
|
|
||||||
### Common dcrup commands
|
### Common dcrup commands
|
||||||
|
|
||||||
@@ -58,6 +49,8 @@ dcrup update
|
|||||||
dcrup list
|
dcrup list
|
||||||
dcrup show
|
dcrup show
|
||||||
dcrup which
|
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.
|
Layout: `~/.dcr/toolchains/<id>/dcr` and `~/.dcr/bin/dcr` → active version.
|
||||||
|
|||||||
Reference in New Issue
Block a user