feat(scripts): add cross-platform tosutil installers
- Add Windows PowerShell installer with SHA256 verification and PATH setup - Add macOS installer with arch detection and quarantine removal - Enhance Linux installer with amd64/arm64 architecture detection - Rename macOS migrate_remote.sh to migrate-remote.sh
This commit is contained in:
4 files changed
+209
-7
No files matched your search
@@ -2,11 +2,6 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Configuration & URLs
|
|
||||||
BIN_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/linux/amd64/tosutil"
|
|
||||||
SHA_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/linux/amd64/tosutil.sha256sum"
|
|
||||||
TARGET_PATH="/usr/local/bin/tosutil"
|
|
||||||
|
|
||||||
# Helper function to print and execute commands
|
# Helper function to print and execute commands
|
||||||
run_cmd() {
|
run_cmd() {
|
||||||
echo ">> Running: $*"
|
echo ">> Running: $*"
|
||||||
@@ -19,13 +14,34 @@ if [ "$(id -u)" -ne 0 ]; then
|
|||||||
SUDO="sudo"
|
SUDO="sudo"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "=== Starting tosutil installation for Linux ==="
|
||||||
|
|
||||||
|
# Architecture Detection
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
case "$ARCH" in
|
||||||
|
x86_64|amd64)
|
||||||
|
BIN_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/linux/amd64/tosutil"
|
||||||
|
SHA_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/linux/amd64/tosutil.sha256sum"
|
||||||
|
echo "Detected architecture: amd64 (${ARCH})"
|
||||||
|
;;
|
||||||
|
aarch64|arm64)
|
||||||
|
BIN_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/linux/arm64/tosutil"
|
||||||
|
SHA_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/linux/arm64/tosutil.sha256sum"
|
||||||
|
echo "Detected architecture: arm64 (${ARCH})"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: Unsupported architecture: ${ARCH}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
TARGET_PATH="/usr/local/bin/tosutil"
|
||||||
|
|
||||||
# Create isolated temporary directory
|
# Create isolated temporary directory
|
||||||
TMP_DIR=$(mktemp -d /tmp/tosutil-install.XXXXXX)
|
TMP_DIR=$(mktemp -d /tmp/tosutil-install.XXXXXX)
|
||||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||||
cd "$TMP_DIR"
|
cd "$TMP_DIR"
|
||||||
|
|
||||||
echo "=== Starting tosutil installation ==="
|
|
||||||
|
|
||||||
# Download binary and checksum
|
# Download binary and checksum
|
||||||
echo -e "\n[1/5] Downloading tosutil binary and SHA256 checksum..."
|
echo -e "\n[1/5] Downloading tosutil binary and SHA256 checksum..."
|
||||||
run_cmd wget -q --show-progress -O tosutil "$BIN_URL"
|
run_cmd wget -q --show-progress -O tosutil "$BIN_URL"
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
# Requires -RunAsAdministrator
|
||||||
|
[CmdletBinding()]
|
||||||
|
param()
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Architecture Check (Only AMD64 / 64-bit Intel/AMD is supported)
|
||||||
|
$arch = $env:PROCESSOR_ARCHITECTURE
|
||||||
|
if ($arch -ne "AMD64") {
|
||||||
|
Write-Error "Error: tosutil for Windows only supports AMD64 architecture. Detected architecture: $arch"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Configuration & URLs
|
||||||
|
$binUrl = "https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/windows/tosutil"
|
||||||
|
$shaUrl = "https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/windows/tosutil.sha256sum"
|
||||||
|
|
||||||
|
$installDir = "$env:ProgramFiles\tosutil"
|
||||||
|
$targetExe = Join-Path $installDir "tosutil.exe"
|
||||||
|
|
||||||
|
# Helper function to print and run commands
|
||||||
|
function Invoke-LoggedCommand {
|
||||||
|
param([string]$CommandText, [scriptblock]$Action)
|
||||||
|
Write-Host ">> Running: $CommandText" -ForegroundColor Cyan
|
||||||
|
& $Action
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create Temporary Workspace
|
||||||
|
$tempDir = Join-Path $env:TEMP ([System.IO.Path]::GetRandomFileName())
|
||||||
|
New-Item -ItemType Directory -Path $tempDir | Out-Null
|
||||||
|
|
||||||
|
try {
|
||||||
|
Write-Host "=== Starting tosutil installation for Windows (AMD64) ===" -ForegroundColor Green
|
||||||
|
|
||||||
|
$tempBin = Join-Path $tempDir "tosutil.exe"
|
||||||
|
$tempSha = Join-Path $tempDir "tosutil.sha256sum"
|
||||||
|
|
||||||
|
# Download binary & checksum
|
||||||
|
Write-Host "`n[1/5] Downloading tosutil binary and SHA256 checksum..." -ForegroundColor Yellow
|
||||||
|
Invoke-LoggedCommand "Invoke-WebRequest -Uri '$binUrl' -OutFile '$tempBin'" {
|
||||||
|
Invoke-WebRequest -Uri $binUrl -OutFile $tempBin -UseBasicParsing
|
||||||
|
}
|
||||||
|
Invoke-LoggedCommand "Invoke-WebRequest -Uri '$shaUrl' -OutFile '$tempSha'" {
|
||||||
|
Invoke-WebRequest -Uri $shaUrl -OutFile $tempSha -UseBasicParsing
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify SHA256
|
||||||
|
Write-Host "`n[2/5] Verifying SHA256 checksum..." -ForegroundColor Yellow
|
||||||
|
$rawExpected = (Get-Content -Path $tempSha -Raw).Trim()
|
||||||
|
$expectedHash = ($rawExpected -split '\s+')[0].ToLowerInvariant()
|
||||||
|
|
||||||
|
$computedHash = (Get-FileHash -Path $tempBin -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||||
|
Write-Host ">> Expected: $expectedHash"
|
||||||
|
Write-Host ">> Actual: $computedHash"
|
||||||
|
|
||||||
|
if ($computedHash -ne $expectedHash) {
|
||||||
|
Write-Error "SHA256 checksum verification failed!"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Write-Host "SHA256 verification passed." -ForegroundColor Green
|
||||||
|
|
||||||
|
# Install binary
|
||||||
|
Write-Host "`n[3/5] Installing binary to $targetExe..." -ForegroundColor Yellow
|
||||||
|
if (-not (Test-Path $installDir)) {
|
||||||
|
Invoke-LoggedCommand "New-Item -ItemType Directory -Path '$installDir'" {
|
||||||
|
New-Item -ItemType Directory -Path $installDir | Out-Null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Invoke-LoggedCommand "Move-Item -Force -Path '$tempBin' -Destination '$targetExe'" {
|
||||||
|
Move-Item -Force -Path $tempBin -Destination $targetExe
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add to System PATH
|
||||||
|
Write-Host "`n[4/5] Updating system PATH environment variable..." -ForegroundColor Yellow
|
||||||
|
$machinePath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine)
|
||||||
|
if ($machinePath -split ';' -notcontains $installDir) {
|
||||||
|
Invoke-LoggedCommand "Add '$installDir' to Machine PATH" {
|
||||||
|
[Environment]::SetEnvironmentVariable("Path", "$machinePath;$installDir", [EnvironmentVariableTarget]::Machine)
|
||||||
|
$env:Path = "$env:Path;$installDir"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "Target directory already present in PATH."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
Write-Host "`n[5/5] Checking installation..." -ForegroundColor Yellow
|
||||||
|
Invoke-LoggedCommand "& '$targetExe' version" {
|
||||||
|
& "$targetExe" version
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "`n========================================================" -ForegroundColor Green
|
||||||
|
Write-Host "✅ tosutil installed successfully to $targetExe." -ForegroundColor Green
|
||||||
|
Write-Host "========================================================" -ForegroundColor Green
|
||||||
|
Write-Host "`nNext Steps:"
|
||||||
|
Write-Host "1. Initialise and configure your credentials (in PowerShell or CMD):"
|
||||||
|
Write-Host ' tosutil config -i "$env:TOS_ACCESS_KEY" -k "$env:TOS_SECRET_KEY" -e "$env:TOS_ENDPOINT" -re "$env:TOS_REGION"' -ForegroundColor Cyan
|
||||||
|
Write-Host "`n2. For more detailed documentation, visit:"
|
||||||
|
Write-Host " https://docs.volcengine.com/docs/6349/148775?lang=zh`n"
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
Remove-Item -Recurse -Force -Path $tempDir -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Helper function to print and execute commands
|
||||||
|
run_cmd() {
|
||||||
|
echo ">> Running: $*"
|
||||||
|
"$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Determine sudo requirement
|
||||||
|
SUDO=""
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
SUDO="sudo"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=== Starting tosutil installation for macOS ==="
|
||||||
|
|
||||||
|
# 1. Architecture Detection
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
case "$ARCH" in
|
||||||
|
x86_64)
|
||||||
|
BIN_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/darwin/amd64/tosutil"
|
||||||
|
SHA_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/darwin/amd64/tosutil.sha256sum"
|
||||||
|
echo "Detected architecture: Intel (amd64)"
|
||||||
|
;;
|
||||||
|
arm64)
|
||||||
|
BIN_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/darwin/arm64/tosutil"
|
||||||
|
SHA_URL="https://m645b3e1bb36e-mrap.mrap.accesspoint.tos-global.volces.com/darwin/arm64/tosutil.sha256sum"
|
||||||
|
echo "Detected architecture: Apple Silicon (arm64)"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: Unsupported architecture: $ARCH" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
TARGET_DIR="/usr/local/bin"
|
||||||
|
TARGET_PATH="${TARGET_DIR}/tosutil"
|
||||||
|
|
||||||
|
# 2. Create isolated temporary directory
|
||||||
|
TMP_DIR=$(mktemp -d /tmp/tosutil-install.XXXXXX)
|
||||||
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||||
|
cd "$TMP_DIR"
|
||||||
|
|
||||||
|
# Step 1: Download binary and checksum via curl
|
||||||
|
echo -e "\n[1/5] Downloading tosutil binary and SHA256 checksum..."
|
||||||
|
run_cmd curl -fsSL -o tosutil "$BIN_URL"
|
||||||
|
run_cmd curl -fsSL -o tosutil.sha256sum "$SHA_URL"
|
||||||
|
|
||||||
|
# Step 2: Verify SHA256
|
||||||
|
echo -e "\n[2/5] Verifying SHA256 checksum..."
|
||||||
|
EXPECTED_HASH=$(awk '{print $1}' tosutil.sha256sum)
|
||||||
|
echo ">> Running: echo \"$EXPECTED_HASH tosutil\" | shasum -a 256 -c -"
|
||||||
|
echo "$EXPECTED_HASH tosutil" | shasum -a 256 -c -
|
||||||
|
|
||||||
|
# Step 3: Ensure /usr/local/bin exists and move binary
|
||||||
|
echo -e "\n[3/5] Moving binary to ${TARGET_PATH}..."
|
||||||
|
if [ ! -d "$TARGET_DIR" ]; then
|
||||||
|
run_cmd $SUDO mkdir -p "$TARGET_DIR"
|
||||||
|
fi
|
||||||
|
run_cmd $SUDO mv tosutil "$TARGET_PATH"
|
||||||
|
|
||||||
|
# Step 4: Set permissions and bypass macOS Gatekeeper quarantine
|
||||||
|
echo -e "\n[4/5] Setting permissions and removing quarantine flag..."
|
||||||
|
run_cmd $SUDO chown root:wheel "$TARGET_PATH"
|
||||||
|
run_cmd $SUDO chmod 755 "$TARGET_PATH"
|
||||||
|
# Remove quarantine attribute if present
|
||||||
|
if run_cmd $SUDO xattr -d com.apple.quarantine "$TARGET_PATH" 2>/dev/null; then
|
||||||
|
echo "Removed quarantine attribute."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Step 5: Verify installation
|
||||||
|
echo -e "\n[5/5] Checking installation..."
|
||||||
|
run_cmd tosutil version || run_cmd tosutil --version || true
|
||||||
|
|
||||||
|
echo -e "\n========================================================"
|
||||||
|
echo -e "✅ tosutil installed successfully to ${TARGET_PATH}."
|
||||||
|
echo -e "========================================================"
|
||||||
|
echo -e "\nNext Steps:"
|
||||||
|
echo -e "1. Initialise and configure your credentials:"
|
||||||
|
echo -e ' tosutil config -i "${TOS_ACCESS_KEY}" -k "${TOS_SECRET_KEY}" -e "${TOS_ENDPOINT}" -re "${TOS_REGION}"'
|
||||||
|
echo -e "\n2. For more detailed documentation, visit:"
|
||||||
|
echo -e " https://docs.volcengine.com/docs/6349/148775?lang=zh\n"
|
||||||
File renamed without changes.
Reference in new issue
Block a user