#!/bin/sh set -eu repository="kunalgoesbyken/gostman" version="${GOSTMAN_VERSION:-latest}" fail() { printf 'gostman install: %s\n' "$1" >&2 exit 1 } case "$(uname -s)" in Linux) os=linux ;; Darwin) os=darwin ;; *) fail "this script supports Linux and macOS. On Windows use: irm https://gostman.com/install.ps1 | iex" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; *) fail "no build for the processor $(uname -m). Downloads: https://github.com/$repository/releases" ;; esac asset="gostman-cli-$os-$arch.tar.gz" if [ -n "${GOSTMAN_BASE_URL:-}" ]; then base="${GOSTMAN_BASE_URL%/}" elif [ "$version" = latest ]; then base="https://github.com/$repository/releases/latest/download" else base="https://github.com/$repository/releases/download/v${version#v}" fi if [ -n "${GOSTMAN_INSTALL_DIR:-}" ]; then target="$GOSTMAN_INSTALL_DIR" elif [ "$(id -u)" = 0 ]; then target="/usr/local/bin" else [ -n "${HOME:-}" ] || fail "HOME is not set. Set GOSTMAN_INSTALL_DIR to the folder to install into." target="$HOME/.local/bin" fi if command -v curl > /dev/null 2>&1; then download() { curl --fail --silent --show-error --location --output "$2" "$1"; } elif command -v wget > /dev/null 2>&1; then download() { wget --quiet --output-document="$2" "$1"; } else fail "curl or wget is needed to download Gostman." fi if command -v sha256sum > /dev/null 2>&1; then checksum() { sha256sum "$1" | cut -d' ' -f1; } elif command -v shasum > /dev/null 2>&1; then checksum() { shasum -a 256 "$1" | cut -d' ' -f1; } else fail "sha256sum or shasum is needed to check the download." fi command -v tar > /dev/null 2>&1 || fail "tar is needed to unpack Gostman." work="$(mktemp -d "${TMPDIR:-/tmp}/gostman-install.XXXXXX")" trap 'rm -rf "$work"' EXIT INT TERM printf 'Downloading %s\n' "$asset" download "$base/$asset" "$work/$asset" || fail "could not download $base/$asset. There may be no $os $arch build in this release." download "$base/SHA256SUMS" "$work/SHA256SUMS" || fail "could not download $base/SHA256SUMS." expected="$(awk -v name="$asset" '{ file = $2; sub(/^\*/, "", file) } file == name { print $1; exit }' "$work/SHA256SUMS")" [ -n "$expected" ] || fail "SHA256SUMS has no entry for $asset." actual="$(checksum "$work/$asset")" [ "$actual" = "$expected" ] || fail "$asset does not match SHA256SUMS (expected $expected, got $actual). Nothing was installed." tar -xzf "$work/$asset" -C "$work" gostman || fail "could not unpack $asset." [ -f "$work/gostman" ] || fail "$asset has no gostman file." mkdir -p "$target" || fail "could not create $target." chmod 755 "$work/gostman" mv -f "$work/gostman" "$target/gostman.new" || fail "could not write to $target. Run with sudo, or set GOSTMAN_INSTALL_DIR." mv -f "$target/gostman.new" "$target/gostman" || fail "could not replace $target/gostman." printf 'Installed gostman in %s\n' "$target/gostman" case ":$PATH:" in *":$target:"*) printf 'Run: gostman version\n' ;; *) printf '%s is not on your PATH. Add it with:\n' "$target" printf ' export PATH="%s:$PATH"\n' "$target" ;; esac