diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index a35144f..7423778 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -75,21 +75,35 @@ jobs: - name: Rename binaries to include platform and architecture run: | - mv binaries/safe-chain-macos-x64/safe-chain binaries/safe-chain-macos-x64/safe-chain-macos-x64 - mv binaries/safe-chain-macos-arm64/safe-chain binaries/safe-chain-macos-arm64/safe-chain-macos-arm64 - mv binaries/safe-chain-linux-x64/safe-chain binaries/safe-chain-linux-x64/safe-chain-linux-x64 - mv binaries/safe-chain-linux-arm64/safe-chain binaries/safe-chain-linux-arm64/safe-chain-linux-arm64 - mv binaries/safe-chain-win-x64/safe-chain.exe binaries/safe-chain-win-x64/safe-chain-win-x64.exe - mv binaries/safe-chain-win-arm64/safe-chain.exe binaries/safe-chain-win-arm64/safe-chain-win-arm64.exe + mkdir release-artifacts + mv binaries/safe-chain-macos-x64/safe-chain release-artifacts/safe-chain-macos-x64 + mv binaries/safe-chain-macos-arm64/safe-chain release-artifacts/safe-chain-macos-arm64 + mv binaries/safe-chain-linux-x64/safe-chain release-artifacts/safe-chain-linux-x64 + mv binaries/safe-chain-linux-arm64/safe-chain release-artifacts/safe-chain-linux-arm64 + mv binaries/safe-chain-win-x64/safe-chain.exe release-artifacts/safe-chain-win-x64.exe + mv binaries/safe-chain-win-arm64/safe-chain.exe release-artifacts/safe-chain-win-arm64.exe + + - name: Move install scripts and hard-code version + env: + VERSION: ${{ needs.set-version.outputs.version }} + run: | + sed "s/\$(fetch_latest_version)/${VERSION}/" install-scripts/install-safe-chain.sh > release-artifacts/install-safe-chain.sh + sed "s/\$Version = Get-LatestVersion/\$Version = \"${VERSION}\"/" install-scripts/install-safe-chain.ps1 > release-artifacts/install-safe-chain.ps1 + cp install-scripts/uninstall-safe-chain.sh release-artifacts/uninstall-safe-chain.sh + cp install-scripts/uninstall-safe-chain.ps1 release-artifacts/uninstall-safe-chain.ps1 - name: Upload binaries to existing GitHub Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release upload ${{ needs.set-version.outputs.version }} \ - binaries/safe-chain-macos-x64/* \ - binaries/safe-chain-macos-arm64/* \ - binaries/safe-chain-linux-x64/* \ - binaries/safe-chain-linux-arm64/* \ - binaries/safe-chain-win-x64/* \ - binaries/safe-chain-win-arm64/* + release-artifacts/safe-chain-macos-x64 \ + release-artifacts/safe-chain-macos-arm64 \ + release-artifacts/safe-chain-linux-x64 \ + release-artifacts/safe-chain-linux-arm64 \ + release-artifacts/safe-chain-win-x64.exe \ + release-artifacts/safe-chain-win-arm64.exe \ + release-artifacts/install-safe-chain.sh \ + release-artifacts/install-safe-chain.ps1 \ + release-artifacts/uninstall-safe-chain.sh \ + release-artifacts/uninstall-safe-chain.ps1 diff --git a/README.md b/README.md index 1d6db62..73735f4 100644 --- a/README.md +++ b/README.md @@ -35,15 +35,31 @@ Installing the Aikido Safe Chain is easy with our one-line installer. ### Unix/Linux/macOS ```shell -curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh +curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh ``` ### Windows (PowerShell) ```powershell -iex (iwr "https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1" -UseBasicParsing) +iex (iwr "https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.ps1" -UseBasicParsing) ``` +### Pinning to a specific version + +To install a specific version instead of the latest, replace `latest` with the version number in the URL (available from version 1.3.2 onwards): + +**Unix/Linux/macOS:** +```shell +curl -fsSL https://github.com/AikidoSec/safe-chain/releases/download/x.x.x/install-safe-chain.sh | sh +``` + +**Windows (PowerShell):** +```powershell +iex (iwr "https://github.com/AikidoSec/safe-chain/releases/download/x.x.x/install-safe-chain.ps1" -UseBasicParsing) +``` + +You can find all available versions on the [releases page](https://github.com/AikidoSec/safe-chain/releases). + ### Verify the installation 1. **❗Restart your terminal** to start using the Aikido Safe Chain. @@ -105,13 +121,13 @@ To uninstall the Aikido Safe Chain, use our one-line uninstaller: ### Unix/Linux/macOS ```shell -curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/uninstall-safe-chain.sh | sh +curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/uninstall-safe-chain.sh | sh ``` ### Windows (PowerShell) ```powershell -iex (iwr "https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/uninstall-safe-chain.ps1" -UseBasicParsing) +iex (iwr "https://github.com/AikidoSec/safe-chain/releases/latest/download/uninstall-safe-chain.ps1" -UseBasicParsing) ``` **❗Restart your terminal** after uninstalling to ensure all aliases are removed. @@ -178,13 +194,13 @@ Use the `--ci` flag to automatically configure Aikido Safe Chain for CI/CD envir ### Unix/Linux/macOS (GitHub Actions, Azure Pipelines, etc.) ```shell -curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci +curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci ``` ### Windows (Azure Pipelines, etc.) ```powershell -iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -ci" +iex "& { $(iwr 'https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.ps1' -UseBasicParsing) } -ci" ``` ## Supported Platforms @@ -203,7 +219,7 @@ iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/inst cache: "npm" - name: Install safe-chain - run: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci + run: curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci - name: Install dependencies run: npm ci @@ -217,7 +233,7 @@ iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/inst versionSpec: "22.x" displayName: "Install Node.js" -- script: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci +- script: curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci displayName: "Install safe-chain" - script: npm ci diff --git a/install-scripts/install-safe-chain.ps1 b/install-scripts/install-safe-chain.ps1 index 23caa5c..51d15ba 100644 --- a/install-scripts/install-safe-chain.ps1 +++ b/install-scripts/install-safe-chain.ps1 @@ -31,6 +31,46 @@ function Write-Error-Custom { exit 1 } +# Get currently installed version of safe-chain +function Get-InstalledVersion { + # Check if safe-chain command exists + if (-not (Get-Command safe-chain -ErrorAction SilentlyContinue)) { + return $null + } + + try { + # Execute safe-chain -v and capture output + $output = & safe-chain -v 2>&1 + + # Extract version from "Current safe-chain version: X.Y.Z" output + if ($output -match "Current safe-chain version:\s*(.+)") { + return $matches[1].Trim() + } + + return $null + } + catch { + return $null + } +} + +# Check if the requested version is already installed +function Test-VersionInstalled { + param([string]$RequestedVersion) + + $installedVersion = Get-InstalledVersion + + if ([string]::IsNullOrWhiteSpace($installedVersion)) { + return $false + } + + # Strip leading 'v' from versions if present for comparison + $requestedClean = $RequestedVersion -replace '^v', '' + $installedClean = $installedVersion -replace '^v', '' + + return $requestedClean -eq $installedClean +} + # Fetch latest release version tag from GitHub function Get-LatestVersion { try { @@ -115,6 +155,12 @@ function Install-SafeChain { $Version = Get-LatestVersion } + # Check if the requested version is already installed + if (Test-VersionInstalled -RequestedVersion $Version) { + Write-Info "safe-chain $Version is already installed" + return + } + # Build installation message $installMsg = "Installing safe-chain $Version" if ($ci) { diff --git a/install-scripts/install-safe-chain.sh b/install-scripts/install-safe-chain.sh index 8e19da7..94a9b55 100755 --- a/install-scripts/install-safe-chain.sh +++ b/install-scripts/install-safe-chain.sh @@ -54,6 +54,38 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } +# Get currently installed version of safe-chain +get_installed_version() { + if ! command_exists safe-chain; then + echo "" + return + fi + + # Extract version from "Current safe-chain version: X.Y.Z" output + installed_version=$(safe-chain -v 2>/dev/null | grep "Current safe-chain version:" | sed -E 's/.*: (.*)/\1/') + echo "$installed_version" +} + +# Check if the requested version is already installed +is_version_installed() { + requested_version="$1" + installed_version=$(get_installed_version) + + if [ -z "$installed_version" ]; then + return 1 # Not installed + fi + + # Strip leading 'v' from versions if present for comparison + requested_clean=$(echo "$requested_version" | sed 's/^v//') + installed_clean=$(echo "$installed_version" | sed 's/^v//') + + if [ "$requested_clean" = "$installed_clean" ]; then + return 0 # Same version installed + else + return 1 # Different version installed + fi +} + # Fetch latest release version tag from GitHub fetch_latest_version() { # Try using GitHub API to get the latest release tag @@ -158,6 +190,12 @@ main() { VERSION=$(fetch_latest_version) fi + # Check if the requested version is already installed + if is_version_installed "$VERSION"; then + info "safe-chain ${VERSION} is already installed" + exit 0 + fi + # Build installation message INSTALL_MSG="Installing safe-chain ${VERSION}" if [ "$USE_CI_SETUP" = "true" ]; then