#!/bin/sh # DeployHQ CLI installer # Usage: curl -fsSL https://deployhq.com/install/cli | sh set -e REPO="deployhq/deployhq-cli" BINARY="dhq" # Detect OS and architecture OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) case "$ARCH" in x86_64|amd64) ARCH="amd64" ;; arm64|aarch64) ARCH="arm64" ;; *) echo "Unsupported architecture: $ARCH"; exit 1 ;; esac case "$OS" in linux|darwin) ;; mingw*|msys*|cygwin*) OS="windows" ;; *) echo "Unsupported OS: $OS"; exit 1 ;; esac # Determine install directory # Priority: explicit env var > existing binary location > writable defaults if [ -n "$INSTALL_DIR" ]; then # Explicit override via env var : elif EXISTING=$(command -v "$BINARY" 2>/dev/null); then # Update in place — install where the current binary lives INSTALL_DIR=$(dirname "$EXISTING") elif [ -w "/usr/local/bin" ]; then INSTALL_DIR="/usr/local/bin" elif [ -d "$HOME/.local/bin" ] || mkdir -p "$HOME/.local/bin" 2>/dev/null; then INSTALL_DIR="$HOME/.local/bin" else INSTALL_DIR="/usr/local/bin" fi # Get latest version echo "Fetching latest version..." VERSION=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/') if [ -z "$VERSION" ]; then echo "Error: could not determine latest version" exit 1 fi echo "Installing dhq v$VERSION ($OS/$ARCH)..." # Download EXT="tar.gz" if [ "$OS" = "windows" ]; then EXT="zip" fi URL="https://github.com/$REPO/releases/download/v$VERSION/${BINARY}_${VERSION}_${OS}_${ARCH}.${EXT}" TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT echo "Downloading $URL..." curl -fsSL "$URL" -o "$TMP/archive.$EXT" # Extract cd "$TMP" if [ "$EXT" = "zip" ]; then unzip -q "archive.$EXT" else tar xzf "archive.$EXT" fi # Install if [ -w "$INSTALL_DIR" ]; then mv "$BINARY" "$INSTALL_DIR/$BINARY" else echo "Installing to $INSTALL_DIR (requires sudo)..." sudo mv "$BINARY" "$INSTALL_DIR/$BINARY" fi chmod +x "$INSTALL_DIR/$BINARY" echo "" echo "dhq v$VERSION installed to $INSTALL_DIR/$BINARY" # Check if install dir is in PATH case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) echo "" echo "NOTE: $INSTALL_DIR is not in your PATH." echo "Add it by running:" echo "" if [ -f "$HOME/.zshrc" ]; then echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.zshrc && source ~/.zshrc" else echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.bashrc && source ~/.bashrc" fi echo "" ;; esac echo "" echo "Get started:" echo " dhq hello (guided onboarding)" echo " dhq auth login (or login directly)" echo " dhq --help"