-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·831 lines (742 loc) · 30.5 KB
/
setup.sh
File metadata and controls
executable file
·831 lines (742 loc) · 30.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
#!/bin/bash
#
# Hummingbot Deploy Instance Installer
#
# Orchestrates cloning and upgrades; Condor and hummingbot-api use their own Makefiles.
#
# Non-interactive / CI: set DEPLOY_NONINTERACTIVE=1 (or CI=true) and provide:
# TELEGRAM_TOKEN, ADMIN_USER_ID (written to condor/.env before first make install)
# Optional: DEPLOY_HUMMINGBOT_API=true|false (default false if omitted)
#
# Standalone API: run this script with --hummingbot-api (see --help).
#
# Nested make: Condor's setup-environment.sh respects SKIP_SETUP_RESTART=1 (no exec restart).
#
set -eu
# --- Configuration ---
CONDOR_REPO="https://github.com/hummingbot/condor.git"
API_REPO="https://github.com/hummingbot/hummingbot-api.git"
# Used in printed hints when the script has no file path (e.g. curl | bash)
DEPLOY_SETUP_RAW_URL="https://raw.githubusercontent.com/hummingbot/deploy/refs/heads/main/setup.sh"
CONDOR_DIR="condor"
API_DIR="hummingbot-api"
DOCKER_COMPOSE=""
CONDOR_BRANCH=""
CONDOR_PR=""
AUTO_YES="n"
HB_API_ONLY_MODE="n"
# --- Color Codes ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
CREATED_DIRS=()
cleanup() {
local exit_code=$?
rm -f get-docker.sh 2>/dev/null || true
# Guard the iteration: on macOS bash 3.2 with `set -u`, "${arr[@]}" on an
# empty array raises an unbound-variable error inside this very trap and
# masks the real failure.
if [ "$exit_code" -ne 0 ] && [ "${#CREATED_DIRS[@]}" -gt 0 ]; then
for dir in "${CREATED_DIRS[@]}"; do
if [ -d "$dir" ]; then
msg_warn "Cleaning up partial installation: $dir"
rm -rf "$dir" 2>/dev/null || true
fi
done
fi
}
trap cleanup EXIT
msg_info() { echo -e "${CYAN}[INFO] $1${NC}"; }
msg_ok() { echo -e "${GREEN}[OK] $1${NC}"; }
msg_warn() { echo -e "${YELLOW}[WARN] $1${NC}" >&2; }
msg_error() { echo -e "${RED}[ERROR] $1${NC}" >&2; }
prompt() { echo -en "${PURPLE}$1${NC}" > /dev/tty 2>/dev/null || echo -en "${PURPLE}$1${NC}"; }
prompt_yesno() {
local answer=""
if [[ "${AUTO_YES}" == "y" ]] || deploy_noninteractive; then
echo "y"
return
fi
while true; do
prompt "$1 (y/n): "
if [[ -r /dev/tty ]] && [[ -w /dev/tty ]]; then
read -r answer < /dev/tty || answer=""
else
read -r answer || answer=""
fi
case "$answer" in
[Yy]) echo "y"; return ;;
[Nn]) echo "n"; return ;;
*) msg_warn "Please answer 'y' or 'n'" ;;
esac
done
}
# Run a command with stdin attached to the real terminal when one exists, so
# child scripts (condor setup-environment.sh, hummingbot-api make setup, etc.)
# can prompt the user even when this installer was started via `curl … | bash`
# — in that case the script's own stdin is the pipe, not the terminal.
# Falls back to inherited stdin when /dev/tty is unavailable or when we are
# explicitly running non-interactively (CI, DEPLOY_NONINTERACTIVE=1, etc.).
run_with_tty() {
if [[ -r /dev/tty ]] && [[ -w /dev/tty ]] && ! deploy_noninteractive; then
"$@" </dev/tty
else
"$@"
fi
}
command_exists() { command -v "$1" >/dev/null 2>&1; }
refresh_tool_path() {
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:/usr/local/bin:$PATH"
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
if [ -s "$NVM_DIR/nvm.sh" ]; then
# shellcheck disable=SC1090
\. "$NVM_DIR/nvm.sh"
nvm use default >/dev/null 2>&1 || nvm use node >/dev/null 2>&1 || true
fi
if command_exists npm; then
local npm_prefix
npm_prefix=$(npm config get prefix 2>/dev/null || true)
if [[ -n "${npm_prefix:-}" ]] && [[ -d "$npm_prefix/bin" ]]; then
export PATH="$npm_prefix/bin:$PATH"
fi
fi
}
deploy_noninteractive() {
[[ "${DEPLOY_NONINTERACTIVE:-}" == "1" ]] || [[ "${CI:-}" == "true" ]] || [[ "${DEBIAN_FRONTEND:-}" == "noninteractive" ]]
}
is_interactive() {
if [[ -t 0 ]] && [[ -t 1 ]] && [[ "${TERM:-dumb}" != "dumb" ]]; then
return 0
fi
if [[ -c /dev/tty ]] && [[ -w /dev/tty ]]; then
return 0
fi
return 1
}
# --- Parse Command Line Arguments ---
UPGRADE_MODE="n"
while [[ $# -gt 0 ]]; do
case $1 in
--upgrade) UPGRADE_MODE="y"; shift ;;
--hummingbot-api) HB_API_ONLY_MODE="y"; shift ;;
--api) HB_API_ONLY_MODE="y"; shift ;; # alias for --hummingbot-api
-y|--yes) AUTO_YES="y"; shift ;;
-b|--branch) CONDOR_BRANCH="$2"; shift 2 ;;
-p|--pr) CONDOR_PR="$2"; shift 2 ;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --upgrade Upgrade existing installation (Condor + optional API)"
echo " --hummingbot-api Install or upgrade Hummingbot API only (Docker stack)"
echo " --api Same as --hummingbot-api (alias)"
echo " -y, --yes Auto-confirm prompts (e.g. API reinstall)"
echo " -b, --branch NAME Clone a specific branch of Condor"
echo " -p, --pr ID Pull a specific PR ID from Condor"
echo " -h, --help Show this help message"
echo ""
echo "Non-interactive Condor install: DEPLOY_NONINTERACTIVE=1 TELEGRAM_TOKEN=... ADMIN_USER_ID=..."
echo ""
echo "Examples:"
echo " $0 # Fresh Condor (+ prompts for Telegram / optional API)"
echo " $0 --upgrade # Pull repos, rebuild Condor, refresh Docker images"
echo " $0 --hummingbot-api # Install or upgrade Hummingbot API stack only"
echo " $0 --hummingbot-api -y # Same, auto-confirm reinstall prompts"
exit 0
;;
*)
msg_error "Unknown option: $1"
exit 1
;;
esac
done
# Absolute path for "bash /path/setup.sh …" hints. Empty when piped: `curl … | bash` leaves
# BASH_SOURCE unset, and `set -u` would error on ${BASH_SOURCE[0]}.
deploy_resolve_script_abs() {
local s="${BASH_SOURCE[0]:-}"
if [[ -n "$s" && -f "$s" ]]; then
echo "$(cd "$(dirname "$s")" >/dev/null 2>&1 && pwd)/$(basename "$s")"
return
fi
if [[ -f "$(pwd)/setup.sh" ]]; then
echo "$(pwd)/setup.sh"
return
fi
echo ""
}
DEPLOY_SCRIPT_ABS="$(deploy_resolve_script_abs)"
# Print either `bash <path> FLAGS` or `curl … | bash -s -- FLAGS` when path is unknown.
deploy_print_rerun() {
local extra="$1"
local suffix="${2:-}"
if [[ -n "${DEPLOY_SCRIPT_ABS:-}" ]]; then
echo -e " ${GREEN}bash ${DEPLOY_SCRIPT_ABS} ${extra}${NC}${suffix}"
else
echo -e " ${GREEN}curl -fsSL ${DEPLOY_SETUP_RAW_URL} | bash -s -- ${extra}${NC}${suffix}"
fi
}
print_tmux_section() {
echo ""
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD} Condor logs (read this first)${NC}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e " Condor runs in tmux session ${CYAN}condor${NC}. To see live logs and tracebacks:"
echo ""
echo -e " ${GREEN}${BOLD}tmux attach -t condor${NC}"
echo ""
echo -e " • Detach without stopping Condor: press ${CYAN}Ctrl+B${NC} then ${CYAN}D${NC}"
echo -e " • Stop Condor completely: ${CYAN}tmux kill-session -t condor${NC}"
echo ""
}
print_telegram_verify_section() {
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD} Telegram — verify the bot came online${NC}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo " Next step: open the Telegram chat with your Condor bot."
echo " After the process starts successfully, Condor notifies admins with:"
echo ""
echo -e " ${GREEN}\"Condor is online and ready.\"${NC}"
echo ""
echo " If that message does not appear within a minute or two:"
echo " • Attach to tmux (command above) and read the error output."
echo " • Confirm condor/.env has a valid TELEGRAM_TOKEN and ADMIN_USER_ID."
echo ""
}
print_hummingbot_api_manual_section() {
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD} Hummingbot API only (no Condor)${NC}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo " Same installer, API-only mode (clones or upgrades ./hummingbot-api, pulls images):"
echo ""
deploy_print_rerun "--hummingbot-api"
echo ""
echo " Fully manual equivalent (after Docker is installed and running):"
echo ""
echo -e " ${GREEN}git clone --depth 1 ${API_REPO} hummingbot-api${NC}"
echo -e " ${GREEN}cd hummingbot-api && make setup && docker compose pull && make deploy${NC}"
echo ""
echo " Condor's setup wizard expects the API repo as ../hummingbot-api when both live side by side."
echo ""
}
print_condor_install_footer() {
echo ""
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD} Later: upgrade Condor + sibling repos${NC}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
deploy_print_rerun "--upgrade"
echo ""
print_hummingbot_api_manual_section
}
detect_os_arch() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
armv7*|armv8*|armv*) ARCH="arm" ;;
*) msg_warn "Unknown architecture: $ARCH, defaulting to amd64"; ARCH="amd64" ;;
esac
msg_info "Detected OS: $OS, Architecture: $ARCH"
if [[ "$OS" == "darwin" ]]; then
if [[ -x "/opt/homebrew/bin/brew" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ -x "/usr/local/bin/brew" ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
fi
}
detect_docker_compose() {
if docker compose version >/dev/null 2>&1; then
DOCKER_COMPOSE="docker compose"
msg_info "Using Docker Compose plugin"
elif command_exists docker-compose; then
DOCKER_COMPOSE="docker-compose"
msg_info "Using standalone docker-compose"
else
msg_error "Neither docker-compose nor docker compose plugin found"
exit 1
fi
}
check_docker_running() {
if ! docker info >/dev/null 2>&1; then
if [[ "$OS" == "darwin" ]]; then
msg_error "Docker Desktop is not running."
else
msg_error "Docker daemon is not running."
fi
exit 1
fi
msg_ok "Docker daemon is running"
}
check_disk_space() {
local required_mb=2048
local available_mb=""
if [[ "$OS" == "linux" ]] || [[ "$OS" == "darwin" ]]; then
# -P forces POSIX single-line output so long device names don't wrap
# and confuse the column extraction below.
available_mb=$(df -mP . 2>/dev/null | awk 'NR==2 {print $4}')
else
return
fi
if [[ -n "${available_mb:-}" ]] && [[ "$available_mb" -lt "$required_mb" ]]; then
msg_error "Insufficient disk space. Need ${required_mb}MB, have ${available_mb}MB"
exit 1
fi
msg_ok "Sufficient disk space available (${available_mb:-unknown}MB)"
}
install_nodejs_via_nvm() {
msg_info "Installing Node.js via nvm..."
if [ ! -d "$HOME/.nvm" ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash || return 1
fi
export NVM_DIR="$HOME/.nvm"
# shellcheck disable=SC1090
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 24 >/dev/null 2>&1 || nvm install --lts >/dev/null 2>&1 || return 1
nvm use 24 >/dev/null 2>&1 || nvm use --lts >/dev/null 2>&1 || true
nvm alias default 24 >/dev/null 2>&1 || nvm alias default "$(nvm version)" >/dev/null 2>&1 || true
export PATH="$NVM_DIR/versions/node/$(nvm version)/bin:$PATH"
}
# $1: all | condor-only (condor-only skips docker / compose requirement)
install_dependencies() {
local mode="${1:-all}"
msg_info "Checking dependencies for git clone / make..."
MISSING_DEPS=()
command_exists git || MISSING_DEPS+=("git")
command_exists curl || MISSING_DEPS+=("curl")
command_exists make || MISSING_DEPS+=("make")
command_exists tmux || MISSING_DEPS+=("tmux")
command_exists uv || MISSING_DEPS+=("uv")
if ! command_exists node || ! command_exists npm; then
MISSING_DEPS+=("nodejs/npm")
fi
if [[ "$mode" == "all" ]]; then
command_exists docker || MISSING_DEPS+=("docker")
if ! (command_exists docker-compose || (command_exists docker && docker compose version >/dev/null 2>&1)); then
MISSING_DEPS+=("docker-compose")
fi
fi
local label="git, curl, make, tmux, uv, node, npm"
[[ "$mode" == "all" ]] && label="$label, docker, docker-compose"
if [ ${#MISSING_DEPS[@]} -eq 0 ]; then
msg_ok "Dependencies present ($label)"
refresh_tool_path
return
fi
msg_warn "Missing: ${MISSING_DEPS[*]}"
if [[ "$OS" != "linux" ]]; then
msg_error "Install these manually, then re-run:"
printf ' - %s\n' "${MISSING_DEPS[@]}"
exit 1
fi
local auto_install=false
if deploy_noninteractive || [[ "${AUTO_YES}" == "y" ]] || ! is_interactive; then
auto_install=true
fi
if ! $auto_install; then
if ! is_interactive; then
msg_error "Non-interactive shell: set DEPLOY_NONINTERACTIVE=1 or install deps manually."
exit 1
fi
if [ "$(prompt_yesno "Install missing packages automatically?")" != "y" ]; then
exit 1
fi
fi
local SUDO_CMD=""
if [[ $EUID -ne 0 ]]; then
command_exists sudo || { msg_error "sudo required to install packages"; exit 1; }
SUDO_CMD="sudo"
fi
if command_exists apt-get; then
$SUDO_CMD env DEBIAN_FRONTEND=noninteractive apt-get update -qq
PKG_INSTALL="$SUDO_CMD env DEBIAN_FRONTEND=noninteractive apt-get install -y"
elif command_exists dnf; then
$SUDO_CMD dnf check-update || true
PKG_INSTALL="$SUDO_CMD dnf install -y"
elif command_exists yum; then
$SUDO_CMD yum install -y || true
PKG_INSTALL="$SUDO_CMD yum install -y"
elif command_exists apk; then
$SUDO_CMD apk update
PKG_INSTALL="$SUDO_CMD apk add"
elif command_exists pacman; then
$SUDO_CMD pacman -Sy --noconfirm
PKG_INSTALL="$SUDO_CMD pacman -S --noconfirm"
else
msg_error "Unsupported package manager"
exit 1
fi
for dep in "${MISSING_DEPS[@]}"; do
case $dep in
git|curl|make|tmux)
msg_info "Installing $dep..."
eval "$PKG_INSTALL $dep" || exit 1
;;
uv)
curl -LsSf https://astral.sh/uv/install.sh | sh || exit 1
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
;;
nodejs/npm)
install_nodejs_via_nvm || exit 1
;;
docker)
curl -fsSL https://get.docker.com -o get-docker.sh
$SUDO_CMD sh get-docker.sh || exit 1
rm -f get-docker.sh
if [[ $EUID -ne 0 ]]; then
$SUDO_CMD usermod -aG docker "$USER" || true
fi
if command_exists systemctl; then
$SUDO_CMD systemctl enable docker --now 2>/dev/null || true
fi
;;
docker-compose)
if command_exists apt-get; then
eval "$PKG_INSTALL docker-compose-plugin" || eval "$PKG_INSTALL docker-compose" || exit 1
else
eval "$PKG_INSTALL docker-compose" || exit 1
fi
;;
*)
msg_info "Installing $dep..."
eval "$PKG_INSTALL $dep" || exit 1
;;
esac
done
msg_ok "Dependencies installed"
refresh_tool_path
}
ensure_condor_env_noninteractive() {
# After clone, before make install — seed .env so setup-environment skips prompts.
if [[ -f "$CONDOR_DIR/.env" ]]; then
return 0
fi
if deploy_noninteractive; then
if [[ -z "${TELEGRAM_TOKEN:-}" ]] || [[ -z "${ADMIN_USER_ID:-}" ]]; then
msg_error "DEPLOY_NONINTERACTIVE requires TELEGRAM_TOKEN and ADMIN_USER_ID in the environment."
exit 1
fi
msg_info "Writing $CONDOR_DIR/.env (non-interactive)"
umask 077
cat > "$CONDOR_DIR/.env" << EOF
TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
ADMIN_USER_ID=${ADMIN_USER_ID}
DEPLOY_HUMMINGBOT_API=${DEPLOY_HUMMINGBOT_API:-false}
EOF
umask 022
return 0
fi
# Interactive path: Condor's setup-environment.sh will prompt for the values.
# That only works if it can read from the user — verify a TTY exists, since
# `curl … | bash` leaves the script's stdin pointed at the pipe.
if [[ ! -r /dev/tty ]] || [[ ! -w /dev/tty ]]; then
msg_error "No controlling terminal available and DEPLOY_NONINTERACTIVE is not set."
msg_error "Condor's setup needs TELEGRAM_TOKEN and ADMIN_USER_ID. Either:"
msg_error " • run this installer from an interactive terminal, or"
msg_error " • re-run with DEPLOY_NONINTERACTIVE=1 TELEGRAM_TOKEN=… ADMIN_USER_ID=… …"
exit 1
fi
}
ensure_api_dotenv_unattended() {
# Skip if setup already ran; otherwise write defaults when unattended so make setup does not prompt.
local api_root="$1"
[[ -f "$api_root/.env" ]] && return 0
# Gate on /dev/tty (not -t 0/-t 1): under `curl … | bash` from a real
# terminal, stdin is the pipe but /dev/tty is still open, and upstream
# hummingbot-api/setup.sh already reads its prompts from /dev/tty. So
# when a TTY exists we leave the .env unwritten and let upstream prompt
# the user. When no TTY exists, upstream's no-tty fallback uses plain
# `read` which would EOF and die under its own `set -e`, so we keep
# seeding defaults in that case.
if [[ -r /dev/tty ]] && [[ -w /dev/tty ]] \
&& [[ "${AUTO_YES}" != "y" ]] && ! deploy_noninteractive; then
return 0
fi
local abs
abs="$(cd "$api_root" && pwd)"
msg_info "Writing default $api_root/.env for unattended setup"
umask 077
cat > "$api_root/.env" << EOF
USERNAME=${HUMMINGBOT_API_USERNAME:-admin}
PASSWORD=${HUMMINGBOT_API_PASSWORD:-admin}
CONFIG_PASSWORD=${HUMMINGBOT_CONFIG_PASSWORD:-admin}
DEBUG_MODE=false
BROKER_HOST=localhost
BROKER_PORT=1883
BROKER_USERNAME=admin
BROKER_PASSWORD=password
DATABASE_URL=postgresql+asyncpg://hbot:hummingbot-api@localhost:5432/hummingbot_api
GATEWAY_URL=http://localhost:15888
GATEWAY_PASSPHRASE=${HUMMINGBOT_CONFIG_PASSWORD:-admin}
BOTS_PATH=$abs
EOF
umask 022
}
update_condor_config() {
local config_file="$CONDOR_DIR/config.yml"
local env_file="$CONDOR_DIR/.env"
if [ ! -d "$CONDOR_DIR" ] || [ ! -f "$env_file" ]; then
return 0
fi
local admin_user_id
admin_user_id=$(grep "^ADMIN_USER_ID=" "$env_file" 2>/dev/null | cut -d= -f2 | tr -d '"' | tr -d "'")
[[ -n "$admin_user_id" ]] || return 0
local current_date
current_date=$(date "+%Y-%m-%d")
if [ ! -f "$config_file" ] || [ ! -s "$config_file" ]; then
msg_info "Creating $config_file with template..."
cat > "$config_file" << 'CONFIGEOF'
servers:
local:
host: localhost
port: 8000
username: admin
password: admin
default_server: local
admin_id: ADMIN_USER_ID_PLACEHOLDER
users: {}
server_access:
local:
owner_id: ADMIN_USER_ID_PLACEHOLDER
created_at: null
shared_with: {}
chat_defaults:
ADMIN_USER_ID_PLACEHOLDER: local
version: 1
CONFIGEOF
fi
if grep -q "ADMIN_USER_ID_PLACEHOLDER" "$config_file" 2>/dev/null; then
sed -i.bak "s/ADMIN_USER_ID_PLACEHOLDER/$admin_user_id/g" "$config_file"
rm -f "$config_file.bak"
msg_ok "Updated admin_id in $config_file"
fi
if grep -q "DATE_PLACEHOLDER" "$config_file" 2>/dev/null; then
sed -i.bak "s/DATE_PLACEHOLDER/$current_date/g" "$config_file"
rm -f "$config_file.bak"
fi
}
sync_condor_config_api_credentials() {
local condor_config="$CONDOR_DIR/config.yml"
local api_env="$API_DIR/.env"
[[ -f "$condor_config" && -f "$api_env" ]] || return 0
local api_username api_password
api_username=$(grep "^USERNAME=" "$api_env" 2>/dev/null | cut -d= -f2-)
api_password=$(grep "^PASSWORD=" "$api_env" 2>/dev/null | cut -d= -f2-)
[[ -n "$api_username" && -n "$api_password" ]] || return 0
if grep -A5 "servers:" "$condor_config" | grep -q "username:"; then
sed -i.bak "/servers:/,/^[^ ]/ s/username: .*/username: $api_username/" "$condor_config"
rm -f "$condor_config.bak"
fi
if grep -A5 "servers:" "$condor_config" | grep -q "password:"; then
sed -i.bak "/servers:/,/^[^ ]/ s/password: .*/password: $api_password/" "$condor_config"
rm -f "$condor_config.bak"
fi
msg_ok "Synced Condor config.yml with API .env credentials"
}
run_condor_make_install() {
if [ ! -d "$CONDOR_DIR" ]; then
msg_error "Condor directory not found"
exit 1
fi
msg_info "Running make install (Condor Makefile)..."
(
cd "$CONDOR_DIR"
export SKIP_SETUP_RESTART=1
run_with_tty make install
) || exit 1
msg_info "Running make build-frontend..."
(cd "$CONDOR_DIR" && run_with_tty make build-frontend) || exit 1
}
start_condor_tmux() {
msg_info "Starting Condor in tmux..."
if tmux has-session -t condor 2>/dev/null; then
tmux kill-session -t condor
fi
if [ -d "$CONDOR_DIR" ]; then
(cd "$CONDOR_DIR" && tmux new-session -d -s condor "uv run python main.py")
sleep 2
if tmux has-session -t condor 2>/dev/null; then
msg_ok "Condor session 'condor' started (tmux attach -t condor)"
else
msg_error "Failed to start Condor tmux session"
fi
fi
}
pull_hummingbot_images() {
msg_info "Pulling Hummingbot Docker images..."
docker pull hummingbot/hummingbot:latest || msg_warn "Could not pull hummingbot/hummingbot:latest"
docker pull hummingbot/hummingbot-api:latest || msg_warn "Could not pull hummingbot/hummingbot-api:latest"
}
run_upgrade() {
msg_info "Starting upgrade..."
if [ -d "$CONDOR_DIR" ]; then
msg_info "Updating Condor (git pull)..."
(cd "$CONDOR_DIR" && git pull) || msg_warn "Condor git pull failed"
refresh_tool_path
msg_info "Rebuilding Condor (make install && make build-frontend)..."
(
cd "$CONDOR_DIR"
export SKIP_SETUP_RESTART=1
run_with_tty make install
) || msg_warn "Condor make install failed"
(cd "$CONDOR_DIR" && run_with_tty make build-frontend) || msg_warn "Condor build-frontend failed"
fi
if [ -d "$API_DIR" ]; then
msg_info "Updating Hummingbot API (git pull)..."
(cd "$API_DIR" && git pull) || msg_warn "API git pull failed"
detect_docker_compose
msg_info "Pulling compose images and restarting API stack..."
(cd "$API_DIR" && eval "$DOCKER_COMPOSE pull") || msg_warn "compose pull failed"
pull_hummingbot_images
(cd "$API_DIR" && eval "$DOCKER_COMPOSE up -d --remove-orphans") || msg_warn "compose up failed"
fi
if [ -d "$CONDOR_DIR" ]; then
start_condor_tmux
fi
update_condor_config
sync_condor_config_api_credentials
msg_ok "Upgrade complete"
echo ""
if [[ -d "$CONDOR_DIR" ]]; then
print_tmux_section
print_telegram_verify_section
fi
if [[ -d "$API_DIR" ]]; then
echo -e "${BOLD} Hummingbot API (Docker)${NC}"
echo -e " Status / logs: ${GREEN}cd ${API_DIR} && ${DOCKER_COMPOSE} ps${NC}"
echo -e " Follow logs: ${GREEN}cd ${API_DIR} && ${DOCKER_COMPOSE} logs -f${NC}"
echo -e " REST docs: ${CYAN}http://localhost:8000/docs${NC}"
echo ""
fi
print_condor_install_footer
}
install_api_standalone() {
SCRIPT_DIR="$(pwd)"
msg_info "Standalone Hummingbot API in $SCRIPT_DIR/$API_DIR"
CREATED_DIRS+=("$API_DIR")
git clone --depth 1 "$API_REPO" "$API_DIR" || exit 1
ensure_api_dotenv_unattended "$SCRIPT_DIR/$API_DIR"
(cd "$API_DIR" && run_with_tty make setup) || exit 1
msg_info "Pulling latest images from docker-compose.yml (postgres, emqx, API)..."
(cd "$API_DIR" && eval "$DOCKER_COMPOSE pull") || exit 1
pull_hummingbot_images
(cd "$API_DIR" && run_with_tty make deploy) || exit 1
msg_ok "Hummingbot API deployed"
print_api_post_install_summary "$SCRIPT_DIR"
}
print_api_post_install_summary() {
local base="$1"
echo ""
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD} Hummingbot API is running${NC}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo " • REST + Swagger: http://localhost:8000/docs"
echo " • EMQX dashboard: http://localhost:18083 (default login is often admin / public — see EMQX docs)"
echo ""
echo -e " Check containers: ${GREEN}cd ${base}/${API_DIR} && ${DOCKER_COMPOSE} ps${NC}"
echo -e " Stream logs: ${GREEN}cd ${base}/${API_DIR} && ${DOCKER_COMPOSE} logs -f${NC}"
echo ""
echo " Refresh images later (same as this installer’s API upgrade path):"
echo -e " ${GREEN}cd ${base}/${API_DIR} && git pull && docker compose pull && docker compose up -d${NC}"
echo ""
echo " Or re-run the installer (pulls repo + compose + client images):"
deploy_print_rerun "--hummingbot-api" " ${CYAN}# use -y if prompted${NC}"
echo ""
}
clone_condor() {
if [ -n "$CONDOR_PR" ]; then
CREATED_DIRS+=("$CONDOR_DIR")
git clone "$CONDOR_REPO" "$CONDOR_DIR"
(cd "$CONDOR_DIR" && git fetch origin "pull/$CONDOR_PR/head:pr-$CONDOR_PR" && git checkout "pr-$CONDOR_PR") || exit 1
elif [ -n "$CONDOR_BRANCH" ]; then
CREATED_DIRS+=("$CONDOR_DIR")
git clone --depth 1 -b "$CONDOR_BRANCH" "$CONDOR_REPO" "$CONDOR_DIR" || exit 1
else
CREATED_DIRS+=("$CONDOR_DIR")
git clone --depth 1 "$CONDOR_REPO" "$CONDOR_DIR" || exit 1
fi
}
run_fresh_install() {
SCRIPT_DIR="$(pwd)"
msg_ok "Installation directory: $SCRIPT_DIR"
echo ""
echo -e "${BLUE}Installing Condor${NC}"
clone_condor
[[ -f "$CONDOR_DIR/Makefile" ]] || { msg_error "Condor Makefile missing"; exit 1; }
ensure_condor_env_noninteractive
run_condor_make_install
update_condor_config
start_condor_tmux
echo ""
msg_ok "Installation complete"
print_tmux_section
print_telegram_verify_section
print_condor_install_footer
}
# --- Main ---
clear 2>/dev/null || true
echo -e "${GREEN}"
cat << "BANNER"
██████╗ ██████╗ ███╗ ██╗██████╗ ██████╗ ██████╗
██╔════╝██╔═══██╗████╗ ██║██╔══██╗██╔═══██╗██╔══██╗
██║ ██║ ██║██╔██╗ ██║██║ ██║██║ ██║██████╔╝
██║ ██║ ██║██║╚██╗██║██║ ██║██║ ██║██╔══██╗
╚██████╗╚██████╔╝██║ ╚████║██████╔╝╚██████╔╝██║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝
BANNER
echo -e "${NC}"
echo -e "${CYAN} Hummingbot Deploy Installer${NC}"
echo ""
detect_os_arch
check_disk_space
if [ "$HB_API_ONLY_MODE" = "y" ]; then
install_dependencies "all"
check_docker_running
detect_docker_compose
if [ -d "$API_DIR" ]; then
msg_warn "Directory exists: $API_DIR"
if [ "$(prompt_yesno "Upgrade existing API (git pull + compose pull + deploy)?")" = "y" ]; then
(cd "$API_DIR" && git pull) || exit 1
msg_info "Pulling latest Compose service images..."
(cd "$API_DIR" && eval "$DOCKER_COMPOSE pull") || exit 1
pull_hummingbot_images
(cd "$API_DIR" && eval "$DOCKER_COMPOSE up -d --remove-orphans") || exit 1
msg_ok "Hummingbot API upgraded"
print_api_post_install_summary "$(pwd)"
fi
else
install_api_standalone
fi
exit 0
fi
should_upgrade() {
[[ "$UPGRADE_MODE" == "y" ]] \
|| [[ -d "$CONDOR_DIR/.git" ]] \
|| ([[ -d "$CONDOR_DIR" ]] && [[ -d "$API_DIR" ]]) \
|| ([[ -d "$CONDOR_DIR" ]] && [[ -f "$CONDOR_DIR/docker-compose.yml" ]])
}
if should_upgrade; then
if [ -d "$API_DIR" ]; then
install_dependencies "all"
check_docker_running
detect_docker_compose
else
install_dependencies "condor-only"
fi
refresh_tool_path
run_upgrade
else
install_dependencies "condor-only"
refresh_tool_path
run_fresh_install
fi