#!/bin/sh # Installs vpsm, the VPS Minute command-line tool, on Linux or macOS: # curl -fsSL https://panel.vps-minute.com/cli/install.sh | sh # Options (environment): VPSM_VERSION=1.0.0 (default: latest), VPSM_INSTALL_DIR=/somewhere/bin # (default: /usr/local/bin when writable, otherwise ~/.local/bin). The archive is checked against SHA256SUMS. set -eu base="${VPSM_DOWNLOAD:-https://panel.vps-minute.com/cli}" version="${VPSM_VERSION:-}" fail() { echo "vpsm: $*" >&2 exit 1 } case "$(uname -s)" in Linux) os=linux ;; Darwin) os=darwin ;; *) fail "this script installs on Linux and macOS; on Windows run: irm $base/install.ps1 | iex" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; *) fail "unsupported processor $(uname -m) (amd64 and arm64 only)" ;; esac fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2" elif command -v wget >/dev/null 2>&1; then wget -q "$1" -O "$2" else fail "curl or wget is needed" fi } tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT INT TERM if [ -z "$version" ]; then fetch "$base/latest" "$tmp/latest.json" || fail "cannot reach $base" version=$(sed -n 's/.*"version": *"\([0-9][0-9.]*\)".*/\1/p' "$tmp/latest.json" | head -n 1) [ -n "$version" ] || fail "cannot read the latest version" fi file="vpsm_${version}_${os}_${arch}.tar.gz" fetch "$base/download/$version/$file" "$tmp/$file" || fail "cannot download $file" fetch "$base/download/$version/SHA256SUMS" "$tmp/SHA256SUMS" || fail "cannot download SHA256SUMS" expected=$(awk -v f="$file" '$2 == f { print $1 }' "$tmp/SHA256SUMS") if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmp/$file" | awk '{ print $1 }') else actual=$(shasum -a 256 "$tmp/$file" | awk '{ print $1 }') fi [ -n "$expected" ] && [ "$expected" = "$actual" ] || fail "checksum mismatch for $file: nothing was installed" tar -xzf "$tmp/$file" -C "$tmp" vpsm dir="${VPSM_INSTALL_DIR:-}" if [ -z "$dir" ]; then if [ -w /usr/local/bin ] || [ "$(id -u)" = 0 ]; then dir=/usr/local/bin else dir="$HOME/.local/bin" fi fi mkdir -p "$dir" cp "$tmp/vpsm" "$dir/vpsm.new" chmod 755 "$dir/vpsm.new" mv -f "$dir/vpsm.new" "$dir/vpsm" echo "vpsm $version installed: $dir/vpsm" case ":$PATH:" in *":$dir:"*) ;; *) echo "Add $dir to your PATH, for example: echo 'export PATH=\"$dir:\$PATH\"' >> ~/.profile" ;; esac echo "Next step: vpsm login (with an API key from your client area, Settings > Security > API keys)"