Compare commits
2
Commits
fbf88ec144
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
726be04d17
|
||
|
|
2bab52879f
|
@@ -142,7 +142,7 @@ You can use the following command to run a bash script that downloads and instal
|
|||||||
OS (Linux/MacOS) and architecture (x86_64/arm64):
|
OS (Linux/MacOS) and architecture (x86_64/arm64):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -fsSL https://raw.githubusercontent.com/Dark-Alex-17/gman/main/install_gman.sh | bash
|
curl -fsSL https://raw.githubusercontent.com/Dark-Alex-17/gman/main/scripts/install_gman.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Windows/Linux/MacOS (`PowerShell`)
|
#### Windows/Linux/MacOS (`PowerShell`)
|
||||||
|
|||||||
+23
-24
@@ -39,19 +39,13 @@ switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) {
|
|||||||
|
|
||||||
if (-not $BinDir) {
|
if (-not $BinDir) {
|
||||||
if ($isWin) { $BinDir = Join-Path $env:LOCALAPPDATA 'gman\bin' }
|
if ($isWin) { $BinDir = Join-Path $env:LOCALAPPDATA 'gman\bin' }
|
||||||
else { $home = $env:HOME; if (-not $home) { $home = (Get-Item -Path ~).FullName }; $BinDir = Join-Path $home '.local/bin' }
|
else { $userHome = $env:HOME; if (-not $userHome) { $userHome = (Get-Item -Path ~).FullName }; $BinDir = Join-Path $userHome '.local/bin' }
|
||||||
}
|
}
|
||||||
New-Item -ItemType Directory -Force -Path $BinDir | Out-Null
|
New-Item -ItemType Directory -Force -Path $BinDir | Out-Null
|
||||||
|
|
||||||
Write-Info "Target: $os-$arch"
|
Write-Info "Target: $os-$arch"
|
||||||
|
|
||||||
$apiBase = "https://api.github.com/repos/$Repo/releases"
|
$dlBase = if ($Version) { "https://github.com/$Repo/releases/download/$Version" } else { "https://github.com/$Repo/releases/latest/download" }
|
||||||
$relUrl = if ($Version) { "$apiBase/tags/$Version" } else { "$apiBase/latest" }
|
|
||||||
Write-Info "Fetching release: $relUrl"
|
|
||||||
try {
|
|
||||||
$release = Invoke-RestMethod -UseBasicParsing -Headers @{ 'User-Agent' = 'gman-installer' } -Uri $relUrl -Method GET
|
|
||||||
} catch { Fail "Failed to fetch release metadata. $_" }
|
|
||||||
if (-not $release.assets) { Fail "No assets found in the release." }
|
|
||||||
|
|
||||||
$candidates = @()
|
$candidates = @()
|
||||||
if ($os -eq 'windows') {
|
if ($os -eq 'windows') {
|
||||||
@@ -62,8 +56,8 @@ if ($os -eq 'windows') {
|
|||||||
else { $candidates += 'gman-aarch64-apple-darwin.tar.gz' }
|
else { $candidates += 'gman-aarch64-apple-darwin.tar.gz' }
|
||||||
} elseif ($os -eq 'linux') {
|
} elseif ($os -eq 'linux') {
|
||||||
if ($arch -eq 'x86_64') {
|
if ($arch -eq 'x86_64') {
|
||||||
$candidates += 'gman-x86_64-unknown-linux-gnu.tar.gz'
|
|
||||||
$candidates += 'gman-x86_64-unknown-linux-musl.tar.gz'
|
$candidates += 'gman-x86_64-unknown-linux-musl.tar.gz'
|
||||||
|
$candidates += 'gman-x86_64-unknown-linux-gnu.tar.gz'
|
||||||
} else {
|
} else {
|
||||||
$candidates += 'gman-aarch64-unknown-linux-musl.tar.gz'
|
$candidates += 'gman-aarch64-unknown-linux-musl.tar.gz'
|
||||||
}
|
}
|
||||||
@@ -71,37 +65,42 @@ if ($os -eq 'windows') {
|
|||||||
Fail "Unsupported OS for this installer: $os"
|
Fail "Unsupported OS for this installer: $os"
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset = $null
|
$tmp = New-Item -ItemType Directory -Force -Path ([IO.Path]::Combine([IO.Path]::GetTempPath(), "gman-$(Get-Random)"))
|
||||||
|
$archive = Join-Path $tmp.FullName 'asset'
|
||||||
|
|
||||||
|
$assetName = $null; $assetUrl = $null
|
||||||
foreach ($c in $candidates) {
|
foreach ($c in $candidates) {
|
||||||
$asset = $release.assets | Where-Object { $_.name -eq $c } | Select-Object -First 1
|
$url = "$dlBase/$c"
|
||||||
if ($asset) { break }
|
Write-Info "Trying $url"
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -UseBasicParsing -Headers @{ 'User-Agent' = 'gman-installer' } -Uri $url -OutFile $archive -ErrorAction Stop
|
||||||
|
$assetName = $c; $assetUrl = $url
|
||||||
|
break
|
||||||
|
} catch { continue }
|
||||||
}
|
}
|
||||||
if (-not $asset) {
|
if (-not $assetName) {
|
||||||
Write-Error "No matching asset found for $os-$arch. Tried:"; $candidates | ForEach-Object { Write-Error " - $_" }
|
$verLabel = if ($Version) { $Version } else { 'latest' }
|
||||||
|
Write-Error "No matching asset found for $os-$arch (version: $verLabel). Tried:"; $candidates | ForEach-Object { Write-Error " - $_" }
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Info "Selected asset: $($asset.name)"
|
Write-Info "Selected asset: $assetName"
|
||||||
Write-Info "Download URL: $($asset.browser_download_url)"
|
Write-Info "Download URL: $assetUrl"
|
||||||
|
|
||||||
$tmp = New-Item -ItemType Directory -Force -Path ([IO.Path]::Combine([IO.Path]::GetTempPath(), "gman-$(Get-Random)"))
|
|
||||||
$archive = Join-Path $tmp.FullName 'asset'
|
|
||||||
try { Invoke-WebRequest -UseBasicParsing -Headers @{ 'User-Agent' = 'gman-installer' } -Uri $asset.browser_download_url -OutFile $archive } catch { Fail "Failed to download asset. $_" }
|
|
||||||
|
|
||||||
$extractDir = Join-Path $tmp.FullName 'extract'; New-Item -ItemType Directory -Force -Path $extractDir | Out-Null
|
$extractDir = Join-Path $tmp.FullName 'extract'; New-Item -ItemType Directory -Force -Path $extractDir | Out-Null
|
||||||
|
|
||||||
if ($asset.name -match '\.zip$') {
|
if ($assetName -match '\.zip$') {
|
||||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($archive, $extractDir)
|
[System.IO.Compression.ZipFile]::ExtractToDirectory($archive, $extractDir)
|
||||||
} elseif ($asset.name -match '\.tar\.gz$' -or $asset.name -match '\.tgz$') {
|
} elseif ($assetName -match '\.tar\.gz$' -or $assetName -match '\.tgz$') {
|
||||||
$tar = Get-Command tar -ErrorAction SilentlyContinue
|
$tar = Get-Command tar -ErrorAction SilentlyContinue
|
||||||
if ($tar) { & $tar.FullName -xzf $archive -C $extractDir }
|
if ($tar) { & $tar.Source -xzf $archive -C $extractDir }
|
||||||
else { Fail "Asset is tar archive but 'tar' is not available." }
|
else { Fail "Asset is tar archive but 'tar' is not available." }
|
||||||
} else {
|
} else {
|
||||||
try { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory($archive, $extractDir) }
|
try { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory($archive, $extractDir) }
|
||||||
catch {
|
catch {
|
||||||
$tar = Get-Command tar -ErrorAction SilentlyContinue
|
$tar = Get-Command tar -ErrorAction SilentlyContinue
|
||||||
if ($tar) { & $tar.FullName -xf $archive -C $extractDir } else { Fail "Unknown archive format; neither zip nor tar workable." }
|
if ($tar) { & $tar.Source -xf $archive -C $extractDir } else { Fail "Unknown archive format; neither zip nor tar workable." }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-51
@@ -83,31 +83,23 @@ esac
|
|||||||
|
|
||||||
log "Target: ${OS}-${ARCH}"
|
log "Target: ${OS}-${ARCH}"
|
||||||
|
|
||||||
API_BASE="https://api.github.com/repos/${REPO}/releases"
|
|
||||||
if [[ -z "${VERSION}" ]]; then
|
if [[ -z "${VERSION}" ]]; then
|
||||||
RELEASE_URL="${API_BASE}/latest"
|
DL_BASE="https://github.com/${REPO}/releases/latest/download"
|
||||||
else
|
else
|
||||||
RELEASE_URL="${API_BASE}/tags/${VERSION}"
|
DL_BASE="https://github.com/${REPO}/releases/download/${VERSION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
http_get() {
|
download() {
|
||||||
if [[ "$DL" == "curl" ]]; then
|
if [[ "$DL" == "curl" ]]; then
|
||||||
curl -fsSL -H 'User-Agent: gman-installer' "$1"
|
curl -fsSL -H 'User-Agent: gman-installer' "$1" -o "$2"
|
||||||
else
|
else
|
||||||
wget -qO- --header='User-Agent: gman-installer' "$1"
|
wget -q --header='User-Agent: gman-installer' "$1" -O "$2"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
TMPDIR="$(mktemp -d)"
|
TMPDIR="$(mktemp -d)"
|
||||||
trap 'rm -rf "$TMPDIR"' EXIT
|
trap 'rm -rf "$TMPDIR"' EXIT
|
||||||
|
|
||||||
log "Fetching release metadata from $RELEASE_URL"
|
|
||||||
JSON="$TMPDIR/release.json"
|
|
||||||
if ! http_get "$RELEASE_URL" > "$JSON"; then
|
|
||||||
echo "Error: failed to fetch release metadata. Check version tag." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
ASSET_CANDIDATES=()
|
ASSET_CANDIDATES=()
|
||||||
if [[ "$OS" == "darwin" ]]; then
|
if [[ "$OS" == "darwin" ]]; then
|
||||||
if [[ "$ARCH" == "x86_64" ]]; then
|
if [[ "$ARCH" == "x86_64" ]]; then
|
||||||
@@ -117,15 +109,8 @@ if [[ "$OS" == "darwin" ]]; then
|
|||||||
fi
|
fi
|
||||||
elif [[ "$OS" == "linux" ]]; then
|
elif [[ "$OS" == "linux" ]]; then
|
||||||
if [[ "$ARCH" == "x86_64" ]]; then
|
if [[ "$ARCH" == "x86_64" ]]; then
|
||||||
LIBC="musl"
|
|
||||||
if command -v getconf >/dev/null 2>&1 && getconf GNU_LIBC_VERSION >/dev/null 2>&1; then LIBC="gnu"; fi
|
|
||||||
if ldd --version 2>&1 | grep -qi glibc; then LIBC="gnu"; fi
|
|
||||||
|
|
||||||
if [[ "$LIBC" == "gnu" ]]; then
|
|
||||||
ASSET_CANDIDATES+=("gman-x86_64-unknown-linux-gnu.tar.gz")
|
|
||||||
fi
|
|
||||||
|
|
||||||
ASSET_CANDIDATES+=("gman-x86_64-unknown-linux-musl.tar.gz")
|
ASSET_CANDIDATES+=("gman-x86_64-unknown-linux-musl.tar.gz")
|
||||||
|
ASSET_CANDIDATES+=("gman-x86_64-unknown-linux-gnu.tar.gz")
|
||||||
else
|
else
|
||||||
ASSET_CANDIDATES+=("gman-aarch64-unknown-linux-musl.tar.gz")
|
ASSET_CANDIDATES+=("gman-aarch64-unknown-linux-musl.tar.gz")
|
||||||
fi
|
fi
|
||||||
@@ -133,34 +118,20 @@ else
|
|||||||
echo "Error: unsupported OS for this installer: $OS" >&2; exit 1
|
echo "Error: unsupported OS for this installer: $OS" >&2; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ARCHIVE="$TMPDIR/asset"
|
||||||
ASSET_NAME=""; ASSET_URL=""
|
ASSET_NAME=""; ASSET_URL=""
|
||||||
for candidate in "${ASSET_CANDIDATES[@]}"; do
|
for candidate in "${ASSET_CANDIDATES[@]}"; do
|
||||||
NAME=$(grep -oE '"name":\s*"[^"]+"' "$JSON" | sed 's/"name":\s*"//; s/"$//' | grep -Fx "$candidate" || true)
|
URL="${DL_BASE}/${candidate}"
|
||||||
if [[ -n "$NAME" ]]; then
|
log "Trying ${URL}"
|
||||||
ASSET_NAME="$NAME"
|
if download "$URL" "$ARCHIVE"; then
|
||||||
ASSET_URL=$(awk -v pat="$NAME" '
|
ASSET_NAME="$candidate"
|
||||||
BEGIN{ FS=":"; want=0 }
|
ASSET_URL="$URL"
|
||||||
/"name"/ {
|
break
|
||||||
line=$0;
|
|
||||||
gsub(/^\s+|\s+$/,"",line);
|
|
||||||
gsub(/"name"\s*:\s*"|"/ ,"", line);
|
|
||||||
want = (line==pat) ? 1 : 0;
|
|
||||||
next
|
|
||||||
}
|
|
||||||
want==1 && /"browser_download_url"/ {
|
|
||||||
u=$0;
|
|
||||||
gsub(/^\s+|\s+$/,"",u);
|
|
||||||
gsub(/.*"browser_download_url"\s*:\s*"|".*/ ,"", u);
|
|
||||||
print u;
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
' "$JSON")
|
|
||||||
if [[ -n "$ASSET_URL" ]]; then break; fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z "$ASSET_URL" ]]; then
|
if [[ -z "$ASSET_NAME" ]]; then
|
||||||
echo "Error: no matching asset found for ${OS}-${ARCH}. Tried:" >&2
|
echo "Error: no matching asset found for ${OS}-${ARCH} (version: ${VERSION:-latest}). Tried:" >&2
|
||||||
for c in "${ASSET_CANDIDATES[@]}"; do echo " - $c" >&2; done
|
for c in "${ASSET_CANDIDATES[@]}"; do echo " - $c" >&2; done
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -168,13 +139,6 @@ fi
|
|||||||
log "Selected asset: $ASSET_NAME"
|
log "Selected asset: $ASSET_NAME"
|
||||||
log "Download URL: $ASSET_URL"
|
log "Download URL: $ASSET_URL"
|
||||||
|
|
||||||
ARCHIVE="$TMPDIR/asset"
|
|
||||||
if [[ "$DL" == "curl" ]]; then
|
|
||||||
curl -fL -H 'User-Agent: gman-installer' "$ASSET_URL" -o "$ARCHIVE"
|
|
||||||
else
|
|
||||||
wget -q --header='User-Agent: gman-installer' "$ASSET_URL" -O "$ARCHIVE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
WORK="$TMPDIR/work"; mkdir -p "$WORK"
|
WORK="$TMPDIR/work"; mkdir -p "$WORK"
|
||||||
EXTRACTED_DIR="$WORK/extracted"; mkdir -p "$EXTRACTED_DIR"
|
EXTRACTED_DIR="$WORK/extracted"; mkdir -p "$EXTRACTED_DIR"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user