#!/usr/bin/env bash # KAppMaker AI — App Army installer. One command, your own laptop (macOS / Linux) or your own server. # Fresh Ubuntu VPS → one command → hardened always-on App Army box. Laptop → the same army, lighter (no hardening, # no services unless you add a worker). # # curl -fsSL https://kappmaker.com/install.sh | bash # curl -fsSL https://kappmaker.com/install.sh | bash -s -- --server [--sudo limited|full] # # Options: # --server this is a server (Linux, run as root): adds a worker user, hardening, systemd units # --sudo limited|full server only: what the worker user may run as root (default limited: only its own # kappmaker-army-worker@* services). full = passwordless sudo for everything (a warning is printed) # --user NAME server only: the worker user (default: army) # --root-login key|no server only: root SSH after hardening (default: key with limited sudo, no with full) # --tailscale server only: afterwards, lock SSH to your Tailscale network (guided, asks first) # --no-harden server only: skip the security baseline (not recommended) # --code CODE one-time install code from "My purchase" on kappmaker.com (short-lived, single use; the # page shows the whole command). The installer swaps it for your licence; the key itself # never lands in your shell history # --key KEY licence key, for experts (prefer KAPPMAKER_LICENSE_KEY=… or the hidden prompt: argv is visible) # --github get the kit with git from KAppMaker/app-army-release (needs repo access) # --tarball FILE install from a downloaded app-army-.tar.gz (SHA256SUMS must sit next to it) # --version VER kit version to install (default: latest) # --update fetch the kit again even when one is installed # --worker NAME always-on worker name (server default: main; laptop: only when given). Asks for the # bot token hidden when there is a terminal; otherwise the worker waits for it # --no-worker server: do not set up the always-on worker service # --runner claude the coding agent workers run (today only claude = Claude Code) # --channel telegram|none the chat channel (today telegram; none = no channel runtime/plugin) # --routines ask|on|off scheduled factory routines (spend Claude usage). ask (default): asked once on a # terminal (servers: default yes); without a terminal they stay off and the summary says so # --extras / --no-extras optional design + terse-mode add-ons (ui-ux-pro-max, caveman). Servers: on; laptops: off # --voice / --no-voice local voice-note transcription for Telegram. Servers: on; laptops: off # --android-api N Android platform to install (the KAppMaker template's compileSdk) default: 37 # --no-claude-mem server: skip claude-mem (memory across restarts; spends some Claude usage) # --no-android skip the Android SDK --no-toolchain skip all dev tools (kit + army only) # --yes no questions at all (by default it asks only what it cannot decide: Homebrew on a Mac, # the licence if none was given, and whether to start the guided first run) # --ask ask the setup questions of `kappmaker-army init` (company, app id prefix, …) now # --no-start do not offer the guided first run (`kappmaker-army start`) at the end # --strict fail when `kappmaker-army doctor` reports a FAIL # --dry-run show what would happen, change nothing, contact nothing # # Safe to re-run: every step checks first, and an installed kit is reused unless --update/--version is given. # The licence key is never printed, logged, stored, or put on a command line. Exit: 0 ok · 1 failed · 2 usage. # # Env: KAPPMAKER_LICENSE_KEY · KAPPMAKER_API (default https://kappmaker.com) · KAPPMAKER_RELEASE_REPO (git URL) set -euo pipefail main() { ORIG_ARGS=("$@") API="${KAPPMAKER_API:-https://kappmaker.com}"; API="${API%/}" UA="kappmaker-army-installer" # fixed: no OS / version / hostname in any request CONTACTED="nothing (no network calls to kappmaker.com)" REPO_SSH="git@github.com:KAppMaker/app-army-release.git" REPO_HTTPS="https://github.com/KAppMaker/app-army-release.git" SERVER=0; SUDO_MODE=limited; SRV_USER=army; ROOT_LOGIN=""; TAILSCALE=0; HARDEN=1; KEY_ARG=""; SOURCE=licence TARBALL=""; VERSION=latest; UPDATE=0; WORKER=""; ANDROID=1; TOOLCHAIN=1; YES=0; STRICT=0; DRY=0 ANDROID_API=37; EXTRAS=""; VOICE="" RUNNER=claude; CHANNEL=telegram; ROUTINES=ask; NO_WORKER=0; CLAUDE_MEM=1; CODE_ARG=""; ASK=0; START=1; WORKER_SET=0 while [ $# -gt 0 ]; do case "$1" in --server) SERVER=1 ;; --sudo) SUDO_MODE="${2:-}"; shift ;; --user) SRV_USER="${2:-}"; shift ;; --root-login) ROOT_LOGIN="${2:-}"; shift ;; --tailscale) TAILSCALE=1 ;; --no-harden) HARDEN=0 ;; --key) KEY_ARG="${2:-}"; shift ;; --code) CODE_ARG="${2:-}"; shift ;; --ask) ASK=1 ;; --no-start) START=0 ;; --github) SOURCE=github ;; --tarball) SOURCE=tarball; TARBALL="${2:-}"; shift ;; --version) VERSION="${2:-}"; UPDATE=1; shift ;; --update) UPDATE=1 ;; --worker) WORKER="${2:-}"; WORKER_SET=1; shift ;; --no-android) ANDROID=0 ;; --no-toolchain) TOOLCHAIN=0 ;; --yes|-y) YES=1 ;; --strict) STRICT=1 ;; --dry-run) DRY=1 ;; --no-worker) NO_WORKER=1 ;; --no-claude-mem) CLAUDE_MEM=0 ;; --extras) EXTRAS=1 ;; --no-extras) EXTRAS=0 ;; --voice) VOICE=1 ;; --no-voice) VOICE=0 ;; --android-api) ANDROID_API="${2:-}"; shift ;; --runner) RUNNER="${2:-}"; shift ;; --channel) CHANNEL="${2:-}"; shift ;; --routines) ROUTINES="${2:-}"; shift ;; -h|--help) usage; exit 0 ;; *) printf 'install.sh: unknown option %s (--help)\n' "$1" >&2; exit 2 ;; esac; shift done case "$SUDO_MODE" in limited|full) ;; *) die2 "--sudo must be limited or full" ;; esac case "$ROOT_LOGIN" in ""|key|no) ;; *) die2 "--root-login must be key or no" ;; esac case "$RUNNER" in claude) ;; *) die2 "--runner: only 'claude' (Claude Code) is supported today" ;; esac case "$CHANNEL" in telegram|none) ;; *) die2 "--channel: telegram or none" ;; esac case "$ROUTINES" in ask|on|off) ;; *) die2 "--routines: ask, on or off" ;; esac [[ "$ANDROID_API" =~ ^[0-9]{2}$ ]] || die2 "--android-api must be a number like 37" [ -n "$EXTRAS" ] || EXTRAS="$SERVER"; [ -n "$VOICE" ] || VOICE="$SERVER" [ "$SERVER" = 1 ] && [ "$NO_WORKER" = 0 ] && [ "$CHANNEL" != none ] && [ -z "$WORKER" ] && WORKER=main [[ "$SRV_USER" =~ ^[a-z_][a-z0-9_-]{0,31}$ ]] && [ "$SRV_USER" != root ] || die2 "bad --user" [ -z "$WORKER" ] || [[ "$WORKER" =~ ^[a-z0-9][a-z0-9-]{0,31}$ ]] || die2 "bad --worker name (a-z 0-9 -)" [[ "$VERSION" =~ ^(latest|v?[0-9]+\.[0-9]+\.[0-9]+([.-][A-Za-z0-9.]+)?)$ ]] || die2 "bad --version '$VERSION'" [ "$SOURCE" != tarball ] || [ -f "$TARBALL" ] || die2 "--tarball: no such file: $TARBALL" TTY=0; { [ -r /dev/tty ] && : /dev/null && TTY=1 [ "$YES" = 1 ] && TTY_IN=/dev/null || { [ "$TTY" = 1 ] && TTY_IN=/dev/tty || TTY_IN=/dev/null; } OS="$(uname -s)" case "$OS" in Darwin) PLATFORM=macos ;; Linux) PLATFORM=linux ;; *) die "unsupported system $OS (macOS or Linux only)" ;; esac WARNS=""; STEPS="" say "KAppMaker AI · App Army installer$([ "$DRY" = 1 ] && echo ' (dry run: nothing is changed)')" if [ "$SERVER" = 1 ]; then [ "$PLATFORM" = linux ] || die "--server is for Linux servers (on a Mac, run without --server)" if [ "$DRY" = 0 ] && [ "$(id -u)" -ne 0 ]; then # Logged in as a sudo user (ubuntu, admin, debian, …): run again as root. The key stays in the environment # (--preserve-env), never on a command line. have sudo || die "--server needs root and this account has no sudo: log in as root and run it again" self="$0" if [ ! -f "$self" ] || ! grep -q 'App Army installer' "$self" 2>/dev/null; then # piped: fetch the same script self="$(mktemp)"; curl -fsSL "$API/install.sh" -o "$self" || die "could not fetch the installer again for sudo; run: curl -fsSL $API/install.sh | sudo bash -s -- --server" fi say "Not root: continuing with sudo (you may be asked for your password)." exec sudo --preserve-env=KAPPMAKER_LICENSE_KEY,KAPPMAKER_API,KAPPMAKER_RELEASE_REPO bash "$self" "${ORIG_ARGS[@]}" fi command -v apt-get >/dev/null 2>&1 || [ "$DRY" = 1 ] || die "--server supports Ubuntu/Debian (apt-get not found)" TARGET_HOME="/home/$SRV_USER" [ "$DRY" = 1 ] || ! id "$SRV_USER" >/dev/null 2>&1 || TARGET_HOME="$(getent passwd "$SRV_USER" | cut -d: -f6)" say "Mode: server (worker user '$SRV_USER', sudo $SUDO_MODE)" else [ "$(id -u)" -ne 0 ] || die "do not run the laptop install as root (Claude Code refuses to run workers as root). On a server use --server." TARGET_HOME="$HOME" say "Mode: $([ "$PLATFORM" = macos ] && echo 'Mac' || echo 'Linux') laptop/desktop, user $(id -un)" fi ARMY_DIR_T="$TARGET_HOME/.army"; KITS="$ARMY_DIR_T/releases"; KIT_LINK="$ARMY_DIR_T/kit" # layout kappmaker-army update expects # ------------------------------------------------------------------ 1. prerequisites if [ "$SERVER" = 1 ]; then step "Prerequisites (server: minimal now; the full toolchain comes with setup-vps.sh)" if [ "$DRY" = 0 ] && have cloud-init && cloud-init status 2>/dev/null | grep -qE 'running|not run'; then say "Waiting for the server's first-boot setup (cloud-init) to finish, usually under a minute…" timeout 900 cloud-init status --wait >/dev/null 2>&1 || true fi run_root apt-get -o DPkg::Lock::Timeout=600 update -qq >/dev/null run_root env DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=600 install -y -qq --no-install-recommends ca-certificates curl git python3 tar gzip sudo >/dev/null \ || die "apt-get install failed (see above; another update may still be running: wait a minute)" if ! id "$SRV_USER" >/dev/null 2>&1; then run_root useradd -m -s /bin/bash "$SRV_USER"; done_ "created user $SRV_USER"; fi else step "Prerequisites" if [ "$PLATFORM" = macos ]; then prereqs_macos; else prereqs_linux_laptop; fi fi # ------------------------------------------------------------------ 2. the kit step "App Army kit" KIT_DIR="" if [ "$UPDATE" = 0 ] && [ "$SOURCE" = licence ] && kit_has_cli "$KIT_LINK"; then KIT_DIR="$KIT_LINK"; KIT_VER="$(cat "$KIT_DIR/VERSION" 2>/dev/null || basename "$(cd "$KIT_DIR" && pwd -P)")" say "kit $KIT_VER already installed, continuing with the next steps (fetch a newer one with --update)" else case "$SOURCE" in licence) fetch_licensed ;; tarball) WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT TB="$TARBALL"; SUMS="$(dirname "$TARBALL")/SHA256SUMS"; KIT_VER="$(ver_from_name "$(basename "$TB")")" [ -f "$SUMS" ] || die "no SHA256SUMS next to $TARBALL (it is published with every release)" verify_and_unpack ;; github) fetch_github ;; esac fi # ------------------------------------------------------------------ 3. server setup / env if [ "$SERVER" = 1 ]; then step "Server setup (toolchain$([ "$HARDEN" = 1 ] && echo ', security baseline'))" set -- --user "$SRV_USER" --kit "$KIT_DIR" --sudo "$SUDO_MODE" [ "$HARDEN" = 1 ] && set -- "$@" --harden [ -n "$ROOT_LOGIN" ] && set -- "$@" --root-login "$ROOT_LOGIN" [ "$TAILSCALE" = 1 ] && set -- "$@" --tailscale set -- "$@" --runner "$RUNNER" --channel "$CHANNEL" --android-api "$ANDROID_API" [ "$ANDROID" = 0 ] && set -- "$@" --no-android [ "$TOOLCHAIN" = 0 ] && set -- "$@" --no-toolchain [ "$DRY" = 1 ] && set -- "$@" --dry-run if [ "$DRY" = 1 ] && [ ! -f "$KIT_DIR/installer/setup-vps.sh" ]; then say "+ $KIT_DIR/installer/setup-vps.sh $(q "$@")" elif bash "$KIT_DIR/installer/setup-vps.sh" "$@"; then done_ "server setup (setup-vps.sh)"; else die "server setup failed (see above). Fix it and run the same command again."; fi else write_laptop_env fi # ------------------------------------------------------------------ 4. kappmaker-army init + doctor step "kappmaker-army init" if [ -f "$KIT_DIR/cli/kappmaker-army-init" ]; then INIT="$KIT_DIR/cli/kappmaker-army-init"; INIT_SUB="" elif [ -f "$KIT_DIR/cli/kappmaker-army" ]; then INIT="$KIT_DIR/cli/kappmaker-army"; INIT_SUB=init else INIT="$KIT_DIR/cli/army-init"; INIT_SUB=""; fi set -- ; { [ "$YES" = 1 ] || [ "$ASK" = 0 ]; } && set -- --yes # defaults now; kappmaker-army start / init change them if [ "$SERVER" = 1 ]; then if [ "$DRY" = 1 ] || bash "$INIT" $INIT_SUB --help 2>/dev/null | grep -q -- '--server'; then set -- "$@" --server else warn "this kit's 'kappmaker-army init' has no --server option yet; ran it without"; fi [ "$CHANNEL" = telegram ] && set -- "$@" --telegram yes if [ "$CLAUDE_MEM" = 1 ] && [ "$CHANNEL" = telegram ]; then set -- "$@" --claude-mem yes; fi if as_target bash "$INIT" $INIT_SUB "$@" <"$TTY_IN"; then done_ "kappmaker-army init"; else die "kappmaker-army init failed (see above); re-run this installer when fixed"; fi else if run_cmd bash "$INIT" $INIT_SUB "$@" <"$TTY_IN"; then done_ "kappmaker-army init"; else die "kappmaker-army init failed (see above); re-run this installer when fixed"; fi fi step_plugins [ "$VOICE" = 1 ] && [ "$CHANNEL" = telegram ] && step_voice step "kappmaker-army doctor" DOC_RC=0 if [ "$DRY" = 1 ]; then say "+ kappmaker-army doctor"; DOC_OUT="(dry run)" else DOC_OUT="$(as_target bash "$(cli_bin)" doctor 2>&1)" || DOC_RC=$? printf '%s\n' "$DOC_OUT" | sed 's/^/ /' fi DOC_LINE="$(printf '%s\n' "$DOC_OUT" | grep '^doctor:' | tail -n1 || true)"; DOC_LINE="${DOC_LINE:-doctor: see above}" # ------------------------------------------------------------------ 5. always-on worker, watchdog, routines [ -z "$WORKER" ] || step_worker step_routines summary offer_start [ "$STRICT" = 1 ] && [ "$DOC_RC" -ne 0 ] && exit 1 exit 0 } # ====================================================================== helpers # The kit's CLI is `kappmaker-army` (older kits: `army`); resolved, never assumed. kit_has_cli() { [ -f "$1/cli/kappmaker-army" ] || [ -f "$1/cli/kappmaker-army-init" ] || [ -f "$1/cli/army-init" ]; } cli_bin() { local n; for n in kappmaker-army army; do [ -f "$ARMY_DIR_T/bin/$n" ] && { echo "$ARMY_DIR_T/bin/$n"; return; }; done echo "$ARMY_DIR_T/bin/kappmaker-army"; } WORKER_UNIT_PREFIX=kappmaker-army-worker@ usage() { sed -n '2,32p' "$0" 2>/dev/null | sed 's/^# \{0,1\}//' || echo "see https://kappmaker.com/install"; } say() { printf '%s\n' "$*"; } step() { printf '\n== %s\n' "$*"; } warn() { printf 'warn: %s\n' "$*"; WARNS="$WARNS - $*"; } done_() { STEPS="$STEPS - $*"; } die() { printf '\nInstall stopped: %s\n' "$*" >&2 printf 'Run the same command again when it is fixed: finished steps are skipped, it continues where it stopped.\n' >&2; exit 1; } die2() { printf 'install.sh: %s\n' "$*" >&2; exit 2; } have() { command -v "$1" >/dev/null 2>&1; } q() { printf '%q ' "$@"; } run_cmd() { if [ "$DRY" = 1 ]; then say "+ $(q "$@")"; else "$@"; fi; } run_root() { # as root (server) or via sudo (Linux laptop) if [ "$DRY" = 1 ]; then say "+ $( [ "$(id -u)" -ne 0 ] && echo 'sudo ')$(q "$@")"; return 0; fi if [ "$(id -u)" -eq 0 ]; then "$@"; else sudo "$@"; fi } as_target() { # run as the user the kit belongs to, with their login env (server: the worker user) if [ "$SERVER" = 0 ]; then run_cmd "$@"; return; fi if [ "$DRY" = 1 ]; then say "+ (as $SRV_USER) $(q "$@")"; return 0; fi sudo -u "$SRV_USER" -H bash -c 'cd "$HOME"; [ -f "$HOME/.army/shellenv" ] && . "$HOME/.army/shellenv"; export PATH="$HOME/.army/bin:$HOME/.local/bin:$PATH"; exec "$@"' bash "$@" } ask_yes() { # question → 0 for yes (default yes); --yes or no terminal = yes [ "$YES" = 1 ] || [ "$TTY" = 0 ] && return 0 local a; printf '%s [Y/n] ' "$1" >/dev/tty; IFS= read -r a /dev/null)" || return 1 "$h/bin/java" -version 2>&1 | head -n1 | grep -qE "\"$1[.\"]" && printf '%s\n' "$h"; } prereqs_macos() { if ! have brew; then for b in /opt/homebrew/bin/brew /usr/local/bin/brew; do [ -x "$b" ] && eval "$("$b" shellenv)" && break; done fi if ! have brew; then ask_yes "Homebrew (the Mac package manager) is needed for git, Node, JDK 17 and tmux. Install it now?" \ || die "Homebrew is required. Install it from https://brew.sh and run this again." if [ "$DRY" = 1 ]; then say "+ install Homebrew (https://brew.sh)" else if [ "$YES" = 1 ] || [ "$TTY" = 0 ]; then NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" /dev/null || [ -d "$(brew --prefix 2>/dev/null)/opt/openjdk@17" ] || pk="$pk openjdk@17" mac_jdk 21 >/dev/null || [ -d "$(brew --prefix 2>/dev/null)/opt/openjdk@21" ] || pk="$pk openjdk@21" # test toolchain fi if [ -n "$pk" ]; then # shellcheck disable=SC2086 run_cmd brew install -q $pk || die "brew install$pk failed (see above)" done_ "installed with Homebrew:$pk" else say "git, gh, tmux, jq, python3, bash 4$([ "$TOOLCHAIN" = 1 ] && echo ', Node, JDK 17 + 21'): present"; fi if [ "$TOOLCHAIN" = 1 ]; then JAVA_HOME_V="$(mac_jdk 17 || true)" [ -n "$JAVA_HOME_V" ] || JAVA_HOME_V="$(brew --prefix 2>/dev/null)/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home" SDK_DEFAULT="$HOME/Library/Android/sdk"; CLT_OS=mac common_tools fi python3 -c 'import yaml' 2>/dev/null || run_cmd python3 -m pip install --user -q pyyaml 2>/dev/null \ || { have brew && run_cmd brew install -q pyyaml; } >/dev/null 2>&1 || warn "python3 has no PyYAML (only the concepts index needs it)" } # ---------------------------------------------------------------------- prerequisites: Linux laptop prereqs_linux_laptop() { local pk="" for t in git curl tmux jq unzip python3; do have "$t" || pk="$pk $t"; done python3 -c 'import yaml' 2>/dev/null || pk="$pk python3-yaml" if [ "$TOOLCHAIN" = 1 ]; then JAVA_HOME_V="" for j in /usr/lib/jvm/java-17-openjdk-*; do [ -x "$j/bin/java" ] && JAVA_HOME_V="$j" && break; done [ -n "$JAVA_HOME_V" ] || pk="$pk openjdk-17-jdk-headless" fi if [ -n "$pk" ]; then have apt-get || die "please install:$pk (this installer only knows apt; then run it again)" say "Installing with apt (asks for your password):$pk" run_root apt-get -o DPkg::Lock::Timeout=600 update -q >/dev/null # shellcheck disable=SC2086 run_root env DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=600 install -y -q --no-install-recommends $pk || die "apt install failed" done_ "installed with apt:$pk" fi if ! have gh && have apt-get; then # GitHub CLI from GitHub's own apt repository (the new-app flow uses it) run_root bash -c 'install -d -m 755 /etc/apt/keyrings && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /etc/apt/keyrings/githubcli-archive-keyring.gpg && chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" >/etc/apt/sources.list.d/github-cli.list && apt-get -o DPkg::Lock::Timeout=600 update -q >/dev/null && apt-get -o DPkg::Lock::Timeout=600 install -y -q gh >/dev/null' \ && done_ "GitHub CLI (gh)" || warn "GitHub CLI not installed (new apps need it: https://cli.github.com)" fi if [ "$TOOLCHAIN" = 1 ]; then if ! have node || [ "$(node -v | tr -d v | cut -d. -f1)" -lt 20 ]; then have apt-get || die "please install Node.js 20+ and run this again" run_root bash -c 'curl -fsSL https://deb.nodesource.com/setup_22.x | bash - >/dev/null && apt-get install -y -q nodejs >/dev/null' \ || die "Node.js install failed" done_ "Node.js 22" fi [ -n "$JAVA_HOME_V" ] || for j in /usr/lib/jvm/java-17-openjdk-*; do [ -x "$j/bin/java" ] && JAVA_HOME_V="$j" && break; done ls -d /usr/lib/jvm/java-21-openjdk-* >/dev/null 2>&1 || ! apt-cache show openjdk-21-jdk-headless >/dev/null 2>&1 \ || { run_root env DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=600 install -y -q --no-install-recommends openjdk-21-jdk-headless >/dev/null && done_ "JDK 21 (test toolchain)"; } \ || warn "JDK 21 not installed (Gradle downloads it when a test needs it)" SDK_DEFAULT="$HOME/Android/Sdk"; CLT_OS=linux common_tools fi } # ---------------------------------------------------------------------- Android SDK, Claude Code, bun, kappmaker common_tools() { SDK_DIR="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-$SDK_DEFAULT}}" if [ "$ANDROID" = 1 ]; then if [ -x "$SDK_DIR/cmdline-tools/latest/bin/sdkmanager" ]; then say "Android SDK: $SDK_DIR" else say "Android SDK command-line tools → $SDK_DIR" run_cmd bash -c 'set -e; t=$(mktemp -d); curl -fsSLo "$t/clt.zip" "https://dl.google.com/android/repository/commandlinetools-$1-11076708_latest.zip"; unzip -q "$t/clt.zip" -d "$t"; mkdir -p "$2/cmdline-tools"; rm -rf "$2/cmdline-tools/latest"; mv "$t/cmdline-tools" "$2/cmdline-tools/latest"; rm -rf "$t"' _ "$CLT_OS" "$SDK_DIR" \ || die "Android command-line tools download failed" done_ "Android command-line tools" fi if [ ! -d "$SDK_DIR/platform-tools" ] || [ ! -d "$SDK_DIR/platforms/android-$ANDROID_API" ] || ! ls -d "$SDK_DIR/build-tools/$ANDROID_API."* >/dev/null 2>&1; then # build-tools: newest $ANDROID_API.x the repository lists (else the newest at all) if run_cmd env JAVA_HOME="$JAVA_HOME_V" bash -c 'sm="$1/cmdline-tools/latest/bin/sdkmanager"; yes | "$sm" --licenses >/dev/null 2>&1 bt=$("$sm" --list 2>/dev/null | grep -oE "build-tools;[0-9][0-9.]*" | sort -u | sort -t";" -k2 -V | grep "build-tools;$2\." | tail -n1) [ -n "$bt" ] || bt=$("$sm" --list 2>/dev/null | grep -oE "build-tools;[0-9][0-9.]*" | sort -u | sort -t";" -k2 -V | tail -n1) "$sm" --install platform-tools "platforms;android-$2" "$bt" >/dev/null' _ "$SDK_DIR" "$ANDROID_API"; then done_ "Android platform $ANDROID_API + matching build tools" else warn "sdkmanager could not install Android platform $ANDROID_API (later: sdkmanager 'platforms;android-$ANDROID_API')"; fi fi fi "install_runner_$RUNNER" [ "$CHANNEL" = none ] || "install_channel_$CHANNEL" if have kappmaker || [ -x "$HOME/.local/bin/kappmaker" ]; then say "kappmaker CLI: present" else local gp; gp="$(npm prefix -g 2>/dev/null || echo /nonexistent)" if [ -w "$gp/lib" ] || [ -w "$gp" ]; then run_cmd npm install -g --silent kappmaker else run_cmd npm install -g --silent --prefix "$HOME/.local" kappmaker; fi || warn "kappmaker CLI install failed (npm i -g kappmaker)" done_ "kappmaker CLI" fi } # Named seams: one function per runner (coding agent) and per channel, so Codex/Gemini or Slack/Discord can be added # beside them. Workers are started only by the kappmaker-army launcher (kappmaker-army worker …), never by a raw agent command here. install_runner_claude() { if have claude || [ -x "$HOME/.local/bin/claude" ]; then say "runner Claude Code: present" else run_cmd bash -c 'curl -fsSL https://claude.ai/install.sh | bash' || die "Claude Code install failed"; done_ "runner: Claude Code"; fi } install_channel_telegram() { # the Telegram plugin runs on bun; the plugin itself is installed by kappmaker-army worker add if have bun || [ -x "$HOME/.bun/bin/bun" ]; then say "channel Telegram runtime (bun): present" else run_cmd bash -c 'curl -fsSL https://bun.sh/install | bash >/dev/null 2>&1' || warn "bun install failed (the Telegram plugin needs it)"; done_ "channel: Telegram runtime (bun)"; fi } # ---------------------------------------------------------------------- laptop env files write_laptop_env() { local envf="$ARMY_DIR_T/env" she="$ARMY_DIR_T/shellenv" jh="${JAVA_HOME_V:-}" sdk="${SDK_DIR:-}" bp bp="$(have brew && brew --prefix 2>/dev/null || true)" local p="$HOME/.army/bin:$HOME/.local/bin:$HOME/.bun/bin" [ -n "$sdk" ] && p="$p:$sdk/platform-tools:$sdk/cmdline-tools/latest/bin" [ -n "$jh" ] && p="$p:$jh/bin" [ -n "$bp" ] && p="$p:$bp/bin:$bp/sbin" p="$p:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" local et="# App Army toolchain env (install.sh). KEY=VALUE only: read by workers and services. ${jh:+JAVA_HOME=$jh }${sdk:+ANDROID_SDK_ROOT=$sdk ANDROID_HOME=$sdk }BUN_INSTALL=$HOME/.bun PATH=$p" local st="# App Army shell env (install.sh). Sourced from your shell profile. ${jh:+export JAVA_HOME=\"$jh\" }${sdk:+export ANDROID_SDK_ROOT=\"$sdk\" ANDROID_HOME=\"$sdk\" }export BUN_INSTALL=\"\$HOME/.bun\" for __p in ${jh:+\"$jh/bin\" }${sdk:+\"$sdk/cmdline-tools/latest/bin\" \"$sdk/platform-tools\" }\"\$HOME/.bun/bin\" \"\$HOME/.local/bin\" \"\$HOME/.army/bin\"; do case \":\$PATH:\" in *\":\$__p:\"*) ;; *) PATH=\"\$__p:\$PATH\" ;; esac done; unset __p; export PATH" if [ "$DRY" = 1 ]; then say "+ write $envf and $she; source $she from your shell profile"; return; fi mkdir -p "$ARMY_DIR_T"; chmod 700 "$ARMY_DIR_T" printf '%s\n' "$et" >"$envf"; printf '%s\n' "$st" >"$she"; chmod 644 "$envf" "$she" local rc line='[ -f "$HOME/.army/shellenv" ] && . "$HOME/.army/shellenv" # App Army' for rc in "$HOME/.profile" "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.bash_profile"; do case "$rc" in */.profile) ;; */.zshrc) [ -f "$rc" ] || [ "$PLATFORM" = macos ] || continue ;; *) [ -f "$rc" ] || continue ;; esac grep -qF '.army/shellenv' "$rc" 2>/dev/null || printf '\n%s\n' "$line" >>"$rc" done # shellcheck disable=SC1090 . "$she" done_ "env: ~/.army/shellenv (shells) + ~/.army/env (workers)" } # ---------------------------------------------------------------------- licence + download install_id() { # random id made once on this machine; the ONLY thing besides the key we ever send local f="$ARMY_DIR_T/install-id" if [ ! -s "$f" ]; then mkdir -p "$ARMY_DIR_T"; chmod 700 "$ARMY_DIR_T" od -An -tx1 -N16 /dev/urandom | tr -d ' \n' >"$f"; chmod 600 "$f" fi tr -cd '0-9a-f' <"$f" } proto_ok() { # https only, except a local mock server (tests) case "$1" in https://*) return 0 ;; http://127.0.0.1:*|http://localhost:*) case "$API" in http://127.0.0.1:*|http://localhost:*) return 0 ;; esac ;; esac return 1 } read_key() { KEY="${KAPPMAKER_LICENSE_KEY:-$KEY_ARG}" if [ -z "$KEY" ]; then if [ "$DRY" = 1 ]; then KEY="dry-run-key"; return; fi [ "$TTY" = 1 ] || die "no licence key: run with KAPPMAKER_LICENSE_KEY= in front of 'bash', or use --github" say "Your licence key is in your purchase email and on kappmaker.com (My purchase)." printf 'Licence key (hidden): ' >/dev/tty; IFS= read -rs KEY /dev/tty fi KEY="$(printf '%s' "$KEY" | tr -d '[:space:]')" [ -n "$KEY" ] || die "no licence key entered" local kre='^[A-Za-z0-9._~+/=:-]{8,200}$' # {m,n} must stay <= 255 (macOS regex limit) [[ "$KEY" =~ $kre ]] || { KEY=""; die "that does not look like a licence key (copy it again from your purchase email)"; } } fetch_licensed() { proto_ok "$API/" || die "KAPPMAKER_API must be https" CODE="${KAPPMAKER_INSTALL_CODE:-$CODE_ARG}"; CODE="$(printf '%s' "$CODE" | tr -d '[:space:]')" if [ -n "$CODE" ]; then local cre='^[A-Za-z0-9-]{4,64}$' [[ "$CODE" =~ $cre ]] || die "that install code looks wrong; copy the whole command again from My purchase on kappmaker.com" if [ "$DRY" = 1 ]; then say "+ POST $API/api/license/redeem-code {code, install_id (random, ~/.army/install-id)}: nothing else is sent" say "+ GET $API/api/license/download?version=$VERSION → verify SHA256SUMS → unpack to ~/.army/releases/" KIT_VER="$VERSION"; KIT_DIR="$KIT_LINK"; return fi redeem_code else read_key fetch_activate [ "$DRY" = 0 ] || return 0 fi download_kit } redeem_code() { # one-time install code → licence key (kept in memory only), install already activated WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT IID="$(install_id)" local body code body="$(CODE="$CODE" IID="$IID" python3 -c 'import json,os;print(json.dumps({"code":os.environ["CODE"],"install_id":os.environ["IID"]}))')" code="$(printf '%s' "$body" | curl -sS -A "$UA" --max-time 30 -o "$WORK/act.json" -w '%{http_code}' -X POST \ -H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary @- "$API/api/license/redeem-code" 2>"$WORK/err")" \ || die "could not reach $API ($(head -c 200 "$WORK/err")). Check the internet connection and run again." body="" CONTACTED="kappmaker.com: your install code + a random install id (~/.army/install-id), nothing else" parse_licence_reply if [ "$code" = 200 ] && [ "$v_ok" = True ]; then KEY="$(python3 -c 'import json,sys d=json.load(open(sys.argv[1])); print(d.get("key") or d.get("license_key") or "")' "$WORK/act.json" 2>/dev/null || true)" rm -f "$WORK/act.json" [ -n "$KEY" ] || die "the licence server accepted the code but sent no licence; contact support" say "install code ok: ${v_tier:-app-army}, this is install ${v_used:-?} of ${v_max:-?}" elif [ "$code" = 422 ]; then die "that install code looks wrong; copy the whole command again from My purchase on kappmaker.com" elif [ "$code" = 403 ] || [ "$code" = 410 ] || [ "$code" = 404 ]; then case "$v_reason" in *used*) die "this install code was already used. Open My purchase on kappmaker.com for a fresh command." ;; *expired*) die "this install code has expired (they are short-lived). Open My purchase on kappmaker.com for a fresh command." ;; *limit*|*activation*) die "this licence is already active on ${v_max:-3} machines. Free one on kappmaker.com (My purchase → reset activations), then get a fresh command." ;; *) die "the install code was not accepted${v_reason:+ ($v_reason)}. Copy the whole command again from My purchase on kappmaker.com." ;; esac else die "licence server answered HTTP $code. Try again in a few minutes."; fi } parse_licence_reply() { # $WORK/act.json → v_ok v_tier v_used v_max v_reason (never the key) local info; info="$(python3 -c 'import json,sys try: d=json.load(open(sys.argv[1])) except Exception: d={} print("%s|%s|%s|%s|%s" % (d.get("valid"), d.get("tier",""), d.get("activations_used",""), d.get("activations_max",""), str(d.get("reason","")).replace("|"," ")))' "$WORK/act.json")" IFS='|' read -r v_ok v_tier v_used v_max v_reason <" KIT_VER="$VERSION"; KIT_DIR="$KIT_LINK"; KEY=""; return fi WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT IID="$(install_id)" local body code body="$(KEY="$KEY" IID="$IID" python3 -c 'import json,os;print(json.dumps({"key":os.environ["KEY"],"install_id":os.environ["IID"]}))')" code="$(printf '%s' "$body" | curl -sS -A "$UA" --max-time 30 -o "$WORK/act.json" -w '%{http_code}' -X POST \ -H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary @- "$API/api/license/activate" 2>"$WORK/err")" \ || die "could not reach $API ($(head -c 200 "$WORK/err")). Check the internet connection and run again." body="" parse_licence_reply CONTACTED="kappmaker.com: your licence key + a random install id (~/.army/install-id), nothing else" if [ "$code" = 200 ] && [ "$v_ok" = True ]; then say "licence ok: ${v_tier:-app-army}, this is install ${v_used:-?} of ${v_max:-?}" elif [ "$code" = 422 ]; then die "that does not look like a licence key (copy it again from your purchase email)" elif [ "$code" = 403 ]; then case "$v_reason" in *limit*|*activation*) die "this licence is already active on ${v_max:-3} machines. Free one on kappmaker.com (My purchase → reset activations), then run this again." ;; *) die "the licence key was not accepted${v_reason:+ ($v_reason)}. Copy it again from your purchase email; contact support if it keeps failing." ;; esac else die "licence server answered HTTP $code. Try again in a few minutes."; fi } download_kit() { # Download: read the 302 ourselves, then fetch the short-lived URL WITHOUT the licence header. # The storage URL may carry no file name (GitHub release assets): the version comes from the X-App-Army-Version # response header, the file name from response-content-disposition (else the path, else app-army-.tar.gz). dl_location "version=$VERSION" ; TB_URL="$LOC" KIT_VER="$LOC_VER"; [ -n "$KIT_VER" ] || KIT_VER="$(ver_from_name "${LOC_NAME:-$TB_URL}")" [[ "$KIT_VER" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+ ]] || die "the licence server did not say which version it is sending" TB_NAME="${LOC_NAME:-app-army-$KIT_VER.tar.gz}" dl_location "version=$KIT_VER&file=SHA256SUMS"; SUMS_URL="$LOC" TB="$WORK/$TB_NAME"; SUMS="$WORK/SHA256SUMS" curl -fsSL -A "$UA" --max-time 600 -o "$TB" "$TB_URL" || die "download of app-army-$KIT_VER failed; run again" curl -fsSL -A "$UA" --max-time 60 -o "$SUMS" "$SUMS_URL" || die "download of SHA256SUMS failed; run again" verify_and_unpack } dl_location() { # query → sets LOC (302 target); the key goes to curl on stdin, never in argv local out code : >"$WORK/hdr" out="$(printf 'header = "Authorization: Bearer %s"\nheader = "X-Install-Id: %s"\n' "$KEY" "$IID" \ | curl -sS -A "$UA" --max-time 30 -K - -D "$WORK/hdr" -o /dev/null -w '%{http_code} %{redirect_url}' "$API/api/license/download?$1" 2>"$WORK/err")" \ || die "could not reach $API for the download ($(head -c 200 "$WORK/err"))" code="${out%% *}"; LOC="${out#* }" [ "$code" = 403 ] && die "the licence server refused the download (licence not active for this install?). Run again; contact support if it repeats." case "$code" in 301|302|303|307|308) ;; *) die "licence server answered HTTP $code for the download" ;; esac proto_ok "$LOC" || die "the download link is not https; refusing it" LOC_VER="$(tr -d '\r' <"$WORK/hdr" | sed -n 's/^[Xx]-[Aa]pp-[Aa]rmy-[Vv]ersion:[[:space:]]*//p' | tail -n1 | tr -cd 'A-Za-z0-9._-')" LOC_NAME="$(LOC="$LOC" python3 -c 'import os,re,urllib.parse as u p=u.urlsplit(os.environ["LOC"]); q=u.parse_qs(p.query) cd=" ".join(q.get("response-content-disposition",[])) m=re.search(r"filename\*?=(?:UTF-8\x27\x27)?\"?([^\";]+)",cd) n=u.unquote(m.group(1)) if m else os.path.basename(p.path) print(n if re.fullmatch(r"app-army-[A-Za-z0-9._-]+\.tar\.gz",n) else "")' 2>/dev/null || true)" } verify_and_unpack() { local name want got name="${TB_NAME:-app-army-$KIT_VER.tar.gz}" if [ "$DRY" = 1 ]; then say "+ verify $name against SHA256SUMS, unpack to $KITS/$KIT_VER"; KIT_DIR="$KIT_LINK"; return; fi want="$(awk -v n="$name" '{f=$2; sub(/^\*/,"",f); if (f==n) print $1}' "$SUMS" | head -n1)" if [ -z "$want" ] && [ "$(grep -cE '[ *]app-army-[^ ]+\.tar\.gz$' "$SUMS")" = 1 ]; then # one tarball per release want="$(awk '$2 ~ /app-army-.*\.tar\.gz$/ {print $1}' "$SUMS")" name="$(awk '$2 ~ /app-army-.*\.tar\.gz$/ {f=$2; sub(/^\*/,"",f); print f}' "$SUMS")" fi [ -n "$want" ] || die "SHA256SUMS has no line for $name" got="$(sha256_of "$TB")" if [ "$want" != "$got" ]; then rm -f "$TB"; die "checksum mismatch for $name: the download is damaged or was tampered with. Nothing was unpacked. Run again."; fi say "checksum ok ($name)" # Refuse absolute paths, .. and links pointing outside before extracting anything. (Listings are captured # first: `tar | grep -q` under pipefail reports SIGPIPE as failure and would hide a match.) local list vlist list="$(tar -tzf "$TB" 2>/dev/null)" || die "$name is not a valid archive" vlist="$(tar -tvzf "$TB" 2>/dev/null)" || die "$name is not a valid archive" if printf '%s\n' "$list" | grep -qE '^/|(^|/)\.\.(/|$)'; then die "$name contains unsafe paths; refusing to unpack"; fi if printf '%s\n' "$vlist" | grep -E '^[lh]' | grep -qE -- '(->|link to) (/|(.*/)?\.\.(/|$))'; then die "$name contains unsafe links; refusing to unpack"; fi install_tree_from "tar" "$TB" } install_tree_from() { # tar | dir local stage root mkdir -p "$KITS"; stage="$(mktemp -d "$KITS/.stage.XXXXXX")" if [ "$1" = tar ]; then tar -xzf "$2" -C "$stage" --no-same-owner 2>/dev/null || tar -xzf "$2" -C "$stage" else mv "$2" "$stage/src"; fi root="$stage" if ! kit_has_cli "$root"; then root="$(find "$stage" -mindepth 2 -maxdepth 3 -type f \( -path '*/cli/kappmaker-army' -o -path '*/cli/army-init' \) | head -n1)" root="${root%/cli/*}" fi [ -n "$root" ] && kit_has_cli "$root" || { rm -rf "$stage"; die "the archive has no App Army kit in it (wrong file?)"; } [ -f "$root/VERSION" ] || printf '%s\n' "$KIT_VER" >"$root/VERSION" rm -rf "$KITS/$KIT_VER.old"; [ -e "$KITS/$KIT_VER" ] && mv "$KITS/$KIT_VER" "$KITS/$KIT_VER.old" mv "$root" "$KITS/$KIT_VER"; rm -rf "$stage" "$KITS/$KIT_VER.old" # ~/.army/kit → releases/. A real folder there (an old manual install) is kept aside, never deleted. if [ -e "$KIT_LINK" ] && [ ! -L "$KIT_LINK" ]; then mv "$KIT_LINK" "$KIT_LINK.before-$(date +%Y%m%d%H%M%S)"; fi ln -sfn "releases/$KIT_VER" "$KIT_LINK" [ "$SERVER" = 1 ] && chown -R "$SRV_USER:$SRV_USER" "$ARMY_DIR_T" && chmod 700 "$ARMY_DIR_T" KIT_DIR="$KIT_LINK" done_ "kit $KIT_VER in ~/.army/releases/$KIT_VER (~/.army/kit points to it)" save_key } fetch_github() { local ver_arg="" src [ "$VERSION" = latest ] || ver_arg="--branch $VERSION" if [ "$DRY" = 1 ]; then say "+ git clone --depth 1 $ver_arg ${KAPPMAKER_RELEASE_REPO:-$REPO_SSH}"; KIT_VER="$VERSION"; KIT_DIR="$KIT_LINK"; return; fi WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT; src="$WORK/kit" CONTACTED="nothing (the kit came from GitHub with your own access)" # shellcheck disable=SC2086 if [ -n "${KAPPMAKER_RELEASE_REPO:-}" ]; then git clone -q --depth 1 $ver_arg "$KAPPMAKER_RELEASE_REPO" "$src" else GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-ssh -o BatchMode=yes}" git clone -q --depth 1 $ver_arg "$REPO_SSH" "$src" 2>/dev/null \ || git clone -q --depth 1 $ver_arg "$REPO_HTTPS" "$src"; fi \ || die "git clone failed. The release repo needs the GitHub invite from your purchase (accept it first), or use the licence key instead." KIT_VER="$(cat "$src/VERSION" 2>/dev/null || git -C "$src" describe --tags --always 2>/dev/null || echo git)" KIT_VER="$(printf '%s' "$KIT_VER" | tr -cd 'A-Za-z0-9._-')" [ "$SERVER" = 0 ] || git config --global --add safe.directory "$KITS/$KIT_VER" 2>/dev/null || true install_tree_from dir "$src" } # ---------------------------------------------------------------------- plugins, skills, voice claude_as_target() { # claude CLI as the kit user, headless channel dir so it can never touch a live worker's bot as_target env TELEGRAM_STATE_DIR="$TARGET_HOME/.claude/channels/telegram-headless" claude "$@"; } plugin_on() { as_target python3 -c 'import json,os,sys try: d=json.load(open(os.path.expanduser("~/.claude/settings.json"))) except Exception: sys.exit(1) sys.exit(0 if (d.get("enabledPlugins") or {}).get(sys.argv[1]) else 1)' "$1" 2>/dev/null; } step_plugins() { # the kappmaker skills plugin (+ extras). The kit's own skills/agents/guard are rendered and linked by # kappmaker-army init (~/.army/skills → ~/.claude/skills); its plugins are NOT installed here (they would hold # unrendered placeholders and add every agent and the guard a second time). step "Plugins and skills" if [ "$DRY" = 1 ]; then say "+ claude plugin marketplace add KAppMaker/KAppMaker-CLI; install kappmaker$([ "$EXTRAS" = 1 ] && echo '; extras: ui-ux-pro-max, caveman')"; return 0; fi as_target bash -c 'command -v claude' >/dev/null 2>&1 || { warn "Claude Code is not installed, so plugins were skipped (run this installer again after installing it)"; return 0; } local ok_list="" p claude_as_target plugin marketplace add KAppMaker/KAppMaker-CLI >/dev/null 2>&1 || true claude_as_target plugin marketplace update >/dev/null 2>&1 || true for p in kappmaker@KAppMaker-CLI; do if plugin_on "$p" || claude_as_target plugin install "$p" >/dev/null 2>&1; then ok_list="$ok_list ${p%@*}" else warn "plugin $p not installed (retry later: claude plugin install $p)"; fi done [ -z "$ok_list" ] || done_ "plugins:$ok_list" if [ "$EXTRAS" = 1 ]; then # optional third-party add-ons, from upstream (THIRD_PARTY.md); never fatal if as_target bash -c 'cd "$HOME" && npx -y github:JuliusBrussee/caveman /dev/null 2>&1'; then done_ "extra: caveman (terse replies)" else warn "extra caveman not installed (later: npx -y github:JuliusBrussee/caveman)"; fi if as_target bash -c 'command -v uipro >/dev/null || npm install -g --silent --prefix "$HOME/.local" uipro-cli >/dev/null 2>&1; cd "$HOME" && uipro init --ai claude --force /dev/null 2>&1'; then done_ "extra: ui-ux-pro-max (design rules)" else warn "extra ui-ux-pro-max not installed (later: npm i -g uipro-cli && (cd ~ && uipro init --ai claude))"; fi fi } step_voice() { # local speech-to-text for Telegram voice notes (W2's kappmaker-army voice setup); never fatal step "Voice notes (local transcription)" if [ "$DRY" = 1 ]; then say "+ kappmaker-army voice setup"; return 0; fi if as_target bash "$(cli_bin)" voice setup /dev/null 2>&1; then done_ "service $WORKER_UNIT_PREFIX$WORKER enabled (starts on boot, restarts on crash; waits until Claude is signed in and the bot token is set)" else warn "could not enable $WORKER_UNIT_PREFIX$WORKER.service (systemctl status $WORKER_UNIT_PREFIX$WORKER)"; fi else warn "no systemd here: start the worker with 'kappmaker-army worker start $WORKER'"; fi if as_target bash "$army" worker cron install >/dev/null 2>&1; then done_ "usage-limit watchdog every 5 min (cron)" else warn "watchdog not scheduled (kappmaker-army worker cron install)"; fi else if [ -n "$tok" ]; then warn "adding a worker asks for the bot token: run 'kappmaker-army worker add $WORKER' in a terminal" elif as_target bash "$army" worker add "$WORKER" "$ARMY_DIR_T/license.key" ) chmod 600 "$ARMY_DIR_T/license.key" [ "$SERVER" = 1 ] && chown "$SRV_USER:$SRV_USER" "$ARMY_DIR_T/license.key" KEY="" } # ---------------------------------------------------------------------- guided first run (W2's kappmaker-army start) has_start() { local c; c="$(cli_bin)"; [ -f "$c" ] || return 1 [ -f "$ARMY_DIR_T/bin/kappmaker-army-start" ] || [ -f "$ARMY_DIR_T/bin/army-start" ] || grep -qE '(^|[|( ])start([|)]|$)' "$c" 2>/dev/null; } offer_start() { [ "$START" = 1 ] && [ "$DRY" = 0 ] || return 0 has_start || { say ""; say "(The guided first run 'kappmaker-army start' is not in this kit yet; follow the Next steps above.)"; return 0; } if [ "$TTY" = 0 ] || [ "$YES" = 1 ]; then say ""; say "Ready. Start the guided first run with: kappmaker-army start"; return 0; fi ask_yes "Start the guided first run now (sign in to Claude, set up your Telegram bot, describe your first app)?" || { say "Any time later: kappmaker-army start"; return 0; } as_target bash "$(cli_bin)" start /dev/null; then WARNS="$WARNS - your app details are still placeholders (app id com.example, company, GitHub owner): kappmaker-army start asks for them" fi [ -n "$WARNS" ] && say "Needs a look:$WARNS" say "" say "Next:" if has_start 2>/dev/null; then [ "$SERVER" = 1 ] && say " As the worker user (ssh $SRV_USER@, or from root: sudo -iu $SRV_USER):" say " kappmaker-army start guided: sign in to Claude, create + check your Telegram bot, describe your first app" say " kappmaker-army doctor health check (kappmaker-army doctor --fix repairs common problems)" [ "$SERVER" = 1 ] && say " Your provider's cloud firewall / security group (if any): allow inbound SSH only." return 0 fi if [ "$SERVER" = 1 ]; then say " 1. Log in as the worker user: ssh $SRV_USER@ (root: sudo -iu $SRV_USER)" say " 2. Sign in to Claude once: claude (then /exit)" if [ -n "$WORKER" ]; then say " 3. Bot token (if not set yet): kappmaker-army worker add $WORKER (typed hidden, never in a chat; the service picks it up)" say " 4. DM your bot, then: kappmaker-army worker attach $WORKER → /telegram:access pair (detach: Ctrl-b d)" else say " 3. Add a worker: kappmaker-army worker add main"; fi say " Board (installed, off): kappmaker-army board link" say " Your provider's cloud firewall / security group (if any): allow inbound SSH only." say " Optional: SSH only over Tailscale: sudo kappmaker-army-tailscale-lockdown --user $SRV_USER" else say " 1. Open a new terminal (so 'kappmaker-army' is on your PATH)." say " 2. Sign in to Claude once: claude" say " 3. Start building: cd ~/projects && claude" say " Optional always-on Telegram worker: kappmaker-army worker add main" fi say " Health check any time: kappmaker-army doctor" } main "$@"