#!/bin/sh # Installs the difinity command line: curl -fsSL https://get.difinity.ai | sh # It needs Node 20 or newer. It puts the program in ~/.difinity/app and a `difinity` # command in ~/.local/bin. It does not sign you in or change Claude Code or Codex; # run `difinity setup` for that. # # Settings (all optional): # DIFINITY_DOWNLOAD_URL where difinity.tgz and difinity.tgz.sha256 are served # DIFINITY_HOME install under here instead of ~/.difinity # DIFINITY_BIN_DIR put the command here instead of ~/.local/bin # DIFINITY_NO_MODIFY_PATH=1 do not add the command's folder to your shell profile set -eu BASE="${DIFINITY_DOWNLOAD_URL:-https://get.difinity.ai}" HOME_DIR="${DIFINITY_HOME:-$HOME/.difinity}" APP="$HOME_DIR/app" BIN_DIR="${DIFINITY_BIN_DIR:-$HOME/.local/bin}" say() { printf '%s\n' "$*"; } fail() { printf 'Install stopped: %s\n' "$*" >&2; exit 1; } command -v node >/dev/null 2>&1 || fail "Node.js 20 or newer is needed and was not found. Install it from https://nodejs.org, then run this again." MAJOR=$(node -p 'process.versions.node.split(".")[0]') [ "$MAJOR" -ge 20 ] || fail "Node.js $MAJOR is too old. Version 20 or newer is needed." command -v curl >/dev/null 2>&1 || fail "curl is needed and was not found." command -v tar >/dev/null 2>&1 || fail "tar is needed and was not found." TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT INT TERM say "Installing Difinity ..." curl -fsSL "$BASE/difinity.tgz" -o "$TMP/difinity.tgz" || fail "could not download $BASE/difinity.tgz" curl -fsSL "$BASE/difinity.tgz.sha256" -o "$TMP/difinity.tgz.sha256" || fail "could not download the checksum" WANT=$(awk '{print $1}' "$TMP/difinity.tgz.sha256") if command -v shasum >/dev/null 2>&1; then GOT=$(shasum -a 256 "$TMP/difinity.tgz" | awk '{print $1}') elif command -v sha256sum >/dev/null 2>&1; then GOT=$(sha256sum "$TMP/difinity.tgz" | awk '{print $1}') else fail "shasum or sha256sum is needed to check the download."; fi [ "$WANT" = "$GOT" ] || fail "the download did not match its checksum. Nothing was installed." mkdir -p "$TMP/app" "$HOME_DIR" "$BIN_DIR" tar -xzf "$TMP/difinity.tgz" -C "$TMP/app" [ -f "$TMP/app/bin/difinity.mjs" ] || fail "the download is not a Difinity release." # Swap the new copy in. The old one stays until the new one is in place. rm -rf "$APP.old" [ -d "$APP" ] && mv "$APP" "$APP.old" mv "$TMP/app" "$APP" rm -rf "$APP.old" LAUNCHER="$BIN_DIR/difinity" printf '#!/bin/sh\nexec node "%s/bin/difinity.mjs" "$@"\n' "$APP" > "$LAUNCHER" chmod 755 "$LAUNCHER" say "Installed Difinity $("$LAUNCHER" version) to $APP" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) LINE="export PATH=\"$BIN_DIR:\$PATH\"" PROFILE="" case "${SHELL:-}" in */zsh) PROFILE="$HOME/.zshrc" ;; */bash) if [ -f "$HOME/.bash_profile" ]; then PROFILE="$HOME/.bash_profile"; else PROFILE="$HOME/.bashrc"; fi ;; esac if [ -n "$PROFILE" ] && [ "${DIFINITY_NO_MODIFY_PATH:-}" != "1" ]; then if ! grep -qF "$BIN_DIR" "$PROFILE" 2>/dev/null; then printf '\n# Added by the Difinity installer\n%s\n' "$LINE" >> "$PROFILE"; fi say "Added $BIN_DIR to your PATH in $PROFILE. Open a new terminal, or run:" else say "Add Difinity to your PATH by running:" fi say " $LINE" ;; esac say "" say "Next, run: difinity setup"