#!/bin/sh # azrouter CLI installer, as https://azrouter.dev/install.sh serves it. # # azrouter.dev fills in the PIN_ lines below each time it serves this script: the latest release, after checking its # manifest's signature against the release key built into the site (apps/web/src/lib/cli-install.ts). The archive # comes from the download site, cli.azrouter.dev, and runs only if its sha256 is the pinned one: the download site # alone cannot change what runs here. # # Installs `azrouter` into ~/.local/bin (no sudo: it updates itself there), plus `az` as a shortcut unless another # `az` is already on PATH (the Azure CLI owns that name). An existing az that is not azrouter's is never replaced. # # Usage: # curl -fsSL https://azrouter.dev/install.sh | sh # curl -fsSL https://azrouter.dev/install.sh | sh -s -- --prefix=/opt/azrouter # curl -fsSL https://azrouter.dev/install.sh | sh -s -- --no-az # skip the az shortcut # curl -fsSL https://azrouter.dev/install.sh | sh -s -- --az # az even with another az on PATH (never over a file) set -eu PIN_VERSION="1.1.22" PIN_SHA256_LINUX_AMD64="ffcc08efc6085c1fd303f2f5bd68ba29ab835d53ebd718df8785cc559696ddb9" PIN_SHA256_LINUX_ARM64="281f9e3d7a3c7930e5fe3f2ffe3902196268208badafbdaaae959f689e99cb8c" PIN_SHA256_DARWIN_AMD64="4ec81d894015d49cb42964b2200259972394608b693cd5cb37d47933a1c1839e" PIN_SHA256_DARWIN_ARM64="9cc26c3cbb2d00e95a34d344bd56f81aa768939541b824fd5a67be2e3388159b" PIN_BASE="https://cli.azrouter.dev" BASE="${AZROUTER_DOWNLOAD_BASE:-$PIN_BASE}" PREFIX="${HOME}/.local" INSTALL_AZ=auto while [ "$#" -gt 0 ]; do case "$1" in --prefix=*) PREFIX="${1#*=}"; shift ;; --prefix) PREFIX="$2"; shift 2 ;; --no-az) INSTALL_AZ=no; shift ;; --az) INSTALL_AZ=yes; shift ;; --version|--version=*) echo "--version is not offered: this installs the latest release, and azrouter updates itself after." >&2; exit 1 ;; *) echo "Unknown option: $1" >&2; exit 1 ;; esac done if [ -z "$PIN_VERSION" ]; then echo "This copy of the installer pins no release. Install with: curl -fsSL https://azrouter.dev/install.sh | sh" >&2 exit 1 fi OS="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m)" case "$ARCH" in x86_64|amd64) ARCH="amd64" ;; arm64|aarch64) ARCH="arm64" ;; *) echo "Unsupported CPU: $ARCH (azrouter runs on x86_64 and arm64)" >&2; exit 1 ;; esac case "$OS" in darwin|linux) ;; *) echo "Unsupported system: $OS (this installer is for Linux and macOS; on Windows, in PowerShell: irm https://azrouter.dev/install.ps1 | iex)" >&2; exit 1 ;; esac case "${OS}_${ARCH}" in linux_amd64) EXPECTED="$PIN_SHA256_LINUX_AMD64" ;; linux_arm64) EXPECTED="$PIN_SHA256_LINUX_ARM64" ;; darwin_amd64) EXPECTED="$PIN_SHA256_DARWIN_AMD64" ;; darwin_arm64) EXPECTED="$PIN_SHA256_DARWIN_ARM64" ;; esac BIN_DIR="$PREFIX/bin" OURS="$BIN_DIR/azrouter" az_ours() { [ -L "$BIN_DIR/az" ] && [ "$(readlink "$BIN_DIR/az")" = "$OURS" ]; } az_taken() { { [ -e "$BIN_DIR/az" ] || [ -L "$BIN_DIR/az" ]; } && ! az_ours; } # --az takes the name from another az on PATH, never from a file already at $BIN_DIR/az: checked before anything is # downloaded, so a refusal leaves the machine as it was. if [ "$INSTALL_AZ" = "yes" ] && az_taken; then echo "$BIN_DIR/az already exists and is not azrouter's: --az never replaces it. Nothing was installed." >&2 echo "Move it away yourself, or install without --az ('azrouter' is the same program)." >&2 exit 1 fi if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL -o "$2" "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -q -O "$2" "$1"; } else echo "curl or wget is required." >&2; exit 1 fi if command -v sha256sum >/dev/null 2>&1; then sha256() { sha256sum "$1" | awk '{print $1}'; } elif command -v shasum >/dev/null 2>&1; then sha256() { shasum -a 256 "$1" | awk '{print $1}'; } else echo "sha256sum or shasum is required to verify the download." >&2; exit 1 fi TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT TARBALL="azrouter_${PIN_VERSION}_${OS}_${ARCH}.tar.gz" echo "Downloading azrouter $PIN_VERSION ($OS/$ARCH)" fetch "$BASE/v$PIN_VERSION/$TARBALL" "$TMP/$TARBALL" || { echo "Could not download $BASE/v$PIN_VERSION/$TARBALL." >&2; exit 1; } ACTUAL="$(sha256 "$TMP/$TARBALL")" if [ "$ACTUAL" != "$EXPECTED" ]; then echo "$TARBALL is not the release azrouter.dev pinned (sha256 $ACTUAL, expected $EXPECTED). Nothing was installed." >&2 exit 1 fi echo "Checksum verified against the release azrouter.dev pinned." mkdir -p "$TMP/x" tar -xzf "$TMP/$TARBALL" -C "$TMP/x" azrouter mkdir -p "$BIN_DIR" # Into place by a rename, so a running azrouter is never half overwritten. cp "$TMP/x/azrouter" "$BIN_DIR/.azrouter.new" chmod 0755 "$BIN_DIR/.azrouter.new" [ "$OS" = "darwin" ] && xattr -d com.apple.quarantine "$BIN_DIR/.azrouter.new" 2>/dev/null || true mv -f "$BIN_DIR/.azrouter.new" "$OURS" # az shortcut: ours if free, or already ours. Never over anything else (ln without -f). AZ=no if [ "$INSTALL_AZ" = "no" ]; then echo "Skipping the 'az' shortcut (--no-az)." elif az_ours; then AZ=yes elif az_taken; then echo "Skipping the 'az' shortcut: $BIN_DIR/az already exists. Use 'azrouter' instead." elif [ "$INSTALL_AZ" = "auto" ] && command -v az >/dev/null 2>&1; then echo "Skipping the 'az' shortcut: $(command -v az) is already on your PATH (the Azure CLI?). Use 'azrouter' instead," echo "or pass --az to put azrouter's az in $BIN_DIR." elif ln -s "$OURS" "$BIN_DIR/az" 2>/dev/null; then AZ=yes else echo "Skipping the 'az' shortcut: could not create $BIN_DIR/az. Use 'azrouter' instead." fi echo "Installed: $("$OURS" version)" if [ "$AZ" = "yes" ]; then echo "Commands: azrouter, az"; else echo "Command: azrouter"; fi case ":$PATH:" in *":$BIN_DIR:"*) ;; *) echo echo "$BIN_DIR is not on your PATH. Add it, then open a new terminal:" echo " echo 'export PATH=\"$BIN_DIR:\$PATH\"' >> ~/.profile" ;; esac echo echo "Next: azrouter login"