|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +usage() { |
| 5 | + cat <<'EOF' |
| 6 | +Usage: |
| 7 | + curl -fsSL https://elephant.agentic-in.ai/install.sh | bash |
| 8 | + bash install.sh [install|upgrade|health] [options] |
| 9 | +
|
| 10 | +Options: |
| 11 | + --install-root PATH Durable install root. Default: $HOME/.elephant |
| 12 | + --bin-dir PATH Directory that will receive the elephant launcher. Default: $HOME/.local/bin |
| 13 | + --python PATH Python interpreter to use. Default: python3 |
| 14 | + --channel CHANNEL Package channel to install. One of: dev, stable. Default: dev |
| 15 | + --pip-spec SPEC Explicit pip-installable package spec. Overrides --channel |
| 16 | + --skip-run Skip the automatic elephant launch after install or upgrade |
| 17 | + --skip-health Deprecated alias for --skip-run |
| 18 | + --help Show this help text |
| 19 | +
|
| 20 | +Environment overrides: |
| 21 | + ELEPHANT_INSTALL_CHANNEL |
| 22 | + ELEPHANT_PIP_SPEC |
| 23 | + ELEPHANT_PYTHON |
| 24 | +EOF |
| 25 | +} |
| 26 | + |
| 27 | +command_name="install" |
| 28 | +install_root="${HOME}/.elephant" |
| 29 | +bin_dir="${HOME}/.local/bin" |
| 30 | +python_bin="${ELEPHANT_PYTHON:-python3}" |
| 31 | +channel="${ELEPHANT_INSTALL_CHANNEL:-dev}" |
| 32 | +pip_spec="${ELEPHANT_PIP_SPEC:-}" |
| 33 | +package_name="elephant-agent" |
| 34 | +skip_run="0" |
| 35 | + |
| 36 | +while [ "$#" -gt 0 ]; do |
| 37 | + case "$1" in |
| 38 | + install|upgrade|health) |
| 39 | + command_name="$1" |
| 40 | + shift |
| 41 | + ;; |
| 42 | + --install-root) |
| 43 | + install_root="$2" |
| 44 | + shift 2 |
| 45 | + ;; |
| 46 | + --bin-dir) |
| 47 | + bin_dir="$2" |
| 48 | + shift 2 |
| 49 | + ;; |
| 50 | + --python) |
| 51 | + python_bin="$2" |
| 52 | + shift 2 |
| 53 | + ;; |
| 54 | + --channel) |
| 55 | + channel="$2" |
| 56 | + shift 2 |
| 57 | + ;; |
| 58 | + --pip-spec|--package-source) |
| 59 | + pip_spec="$2" |
| 60 | + shift 2 |
| 61 | + ;; |
| 62 | + --skip-run|--skip-health) |
| 63 | + skip_run="1" |
| 64 | + shift |
| 65 | + ;; |
| 66 | + --help|-h) |
| 67 | + usage |
| 68 | + exit 0 |
| 69 | + ;; |
| 70 | + *) |
| 71 | + echo "Unknown argument: $1" >&2 |
| 72 | + usage >&2 |
| 73 | + exit 2 |
| 74 | + ;; |
| 75 | + esac |
| 76 | +done |
| 77 | + |
| 78 | +venv_dir="${install_root}/venv" |
| 79 | +venv_python="${venv_dir}/bin/python" |
| 80 | +state_dir="${install_root}/herd" |
| 81 | +launcher_path="${bin_dir}/elephant" |
| 82 | + |
| 83 | +require_command() { |
| 84 | + if ! command -v "$1" >/dev/null 2>&1; then |
| 85 | + echo "Missing required command: $1" >&2 |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | +} |
| 89 | + |
| 90 | +has_uv() { |
| 91 | + command -v uv >/dev/null 2>&1 |
| 92 | +} |
| 93 | + |
| 94 | +require_python_version() { |
| 95 | + if ! "$python_bin" - <<'PY' |
| 96 | +import sys |
| 97 | +sys.exit(0 if sys.version_info >= (3, 12) else 1) |
| 98 | +PY |
| 99 | + then |
| 100 | + echo "Elephant Agent currently requires Python 3.12 or newer." >&2 |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | +} |
| 104 | + |
| 105 | +ensure_config_yaml() { |
| 106 | + mkdir -p "${state_dir}" |
| 107 | + local config_path="${install_root}/config.yaml" |
| 108 | + if [ ! -f "${config_path}" ]; then |
| 109 | + cat > "${config_path}" <<EOF |
| 110 | +runtime: |
| 111 | + state_dir: ${state_dir} |
| 112 | + default_profile_id: default |
| 113 | +models: |
| 114 | + default_provider_source: config |
| 115 | + provider: null |
| 116 | +sessions: |
| 117 | + persist_system_prompts: true |
| 118 | + persist_assistant_responses: true |
| 119 | + max_history_rows: 200 |
| 120 | +skills: |
| 121 | + enable_profile_overrides: true |
| 122 | + external_dirs: ["~/.agents/skills"] |
| 123 | +tools: |
| 124 | + require_approval_for_risky: true |
| 125 | +gateway: |
| 126 | + enabled: false |
| 127 | + state_dir: ${state_dir} |
| 128 | +dashboard: |
| 129 | + host: "127.0.0.1" |
| 130 | + port: 4174 |
| 131 | +extensions: {} |
| 132 | +EOF |
| 133 | + fi |
| 134 | +} |
| 135 | + |
| 136 | +normalize_channel() { |
| 137 | + case "$channel" in |
| 138 | + dev|stable) |
| 139 | + ;; |
| 140 | + *) |
| 141 | + echo "Unsupported channel: $channel" >&2 |
| 142 | + exit 2 |
| 143 | + ;; |
| 144 | + esac |
| 145 | +} |
| 146 | + |
| 147 | +describe_package_selection() { |
| 148 | + if [ -n "${pip_spec}" ]; then |
| 149 | + printf '%s\n' "${pip_spec}" |
| 150 | + return |
| 151 | + fi |
| 152 | + |
| 153 | + case "${channel}" in |
| 154 | + dev) |
| 155 | + printf '%s\n' "${package_name} (--pre, latest development release)" |
| 156 | + ;; |
| 157 | + stable) |
| 158 | + printf '%s\n' "${package_name} (latest stable release)" |
| 159 | + ;; |
| 160 | + esac |
| 161 | +} |
| 162 | + |
| 163 | +ensure_runtime() { |
| 164 | + mkdir -p "${install_root}" |
| 165 | + |
| 166 | + if has_uv; then |
| 167 | + if [ ! -x "${venv_python}" ]; then |
| 168 | + uv venv "${venv_dir}" --python "${python_bin}" |
| 169 | + fi |
| 170 | + if [ -n "${pip_spec}" ]; then |
| 171 | + uv pip install --python "${venv_python}" --upgrade "${pip_spec}" |
| 172 | + else |
| 173 | + case "${channel}" in |
| 174 | + dev) |
| 175 | + uv pip install --python "${venv_python}" --upgrade --prerelease=allow "${package_name}" |
| 176 | + ;; |
| 177 | + stable) |
| 178 | + uv pip install --python "${venv_python}" --upgrade "${package_name}" |
| 179 | + ;; |
| 180 | + esac |
| 181 | + fi |
| 182 | + else |
| 183 | + if [ ! -x "${venv_python}" ]; then |
| 184 | + "${python_bin}" -m venv "${venv_dir}" |
| 185 | + fi |
| 186 | + "${venv_python}" -m pip install --upgrade pip setuptools wheel >/dev/null |
| 187 | + if [ -n "${pip_spec}" ]; then |
| 188 | + "${venv_python}" -m pip install --upgrade "${pip_spec}" |
| 189 | + else |
| 190 | + case "${channel}" in |
| 191 | + dev) |
| 192 | + "${venv_python}" -m pip install --upgrade --pre "${package_name}" |
| 193 | + ;; |
| 194 | + stable) |
| 195 | + "${venv_python}" -m pip install --upgrade "${package_name}" |
| 196 | + ;; |
| 197 | + esac |
| 198 | + fi |
| 199 | + fi |
| 200 | + |
| 201 | + ensure_browser_runtime |
| 202 | +} |
| 203 | + |
| 204 | +ensure_browser_runtime() { |
| 205 | + if [ "${ELEPHANT_SKIP_BROWSER_INSTALL:-0}" = "1" ]; then |
| 206 | + return |
| 207 | + fi |
| 208 | + if "${venv_python}" -m playwright install --only-shell chromium >/dev/null 2>&1; then |
| 209 | + return |
| 210 | + fi |
| 211 | + echo "Warning: browser runtime install failed; browser tools will retry on first use." >&2 |
| 212 | + echo " To repair manually, run: ${venv_python} -m playwright install --only-shell chromium" >&2 |
| 213 | +} |
| 214 | + |
| 215 | +write_launcher() { |
| 216 | + mkdir -p "${bin_dir}" |
| 217 | + cat > "${launcher_path}" <<EOF |
| 218 | +#!/usr/bin/env bash |
| 219 | +set -euo pipefail |
| 220 | +install_root="\${ELEPHANT_HOME:-${install_root}}" |
| 221 | +state_dir="\${ELEPHANT_HERD_DIR:-${state_dir}}" |
| 222 | +venv_python="\${ELEPHANT_PYTHON:-${venv_python}}" |
| 223 | +
|
| 224 | +if [ ! -x "\${venv_python}" ]; then |
| 225 | + echo "Elephant Agent runtime is missing: \${venv_python}" >&2 |
| 226 | + echo "Run the installer again." >&2 |
| 227 | + exit 1 |
| 228 | +fi |
| 229 | +
|
| 230 | +export ELEPHANT_HOME="\${install_root}" |
| 231 | +export ELEPHANT_HERD_DIR="\${state_dir}" |
| 232 | +exec "\${venv_python}" -m apps.launcher "\$@" |
| 233 | +EOF |
| 234 | + chmod +x "${launcher_path}" |
| 235 | +} |
| 236 | + |
| 237 | +run_health() { |
| 238 | + if [ ! -x "${launcher_path}" ]; then |
| 239 | + echo "Launcher not found: ${launcher_path}" >&2 |
| 240 | + echo "Run 'curl -fsSL https://elephant.agentic-in.ai/install.sh | bash' first." >&2 |
| 241 | + exit 1 |
| 242 | + fi |
| 243 | + "${launcher_path}" status |
| 244 | +} |
| 245 | + |
| 246 | +run_launcher() { |
| 247 | + if [ ! -x "${launcher_path}" ]; then |
| 248 | + echo "Launcher not found: ${launcher_path}" >&2 |
| 249 | + echo "Run 'curl -fsSL https://elephant.agentic-in.ai/install.sh | bash' first." >&2 |
| 250 | + exit 1 |
| 251 | + fi |
| 252 | + "${launcher_path}" |
| 253 | +} |
| 254 | + |
| 255 | +install_or_upgrade() { |
| 256 | + require_command "${python_bin}" |
| 257 | + require_python_version |
| 258 | + normalize_channel |
| 259 | + mkdir -p "${install_root}" "${state_dir}" |
| 260 | + ensure_config_yaml |
| 261 | + ensure_runtime |
| 262 | + write_launcher |
| 263 | + |
| 264 | + echo "Installed Elephant Agent CLI launcher" |
| 265 | + echo " package: $(describe_package_selection)" |
| 266 | + echo " install_root: ${install_root}" |
| 267 | + echo " herd_dir: ${state_dir}" |
| 268 | + echo " runtime_db: ${state_dir}/elephant.sqlite3" |
| 269 | + echo " config: ${install_root}/config.yaml" |
| 270 | + echo " runtime: ${venv_python}" |
| 271 | + echo " launcher: ${launcher_path}" |
| 272 | + if ! printf '%s' ":${PATH}:" | grep -Fq ":${bin_dir}:"; then |
| 273 | + echo " path_hint: add ${bin_dir} to PATH to call 'elephant' directly" |
| 274 | + fi |
| 275 | + echo "Next commands" |
| 276 | + echo " - elephant" |
| 277 | + echo " - elephant init" |
| 278 | + echo " - elephant status" |
| 279 | + echo " - elephant wake" |
| 280 | + echo " - elephant herd new nova" |
| 281 | + |
| 282 | + if [ "${skip_run}" != "1" ]; then |
| 283 | + echo |
| 284 | + echo "Launching Elephant Agent" |
| 285 | + run_launcher |
| 286 | + fi |
| 287 | +} |
| 288 | + |
| 289 | +case "${command_name}" in |
| 290 | + install|upgrade) |
| 291 | + install_or_upgrade |
| 292 | + ;; |
| 293 | + health) |
| 294 | + run_health |
| 295 | + ;; |
| 296 | + *) |
| 297 | + echo "Unsupported command: ${command_name}" >&2 |
| 298 | + exit 2 |
| 299 | + ;; |
| 300 | +esac |
0 commit comments