-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·1517 lines (1346 loc) · 60.7 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·1517 lines (1346 loc) · 60.7 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
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# NimbleCo Interactive Setup Script
# Works both interactively and headlessly (with pre-configured .env)
#
# Supported platforms:
# - macOS (Darwin)
# - Linux (Debian/Ubuntu, RHEL/CentOS/Fedora, Arch)
# - Windows (via WSL)
#
# Usage:
# ./setup.sh # Interactive setup
# ./setup.sh --quick # Use last session config, skip confirmations
# ./setup.sh -q # Same as --quick
set -e
# ============================================================================
# Platform Detection
# ============================================================================
# Detect operating system
if [[ "$OSTYPE" == "darwin"* ]]; then
PLATFORM="macos"
PLATFORM_NAME="macOS"
elif [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "linux" ]]; then
PLATFORM="linux"
PLATFORM_NAME="Linux"
# Detect Linux distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
LINUX_DISTRO=$ID
LINUX_VERSION=$VERSION_ID
elif [ -f /etc/redhat-release ]; then
LINUX_DISTRO="rhel"
elif [ -f /etc/debian_version ]; then
LINUX_DISTRO="debian"
else
LINUX_DISTRO="unknown"
fi
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ -n "$WSL_DISTRO_NAME" ]]; then
PLATFORM="windows"
PLATFORM_NAME="Windows (WSL)"
else
echo "❌ Unsupported operating system: $OSTYPE"
echo " Supported platforms: macOS, Linux, Windows (via WSL)"
exit 1
fi
# ============================================================================
# Package Manager Detection and Helpers
# ============================================================================
# Detect and set up package manager
case $PLATFORM in
macos)
PKG_MANAGER="brew"
PKG_INSTALL_CMD="brew install"
PKG_CASK_CMD="brew install --cask"
;;
linux)
case $LINUX_DISTRO in
ubuntu|debian)
PKG_MANAGER="apt"
PKG_INSTALL_CMD="sudo apt-get install -y"
;;
fedora|rhel|centos)
PKG_MANAGER="dnf"
PKG_INSTALL_CMD="sudo dnf install -y"
;;
arch|manjaro)
PKG_MANAGER="pacman"
PKG_INSTALL_CMD="sudo pacman -S --noconfirm"
;;
opensuse*)
PKG_MANAGER="zypper"
PKG_INSTALL_CMD="sudo zypper install -y"
;;
*)
PKG_MANAGER="unknown"
echo -e "${YELLOW}⚠${NC} Unknown Linux distribution: $LINUX_DISTRO"
echo " You may need to install dependencies manually"
;;
esac
;;
windows)
# WSL uses the Linux distribution's package manager
if [ -f /etc/os-release ]; then
. /etc/os-release
case $ID in
ubuntu|debian)
PKG_MANAGER="apt"
PKG_INSTALL_CMD="sudo apt-get install -y"
;;
fedora|rhel|centos)
PKG_MANAGER="dnf"
PKG_INSTALL_CMD="sudo dnf install -y"
;;
*)
PKG_MANAGER="unknown"
;;
esac
fi
;;
esac
# Parse command line arguments
QUICK_MODE=false
for arg in "$@"; do
case $arg in
--quick|-q)
QUICK_MODE=true
shift
;;
esac
done
BLUE='\033[0;34m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ 🚀 NimbleCo Interactive Setup ║"
echo "║ ║"
echo "║ Self-hosted agent orchestration for teams ║"
echo "║ Platform: ${PLATFORM_NAME} ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo -e "${NC}"
echo ""
# ============================================================================
# Helper Functions (must be defined before dependency checks)
# ============================================================================
# Function to prompt for input with default
prompt() {
local var_name=$1
local prompt_text=$2
local default_value=$3
local is_secret=$4
if [ -n "${!var_name}" ]; then
echo -e "${GREEN}✓${NC} $prompt_text: ${BLUE}[already set]${NC}"
return
fi
if [ "$is_secret" = "true" ]; then
read -s -p "$(echo -e ${YELLOW}?${NC} $prompt_text ${default_value:+[default: $default_value]}: )" input
echo ""
else
read -p "$(echo -e ${YELLOW}?${NC} $prompt_text ${default_value:+[default: $default_value]}: )" input
fi
if [ -z "$input" ] && [ -n "$default_value" ]; then
input=$default_value
fi
eval "$var_name='$input'"
}
# Function to confirm yes/no
confirm() {
local prompt_text=$1
local default=$2
# In quick setup mode, use saved answer if available
if [ "$QUICK_SETUP" = "true" ]; then
local var_name="SAVED_$(echo "$prompt_text" | sed 's/[^a-zA-Z0-9]/_/g' | tr '[:lower:]' '[:upper:]')"
if [ -n "${!var_name}" ]; then
[[ "${!var_name}" =~ ^[Yy] ]] && return 0 || return 1
fi
fi
if [ "$default" = "y" ]; then
read -p "$(echo -e ${YELLOW}?${NC} $prompt_text [Y/n]: )" response
response=${response:-y}
else
read -p "$(echo -e ${YELLOW}?${NC} $prompt_text [y/N]: )" response
response=${response:-n}
fi
# Save the answer for next time
local var_name="SAVED_$(echo "$prompt_text" | sed 's/[^a-zA-Z0-9]/_/g' | tr '[:lower:]' '[:upper:]')"
eval "$var_name='$response'"
[[ "$response" =~ ^[Yy] ]]
}
# ============================================================================
# Dependency Checks
# ============================================================================
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Checking Dependencies${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
MISSING_DEPS=false
# Check for package manager
if [ "$PLATFORM" = "macos" ]; then
# Check for Homebrew on macOS
if ! command -v brew &> /dev/null; then
echo -e "${YELLOW}ℹ${NC} Homebrew not found (optional, but makes installation easier)"
if confirm "Install Homebrew now?" "y"; then
echo -e "${BLUE}⏳${NC} Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Source Homebrew for current session (Apple Silicon)
if [ -f /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
echo -e "${GREEN}✓${NC} Homebrew installed"
else
echo -e "${YELLOW}⚠${NC} Skipping Homebrew - you'll need to install dependencies manually"
fi
else
echo -e "${GREEN}✓${NC} Homebrew found: $(brew --version | head -n1)"
fi
elif [ "$PLATFORM" = "linux" ]; then
# Update package cache on Linux
case $PKG_MANAGER in
apt)
echo -e "${BLUE}⏳${NC} Updating apt package cache..."
sudo apt-get update > /dev/null 2>&1
echo -e "${GREEN}✓${NC} Package manager: apt"
;;
dnf)
echo -e "${GREEN}✓${NC} Package manager: dnf"
;;
pacman)
echo -e "${GREEN}✓${NC} Package manager: pacman"
;;
zypper)
echo -e "${GREEN}✓${NC} Package manager: zypper"
;;
*)
echo -e "${YELLOW}⚠${NC} Unknown package manager"
;;
esac
fi
echo ""
# Check for Node.js
if ! command -v node &> /dev/null; then
echo -e "${RED}✗${NC} Node.js not found (REQUIRED)"
echo -e " Node.js is required to run NimbleCo"
CAN_INSTALL=false
case $PLATFORM in
macos)
if command -v brew &> /dev/null; then
CAN_INSTALL=true
if confirm "Install Node.js via Homebrew?" "y"; then
echo -e "${BLUE}⏳${NC} Installing Node.js..."
brew install node
echo -e "${GREEN}✓${NC} Node.js installed"
fi
fi
;;
linux|windows)
if [ "$PKG_MANAGER" != "unknown" ]; then
CAN_INSTALL=true
if confirm "Install Node.js via $PKG_MANAGER?" "y"; then
echo -e "${BLUE}⏳${NC} Installing Node.js..."
case $PKG_MANAGER in
apt)
# Use NodeSource for latest version
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
$PKG_INSTALL_CMD nodejs
;;
dnf)
$PKG_INSTALL_CMD nodejs
;;
pacman)
$PKG_INSTALL_CMD nodejs npm
;;
zypper)
$PKG_INSTALL_CMD nodejs
;;
esac
echo -e "${GREEN}✓${NC} Node.js installed"
fi
fi
;;
esac
if [ "$CAN_INSTALL" = "false" ]; then
MISSING_DEPS=true
echo -e "${RED}✗${NC} Please install Node.js manually: https://nodejs.org/"
fi
else
NODE_VERSION=$(node --version)
NODE_MAJOR=$(echo $NODE_VERSION | cut -d'.' -f1 | sed 's/v//')
if [ "$NODE_MAJOR" -lt 18 ]; then
echo -e "${YELLOW}⚠${NC} Node.js $NODE_VERSION found (version 18+ recommended)"
if [ "$PLATFORM" = "macos" ] && command -v brew &> /dev/null; then
if confirm "Upgrade Node.js via Homebrew?" "y"; then
echo -e "${BLUE}⏳${NC} Upgrading Node.js..."
brew upgrade node
echo -e "${GREEN}✓${NC} Node.js upgraded"
fi
elif [ "$PKG_MANAGER" != "unknown" ]; then
if confirm "Upgrade Node.js via $PKG_MANAGER?" "y"; then
echo -e "${BLUE}⏳${NC} Upgrading Node.js..."
# Platform-specific upgrade commands
case $PKG_MANAGER in
apt)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
$PKG_INSTALL_CMD nodejs
;;
*)
$PKG_INSTALL_CMD nodejs
;;
esac
echo -e "${GREEN}✓${NC} Node.js upgraded"
fi
fi
else
echo -e "${GREEN}✓${NC} Node.js $NODE_VERSION found"
fi
fi
echo ""
# Check for Docker
if ! command -v docker &> /dev/null; then
echo -e "${RED}✗${NC} Docker not found (REQUIRED)"
echo -e " Docker is required for PostgreSQL and NATS"
CAN_INSTALL=false
case $PLATFORM in
macos)
if command -v brew &> /dev/null; then
CAN_INSTALL=true
if confirm "Install Docker Desktop via Homebrew?" "y"; then
echo -e "${BLUE}⏳${NC} Installing Docker Desktop (this may take a few minutes)..."
brew install --cask docker
echo -e "${GREEN}✓${NC} Docker Desktop installed"
echo -e "${YELLOW}ℹ${NC} Opening Docker Desktop..."
open -a Docker
echo -e "${BLUE}⏳${NC} Waiting for Docker Desktop to start..."
for i in {1..90}; do
if docker info &> /dev/null 2>&1; then
echo -e "${GREEN}✓${NC} Docker Desktop is ready"
break
fi
sleep 2
done
if ! docker info &> /dev/null 2>&1; then
echo -e "${YELLOW}⚠${NC} Docker Desktop is taking a while to start"
read -p "Press Enter once Docker Desktop is ready..."
fi
fi
fi
;;
linux|windows)
if [ "$PKG_MANAGER" != "unknown" ]; then
CAN_INSTALL=true
if confirm "Install Docker via $PKG_MANAGER?" "y"; then
echo -e "${BLUE}⏳${NC} Installing Docker..."
case $PKG_MANAGER in
apt)
# Install Docker Engine on Ubuntu/Debian
$PKG_INSTALL_CMD apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
$PKG_INSTALL_CMD docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
echo -e "${YELLOW}ℹ${NC} You may need to log out and back in for Docker permissions to take effect"
;;
dnf)
$PKG_INSTALL_CMD docker docker-compose
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
;;
pacman)
$PKG_INSTALL_CMD docker docker-compose
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
;;
zypper)
$PKG_INSTALL_CMD docker docker-compose
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
;;
esac
echo -e "${GREEN}✓${NC} Docker installed"
fi
fi
;;
esac
if [ "$CAN_INSTALL" = "false" ]; then
MISSING_DEPS=true
if [ "$PLATFORM" = "macos" ]; then
echo -e "${RED}✗${NC} Please install Docker Desktop: https://www.docker.com/products/docker-desktop"
else
echo -e "${RED}✗${NC} Please install Docker: https://docs.docker.com/engine/install/"
fi
fi
elif ! docker ps &> /dev/null 2>&1; then
echo -e "${YELLOW}⚠${NC} Docker installed but daemon not accessible"
if [ "$PLATFORM" = "macos" ]; then
# PREFER Docker Desktop if installed
if [ -d "/Applications/Docker.app" ]; then
echo -e "${BLUE}⏳${NC} Starting Docker Desktop..."
open -a Docker
echo -e "${BLUE}⏳${NC} Waiting for Docker to be ready..."
for i in {1..60}; do
if docker ps &> /dev/null 2>&1; then
echo -e "${GREEN}✓${NC} Docker is ready"
break
fi
sleep 1
done
if ! docker ps &> /dev/null 2>&1; then
echo -e "${RED}✗${NC} Docker failed to start in time"
echo -e " Please start Docker Desktop manually and try again"
exit 1
fi
else
# Docker Desktop not installed - try to detect and use any running daemon
echo -e "${BLUE}ℹ${NC} Docker Desktop not found, checking for alternative daemons..."
# Try to find and use Colima
if command -v colima &> /dev/null && colima status 2>&1 | grep -q "colima is running"; then
COLIMA_CONTEXT=$(docker context ls --format "{{.Name}}" 2>/dev/null | grep -i colima | head -1)
if [ -n "$COLIMA_CONTEXT" ]; then
docker context use "$COLIMA_CONTEXT" &> /dev/null 2>&1
else
export DOCKER_HOST="unix://$HOME/.colima/default/docker.sock"
fi
sleep 1
fi
# Try to find and use OrbStack
if ! docker ps &> /dev/null 2>&1 && [ -d "/Applications/OrbStack.app" ]; then
ORBSTACK_CONTEXT=$(docker context ls --format "{{.Name}}" 2>/dev/null | grep -i orbstack | head -1)
if [ -n "$ORBSTACK_CONTEXT" ]; then
docker context use "$ORBSTACK_CONTEXT" &> /dev/null 2>&1
sleep 1
fi
fi
# Check if any of the above worked
if docker ps &> /dev/null 2>&1; then
DOCKER_CONTEXT=$(docker context show 2>/dev/null || echo "unknown")
echo -e "${GREEN}✓${NC} Docker is ready (using $DOCKER_CONTEXT)"
else
# No working daemon found - show options
echo -e "${YELLOW}ℹ${NC} No running Docker daemon found"
echo ""
echo -e "${BLUE}Options:${NC}"
echo -e " 1. Install Docker Desktop (recommended): ${YELLOW}brew install --cask docker${NC}"
echo -e " 2. Use Colima (lightweight): ${YELLOW}brew install colima && colima start${NC}"
echo -e " 3. Use OrbStack: ${YELLOW}brew install --cask orbstack${NC}"
echo ""
echo -e "Or if you've already started one:"
echo -e " ${YELLOW}docker context ls${NC} (list available contexts)"
echo -e " ${YELLOW}docker context use <name>${NC} (switch to it)"
exit 1
fi
fi
else
echo -e "${BLUE}⏳${NC} Starting Docker..."
sudo systemctl start docker
sleep 2
if docker ps &> /dev/null 2>&1; then
echo -e "${GREEN}✓${NC} Docker is ready"
else
echo -e "${RED}✗${NC} Docker failed to start"
echo -e " Please check: sudo systemctl status docker"
echo ""
echo -e " If the error is a permissions issue, add your user to the docker group:"
echo -e " ${YELLOW}sudo usermod -aG docker \$USER${NC}"
echo -e " Then activate without logging out: ${YELLOW}newgrp docker${NC}"
exit 1
fi
fi
else
echo -e "${GREEN}✓${NC} Docker is running"
fi
# Detect Docker Compose version (v2 plugin vs v1 standalone)
if docker compose version &> /dev/null 2>&1; then
DOCKER_COMPOSE="docker compose"
echo -e "${GREEN}✓${NC} Docker Compose (v2) available"
elif command -v docker-compose &> /dev/null 2>&1; then
DOCKER_COMPOSE="docker-compose"
echo -e "${GREEN}✓${NC} Docker Compose (v1) available"
else
echo -e "${RED}✗${NC} Docker Compose not found"
echo ""
# Provide context-specific instructions
if command -v colima &> /dev/null && colima status 2>&1 | grep -q "colima is running"; then
echo -e "${BLUE}For Colima users:${NC}"
echo -e " ${YELLOW}brew install docker-compose${NC} (installs docker-compose v1)"
echo -e " Or install Docker Desktop which includes compose v2"
elif [ "$PLATFORM" = "macos" ]; then
echo -e "${BLUE}For macOS:${NC}"
echo -e " ${YELLOW}brew install docker-compose${NC}"
else
echo -e "${BLUE}Install options:${NC}"
echo -e " ${YELLOW}docker-compose-plugin${NC} (v2) or ${YELLOW}docker-compose${NC} (v1)"
fi
exit 1
fi
echo ""
# Check for Ollama (optional, for local LLMs)
if ! command -v ollama &> /dev/null; then
echo -e "${YELLOW}ℹ${NC} Ollama not found (optional - for local LLM support)"
case $PLATFORM in
macos)
if command -v brew &> /dev/null; then
if confirm "Install Ollama for local LLM support?" "n"; then
echo -e "${BLUE}⏳${NC} Installing Ollama..."
brew install ollama
brew services start ollama
echo -e "${GREEN}✓${NC} Ollama installed and started"
else
echo -e "${YELLOW}ℹ${NC} Skipping Ollama - install later: brew install ollama"
fi
fi
;;
linux|windows)
if confirm "Install Ollama for local LLM support?" "n"; then
echo -e "${BLUE}⏳${NC} Installing Ollama..."
curl -fsSL https://ollama.com/install.sh | sh
echo -e "${YELLOW}ℹ${NC} Starting Ollama service..."
if command -v systemctl &> /dev/null; then
sudo systemctl start ollama 2>/dev/null || true
sudo systemctl enable ollama 2>/dev/null || true
fi
echo -e "${GREEN}✓${NC} Ollama installed"
else
echo -e "${YELLOW}ℹ${NC} Skipping Ollama - install later: https://ollama.com"
fi
;;
esac
else
echo -e "${GREEN}✓${NC} Ollama found"
# Check if Ollama service is running
if ! pgrep -x "ollama" > /dev/null; then
echo -e "${BLUE}⏳${NC} Starting Ollama service..."
if [ "$PLATFORM" = "macos" ] && command -v brew &> /dev/null; then
brew services start ollama
elif command -v systemctl &> /dev/null; then
sudo systemctl start ollama 2>/dev/null || true
fi
sleep 2
echo -e "${GREEN}✓${NC} Ollama service started"
fi
fi
echo ""
# Exit if required dependencies are missing
if [ "$MISSING_DEPS" = true ]; then
echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${RED} Missing Required Dependencies${NC}"
echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e "${RED}Please install the missing dependencies above and run setup again.${NC}"
echo ""
exit 1
fi
echo -e "${GREEN}✓${NC} All dependencies satisfied!"
echo ""
# ============================================================================
# Session Management
# ============================================================================
# Check for previous session config
QUICK_SETUP=false
if [ -f .setup-last-session ]; then
echo -e "${GREEN}✓${NC} Found configuration from previous session"
echo ""
# If --quick flag was passed, skip the confirmation
if [ "$QUICK_MODE" = "true" ]; then
source .setup-last-session
QUICK_SETUP=true
echo -e "${GREEN}✓${NC} Quick mode: loaded previous session configuration"
echo ""
if [ -f .env ]; then
source .env
fi
elif confirm "Keep everything the same as last session?" "y"; then
source .setup-last-session
QUICK_SETUP=true
echo -e "${GREEN}✓${NC} Loaded previous session configuration"
echo -e "${BLUE}ℹ${NC} Skipping interactive setup, using saved answers..."
echo ""
# Also load the .env if it exists
if [ -f .env ]; then
source .env
fi
else
echo -e "${BLUE}ℹ${NC} Starting fresh setup..."
echo ""
fi
elif [ "$QUICK_MODE" = "true" ]; then
echo -e "${YELLOW}⚠${NC} Quick mode requested but no previous session found"
echo -e "${BLUE}ℹ${NC} Running interactive setup..."
echo ""
fi
# Check if .env exists (skip this prompt if in quick setup mode)
if [ "$QUICK_SETUP" = "false" ]; then
if [ -f .env ]; then
echo -e "${YELLOW}ℹ${NC} Found existing .env file"
if confirm "Load existing configuration?" "y"; then
source .env
echo -e "${GREEN}✓${NC} Loaded existing .env"
else
echo -e "${YELLOW}⚠${NC} Creating new configuration (old .env backed up to .env.backup)"
cp .env .env.backup
rm .env
fi
else
echo -e "${BLUE}ℹ${NC} No .env found, creating new configuration"
fi
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} LLM Configuration${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "NimbleCo supports multiple LLM providers."
echo "You need AT LEAST ONE. Local (Ollama) is free, cloud provides better quality."
echo ""
# Ollama (local, free)
if confirm "Use Ollama for local LLM? (FREE, recommended)" "y"; then
OLLAMA_URL=${OLLAMA_URL:-http://localhost:11434}
echo -e "${BLUE}ℹ${NC} Checking if Ollama is running..."
if curl -s "$OLLAMA_URL/api/tags" > /dev/null 2>&1; then
echo -e "${GREEN}✓${NC} Ollama is running at $OLLAMA_URL"
# Check for models
if curl -s "$OLLAMA_URL/api/tags" | grep -q "qwen3.5:9b"; then
echo -e "${GREEN}✓${NC} Qwen 3.5 (9B) already installed"
else
if confirm " Install Qwen 3.5 (9B, latest best small model with 256K context)?" "y"; then
echo -e "${BLUE}⏳${NC} Pulling qwen3.5:9b (this may take 2-3 minutes)..."
ollama pull qwen3.5:9b
fi
fi
if curl -s "$OLLAMA_URL/api/tags" | grep -q "qwen2.5-coder"; then
echo -e "${GREEN}✓${NC} Qwen 2.5 Coder (32B) already installed"
else
if confirm " Install Qwen 2.5 Coder (32B, best for code)?" "y"; then
echo -e "${BLUE}⏳${NC} Pulling qwen2.5-coder:32b (this may take 5-10 minutes)..."
ollama pull qwen2.5-coder:32b
fi
fi
LLM_MODEL_QUICK=${LLM_MODEL_QUICK:-qwen3.5:9b}
LLM_MODEL_CODE=${LLM_MODEL_CODE:-qwen2.5-coder:32b}
else
echo -e "${YELLOW}⚠${NC} Ollama not running. Install with:"
echo " brew install ollama"
echo " ollama serve"
echo " ollama pull qwen3.5:9b # Latest best small model (256K context)"
echo " ollama pull qwen2.5-coder:32b # Best for code"
echo ""
fi
fi
echo ""
# Anthropic Claude
if confirm "Use Anthropic Claude? (Paid, best quality)" "n"; then
prompt ANTHROPIC_API_KEY "Anthropic API key" "" "true"
ANTHROPIC_MODEL=${ANTHROPIC_MODEL:-claude-sonnet-4-5-20250929}
fi
# Google AI (Gemini API with API key)
if confirm "Use Google AI / Gemini? (Free tier available)" "n"; then
prompt GOOGLE_CLOUD_API_KEY "Google AI API key" "" "true"
GOOGLE_MODEL=${GOOGLE_MODEL:-gemini-2.5-flash-lite}
GOOGLE_MAX_OUTPUT_TOKENS=${GOOGLE_MAX_OUTPUT_TOKENS:-30000}
echo -e "${BLUE}ℹ${NC} Get API key at: https://aistudio.google.com/apikey"
fi
# Google Vertex AI
if confirm "Use Google Vertex AI? (\$300 free credits)" "n"; then
prompt VERTEX_AI_PROJECT "GCP Project ID" ""
prompt VERTEX_AI_LOCATION "GCP Region" "us-central1"
echo -e "${BLUE}ℹ${NC} Make sure you've run: gcloud auth application-default login"
fi
# AWS Bedrock
SETUP_BEDROCK=false
if [ -n "$AWS_REGION" ] && [ -n "$BEDROCK_MODEL_ID" ]; then
echo -e "${GREEN}✓${NC} AWS Bedrock already configured"
echo -e " Model: ${BLUE}$BEDROCK_MODEL_ID${NC}"
echo -e " Region: ${BLUE}$AWS_REGION${NC}"
echo " [u]pdate / [r]emove / [k]eep (default: keep)"
read -p " Choice: " BEDROCK_CHOICE
case "$BEDROCK_CHOICE" in
u|U|update)
unset AWS_REGION BEDROCK_MODEL_ID AWS_BEARER_TOKEN_BEDROCK
SETUP_BEDROCK=true
;;
r|R|remove)
unset AWS_REGION BEDROCK_MODEL_ID AWS_BEARER_TOKEN_BEDROCK
echo -e "${YELLOW}ℹ${NC} Bedrock configuration will be removed"
;;
esac
else
if confirm "Use AWS Bedrock? (Free tier available)" "n"; then
SETUP_BEDROCK=true
fi
fi
if [ "$SETUP_BEDROCK" = "true" ]; then
prompt AWS_REGION "AWS Region" "us-east-1"
prompt BEDROCK_MODEL_ID "Bedrock Model ID or ARN" "anthropic.claude-sonnet-4-20250514-v1:0"
prompt AWS_BEARER_TOKEN_BEDROCK "AWS Bearer Token (optional)" "" "true"
echo -e "${BLUE}ℹ${NC} Bedrock uses AWS credentials from: aws configure"
echo -e "${BLUE}ℹ${NC} Or provide bearer token for temporary access"
fi
# LLM Routing
prompt LLM_DAILY_COST_LIMIT "Daily LLM cost limit (USD)" "10.00"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Core Infrastructure${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
NATS_URL=${NATS_URL:-nats://localhost:4222}
if [ -n "${DATABASE_URL+x}" ] && [ "$DATABASE_URL" != "postgresql://agent:change-this-password@localhost:5432/nimbleco" ]; then
echo -e "${YELLOW}⚠${NC} DATABASE_URL is already set in your environment: $DATABASE_URL"
echo -e " This will override the value in .env (dotenv does not replace existing env vars)."
echo -e " If this is a stale value (e.g. from ~/.bashrc), fix it with:"
echo -e " ${YELLOW}unset DATABASE_URL${NC} — then kill and restart the PM2 daemon: ${YELLOW}pm2 kill${NC}"
echo ""
fi
DATABASE_URL=${DATABASE_URL:-postgresql://agent:change-this-password@localhost:5432/nimbleco}
echo -e "${GREEN}✓${NC} NATS: $NATS_URL"
echo -e "${GREEN}✓${NC} PostgreSQL: $DATABASE_URL"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Integration Tools${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# Mattermost
SETUP_MATTERMOST=false
MATTERMOST_REMOVED=false
if [ -n "$MATTERMOST_BOT_TOKEN" ]; then
echo -e "${GREEN}✓${NC} Mattermost already configured"
echo " [u]pdate / [r]emove / [k]eep (default: keep)"
read -p " Choice: " MM_CHOICE
case "$MM_CHOICE" in
u|U|update)
unset MATTERMOST_BOT_TOKEN MATTERMOST_URL MATTERMOST_CHANNEL
SETUP_MATTERMOST=true
;;
r|R|remove)
unset MATTERMOST_BOT_TOKEN MATTERMOST_URL MATTERMOST_CHANNEL
MATTERMOST_REMOVED=true
echo -e "${YELLOW}ℹ${NC} Mattermost configuration will be removed"
;;
esac
else
if confirm "Set up Mattermost integration?" "n"; then
SETUP_MATTERMOST=true
fi
fi
if [ "$SETUP_MATTERMOST" = "true" ]; then
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Mattermost Setup${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "Mattermost can run locally (testing) or connect to a hosted server (production)."
echo ""
echo "Options:"
echo -e " 1. ${GREEN}Hosted/Production${NC} - Connect to existing Mattermost server (RECOMMENDED)"
echo " + Use your team's production server"
echo " + No local setup needed"
echo " - Requires bot account to be created"
echo ""
echo -e " 2. ${GREEN}Local${NC} - Run Mattermost on this machine (http://localhost:8065)"
echo " + Full control, local testing"
echo " - Only accessible from this device"
echo " - Takes ~30s to start"
echo ""
USE_LOCAL_MATTERMOST="false"
if confirm "Use local Mattermost server?" "n"; then
USE_LOCAL_MATTERMOST="true"
MATTERMOST_URL="http://localhost:8065"
else
USE_LOCAL_MATTERMOST="false"
echo ""
read -p "Enter Mattermost server URL (e.g., https://mattermost.example.com): " CUSTOM_MATTERMOST
# Auto-add https:// if missing
if [[ ! "$CUSTOM_MATTERMOST" =~ ^https?:// ]]; then
CUSTOM_MATTERMOST="https://${CUSTOM_MATTERMOST}"
echo -e "${BLUE}ℹ${NC} Added https:// → $CUSTOM_MATTERMOST"
fi
MATTERMOST_URL="${CUSTOM_MATTERMOST}"
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Bot Configuration${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e "Server: ${GREEN}$MATTERMOST_URL${NC}"
echo ""
if [ "$USE_LOCAL_MATTERMOST" = "true" ]; then
echo "For local Mattermost:"
echo " 1. Run setup to completion (Mattermost will start automatically)"
echo " 2. Open $MATTERMOST_URL"
echo " 3. Create admin account"
echo " 4. Go to System Console → Integrations → Bot Accounts"
echo " 5. Create a bot and copy the token"
echo " 6. Add token to .env: MATTERMOST_BOT_TOKEN=..."
echo ""
echo "Leave blank for now to configure later:"
else
echo "Steps to create bot account:"
echo " 1. Log in to $MATTERMOST_URL as admin"
echo " 2. Go to Integrations → Bot Accounts"
echo " 3. Create a bot with post:all and post:channels permissions"
echo " 4. Copy the bot token"
echo ""
fi
prompt MATTERMOST_BOT_TOKEN "Mattermost bot token (optional for now)" "" "true"
prompt MATTERMOST_CHANNEL "Default channel" "agent-tasks"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Bot Access Controls (Optional)${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "Admin users get special permissions:"
echo " • Can use privileged operations"
echo " • Bypass rate limiting"
echo " • Access sensitive tools"
echo ""
echo "Non-admin users have standard access."
echo ""
if confirm "Configure admin users?" "n"; then
echo ""
echo "Enter Mattermost user IDs (comma-separated)."
echo "Find user IDs in Mattermost: Profile → Advanced → User ID"
echo ""
read -p "Admin user IDs: " MATTERMOST_ADMIN_USERS
if [ -n "$MATTERMOST_ADMIN_USERS" ]; then
echo -e "${GREEN}✓${NC} Admin users: $MATTERMOST_ADMIN_USERS"
fi
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Direct Message (DM) Access Control${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "For security, you can restrict who can DM the bot."
echo ""
echo "Options:"
echo -e " • ${GREEN}Block DMs (recommended)${NC} - Only allow specific users"
echo " • Allow all DMs - Anyone can message the bot privately"
echo ""
# Default BLOCK_DMS to true
MATTERMOST_BLOCK_DMS=${MATTERMOST_BLOCK_DMS:-true}
if confirm "Block DMs (require allowlist)?" "y"; then
MATTERMOST_BLOCK_DMS="true"
# Default allowed users to admin users if they were configured
if [ -n "$MATTERMOST_ADMIN_USERS" ]; then
MATTERMOST_ALLOWED_USERS=${MATTERMOST_ALLOWED_USERS:-$MATTERMOST_ADMIN_USERS}
echo ""
echo -e "${GREEN}✓${NC} Admin users automatically allowed for DMs"
echo -e " ${BLUE}$MATTERMOST_ADMIN_USERS${NC}"
echo ""
if confirm "Allow additional users for DMs?" "n"; then
echo ""
echo "Enter additional Mattermost user IDs (comma-separated)."
echo "These users can DM the bot but won't have admin privileges."
echo ""
read -p "Additional DM-allowed user IDs: " ADDITIONAL_ALLOWED_USERS
if [ -n "$ADDITIONAL_ALLOWED_USERS" ]; then
MATTERMOST_ALLOWED_USERS="$MATTERMOST_ALLOWED_USERS,$ADDITIONAL_ALLOWED_USERS"
fi
fi
else
# No admin users configured, ask for allowed users
echo ""
echo "Enter Mattermost user IDs allowed to DM (comma-separated)."
echo "Find user IDs in Mattermost: Profile → Advanced → User ID"
echo ""
read -p "DM-allowed user IDs: " MATTERMOST_ALLOWED_USERS
fi
if [ -n "$MATTERMOST_ALLOWED_USERS" ]; then
echo -e "${GREEN}✓${NC} DMs allowed for: $MATTERMOST_ALLOWED_USERS"
echo -e "${YELLOW}ℹ${NC} Non-whitelisted users will get a polite error message"
else
echo -e "${YELLOW}⚠${NC} No users whitelisted - DMs will be blocked for everyone"
fi
else
MATTERMOST_BLOCK_DMS="false"
MATTERMOST_ALLOWED_USERS=""
echo -e "${YELLOW}⚠${NC} DMs allowed for all users (not recommended for production)"
fi
echo ""
echo -e "${GREEN}✓${NC} Mattermost configuration complete!"
fi
# GitHub
SETUP_GITHUB=false
if [ -n "$GITHUB_TOKEN" ]; then
echo -e "${GREEN}✓${NC} GitHub already configured"
echo " [u]pdate / [r]emove / [k]eep (default: keep)"
read -p " Choice: " GH_CHOICE
case "$GH_CHOICE" in
u|U|update)
unset GITHUB_TOKEN
SETUP_GITHUB=true
;;
r|R|remove)
unset GITHUB_TOKEN
echo -e "${YELLOW}ℹ${NC} GitHub configuration will be removed"
;;
esac
else
if confirm "Set up GitHub integration?" "y"; then
SETUP_GITHUB=true
fi
fi
if [ "$SETUP_GITHUB" = "true" ]; then
prompt GITHUB_TOKEN "GitHub Personal Access Token" "" "true"
echo -e "${BLUE}ℹ${NC} Create token at: https://github.com/settings/tokens"
echo " Scopes needed: repo, workflow"
fi
echo ""
# Attio CRM
SETUP_ATTIO=false
if [ -n "$ATTIO_API_KEY" ]; then
echo -e "${GREEN}✓${NC} Attio CRM already configured"