forked from ShipSecAI/studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
1528 lines (1420 loc) · 51.8 KB
/
install.sh
File metadata and controls
1528 lines (1420 loc) · 51.8 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
#!/usr/bin/env bash
# install.sh - One-liner installer for ShipSec Studio (Production/Docker mode)
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/ShipSecAI/studio/main/install.sh | bash
#
# This script installs ShipSec Studio using pre-built Docker images from GHCR.
# For development setup, see: https://github.com/ShipSecAI/studio#option-3-development-setup
#
# Supported platforms: macOS, Linux, Windows (Git Bash/MSYS2/WSL)
set -u -o pipefail
# Note: We intentionally keep the default IFS (space, tab, newline)
# because we use space-separated lists for MISSING_DEPS and INSTALL_FAILED
# ---------- Config ----------
REPO_URL="https://github.com/ShipSecAI/studio"
REPO_DIR="studio"
WAIT_DOCKER_SEC=60
# ---------- Colors ----------
setup_colors() {
if [[ -t 1 ]] && [[ -n "${TERM:-}" ]]; then
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m'
else
GREEN=''
YELLOW=''
RED=''
CYAN=''
BLUE=''
BOLD=''
NC=''
fi
}
setup_colors
# ---------- Logging ----------
# Note: Using %b to interpret escape sequences in the argument
log() { printf "\n${GREEN}==>${NC} ${BOLD}%s${NC}\n" "$1"; }
info() { printf " %b\n" "$1"; }
warn() { printf " ${YELLOW}Warning:${NC} %b\n" "$1"; }
err() { printf " ${RED}Error:${NC} %b\n" "$1"; }
# ---------- Traps ----------
on_err() {
local rc=$?
printf "\n"
err "Installation failed (exit code: $rc)"
err "If you need help, please visit: https://github.com/ShipSecAI/studio/issues"
exit $rc
}
on_int() {
printf "\n"
warn "Installation cancelled by user."
exit 130
}
trap 'on_err' ERR
trap 'on_int' INT
# ---------- Utility ----------
command_exists() { command -v "$1" >/dev/null 2>&1; }
# Check if we can interact with user (even when piped via curl | bash)
is_interactive() {
# stdin is a terminal
[ -t 0 ] && return 0
# stdin is piped but /dev/tty exists (curl | bash scenario)
[ -e /dev/tty ] && return 0
# Truly non-interactive
return 1
}
# Cross-platform user input
# Uses /dev/tty to allow prompts even when script is piped (curl | bash)
ask_yes_no() {
local prompt="$1"
local default="${2:-n}"
local yn_hint
if [ "$default" = "y" ]; then
yn_hint="[Y/n]"
else
yn_hint="[y/N]"
fi
# Check if we can read from /dev/tty (works even when script is piped)
if [ -t 0 ]; then
# stdin is a terminal
:
elif [ -e /dev/tty ]; then
# stdin is piped but /dev/tty exists - we can still prompt
exec < /dev/tty
else
# Truly non-interactive (no terminal available)
case "$default" in
y|Y) return 0 ;;
*) return 1 ;;
esac
fi
while true; do
printf " %s %s " "$prompt" "$yn_hint"
read -r ans || ans=""
ans="${ans:-$default}"
case "$ans" in
y|Y|yes|YES|Yes) return 0 ;;
n|N|no|NO|No) return 1 ;;
*) printf " Please enter 'y' for yes or 'n' for no.\n" ;;
esac
done
}
# ---------- Platform Detection ----------
detect_platform() {
local os_raw
os_raw="$(uname -s 2>/dev/null || echo Unknown)"
case "$os_raw" in
Darwin)
PLATFORM="macos"
PLATFORM_NAME="macOS"
;;
Linux)
if grep -qEi "(microsoft|wsl)" /proc/version 2>/dev/null; then
PLATFORM="wsl"
PLATFORM_NAME="Windows (WSL)"
else
PLATFORM="linux"
PLATFORM_NAME="Linux"
fi
;;
MINGW*|MSYS*|CYGWIN*)
PLATFORM="windows"
PLATFORM_NAME="Windows (Git Bash)"
;;
*)
PLATFORM="unknown"
PLATFORM_NAME="Unknown"
;;
esac
}
# ---------- Dependency Installation ----------
# Check if we can use sudo
can_sudo() {
if command_exists sudo; then
# Check if user can sudo without password or is root
if [ "$(id -u)" = "0" ] || sudo -n true 2>/dev/null; then
return 0
fi
# In interactive mode, try to get sudo access (let user see password prompt)
if is_interactive; then
info "Some operations require administrator privileges."
if sudo -v; then
return 0
fi
fi
fi
return 1
}
# Check if current user is in docker group (for Linux/WSL)
check_docker_group() {
# Skip on macOS and Windows - they don't use docker group
if [ "$PLATFORM" = "macos" ] || [ "$PLATFORM" = "windows" ]; then
return 0
fi
# Root doesn't need docker group
if [ "$(id -u)" = "0" ]; then
return 0
fi
# Check if docker group exists and user is a member
if command_exists docker && getent group docker >/dev/null 2>&1; then
if ! groups 2>/dev/null | grep -qw docker; then
return 1 # User not in docker group
fi
fi
return 0
}
# Install Docker - always asks for permission
install_docker() {
log "Installing Docker"
printf "\n"
warn "Docker installation requires your permission."
printf "\n"
case "$PLATFORM" in
macos)
info "On macOS, you can install Docker in two ways:"
printf "\n"
info " ${BOLD} Option 1: Docker Desktop${NC} (GUI app, easiest)"
info " ${BOLD} Option 2: Colima${NC} (CLI-only, lightweight)"
printf "\n"
if ! ask_yes_no "Would you like to install Docker now?" "y"; then
info "Docker installation skipped."
show_install_instructions "docker"
return 1
fi
if command_exists brew; then
printf "\n"
info "Which Docker runtime would you prefer?"
printf "\n"
info " 1) Docker Desktop (GUI application)"
info " 2) Colima (CLI-only, runs in terminal)"
printf "\n"
local choice=""
if is_interactive; then
printf " Enter choice [1/2]: "
read -r choice || choice="1"
else
choice="1"
fi
case "$choice" in
2)
info "Installing Colima and Docker CLI via Homebrew..."
printf "\n"
if brew install colima docker docker-compose; then
printf "\n"
info "${GREEN}Colima and Docker CLI installed successfully!${NC}"
info "Starting Colima..."
if colima start; then
info "${GREEN}Colima is running! Docker daemon is ready.${NC}"
return 0
else
warn "Colima installed but failed to start. Try: colima start"
return 0
fi
else
err "Failed to install Colima"
return 1
fi
;;
*)
info "Installing Docker Desktop via Homebrew..."
printf "\n"
if brew install --cask docker; then
printf "\n"
info "${GREEN}Docker Desktop installed successfully!${NC}"
return 0
else
err "Failed to install Docker via Homebrew"
return 1
fi
;;
esac
else
printf "\n"
warn "Homebrew is not installed."
info "Please install Docker Desktop manually from:"
printf "\n"
printf " https://www.docker.com/products/docker-desktop\n"
printf "\n"
info "Or install Homebrew first:"
printf "\n"
printf " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"\n"
printf "\n"
return 1
fi
;;
linux)
if ! ask_yes_no "Would you like to install Docker Engine now?" "y"; then
info "Docker installation skipped."
show_install_instructions "docker"
return 1
fi
if can_sudo; then
info "Installing Docker Engine via official script..."
printf "\n"
if curl -fsSL https://get.docker.com | sudo sh; then
printf "\n"
info "Adding current user to docker group..."
sudo usermod -aG docker "$USER" 2>/dev/null || true
printf "\n"
printf "${GREEN}┌─────────────────────────────────────────────────────────────────┐${NC}\n"
printf "${GREEN}│${NC} ${BOLD}🚨 Docker installed but requires logout/login${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} Your user has been added to the 'docker' group, but this ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} change won't take effect until you log out and back in. ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${BOLD}➡️ Please log out, log back in, then run:${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} curl -fsSL https://raw.githubusercontent.com/ShipSecAI/ ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} studio/main/install.sh | bash ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${GREEN}│${NC}\n"
printf "${GREEN}└─────────────────────────────────────────────────────────────────┘${NC}\n"
printf "\n"
info "Exiting now to avoid permission issues."
exit 0
else
err "Failed to install Docker"
return 1
fi
else
printf "\n"
err "Cannot install Docker without sudo access."
info "Please install Docker manually:"
printf "\n"
printf " curl -fsSL https://get.docker.com | sudo sh\n"
printf " sudo usermod -aG docker \$USER\n"
printf "\n"
return 1
fi
;;
wsl)
printf "\n"
info "For WSL, you have two options:"
printf "\n"
info " ${BOLD} Option 1: Docker Desktop for Windows (Recommended)${NC}"
info " - Install Docker Desktop from: https://www.docker.com/products/docker-desktop"
info " - Enable WSL2 integration in Docker Desktop Settings > Resources > WSL Integration"
printf "\n"
info " ${BOLD} Option 2: Docker Engine in WSL${NC}"
if ! ask_yes_no "Would you like to install Docker Engine directly in WSL?" "y"; then
info "Docker installation skipped."
info "Please install Docker Desktop for Windows and enable WSL2 integration."
return 1
fi
if can_sudo; then
info "Installing Docker Engine..."
printf "\n"
if curl -fsSL https://get.docker.com | sudo sh; then
printf "\n"
info "Adding current user to docker group..."
sudo usermod -aG docker "$USER" 2>/dev/null || true
printf "\n"
printf "${GREEN}┌─────────────────────────────────────────────────────────────────┐${NC}\n"
printf "${GREEN}│${NC} ${BOLD}🚨 Docker installed but requires logout/login${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} Your user has been added to the 'docker' group, but this ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} change won't take effect until you log out and back in. ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${BOLD}➡️ Please log out, log back in, then run:${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} curl -fsSL https://raw.githubusercontent.com/ShipSecAI/ ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} studio/main/install.sh | bash ${GREEN}│${NC}\n"
printf "${GREEN}│${NC} ${GREEN}│${NC}\n"
printf "${GREEN}└─────────────────────────────────────────────────────────────────┘${NC}\n"
printf "\n"
info "Exiting now to avoid permission issues."
exit 0
else
err "Failed to install Docker"
return 1
fi
else
err "Cannot install Docker without sudo access."
return 1
fi
;;
windows)
printf "\n"
info "Docker Desktop for Windows is required."
printf "\n"
if ! ask_yes_no "Would you like to install Docker Desktop now?" "y"; then
info "Docker installation skipped."
show_install_instructions "docker"
return 1
fi
if command_exists winget; then
info "Installing Docker Desktop via winget..."
printf "\n"
if winget install Docker.DockerDesktop --accept-source-agreements --accept-package-agreements; then
printf "\n"
info "${GREEN}Docker Desktop installed successfully!${NC}"
info "Please restart your terminal and run this script again."
return 0
else
err "Failed to install Docker Desktop"
return 1
fi
fi
info "Please install Docker Desktop manually from:"
printf "\n"
printf " https://www.docker.com/products/docker-desktop\n"
printf "\n"
return 1
;;
*)
err "Automatic Docker installation not supported on this platform."
info "Please install Docker manually."
return 1
;;
esac
}
# Install just automatically
install_just() {
log "Installing just"
case "$PLATFORM" in
macos)
if command_exists brew; then
info "Installing just via Homebrew..."
if brew install just; then
info "${GREEN}just installed successfully!${NC}"
return 0
else
err "Failed to install just"
return 1
fi
else
warn "Homebrew is not installed. Installing just via script..."
mkdir -p ~/.local/bin
# Use --force to overwrite if already exists
if curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to ~/.local/bin --force; then
export PATH="$HOME/.local/bin:$PATH"
info "${GREEN}just installed to ~/.local/bin${NC}"
warn "Add ~/.local/bin to your PATH permanently by adding this to your shell profile:"
printf " export PATH=\"\$HOME/.local/bin:\$PATH\"\n"
return 0
else
err "Failed to install just"
return 1
fi
fi
;;
linux|wsl)
info "Installing just via official script..."
mkdir -p ~/.local/bin
# Use --force to overwrite if already exists
if curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to ~/.local/bin --force; then
# Add to PATH for current session
export PATH="$HOME/.local/bin:$PATH"
info "${GREEN}just installed to ~/.local/bin${NC}"
# Check if ~/.local/bin is already in shell profile
local shell_profile=""
if [ -n "${BASH_VERSION:-}" ]; then
shell_profile="$HOME/.bashrc"
elif [ -n "${ZSH_VERSION:-}" ]; then
shell_profile="$HOME/.zshrc"
elif [ -f "$HOME/.bashrc" ]; then
shell_profile="$HOME/.bashrc"
elif [ -f "$HOME/.profile" ]; then
shell_profile="$HOME/.profile"
fi
# Add to shell profile if not already there
if [ -n "$shell_profile" ] && [ -f "$shell_profile" ]; then
if ! grep -q '\.local/bin' "$shell_profile" 2>/dev/null; then
printf '\n# Added by ShipSec Studio installer\nexport PATH="$HOME/.local/bin:$PATH"\n' >> "$shell_profile"
info "Added ~/.local/bin to PATH in $shell_profile"
fi
else
warn "Add ~/.local/bin to your PATH permanently by adding this to your shell profile:"
printf " export PATH=\"\$HOME/.local/bin:\$PATH\"\n"
fi
return 0
else
err "Failed to install just"
return 1
fi
;;
windows)
if command_exists scoop; then
info "Installing just via Scoop..."
if scoop install just; then
info "${GREEN}just installed successfully!${NC}"
return 0
fi
elif command_exists choco; then
info "Installing just via Chocolatey..."
if choco install just -y; then
info "${GREEN}just installed successfully!${NC}"
return 0
fi
fi
err "Could not install just automatically."
info "Please install just manually from: https://github.com/casey/just/releases"
return 1
;;
*)
err "Automatic just installation not supported on this platform."
return 1
;;
esac
}
# Install jq automatically
install_jq() {
log "Installing jq"
case "$PLATFORM" in
macos)
if command_exists brew; then
info "Installing jq via Homebrew..."
if brew install jq; then
info "${GREEN}jq installed successfully!${NC}"
return 0
fi
fi
err "Failed to install jq"
return 1
;;
linux|wsl)
if can_sudo; then
# Detect package manager
if command_exists apt-get; then
info "Installing jq via apt..."
if sudo apt-get update -qq && sudo apt-get install -y jq; then
info "${GREEN}jq installed successfully!${NC}"
return 0
fi
elif command_exists dnf; then
info "Installing jq via dnf..."
if sudo dnf install -y jq; then
info "${GREEN}jq installed successfully!${NC}"
return 0
fi
elif command_exists yum; then
info "Installing jq via yum..."
if sudo yum install -y jq; then
info "${GREEN}jq installed successfully!${NC}"
return 0
fi
elif command_exists pacman; then
info "Installing jq via pacman..."
if sudo pacman -S --noconfirm jq; then
info "${GREEN}jq installed successfully!${NC}"
return 0
fi
fi
fi
err "Failed to install jq"
return 1
;;
windows)
if command_exists scoop; then
info "Installing jq via Scoop..."
if scoop install jq; then
info "${GREEN}jq installed successfully!${NC}"
return 0
fi
elif command_exists choco; then
info "Installing jq via Chocolatey..."
if choco install jq -y; then
info "${GREEN}jq installed successfully!${NC}"
return 0
fi
fi
err "Failed to install jq"
return 1
;;
*)
err "Automatic jq installation not supported on this platform."
return 1
;;
esac
}
# Install git automatically
install_git() {
log "Installing git"
case "$PLATFORM" in
macos)
info "Installing git via Xcode Command Line Tools..."
if xcode-select --install 2>/dev/null; then
info "Please complete the Xcode Command Line Tools installation and run this script again."
return 1
elif command_exists brew; then
info "Installing git via Homebrew..."
if brew install git; then
info "${GREEN}git installed successfully!${NC}"
return 0
fi
fi
err "Failed to install git"
return 1
;;
linux|wsl)
if can_sudo; then
if command_exists apt-get; then
info "Installing git via apt..."
if sudo apt-get update -qq && sudo apt-get install -y git; then
info "${GREEN}git installed successfully!${NC}"
return 0
fi
elif command_exists dnf; then
info "Installing git via dnf..."
if sudo dnf install -y git; then
info "${GREEN}git installed successfully!${NC}"
return 0
fi
elif command_exists yum; then
info "Installing git via yum..."
if sudo yum install -y git; then
info "${GREEN}git installed successfully!${NC}"
return 0
fi
elif command_exists pacman; then
info "Installing git via pacman..."
if sudo pacman -S --noconfirm git; then
info "${GREEN}git installed successfully!${NC}"
return 0
fi
fi
fi
err "Failed to install git"
return 1
;;
windows)
if command_exists winget; then
info "Installing git via winget..."
if winget install Git.Git --accept-source-agreements --accept-package-agreements; then
info "${GREEN}git installed successfully!${NC}"
info "Please restart your terminal for git to be available."
return 0
fi
fi
err "Failed to install git"
info "Please install git from: https://git-scm.com/download/win"
return 1
;;
*)
err "Automatic git installation not supported on this platform."
return 1
;;
esac
}
# Install curl automatically
install_curl() {
log "Installing curl"
case "$PLATFORM" in
macos)
# curl is pre-installed on macOS
if command_exists brew; then
info "Installing curl via Homebrew..."
if brew install curl; then
info "${GREEN}curl installed successfully!${NC}"
return 0
fi
fi
err "Failed to install curl"
return 1
;;
linux|wsl)
if can_sudo; then
if command_exists apt-get; then
info "Installing curl via apt..."
if sudo apt-get update -qq && sudo apt-get install -y curl; then
info "${GREEN}curl installed successfully!${NC}"
return 0
fi
elif command_exists dnf; then
info "Installing curl via dnf..."
if sudo dnf install -y curl; then
info "${GREEN}curl installed successfully!${NC}"
return 0
fi
elif command_exists yum; then
info "Installing curl via yum..."
if sudo yum install -y curl; then
info "${GREEN}curl installed successfully!${NC}"
return 0
fi
fi
fi
err "Failed to install curl"
return 1
;;
windows)
# curl is included in Windows 10+ and Git Bash
if command_exists choco; then
info "Installing curl via Chocolatey..."
if choco install curl -y; then
info "${GREEN}curl installed successfully!${NC}"
return 0
fi
fi
err "Failed to install curl"
return 1
;;
*)
err "Automatic curl installation not supported on this platform."
return 1
;;
esac
}
# Try to install a missing dependency
try_install_dep() {
local dep="$1"
case "$dep" in
docker) install_docker ;;
just) install_just ;;
jq) install_jq ;;
git) install_git ;;
curl) install_curl ;;
*) return 1 ;;
esac
}
# Start Docker daemon
start_docker_daemon() {
log "Starting Docker daemon"
case "$PLATFORM" in
macos)
# Check for Colima first (CLI-based, can start from terminal)
if command_exists colima; then
info "Found Colima - starting Docker runtime from terminal..."
printf "\n"
# Check if Colima is already running
if colima status 2>/dev/null | grep -q "Running"; then
info "${GREEN}Colima is already running!${NC}"
return 0
fi
info "Starting Colima..."
if colima start 2>&1; then
printf "\n"
# Wait for Docker to be ready
printf " Waiting for Docker to be ready"
local start=$(date +%s)
while ! docker info >/dev/null 2>&1; do
local now=$(date +%s)
local elapsed=$((now - start))
if [ "$elapsed" -ge "$WAIT_DOCKER_SEC" ]; then
printf "\n\n"
err "Docker did not become ready within ${WAIT_DOCKER_SEC} seconds."
return 1
fi
printf "."
sleep 2
done
printf " ${GREEN}ready!${NC}\n"
return 0
else
warn "Failed to start Colima, trying Docker Desktop..."
fi
fi
# Try Docker Desktop - check multiple possible locations
local docker_app=""
if [ -d "/Applications/Docker.app" ]; then
docker_app="/Applications/Docker.app"
elif [ -d "$HOME/Applications/Docker.app" ]; then
docker_app="$HOME/Applications/Docker.app"
fi
if [ -n "$docker_app" ]; then
info "Starting Docker Desktop..."
open -g "$docker_app"
printf " Waiting for Docker to be ready"
local start=$(date +%s)
while ! docker info >/dev/null 2>&1; do
local now=$(date +%s)
local elapsed=$((now - start))
if [ "$elapsed" -ge "$WAIT_DOCKER_SEC" ]; then
printf "\n\n"
err "Docker did not start within ${WAIT_DOCKER_SEC} seconds."
info "Docker Desktop may need to complete first-time setup."
info "Please open Docker Desktop manually from Applications, complete the setup,"
info "then run this script again."
return 1
fi
printf "."
sleep 2
done
printf " ${GREEN}ready!${NC}\n"
return 0
fi
# Docker CLI exists but no runtime - user probably installed just 'docker' via brew
if command_exists docker; then
printf "\n"
warn "Docker CLI is installed, but no Docker runtime is running."
info "The 'docker' command needs a runtime (Docker Desktop or Colima) to work."
printf "\n"
if is_interactive && command_exists brew; then
info "Would you like to install a Docker runtime now?"
printf "\n"
info " 1) Colima (CLI-only, lightweight, recommended)"
info " 2) Docker Desktop (GUI application)"
info " 3) Skip (I'll install manually)"
printf "\n"
printf " Enter choice [1/2/3]: "
local choice=""
read -r choice || choice="3"
case "$choice" in
1)
info "Installing Colima..."
printf "\n"
if brew install colima docker-compose; then
info "${GREEN}Colima installed!${NC}"
info "Starting Colima..."
if colima start; then
info "${GREEN}Colima is running! Docker daemon is ready.${NC}"
return 0
else
err "Failed to start Colima. Try running: colima start"
return 1
fi
else
err "Failed to install Colima"
return 1
fi
;;
2)
info "Installing Docker Desktop..."
printf "\n"
if brew install --cask docker; then
info "${GREEN}Docker Desktop installed!${NC}"
info "Starting Docker Desktop..."
open -g "/Applications/Docker.app"
printf " Waiting for Docker to be ready"
local start=$(date +%s)
while ! docker info >/dev/null 2>&1; do
local now=$(date +%s)
local elapsed=$((now - start))
if [ "$elapsed" -ge "$WAIT_DOCKER_SEC" ]; then
printf "\n\n"
warn "Docker Desktop is taking a while to start."
info "Please wait for Docker Desktop to finish starting, then run this script again."
return 1
fi
printf "."
sleep 2
done
printf " ${GREEN}ready!${NC}\n"
return 0
else
err "Failed to install Docker Desktop"
return 1
fi
;;
*)
info "Skipping Docker runtime installation."
;;
esac
fi
printf "\n"
info "Please install a Docker runtime manually:"
printf "\n"
info " ${BOLD}Option 1: Colima (CLI-only, lightweight)${NC}"
printf " brew install colima docker-compose\n"
printf " colima start\n"
printf "\n"
info " ${BOLD}Option 2: Docker Desktop${NC}"
printf " brew install --cask docker\n"
printf " # Then open Docker Desktop from Applications\n"
printf "\n"
return 1
fi
# Neither Colima nor Docker Desktop found, and no docker CLI
err "No Docker installation found."
info "Please install Docker using one of these methods:"
printf "\n"
info " ${BOLD} Option 1: Colima (CLI-only, recommended for terminal users)${NC}"
printf " brew install colima docker docker-compose\n"
printf " colima start\n"
printf "\n"
info " ${BOLD} Option 2: Docker Desktop${NC}"
printf " brew install --cask docker\n"
printf " # Then open Docker Desktop from Applications\n"
printf "\n"
return 1
;;
linux)
if can_sudo; then
# Try systemctl first (systemd) - preferred method
if command_exists systemctl; then
info "Starting Docker via systemctl..."
if sudo systemctl start docker 2>/dev/null; then
# Wait for Docker to be ready (use sudo for docker info if needed)
printf " Waiting for Docker to be ready"
local start=$(date +%s)
while ! sudo docker info >/dev/null 2>&1; do
local now=$(date +%s)
local elapsed=$((now - start))
if [ "$elapsed" -ge "$WAIT_DOCKER_SEC" ]; then
printf "\n\n"
err "Docker did not start within ${WAIT_DOCKER_SEC} seconds."
return 1
fi
printf "."
sleep 2
done
printf " ${GREEN}ready!${NC}\n"
# Enable Docker to start on boot
sudo systemctl enable docker 2>/dev/null || true
return 0
fi
fi
# Try service command (SysVinit) - fallback for non-systemd systems
if command_exists service; then
info "Starting Docker via service command..."
if sudo service docker start 2>/dev/null; then
sleep 3
if sudo docker info >/dev/null 2>&1; then
info "${GREEN}Docker daemon started!${NC}"
return 0
fi
fi
fi
fi
# No backgrounding dockerd - it's dangerous and conflicts with init systems
err "Failed to start Docker daemon."
info "Please start Docker manually using your system's init system:"
printf "\n"
printf " # For systemd (most modern Linux):\n"
printf " sudo systemctl start docker\n"
printf "\n"
printf " # For SysVinit:\n"
printf " sudo service docker start\n"
return 1
;;
wsl)
# In WSL, try service command
if can_sudo; then
if command_exists service; then
info "Starting Docker via service command..."
if sudo service docker start 2>/dev/null; then
sleep 3
if sudo docker info >/dev/null 2>&1; then
info "${GREEN}Docker daemon started!${NC}"
return 0
fi
fi
fi
fi
# No backgrounding dockerd - it's dangerous
printf "\n"
warn "Could not start Docker daemon automatically in WSL."
info "Please use one of these options:"
printf "\n"
info " 1. Start Docker Desktop for Windows (with WSL2 integration enabled)"
info " 2. Start the Docker service manually: sudo service docker start"
return 1
;;
windows)
# On Windows (Git Bash), try to start Docker Desktop via cmd.exe
# This is more robust than hardcoding paths (handles non-C drives, localized Windows, etc.)
info "Attempting to start Docker Desktop..."
if cmd.exe /c start "" "Docker Desktop" 2>/dev/null; then
printf " Waiting for Docker to be ready"
local start=$(date +%s)
while ! docker info >/dev/null 2>&1; do
local now=$(date +%s)
local elapsed=$((now - start))
if [ "$elapsed" -ge "$WAIT_DOCKER_SEC" ]; then
printf "\n\n"
warn "Docker did not become ready within ${WAIT_DOCKER_SEC} seconds."
info "Docker Desktop may still be starting. Please wait and try again."
return 1
fi
printf "."
sleep 2
done
printf " ${GREEN}ready!${NC}\n"
return 0
else
warn "Could not start Docker Desktop automatically."
info "Please start Docker Desktop manually from the Start menu."
return 1
fi
;;
*)
err "Cannot start Docker daemon on this platform automatically."
return 1