#!/bin/sh # Installs the Comity CLI (the npm package comity-cli) with your existing Node.js and npm. # curl -fsSL https://comity.so/install | sh # COMITY_CLI_VERSION picks a version or dist-tag (default: latest), e.g. COMITY_CLI_VERSION=next. # This script never installs Node.js, never uses sudo and sends nothing anywhere but the npm registry. set -eu NODE_MIN=22 PKG="comity-cli@${COMITY_CLI_VERSION:-latest}" fail() { printf 'comity: %s\n' "$1" >&2 exit 1 } command -v node >/dev/null 2>&1 || fail "Node.js $NODE_MIN or newer is required. Install it from https://nodejs.org, then run this again." command -v npm >/dev/null 2>&1 || fail "npm was not found. It ships with Node.js: https://nodejs.org" node_version=$(node -p 'process.versions.node' 2>/dev/null) || fail "could not run node. Reinstall Node.js $NODE_MIN or newer from https://nodejs.org" node_major=${node_version%%.*} [ "$node_major" -ge "$NODE_MIN" ] 2>/dev/null || fail "Node.js $NODE_MIN or newer is required (found $node_version). Update it from https://nodejs.org (or with nvm: nvm install $NODE_MIN)." printf 'Installing %s with npm (Node.js %s)...\n' "$PKG" "$node_version" log=$(mktemp "${TMPDIR:-/tmp}/comity-install.XXXXXX") trap 'rm -f "$log"' EXIT if ! npm install -g "$PKG" >"$log" 2>&1; then cat "$log" >&2 if grep -q -e EACCES -e EPERM "$log"; then prefix=$(npm prefix -g 2>/dev/null || echo "the global npm folder") cat >&2 </bin (into itself on Windows, e.g. Git Bash). prefix=$(npm prefix -g) command -v cygpath >/dev/null 2>&1 && prefix=$(cygpath -u "$prefix") bin="$prefix/bin" [ -e "$bin/comity" ] || bin="$prefix" [ -e "$bin/comity" ] || fail "npm finished but the comity command was not found in $prefix." version=$("$bin/comity" --version) || fail "comity was installed but 'comity --version' failed." case ":$PATH:" in *":$bin:"*) ;; *) printf '\nNote: %s is not on your PATH. Add it to your shell profile:\n export PATH="%s:$PATH"\n' "$bin" "$bin" ;; esac printf '\nInstalled comity %s.\nNext: run `comity login`, then `comity init` in your repo.\n' "$version"