#!/usr/bin/env bash set -euo pipefail APP_BASE_URL="https://app.buildbygrok.com" PACKAGE_URL="https://install.buildbygrok.com/downloads/grok-build-latest.tgz" CHECKSUM_URL="${PACKAGE_URL}.sha256" RUN_LOGIN=0 RUN_LAUNCH=1 LAUNCH_MODE="terminal" fail() { printf 'Build by Grok install failed: %s\n' "$1" >&2 exit 1 } usage() { cat < in that current folder. The CLI installs locally on your machine and does not connect GitHub by itself. Build by Grok uses the current local folder as the repo root when you start it. Run /login later only when you want the web workspace or GitHub-connected features. Git is optional unless you want git-specific flows like bootstrap, branch publish, or GitHub-connected workspace work. EOF } need_cmd() { command -v "$1" >/dev/null 2>&1 || fail "$1 is required." } has_cmd() { command -v "$1" >/dev/null 2>&1 } run_cli_with_tty() { if [ ! -r /dev/tty ] || [ ! -w /dev/tty ]; then fail "interactive CLI launch requires a terminal." fi "$@" /dev/tty 2>/dev/tty } resolve_cli_bin() { if command -v grok-build >/dev/null 2>&1; then command -v grok-build return fi prefix="$(npm config get prefix 2>/dev/null || npm prefix -g 2>/dev/null || true)" root="$(npm root -g 2>/dev/null || true)" for candidate in \ "${prefix}/bin/grok-build" \ "${prefix}/grok-build" \ "${prefix}/lib/node_modules/grok-build/dist/index.js" \ "${prefix}/node_modules/grok-build/dist/index.js" \ "${root}/../bin/grok-build" \ "${root}/grok-build/dist/index.js" do if [ -n "${candidate}" ] && [ -x "${candidate}" ]; then printf '%s\n' "${candidate}" return fi done return 1 } print_cli_path_notice() { prefix="$(npm config get prefix 2>/dev/null || npm prefix -g 2>/dev/null || true)" if [ -n "${prefix}" ]; then cat </dev/null 2>&1; then xdg-open "${url}" >/dev/null 2>&1 & return 0 fi if command -v open >/dev/null 2>&1; then open "${url}" >/dev/null 2>&1 & return 0 fi if command -v cmd.exe >/dev/null 2>&1; then cmd.exe /c start "" "${url}" >/dev/null 2>&1 return 0 fi return 1 } open_app_surface() { app_url="${APP_BASE_URL}/app/" printf '\nOpening the Build by Grok app...\n' if open_url "${app_url}"; then printf 'Opened %s\n' "${app_url}" return fi cat </dev/null 2>&1; then printf 'sha256sum' return fi if command -v shasum >/dev/null 2>&1; then printf 'shasum -a 256' return fi fail "sha256sum or shasum is required." } verify_checksum() { check_cmd="$(sha256_check_cmd)" if [ "${check_cmd}" = "sha256sum" ]; then ( cd "${TMPDIR}" sha256sum -c "${CHECKSUM_FILE}" ) >/dev/null return fi expected="$(awk '{print $1}' "${CHECKSUM_FILE}")" actual="$(shasum -a 256 "${PACKAGE_FILE}" | awk '{print $1}')" [ "${expected}" = "${actual}" ] || fail "checksum verification failed." } NODE_MAJOR="$(node -p "process.versions.node.split('.')[0]")" if [ "${NODE_MAJOR}" -lt 20 ]; then fail "Node.js 20 or newer is required. Found $(node -v)." fi printf 'Installing Build by Grok CLI from %s\n' "${PACKAGE_URL}" curl -fsSL "${PACKAGE_URL}" -o "${PACKAGE_FILE}" curl -fsSL "${CHECKSUM_URL}" -o "${CHECKSUM_FILE}" verify_checksum npm install -g "${PACKAGE_FILE}" NPM_GLOBAL_PREFIX="$(npm config get prefix 2>/dev/null || npm prefix -g 2>/dev/null || true)" if [ -n "${NPM_GLOBAL_PREFIX}" ] && [ -d "${NPM_GLOBAL_PREFIX}/bin" ]; then export PATH="${NPM_GLOBAL_PREFIX}/bin:${PATH}" fi CLI_BIN="$(resolve_cli_bin || true)" if [ "${RUN_LOGIN}" -eq 1 ] || [ "${RUN_LAUNCH}" -eq 1 ]; then run_onboarding_flow "${CLI_BIN}" exit 0 fi cat <