#!/bin/sh # Polign installer. Downloads the latest polign_db release for this machine, # verifies its checksum, and puts the binaries on your PATH. # # curl -fsSL https://get.polign.com | sh # # Options, set as environment variables: # POLIGN_VERSION install a specific version, e.g. v0.2.1 (default: latest) # POLIGN_BIN_DIR install directory (default: /usr/local/bin when writable, # otherwise ~/.local/bin) set -eu DL="https://dl.polign.com" fail() { echo "install failed: $1" >&2; exit 1; } command -v curl >/dev/null 2>&1 || fail "curl is required" command -v tar >/dev/null 2>&1 || fail "tar is required" os=$(uname -s) case "$os" in Linux) os=linux ;; Darwin) os=darwin ;; *) fail "unsupported operating system: $os (releases cover linux and darwin)" ;; esac arch=$(uname -m) case "$arch" in x86_64 | amd64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "unsupported architecture: $arch (releases cover amd64 and arm64)" ;; esac version=${POLIGN_VERSION:-$(curl -fsSL "$DL/latest/version")} || fail "could not resolve the latest version" case "$version" in v*) ;; *) fail "unexpected version \"$version\"" ;; esac asset="polign_db_${os}_${arch}.tar.gz" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT echo "downloading polign_db $version for $os/$arch ..." curl -fsSL -o "$tmp/$asset" "$DL/$version/$asset?c=install" || fail "download failed" curl -fsSL -o "$tmp/checksums.txt" "$DL/$version/checksums.txt?c=install" || fail "checksum download failed" # Verify the archive against the release checksums with whichever sha256 tool # this machine has. if command -v sha256sum >/dev/null 2>&1; then (cd "$tmp" && grep " $asset\$" checksums.txt | sha256sum -c - >/dev/null) || fail "checksum mismatch for $asset" elif command -v shasum >/dev/null 2>&1; then (cd "$tmp" && grep " $asset\$" checksums.txt | shasum -a 256 -c - >/dev/null) || fail "checksum mismatch for $asset" else echo "warning: no sha256 tool found, skipping checksum verification" >&2 fi tar -xzf "$tmp/$asset" -C "$tmp" # Default to /usr/local/bin, but never ask for sudo: fall back to ~/.local/bin # when it is not writable. An explicit POLIGN_BIN_DIR must work as given. bin_dir=${POLIGN_BIN_DIR:-/usr/local/bin} if [ ! -d "$bin_dir" ] || [ ! -w "$bin_dir" ]; then if [ -n "${POLIGN_BIN_DIR:-}" ]; then fail "$bin_dir is not a writable directory" fi bin_dir="$HOME/.local/bin" mkdir -p "$bin_dir" fi installed="" for b in polign polign-server polign-persistor polign-apikey polign-maintain; do if [ -f "$tmp/$b" ]; then cp "$tmp/$b" "$bin_dir/$b" chmod 0755 "$bin_dir/$b" installed="$installed $b" fi done [ -n "$installed" ] || fail "no binaries found in $asset" echo "installed$installed to $bin_dir" case ":$PATH:" in *":$bin_dir:"*) ;; *) echo "note: $bin_dir is not on your PATH; add it to your shell profile" ;; esac echo "start a development server with: polign-server"