#!/bin/sh # Install the pixy client on Linux or macOS. # # curl -fsSL https://get.demotwo.site/install.sh | sh # # Environment: # PIXY_BASE_URL download base (default: https://get.demotwo.site) # PIXY_INSTALL install directory (default: /usr/local/bin, or ~/.local/bin # when that is not writable) set -eu BASE_URL="${PIXY_BASE_URL:-https://get.demotwo.site}" die() { printf '\033[31merror\033[0m: %s\n' "$1" >&2; exit 1; } info() { printf ' %s\n' "$1"; } if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL "$1" -o "$2"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -qO "$2" "$1"; } else die "either curl or wget is required" fi os=$(uname -s | tr '[:upper:]' '[:lower:]') case "$os" in linux|darwin) ;; *) die "unsupported OS: $os (on Windows use install.ps1)" ;; esac arch=$(uname -m) case "$arch" in x86_64|amd64) arch=amd64 ;; aarch64|arm64) arch=arm64 ;; *) die "unsupported architecture: $arch" ;; esac # Prefer a system-wide install, but fall back to the user's own bin directory # rather than demanding sudo. dest="${PIXY_INSTALL:-}" if [ -z "$dest" ]; then if [ -w /usr/local/bin ] 2>/dev/null; then dest=/usr/local/bin else dest="$HOME/.local/bin" fi fi mkdir -p "$dest" || die "cannot create $dest" [ -w "$dest" ] || die "$dest is not writable (set PIXY_INSTALL, or re-run with sudo)" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT INT TERM asset="pixy-${os}-${arch}" info "downloading $asset" fetch "$BASE_URL/$asset" "$tmp/pixy" || die "download failed: $BASE_URL/$asset" # Verify against the published checksum list whenever it is reachable. if fetch "$BASE_URL/checksums.txt" "$tmp/checksums.txt" 2>/dev/null; then if command -v sha256sum >/dev/null 2>&1; then got=$(sha256sum "$tmp/pixy" | cut -d' ' -f1) elif command -v shasum >/dev/null 2>&1; then got=$(shasum -a 256 "$tmp/pixy" | cut -d' ' -f1) else got="" fi if [ -n "$got" ]; then want=$(grep " $asset\$" "$tmp/checksums.txt" | cut -d' ' -f1) [ -n "$want" ] || die "no checksum published for $asset" [ "$got" = "$want" ] || die "checksum mismatch for $asset" info "checksum verified" fi else info "could not fetch checksums.txt; skipping verification" fi chmod 0755 "$tmp/pixy" # Replacing a running binary fails on some systems; move rather than copy so an # in-use file is unlinked instead of written through. mv -f "$tmp/pixy" "$dest/pixy" || die "could not write $dest/pixy (is pixy running?)" info "installed $dest/pixy" printf '\n\033[32m✓\033[0m pixy installed\n\n' case ":$PATH:" in *":$dest:"*) ;; *) printf ' Add it to your PATH:\n export PATH="%s:$PATH"\n\n' "$dest" ;; esac printf ' Next:\n pixy login --token \n pixy\n\n'