#!/usr/bin/env bash # Diazolvera Jumpstart v0.15 — bundled for curl | bash # Source: https://gitlab.com/doprofessional/diazolvera-jumpstart set -euo pipefail JUMPSTART_VERSION="0.15" JUMPSTART_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" DEBUG_LOG="${HOME}/.config/diazolvera/jumpstart-debug.log" SESSION_DEBUG_LOG="/home/liveuser/.cursor/debug-1745c1.log" BITBUCKET_WORKSPACE="${BITBUCKET_WORKSPACE:-diazolvera}" GITLAB_HOST="${GITLAB_HOST:-gitlab.com}" BB_BIN="${BB_BIN:-${HOME}/.local/bin/bb}" RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $*"; } log_ok() { echo -e "${GREEN}[OK]${NC} $*"; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } log_error() { echo -e "${RED}[ERROR]${NC} $*"; } command_exists() { command -v "$1" >/dev/null 2>&1; } ensure_path() { export PATH="${HOME}/.local/bin:${HOME}/bin:${PATH}" } #region agent log jumpstart_debug() { local message="$1" local data="$2" local hypothesis_id="${3:-H0}" local ts ts="$(($(date +%s) * 1000))" local line line="$(printf '{"sessionId":"1745c1","timestamp":%s,"location":"jumpstart.sh","message":"%s","data":%s,"runId":"v%s","hypothesisId":"%s"}\n' \ "${ts}" "${message}" "${data}" "${JUMPSTART_VERSION}" "${hypothesis_id}")" mkdir -p "$(dirname "${DEBUG_LOG}")" printf '%s' "${line}" >> "${DEBUG_LOG}" 2>/dev/null || true printf '%s' "${line}" >> "${SESSION_DEBUG_LOG}" 2>/dev/null || true } #endregion require_tty() { if [[ ! -t 0 || ! -t 1 ]]; then log_error "Interactive TTY required for OAuth/token prompts." jumpstart_debug "tty missing" '{"ok":false}' "H1" return 1 fi jumpstart_debug "tty attached" '{"ok":true}' "H1" } oauth_with_qr() { local URL_REGEX="$1" shift [[ "${1:-}" == "--" ]] && shift local LOG_FILE PID URL EC LOG_FILE="$(mktemp)" trap 'rm -f "${LOG_FILE}"' RETURN "$@" 2>&1 | tee "${LOG_FILE}" & PID=$! URL="" for _ in $(seq 1 120); do URL="$(grep -oE "${URL_REGEX}" "${LOG_FILE}" 2>/dev/null | head -1 || true)" [[ -n "${URL}" ]] && break kill -0 "${PID}" 2>/dev/null || break sleep 0.5 done if [[ -n "${URL}" ]]; then echo ">>> Scan on phone — complete auth before this session exits:" command -v qrencode >/dev/null 2>&1 && qrencode -t ANSIUTF8 "${URL}" || echo ">>> URL: ${URL}" fi wait "${PID}" && return 0 EC=$? return "${EC}" } # --- deps.sh --- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=common.sh install_bb() { if [[ -x "${BB_BIN}" ]]; then return 0 fi if command_exists bb; then BB_BIN="$(command -v bb)" return 0 fi log_info "Installing Bitbucket CLI (bb)..." mkdir -p "${HOME}/.local/bin" local tmp="/tmp/bb-install.$$" mkdir -p "${tmp}" curl -fsSL -o "${tmp}/bb.tar.gz" \ "https://github.com/rbansal42/bitbucket-cli/releases/download/v0.3.2/bb_0.3.2_linux_amd64.tar.gz" tar xzf "${tmp}/bb.tar.gz" -C "${tmp}" mv "${tmp}/bb" "${HOME}/.local/bin/bb" chmod +x "${HOME}/.local/bin/bb" BB_BIN="${HOME}/.local/bin/bb" rm -rf "${tmp}" } jumpstart_deps() { ensure_path log_info "Checking dependencies..." if ! command_exists glab; then log_info "Installing glab..." sudo dnf install -y glab fi glab config set -g git_protocol https 2>/dev/null || true git config --global credential.helper '!glab auth git-credential' 2>/dev/null || true install_bb if ! command_exists agent; then log_info "Installing Cursor CLI..." curl -fsSL https://cursor.com/install | bash ensure_path fi if ! command_exists qrencode; then log_info "Installing qrencode (OAuth QR display)..." sudo dnf install -y qrencode fi jumpstart_debug "deps ok" '{"ok":true}' "H4" log_ok "Dependencies ready (glab, bb, agent, qrencode)" } # --- gitlab-auth.sh --- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=common.sh gitlab_already_authed() { glab auth status --hostname "${GITLAB_HOST}" >/dev/null 2>&1 } jumpstart_gitlab() { ensure_path if gitlab_already_authed; then jumpstart_debug "gitlab skip" '{"already":true}' "H5" log_ok "GitLab already authenticated ($(glab auth status --hostname "${GITLAB_HOST}" 2>&1 | grep -o 'as [^ ]*' | head -1 || echo ok))" return 0 fi require_tty || return 1 log_info "GitLab auth (${GITLAB_HOST}) — device OAuth..." if oauth_with_qr 'https://[^[:space:]]+' -- glab auth login --hostname "${GITLAB_HOST}" --device; then jumpstart_debug "gitlab oauth finished" '{"cmd_exit":0}' "H5" else jumpstart_debug "gitlab oauth finished" '{"cmd_exit":1}' "H5" log_error "GitLab auth failed" return 1 fi if gitlab_already_authed; then jumpstart_debug "gitlab ok" '{"ok":true}' "H5" log_ok "GitLab authenticated" return 0 fi jumpstart_debug "gitlab ok" '{"ok":false}' "H5" log_error "GitLab auth status check failed after login" return 1 } # --- bitbucket-auth.sh --- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=common.sh bb_cmd() { ensure_path if [[ -x "${BB_BIN}" ]]; then "${BB_BIN}" "$@" elif command_exists bb; then bb "$@" else log_error "bb CLI not found" return 127 fi } bitbucket_already_authed() { bb_cmd auth status 2>&1 | grep -q 'Logged in to' } validate_bitbucket_token() { local token="$1" local http_code http_code="$(curl -sS -o /dev/null -w "%{http_code}" \ --header "Authorization: Bearer ${token}" \ "https://api.bitbucket.org/2.0/user" 2>/dev/null || echo "000")" [[ "${http_code}" == "200" ]] } jumpstart_bitbucket() { ensure_path if bitbucket_already_authed; then jumpstart_debug "bitbucket skip" '{"already":true}' "H9" log_ok "Bitbucket already authenticated" return 0 fi if [[ -n "${BITBUCKET_API_TOKEN:-}" ]]; then log_info "Bitbucket auth via BITBUCKET_API_TOKEN..." if printf '%s' "${BITBUCKET_API_TOKEN}" | bb_cmd auth login --with-token; then jumpstart_debug "bitbucket token login" '{"ok":true,"source":"env"}' "H9" else jumpstart_debug "bitbucket token login" '{"ok":false,"source":"env"}' "H9" log_error "Bitbucket token auth failed" return 1 fi elif [[ -t 0 ]] || [[ -e /dev/tty ]]; then log_info "Bitbucket auth — OAuth (scan QR on phone)..." export NO_OPEN_BROWSER=1 if oauth_with_qr 'https://bitbucket.org[^[:space:]]+' -- bb_cmd auth login; then jumpstart_debug "bitbucket oauth finished" '{"cmd_exit":0}' "H9" else jumpstart_debug "bitbucket oauth finished" '{"cmd_exit":1}' "H9" log_error "Bitbucket OAuth failed" return 1 fi else jumpstart_debug "bitbucket no creds" '{"ok":false,"tty":false}' "H9" log_error "No Bitbucket credentials. Set BITBUCKET_API_TOKEN or run interactively." return 1 fi if bitbucket_already_authed; then jumpstart_debug "bitbucket ok" '{"ok":true}' "H9" log_ok "Bitbucket authenticated (workspace: ${BITBUCKET_WORKSPACE})" if bb_cmd repo list --workspace "${BITBUCKET_WORKSPACE}" >/dev/null 2>&1; then jumpstart_debug "bitbucket workspace ok" "{\"workspace\":\"${BITBUCKET_WORKSPACE}\"}" "H10" else log_warn "Authenticated but could not list workspace ${BITBUCKET_WORKSPACE}" jumpstart_debug "bitbucket workspace fail" "{\"workspace\":\"${BITBUCKET_WORKSPACE}\"}" "H10" fi return 0 fi jumpstart_debug "bitbucket ok" '{"ok":false}' "H9" log_error "Bitbucket auth status check failed after login" return 1 } # --- cursor-auth.sh --- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=common.sh cursor_already_authed() { ensure_path agent status >/dev/null 2>&1 } jumpstart_cursor() { ensure_path if ! command_exists agent; then log_error "Cursor CLI (agent) not installed" return 1 fi jumpstart_debug "cursor installed" '{"ok":true}' "H6" if cursor_already_authed; then jumpstart_debug "cursor skip" '{"already":true}' "H7" log_ok "Cursor already authenticated" return 0 fi require_tty || return 1 log_info "Cursor auth — browser OAuth..." if oauth_with_qr 'https://cursor.com/loginDeepControl[^[:space:]]+' -- agent login; then jumpstart_debug "cursor oauth finished" '{"cmd_exit":0}' "H7" else jumpstart_debug "cursor oauth finished" '{"cmd_exit":1}' "H7" log_error "Cursor auth failed" return 1 fi if cursor_already_authed; then jumpstart_debug "cursor ok" '{"ok":true}' "H7" log_ok "Cursor authenticated" return 0 fi jumpstart_debug "cursor ok" '{"ok":false}' "H7" log_warn "agent login finished but agent status check inconclusive" return 0 } attach_tty() { if [[ -e /dev/tty ]] && exec 3<>/dev/tty 2>/dev/null; then exec 0<&3 jumpstart_debug "tty attached" '{"ok":true}' "H1" fi } echo "Diazolvera Jumpstart v0.15" echo "Phases: GitLab → Bitbucket → Cursor" attach_tty ensure_path jumpstart_deps jumpstart_gitlab jumpstart_bitbucket jumpstart_cursor log_ok "Jumpstart complete"