#!/usr/bin/env bash set -euo pipefail # Accessible ANSI output; no extra TUI dependency or font installation. CARLOS_COL='' ; CARLOS_RESET='' ; CARLOS_SUCCESS='' if [ -t 1 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-dumb}" != dumb ]; then CARLOS_COL=$'\033[1;35m'; CARLOS_RESET=$'\033[0m'; CARLOS_SUCCESS=$'\033[32m' fi CARLOS_COLS=80 if command -v tput >/dev/null 2>&1; then CARLOS_COLS="$(tput cols 2>/dev/null || printf 80)"; fi if [[ ! "$CARLOS_COLS" =~ ^[0-9]+$ ]]; then CARLOS_COLS=80; fi if [ "$CARLOS_COLS" -ge 64 ]; then printf '%s' "$CARLOS_COL" cat <<'CARLOS_LOGO' ██████╗ █████╗ ██████╗ ██╗ ██████╗ ███████╗ ██╔════╝██╔══██╗██╔══██╗██║ ██╔═══██╗██╔════╝ ██║ ███████║██████╔╝██║ ██║ ██║███████╗ ██║ ██╔══██║██╔══██╗██║ ██║ ██║╚════██║ ╚██████╗██║ ██║██║ ██║███████╗╚██████╔╝███████║ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚══════╝ CARLOS_LOGO printf '%s' "$CARLOS_RESET" else printf '%s◆ CARLOS%s\n' "$CARLOS_COL" "$CARLOS_RESET" fi printf ' Your AI. Your Computer. Connected.\n\n' carlos_done(){ printf ' %s✓%s %s\n' "$CARLOS_SUCCESS" "$CARLOS_RESET" "$1"; } carlos_current(){ printf ' ◉ %s\n' "$1"; } carlos_warning(){ printf ' ! %s\n' "$1"; } CARLOS_HOME="${CARLOS_HOME:-$HOME/.carlos}" RUNTIME="$CARLOS_HOME/runtime" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT # Create the runtime only after the non-destructive preview has finished. # Ask the customer in the terminal itself. curl | bash uses stdin for the script; # read from the controlling TTY, never from the installer program. CARLOS_LANG_FILE="$CARLOS_HOME/language" LANGUAGE_CODES=(en fr de es it pt nl pl sv da fi no cs ro hu tr ja ko zh) LANGUAGE_NAMES=("English" "Français" "Deutsch" "Español" "Italiano" "Português" "Nederlands" "Polski" "Svenska" "Dansk" "Suomi" "Norsk" "Čeština" "Română" "Magyar" "Türkçe" "日本語" "한국어" "中文") if [ -n "${CARLOS_LANG:-}" ]; then CARLOS_LANGUAGE="$CARLOS_LANG" elif [ -r "$CARLOS_LANG_FILE" ]; then CARLOS_LANGUAGE="$(head -n 1 "$CARLOS_LANG_FILE")" else systemLang="${LC_ALL:-${LC_MESSAGES:-${LANG:-en}}}" CARLOS_LANGUAGE="$(printf '%s' "$systemLang" | tr '[:upper:]' '[:lower:]' | cut -d '_' -f 1 | cut -d '-' -f 1)" case " ${LANGUAGE_CODES[*]} " in *" $CARLOS_LANGUAGE "*) ;; *) CARLOS_LANGUAGE=en ;; esac if [ -t 1 ] && [ -r /dev/tty ]; then printf '\nCarlos · Choose your language / Choisissez votre langue\n' >/dev/tty for i in "${!LANGUAGE_CODES[@]}"; do printf ' %2d. %s (%s)\n' "$((i+1))" "${LANGUAGE_NAMES[$i]}" "${LANGUAGE_CODES[$i]}" >/dev/tty done printf 'Language / Langue [%s]: ' "$CARLOS_LANGUAGE" >/dev/tty IFS= read -r answer "$CARLOS_LANG_FILE" chmod 600 "$CARLOS_LANG_FILE" export CARLOS_LANG="$CARLOS_LANGUAGE" case "$CARLOS_LANGUAGE" in en) CARLOS_TXT_1='Installing the Carlos agent…' CARLOS_TXT_2='Approve this computer in the browser that opens.' CARLOS_TXT_3='Carlos Remote agent installed.' CARLOS_TXT_4='Check the terminal status and run carlos doctor.' CARLOS_TXT_5='Carlos Remote is ready. Connect your AI assistant to the Carlos MCP connector.' ;; fr) CARLOS_TXT_1='Installation de l’agent Carlos…' CARLOS_TXT_2='Autorisez cet ordinateur dans le navigateur qui s’ouvre.' CARLOS_TXT_3='Agent Carlos Remote installé.' CARLOS_TXT_4='Vérifiez l’état du terminal avec carlos doctor.' CARLOS_TXT_5='Carlos Remote est prêt. Connectez votre assistant IA au connecteur Carlos MCP.' ;; de) CARLOS_TXT_1='Carlos-Agent wird installiert…' CARLOS_TXT_2='Bestätige diesen Computer im Browser.' CARLOS_TXT_3='Carlos Remote-Agent installiert.' CARLOS_TXT_4='Prüfe den Status mit carlos doctor.' CARLOS_TXT_5='Carlos Remote ist bereit. Verbinde deinen KI-Assistenten mit Carlos MCP.' ;; es) CARLOS_TXT_1='Instalando el agente Carlos…' CARLOS_TXT_2='Autoriza este ordenador en el navegador.' CARLOS_TXT_3='Agente Carlos Remote instalado.' CARLOS_TXT_4='Comprueba el estado con carlos doctor.' CARLOS_TXT_5='Carlos Remote está listo. Conecta tu asistente de IA a Carlos MCP.' ;; it) CARLOS_TXT_1='Installazione agente Carlos…' CARLOS_TXT_2='Autorizza questo computer nel browser.' CARLOS_TXT_3='Agente Carlos Remote installato.' CARLOS_TXT_4='Controlla lo stato con carlos doctor.' CARLOS_TXT_5='Carlos Remote è pronto. Collega il tuo assistente IA a Carlos MCP.' ;; pt) CARLOS_TXT_1='A instalar o agente Carlos…' CARLOS_TXT_2='Autoriza este computador no navegador.' CARLOS_TXT_3='Agente Carlos Remote instalado.' CARLOS_TXT_4='Verifica o estado com carlos doctor.' CARLOS_TXT_5='Carlos Remote está pronto. Liga o teu assistente de IA ao Carlos MCP.' ;; nl) CARLOS_TXT_1='Carlos-agent installeren…' CARLOS_TXT_2='Keur deze computer goed in de browser.' CARLOS_TXT_3='Carlos Remote-agent geïnstalleerd.' CARLOS_TXT_4='Controleer de status met carlos doctor.' CARLOS_TXT_5='Carlos Remote is klaar. Verbind je AI-assistent met Carlos MCP.' ;; pl) CARLOS_TXT_1='Instalowanie agenta Carlos…' CARLOS_TXT_2='Autoryzuj komputer w przeglądarce.' CARLOS_TXT_3='Agent Carlos Remote zainstalowany.' CARLOS_TXT_4='Sprawdź stan przez carlos doctor.' CARLOS_TXT_5='Carlos Remote jest gotowy. Połącz asystenta AI z Carlos MCP.' ;; sv) CARLOS_TXT_1='Installerar Carlos-agenten…' CARLOS_TXT_2='Godkänn datorn i webbläsaren.' CARLOS_TXT_3='Carlos Remote-agenten installerad.' CARLOS_TXT_4='Kontrollera med carlos doctor.' CARLOS_TXT_5='Carlos Remote är redo. Anslut din AI-assistent till Carlos MCP.' ;; da) CARLOS_TXT_1='Installerer Carlos-agenten…' CARLOS_TXT_2='Godkend computeren i browseren.' CARLOS_TXT_3='Carlos Remote-agent installeret.' CARLOS_TXT_4='Kontroller med carlos doctor.' CARLOS_TXT_5='Carlos Remote er klar. Forbind din AI-assistent til Carlos MCP.' ;; fi) CARLOS_TXT_1='Asennetaan Carlos-agenttia…' CARLOS_TXT_2='Hyväksy tietokone selaimessa.' CARLOS_TXT_3='Carlos Remote-agentti asennettu.' CARLOS_TXT_4='Tarkista tila komennolla carlos doctor.' CARLOS_TXT_5='Carlos Remote on valmis. Yhdistä tekoälyavustajasi Carlos MCP:hen.' ;; no) CARLOS_TXT_1='Installerer Carlos-agenten…' CARLOS_TXT_2='Godkjenn datamaskinen i nettleseren.' CARLOS_TXT_3='Carlos Remote-agent installert.' CARLOS_TXT_4='Kontroller med carlos doctor.' CARLOS_TXT_5='Carlos Remote er klar. Koble KI-assistenten til Carlos MCP.' ;; cs) CARLOS_TXT_1='Instaluje se agent Carlos…' CARLOS_TXT_2='Povolte počítač v prohlížeči.' CARLOS_TXT_3='Agent Carlos Remote nainstalován.' CARLOS_TXT_4='Ověřte stav pomocí carlos doctor.' CARLOS_TXT_5='Carlos Remote je připraven. Připojte AI asistenta ke Carlos MCP.' ;; ro) CARLOS_TXT_1='Se instalează agentul Carlos…' CARLOS_TXT_2='Autorizează computerul în browser.' CARLOS_TXT_3='Agent Carlos Remote instalat.' CARLOS_TXT_4='Verifică starea cu carlos doctor.' CARLOS_TXT_5='Carlos Remote este gata. Conectează asistentul AI la Carlos MCP.' ;; hu) CARLOS_TXT_1='Carlos ügynök telepítése…' CARLOS_TXT_2='Engedélyezd a számítógépet a böngészőben.' CARLOS_TXT_3='Carlos Remote ügynök telepítve.' CARLOS_TXT_4='Ellenőrizd a carlos doctor paranccsal.' CARLOS_TXT_5='Carlos Remote kész. Csatlakoztasd AI-asszisztensed a Carlos MCP-hez.' ;; tr) CARLOS_TXT_1='Carlos aracısı yükleniyor…' CARLOS_TXT_2='Bilgisayarı tarayıcıda onaylayın.' CARLOS_TXT_3='Carlos Remote aracısı yüklendi.' CARLOS_TXT_4='carlos doctor ile durumu kontrol edin.' CARLOS_TXT_5='Carlos Remote hazır. Yapay zekâ asistanınızı Carlos MCP’ye bağlayın.' ;; ja) CARLOS_TXT_1='Carlosエージェントをインストール中…' CARLOS_TXT_2='ブラウザでこのコンピューターを承認してください。' CARLOS_TXT_3='Carlos Remoteエージェントをインストールしました。' CARLOS_TXT_4='carlos doctorで接続を確認してください。' CARLOS_TXT_5='Carlos Remoteの準備ができました。AIアシスタントをCarlos MCPに接続してください。' ;; ko) CARLOS_TXT_1='Carlos 에이전트 설치 중…' CARLOS_TXT_2='브라우저에서 이 컴퓨터를 승인하세요.' CARLOS_TXT_3='Carlos Remote 에이전트가 설치되었습니다.' CARLOS_TXT_4='carlos doctor로 상태를 확인하세요.' CARLOS_TXT_5='Carlos Remote가 준비되었습니다. AI 어시스턴트를 Carlos MCP에 연결하세요.' ;; zh) CARLOS_TXT_1='正在安装 Carlos 代理…' CARLOS_TXT_2='请在浏览器中授权此电脑。' CARLOS_TXT_3='Carlos Remote 代理已安装。' CARLOS_TXT_4='请运行 carlos doctor 检查状态。' CARLOS_TXT_5='Carlos Remote 已就绪。请将 AI 助手连接到 Carlos MCP。' ;; esac use_system=false use_private=false if [ -x "$CARLOS_HOME/node/bin/node" ] && [ -x "$CARLOS_HOME/node/bin/npm" ]; then private_major="$("$CARLOS_HOME/node/bin/node" -p 'Number(process.versions.node.split(".")[0])' 2>/dev/null || echo 0)" if [ "$private_major" -ge 20 ]; then use_private=true; fi fi if command -v node >/dev/null 2>&1 && command -v npm >/dev/null 2>&1; then major="$(node -p 'Number(process.versions.node.split(".")[0])' 2>/dev/null || echo 0)" if [ "$major" -ge 20 ]; then use_system=true; fi fi if [ "$use_private" = true ]; then NODE_BIN="$CARLOS_HOME/node/bin/node" NPM_BIN="$CARLOS_HOME/node/bin/npm" elif [ "$use_system" = true ]; then NODE_BIN="$(command -v node)" NPM_BIN="$(command -v npm)" else case "$(uname -s)" in Darwin) platform=darwin ;; Linux) platform=linux ;; *) echo "Carlos: système non pris en charge par cet installateur."; exit 1 ;; esac case "$(uname -m)" in arm64|aarch64) arch=arm64 ;; x86_64|amd64) arch=x64 ;; *) echo "Carlos: architecture non prise en charge."; exit 1 ;; esac index="$(curl -fsSL https://nodejs.org/dist/latest-v22.x/)" file="$(printf '%s' "$index" | grep -oE "node-v[0-9.]+-$platform-$arch[.]tar[.]gz" | head -1)" [ -n "$file" ] || { echo "Carlos: runtime Node introuvable."; exit 1; } curl -fsSL "https://nodejs.org/dist/latest-v22.x/$file" -o "$TMP/$file" curl -fsSL https://nodejs.org/dist/latest-v22.x/SHASUMS256.txt -o "$TMP/node-SHASUMS256.txt" node_expected="$(awk -v name="$file" '$2==name{print $1}' "$TMP/node-SHASUMS256.txt")" if command -v shasum >/dev/null 2>&1; then node_actual="$(shasum -a 256 "$TMP/$file" | cut -d ' ' -f 1)" elif command -v sha256sum >/dev/null 2>&1; then node_actual="$(sha256sum "$TMP/$file" | cut -d ' ' -f 1)" else echo "Carlos: utilitaire SHA-256 absent sur ce système."; exit 1 fi [ -n "$node_expected" ] && [ "$node_expected" = "$node_actual" ] || { echo "Carlos: archive Node.js non vérifiée."; exit 1; } tar -xzf "$TMP/$file" -C "$TMP" rm -rf "$CARLOS_HOME/node" folder="$(printf '%s' "$file" | sed 's/[.]tar[.]gz$//')" mv "$TMP/$folder" "$CARLOS_HOME/node" NODE_BIN="$CARLOS_HOME/node/bin/node" NPM_BIN="$CARLOS_HOME/node/bin/npm" fi export PATH="$(dirname "$NODE_BIN"):$PATH" case "$(uname -s)" in Darwin|Linux) ;; *) carlos_warning 'Unsupported operating system / Système non pris en charge'; exit 1 ;; esac case "$(uname -m)" in arm64|aarch64|x86_64|amd64) ;; *) carlos_warning 'Unsupported CPU / Architecture non prise en charge'; exit 1 ;; esac carlos_done "$CARLOS_LANGUAGE · $(uname -s) · $(uname -m)" carlos_current "$CARLOS_TXT_1" # Never downgrade a newer Carlos agent already present in the private runtime. EXISTING_PACKAGE="$RUNTIME/lib/node_modules/carlos-remote/package.json" SKIP_INSTALL=false if [ -r "$EXISTING_PACKAGE" ]; then EXISTING_VERSION="$("$NODE_BIN" -p 'try{require(process.argv[1]).version}catch{""}' "$EXISTING_PACKAGE" 2>/dev/null || true)" if "$NODE_BIN" -e 'const parse=s=>{const m=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);return m?{main:m.slice(1,4).map(Number),pre:m[4]?m[4].split("."):[]}:null}; const a=parse(process.argv[1]),b=parse(process.argv[2]);if(!a||!b)process.exit(1); let delta=0;for(let i=0;i<3&&!delta;i++)delta=Math.sign(a.main[i]-b.main[i]); if(a.pre[0]==="canary")process.exit(0); if(!delta){if(!a.pre.length&&b.pre.length)delta=1;else if(a.pre.length&&!b.pre.length)delta=-1;else for(let i=0;i=0?0:1)' "$EXISTING_VERSION" "0.18.151"; then SKIP_INSTALL=true echo "Carlos — version plus récente conservée : $EXISTING_VERSION" fi fi if [ "$SKIP_INSTALL" = false ]; then PACKAGE="$TMP/carlos-agent.tgz" curl -fsSL https://www.usecarlos.com/downloads/carlos-agent-0.18.151.tgz -o "$PACKAGE" CHECKSUM="$(curl -fsSL https://www.usecarlos.com/downloads/carlos-agent-0.18.151.tgz.sha256)" EXPECTED="$(printf '%s' "$CHECKSUM" | cut -d ' ' -f 1)" [[ "$EXPECTED" =~ ^[a-f0-9]{64}$ ]] || { echo "Carlos: empreinte de distribution invalide."; exit 1; } ACTUAL="$("$NODE_BIN" -e 'const fs=require("fs"),crypto=require("crypto");process.stdout.write(crypto.createHash("sha256").update(fs.readFileSync(process.argv[1])).digest("hex"))' "$PACKAGE")" [ "$ACTUAL" = "$EXPECTED" ] || { echo "Carlos: archive modifiée ou téléchargement corrompu."; exit 1; } "$NPM_BIN" install -g --prefix "$RUNTIME" "$PACKAGE" --silent fi CARLOS="$RUNTIME/bin/carlos" [ -x "$CARLOS" ] || { echo "Carlos: installation incomplète."; exit 1; } # A stable launcher pins Node, including when it was downloaded by this installer. BIN="$CARLOS_HOME/bin" mkdir -p "$BIN" printf '#!/usr/bin/env bash\nexec %q %q "$@"\n' "$NODE_BIN" "$RUNTIME/lib/node_modules/carlos-remote/cli.mjs" > "$BIN/carlos" chmod 700 "$BIN/carlos" cp "$BIN/carlos" "$BIN/carlos-remote" export PATH="$BIN:$PATH" PATH_LINE='export PATH="$HOME/.carlos/bin:$PATH"' register_profile(){ profile="$1" if ! grep -Fqx "$PATH_LINE" "$profile" 2>/dev/null; then printf '\n# Carlos Remote\n%s\n' "$PATH_LINE" >> "$profile" fi } case "$(uname -s)" in Darwin) register_profile "$HOME/.zprofile" register_profile "$HOME/.zshrc" register_profile "$HOME/.bash_profile" register_profile "$HOME/.bashrc" ;; *) register_profile "$HOME/.profile" register_profile "$HOME/.bashrc" register_profile "$HOME/.zshrc" ;; esac CARLOS="$BIN/carlos" carlos_done "$CARLOS_TXT_3" carlos_current "$CARLOS_TXT_2" "$CARLOS" remote --install-service --lang "$CARLOS_LANGUAGE" echo "" # Every available RGB capability comes from the actual installed local agent. if [ "$(uname -s)" = Darwin ]; then "$CARLOS" rgb status --json fi carlos_current "$CARLOS_TXT_4" "$CARLOS" doctor printf '\n' carlos_done "$CARLOS_TXT_3" printf ' carlos doctor · carlos rgb status · carlos rgb preview\n' printf ' https://www.usecarlos.com\n' # Doctor can report missing permissions, pairing or network connectivity: # never assert success of the entire installation merely because npm succeeded.