-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·820 lines (699 loc) · 23.6 KB
/
install.sh
File metadata and controls
executable file
·820 lines (699 loc) · 23.6 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
#!/bin/bash
# GITD Installer v2.0
# Interactive installer with backup, restore, and configuration support
set -e
# =============================================================================
# CONFIGURATION
# =============================================================================
GITD_VERSION="2.0.0"
GITD_REPO="https://github.com/Obed0101/gitd.git"
GITD_INSTALL_DIR="${GITD_INSTALL:-$HOME/.gitd}"
# Temporary directory for installer modules
INSTALLER_TMP=""
# Rollback stack
declare -a ROLLBACK_STACK=()
# =============================================================================
# INLINE UI FUNCTIONS (before cloning)
# =============================================================================
setup_colors() {
if [ -t 1 ] && [ -z "$NO_COLOR" ]; then
COLOR_RED='\033[1;31m'
COLOR_GREEN='\033[1;32m'
COLOR_YELLOW='\033[1;33m'
COLOR_BLUE='\033[1;34m'
COLOR_MAGENTA='\033[1;35m'
COLOR_CYAN='\033[1;36m'
COLOR_WHITE='\033[1;37m'
COLOR_GRAY='\033[0;90m'
COLOR_RESET='\033[0m'
COLOR_BOLD='\033[1m'
ICON_CHECK="✔"
ICON_CROSS="✖"
ICON_ARROW="❯"
ICON_INFO="ℹ"
ICON_WARN="⚠"
ICON_ROCKET="🚀"
ICON_GEAR="⚙"
ICON_FOLDER="📁"
ICON_PACKAGE="📦"
else
COLOR_RED=''
COLOR_GREEN=''
COLOR_YELLOW=''
COLOR_BLUE=''
COLOR_MAGENTA=''
COLOR_CYAN=''
COLOR_WHITE=''
COLOR_GRAY=''
COLOR_RESET=''
COLOR_BOLD=''
ICON_CHECK="[OK]"
ICON_CROSS="[X]"
ICON_ARROW=">"
ICON_INFO="[i]"
ICON_WARN="[!]"
ICON_ROCKET="[R]"
ICON_GEAR="[G]"
ICON_FOLDER="[F]"
ICON_PACKAGE="[P]"
fi
}
show_banner() {
echo -e "${COLOR_CYAN}"
cat << 'EOF'
██████╗ ██╗████████╗██████╗
██╔════╝ ██║╚══██╔══╝██╔══██╗
██║ ███╗██║ ██║ ██║ ██║
██║ ██║██║ ██║ ██║ ██║
╚██████╔╝██║ ██║ ██████╔╝
╚═════╝ ╚═╝ ╚═╝ ╚═════╝
EOF
echo -e "${COLOR_RESET}"
echo -e "${COLOR_GRAY} Git Download Tool ${COLOR_WHITE}v${GITD_VERSION}${COLOR_RESET}"
echo ""
}
msg_info() { echo -e "${COLOR_BLUE}${ICON_INFO}${COLOR_RESET} $1"; }
msg_success() { echo -e "${COLOR_GREEN}${ICON_CHECK}${COLOR_RESET} $1"; }
msg_warning() { echo -e "${COLOR_YELLOW}${ICON_WARN}${COLOR_RESET} $1"; }
msg_error() { echo -e "${COLOR_RED}${ICON_CROSS}${COLOR_RESET} $1"; }
msg_step() { echo -e "${COLOR_CYAN}${ICON_ARROW}${COLOR_RESET} $1"; }
# Interactive menu selector
select_menu() {
local title="$1"
shift
local options=("$@")
local selected=0
local total=${#options[@]}
if [ ! -t 0 ] || [ ! -t 1 ]; then
echo "0"
return
fi
tput civis 2>/dev/null
trap 'tput cnorm 2>/dev/null; tput sgr0 2>/dev/null' EXIT INT TERM
tput sc 2>/dev/null
while true; do
tput rc 2>/dev/null
tput ed 2>/dev/null
echo -e "${COLOR_CYAN}┌─────────────────────────────────────────────┐${COLOR_RESET}"
echo -e "${COLOR_CYAN}│${COLOR_RESET} ${COLOR_BOLD}${title}${COLOR_RESET}"
echo -e "${COLOR_CYAN}├─────────────────────────────────────────────┤${COLOR_RESET}"
for i in "${!options[@]}"; do
if [[ $i -eq $selected ]]; then
echo -e "${COLOR_CYAN}│${COLOR_RESET} ${COLOR_GREEN}${ICON_ARROW}${COLOR_RESET} ${COLOR_WHITE}${options[$i]}${COLOR_RESET}"
else
echo -e "${COLOR_CYAN}│${COLOR_RESET} ${COLOR_GRAY}${options[$i]}${COLOR_RESET}"
fi
done
echo -e "${COLOR_CYAN}└─────────────────────────────────────────────┘${COLOR_RESET}"
echo -e "${COLOR_GRAY} ↑/↓ Navigate Enter Select q Quit${COLOR_RESET}"
local key
IFS= read -rsn1 key
case "$key" in
$'\x1b')
read -rsn2 -t 0.1 key
case "$key" in
'[A') ((selected > 0)) && ((selected--)) ;;
'[B') ((selected < total - 1)) && ((selected++)) ;;
esac
;;
'k'|'K') ((selected > 0)) && ((selected--)) ;;
'j'|'J') ((selected < total - 1)) && ((selected++)) ;;
''|$'\n') break ;;
'q'|'Q')
tput cnorm 2>/dev/null
echo "-1"
return 1
;;
[1-9])
if ((key <= total)); then
selected=$((key - 1))
break
fi
;;
esac
done
tput cnorm 2>/dev/null
echo "$selected"
}
confirm() {
local prompt="$1"
local default="${2:-y}"
local yn_hint="[Y/n]"
[[ ! "$default" =~ ^[Yy] ]] && yn_hint="[y/N]"
echo -en "${COLOR_BLUE}?${COLOR_RESET} ${prompt} ${COLOR_GRAY}${yn_hint}${COLOR_RESET} "
local response
read -r response
response=${response:-$default}
[[ "$response" =~ ^[Yy] ]]
}
input_text() {
local prompt="$1"
local default="$2"
if [[ -n "$default" ]]; then
echo -en "${COLOR_BLUE}?${COLOR_RESET} ${prompt} ${COLOR_GRAY}[${default}]${COLOR_RESET}: "
else
echo -en "${COLOR_BLUE}?${COLOR_RESET} ${prompt}: "
fi
local value
read -r value
echo "${value:-$default}"
}
# =============================================================================
# ROLLBACK MECHANISM
# =============================================================================
rollback_push() {
ROLLBACK_STACK+=("$1")
}
rollback_execute() {
msg_warning "Rolling back changes..."
for ((i=${#ROLLBACK_STACK[@]}-1; i>=0; i--)); do
eval "${ROLLBACK_STACK[$i]}" 2>/dev/null || true
done
ROLLBACK_STACK=()
}
rollback_clear() {
ROLLBACK_STACK=()
}
# =============================================================================
# SHELL DETECTION & CONFIG
# =============================================================================
detect_shell() {
basename "${SHELL:-/bin/bash}"
}
get_rc_file() {
local shell_type="${1:-$(detect_shell)}"
case "$shell_type" in
bash)
if [[ -f "$HOME/.bash_profile" && "$(uname)" == "Darwin" ]]; then
echo "$HOME/.bash_profile"
else
echo "$HOME/.bashrc"
fi
;;
zsh) echo "$HOME/.zshrc" ;;
fish) echo "$HOME/.config/fish/config.fish" ;;
*) echo "$HOME/.profile" ;;
esac
}
backup_rc_file() {
local rc_file="$1"
# Store backups in home directory to avoid deletion during clone
local backup_dir="$HOME/.gitd-backups"
local timestamp
timestamp=$(date +%Y-%m-%dT%H-%M-%S)
mkdir -p "$backup_dir"
if [[ -f "$rc_file" ]]; then
local backup_path="${backup_dir}/$(basename "$rc_file").${timestamp}"
cp "$rc_file" "$backup_path"
echo "$backup_path"
fi
}
create_minimal_rc() {
local rc_file="$1"
local shell_type="${2:-bash}"
mkdir -p "$(dirname "$rc_file")"
case "$shell_type" in
zsh)
cat > "$rc_file" << 'ZSHRC'
# Zsh configuration - Created by gitd
HISTSIZE=10000
SAVEHIST=10000
setopt HIST_IGNORE_DUPS SHARE_HISTORY
export PATH="$HOME/.local/bin:$PATH"
autoload -Uz compinit && compinit
PROMPT='%F{cyan}%~%f %# '
ZSHRC
;;
fish)
cat > "$rc_file" << 'FISHRC'
# Fish configuration - Created by gitd
set -g fish_history_max 10000
fish_add_path $HOME/.local/bin
FISHRC
;;
*)
cat > "$rc_file" << 'BASHRC'
# Bash configuration - Created by gitd
HISTSIZE=10000
HISTFILESIZE=20000
HISTCONTROL=ignoredups:erasedups
export PATH="$HOME/.local/bin:$PATH"
PS1='\[\033[01;34m\]\w\[\033[00m\]\$ '
BASHRC
;;
esac
}
update_rc_file() {
local rc_file="$1"
local gitd_install="$2"
local shell_type="${3:-bash}"
local section_start="# === GITD START ==="
local section_end="# === GITD END ==="
# Remove existing section if present
if [[ -f "$rc_file" ]] && grep -q "$section_start" "$rc_file" 2>/dev/null; then
local tmp
tmp=$(mktemp)
awk "/$section_start/,/$section_end/ { next } { print }" "$rc_file" > "$tmp"
mv "$tmp" "$rc_file"
fi
# Create file if doesn't exist
[[ ! -f "$rc_file" ]] && touch "$rc_file"
# Get source file based on shell
local source_file
case "$shell_type" in
zsh) source_file="\$GITD_INSTALL/src/zsh/gitd.zsh" ;;
fish) source_file="\$GITD_INSTALL/src/fish/gitd.fish" ;;
*) source_file="\$GITD_INSTALL/src/bash/gitd.bash" ;;
esac
# Append gitd configuration (GITD_BASE_DIR is now read from config.json inside gitd scripts)
cat >> "$rc_file" << EOF
${section_start}
# gitd - Git Download Tool v${GITD_VERSION}
export GITD_INSTALL="${gitd_install}"
source "${source_file}"
${section_end}
EOF
}
# =============================================================================
# CONFIG FILE
# =============================================================================
create_config() {
local js_pm="${1:-bun}"
local py_pm="${2:-uv}"
local repos_dir="${3:-~/Repos}"
mkdir -p "$GITD_INSTALL_DIR"
cat > "${GITD_INSTALL_DIR}/config.json" << EOF
{
"version": "${GITD_VERSION}",
"repos": {
"baseDir": "${repos_dir}",
"organizeByOwner": false,
"removeGitDir": true
},
"packageManagers": {
"javascript": "${js_pm}",
"typescript": "${js_pm}",
"python": "${py_pm}",
"ruby": "bundle",
"java": "mvn",
"go": "go",
"rust": "cargo",
"php": "composer"
},
"setup": {
"autoInstallDeps": true,
"autoDetectProject": true,
"confirmBeforeInstall": true
},
"shell": {
"modifyRcFile": true,
"createBackups": true
},
"ui": {
"showBanner": true,
"useColors": true
}
}
EOF
}
# =============================================================================
# INSTALLATION FUNCTIONS
# =============================================================================
check_dependencies() {
local missing=()
if ! command -v git &>/dev/null; then
missing+=("git")
fi
if [[ ${#missing[@]} -gt 0 ]]; then
msg_error "Missing required dependencies: ${missing[*]}"
echo ""
echo "Please install them and try again."
exit 1
fi
# Optional: warn about jq
if ! command -v jq &>/dev/null; then
msg_warning "jq not found - using fallback config parser"
fi
}
clone_gitd() {
local target="$1"
if [[ -d "$target" ]]; then
rm -rf "$target"
fi
msg_step "Cloning gitd repository..."
if git clone --depth 1 "$GITD_REPO" "$target" 2>/dev/null; then
msg_success "Repository cloned successfully"
return 0
else
msg_error "Failed to clone repository"
return 1
fi
}
# =============================================================================
# INSTALLATION MODES
# =============================================================================
install_quick() {
msg_info "Quick Install - Using recommended settings"
echo ""
local shell_type
shell_type=$(detect_shell)
local rc_file
rc_file=$(get_rc_file "$shell_type")
# Step 1: Backup
msg_step "Creating backup of shell configuration..."
local backup_path=""
if [[ -f "$rc_file" ]]; then
backup_path=$(backup_rc_file "$rc_file")
rollback_push "cp '$backup_path' '$rc_file'"
msg_success "Backup created: $backup_path"
fi
# Step 2: Clone
if ! clone_gitd "$GITD_INSTALL_DIR"; then
rollback_execute
exit 1
fi
rollback_push "rm -rf '$GITD_INSTALL_DIR'"
# Step 3: Create config
msg_step "Creating configuration..."
create_config "bun" "uv" "~/Repos"
msg_success "Configuration created"
# Step 4: Update RC
msg_step "Updating shell configuration..."
update_rc_file "$rc_file" "$GITD_INSTALL_DIR" "$shell_type"
msg_success "Shell configuration updated"
# Success
rollback_clear
show_success_message "$shell_type" "$rc_file"
}
install_custom() {
msg_info "Custom Install - Configure your preferences"
echo ""
# Shell selection
local shell_choice
shell_choice=$(select_menu "Select your shell" \
"bash" \
"zsh" \
"fish" \
"Auto-detect ($(detect_shell))")
clear
show_banner
local shell_type
case "$shell_choice" in
0) shell_type="bash" ;;
1) shell_type="zsh" ;;
2) shell_type="fish" ;;
*) shell_type=$(detect_shell) ;;
esac
local rc_file
rc_file=$(get_rc_file "$shell_type")
# RC file handling
echo ""
local rc_choice
if [[ -f "$rc_file" ]]; then
rc_choice=$(select_menu "Shell configuration ($rc_file exists)" \
"Add to existing file (recommended)" \
"Skip - I'll configure manually")
else
rc_choice=$(select_menu "Shell configuration ($rc_file not found)" \
"Create new minimal RC file (recommended)" \
"Skip - I'll configure manually")
fi
clear
show_banner
local modify_rc=true
local create_new_rc=false
case "$rc_choice" in
0)
modify_rc=true
[[ ! -f "$rc_file" ]] && create_new_rc=true
;;
1) modify_rc=false ;;
esac
# Default JS package manager
echo ""
local js_choice
js_choice=$(select_menu "Default JavaScript package manager" \
"bun (fastest, recommended)" \
"pnpm (disk efficient)" \
"yarn" \
"npm (most compatible)")
clear
show_banner
local js_pm
case "$js_choice" in
0) js_pm="bun" ;;
1) js_pm="pnpm" ;;
2) js_pm="yarn" ;;
*) js_pm="npm" ;;
esac
# Default Python package manager
echo ""
local py_choice
py_choice=$(select_menu "Default Python package manager" \
"uv (fastest, recommended)" \
"pip (standard)" \
"poetry" \
"pipenv")
clear
show_banner
local py_pm
case "$py_choice" in
0) py_pm="uv" ;;
1) py_pm="pip" ;;
2) py_pm="poetry" ;;
*) py_pm="pipenv" ;;
esac
# Repos directory
echo ""
local repos_dir
repos_dir=$(input_text "Repositories directory" "~/Repos")
echo ""
# Confirmation
echo -e "${COLOR_CYAN}┌─────────────────────────────────────────────┐${COLOR_RESET}"
echo -e "${COLOR_CYAN}│${COLOR_RESET} ${COLOR_BOLD}Installation Summary${COLOR_RESET}"
echo -e "${COLOR_CYAN}├─────────────────────────────────────────────┤${COLOR_RESET}"
echo -e "${COLOR_CYAN}│${COLOR_RESET} Shell: ${COLOR_WHITE}${shell_type}${COLOR_RESET}"
echo -e "${COLOR_CYAN}│${COLOR_RESET} RC File: ${COLOR_WHITE}${rc_file}${COLOR_RESET}"
echo -e "${COLOR_CYAN}│${COLOR_RESET} Modify RC: ${COLOR_WHITE}${modify_rc}${COLOR_RESET}"
echo -e "${COLOR_CYAN}│${COLOR_RESET} JS Manager: ${COLOR_WHITE}${js_pm}${COLOR_RESET}"
echo -e "${COLOR_CYAN}│${COLOR_RESET} Python Manager: ${COLOR_WHITE}${py_pm}${COLOR_RESET}"
echo -e "${COLOR_CYAN}│${COLOR_RESET} Repos Dir: ${COLOR_WHITE}${repos_dir}${COLOR_RESET}"
echo -e "${COLOR_CYAN}└─────────────────────────────────────────────┘${COLOR_RESET}"
echo ""
if ! confirm "Proceed with installation?"; then
msg_warning "Installation cancelled"
exit 0
fi
echo ""
# Step 1: Backup (if modifying)
if $modify_rc && [[ -f "$rc_file" ]]; then
msg_step "Creating backup of shell configuration..."
local backup_path
backup_path=$(backup_rc_file "$rc_file")
rollback_push "cp '$backup_path' '$rc_file'"
msg_success "Backup created: $backup_path"
fi
# Step 2: Clone
if ! clone_gitd "$GITD_INSTALL_DIR"; then
rollback_execute
exit 1
fi
rollback_push "rm -rf '$GITD_INSTALL_DIR'"
# Step 3: Create config
msg_step "Creating configuration..."
create_config "$js_pm" "$py_pm" "$repos_dir"
msg_success "Configuration created"
# Step 4: Update RC (if requested)
if $modify_rc; then
if $create_new_rc; then
msg_step "Creating minimal shell configuration..."
create_minimal_rc "$rc_file" "$shell_type"
fi
msg_step "Updating shell configuration..."
update_rc_file "$rc_file" "$GITD_INSTALL_DIR" "$shell_type"
msg_success "Shell configuration updated"
fi
# Success
rollback_clear
show_success_message "$shell_type" "$rc_file" "$modify_rc"
}
upgrade_existing() {
if [[ ! -d "$GITD_INSTALL_DIR" ]]; then
msg_error "No existing installation found at $GITD_INSTALL_DIR"
exit 1
fi
msg_info "Upgrading existing installation..."
echo ""
# Backup config
if [[ -f "${GITD_INSTALL_DIR}/config.json" ]]; then
cp "${GITD_INSTALL_DIR}/config.json" "${GITD_INSTALL_DIR}/config.json.backup"
msg_success "Config backed up"
fi
# Pull latest
msg_step "Pulling latest changes..."
if cd "$GITD_INSTALL_DIR" && git pull origin main 2>/dev/null; then
msg_success "Updated to latest version"
else
# If git pull fails, do fresh clone
msg_warning "Git pull failed, doing fresh install..."
local config_backup=""
[[ -f "${GITD_INSTALL_DIR}/config.json.backup" ]] && \
config_backup=$(cat "${GITD_INSTALL_DIR}/config.json.backup")
rm -rf "$GITD_INSTALL_DIR"
clone_gitd "$GITD_INSTALL_DIR"
# Restore config
if [[ -n "$config_backup" ]]; then
echo "$config_backup" > "${GITD_INSTALL_DIR}/config.json"
msg_success "Config restored"
fi
fi
echo ""
msg_success "Upgrade complete!"
msg_info "Restart your terminal or run: source $(get_rc_file)"
}
uninstall() {
msg_warning "Uninstalling gitd..."
echo ""
if [[ ! -d "$GITD_INSTALL_DIR" ]]; then
msg_info "gitd is not installed"
exit 0
fi
if ! confirm "Are you sure you want to uninstall gitd?" "n"; then
msg_info "Uninstall cancelled"
exit 0
fi
echo ""
# Remove from shell configs
for shell_type in bash zsh fish; do
local rc_file
rc_file=$(get_rc_file "$shell_type")
if [[ -f "$rc_file" ]] && grep -q "GITD START" "$rc_file" 2>/dev/null; then
msg_step "Removing from $rc_file..."
local tmp
tmp=$(mktemp)
awk '/# === GITD START ===/,/# === GITD END ===/ { next } { print }' "$rc_file" > "$tmp"
mv "$tmp" "$rc_file"
msg_success "Removed from $rc_file"
fi
done
# Remove directory
msg_step "Removing $GITD_INSTALL_DIR..."
rm -rf "$GITD_INSTALL_DIR"
msg_success "Directory removed"
echo ""
msg_success "gitd has been uninstalled"
msg_info "Restart your terminal to complete uninstallation"
}
show_success_message() {
local shell_type="$1"
local rc_file="$2"
local modified_rc="${3:-true}"
echo ""
echo -e "${COLOR_GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${COLOR_RESET}"
echo -e "${COLOR_GREEN}${ICON_ROCKET}${COLOR_RESET} ${COLOR_BOLD}Installation Complete!${COLOR_RESET}"
echo -e "${COLOR_GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${COLOR_RESET}"
echo ""
echo -e "${COLOR_CYAN}${ICON_FOLDER}${COLOR_RESET} Install location: ${COLOR_WHITE}${GITD_INSTALL_DIR}${COLOR_RESET}"
echo -e "${COLOR_CYAN}${ICON_GEAR}${COLOR_RESET} Config file: ${COLOR_WHITE}${GITD_INSTALL_DIR}/config.json${COLOR_RESET}"
echo ""
if [[ "$modified_rc" == "true" ]]; then
echo -e "${COLOR_YELLOW}${ICON_WARN}${COLOR_RESET} To start using gitd, run:"
echo ""
echo -e " ${COLOR_WHITE}source ${rc_file}${COLOR_RESET}"
echo ""
echo "Or restart your terminal."
else
echo -e "${COLOR_YELLOW}${ICON_WARN}${COLOR_RESET} Manual configuration required!"
echo ""
echo "Add the following to your shell configuration:"
echo ""
echo -e "${COLOR_GRAY}# === GITD START ===${COLOR_RESET}"
echo -e "${COLOR_WHITE}export GITD_INSTALL=\"${GITD_INSTALL_DIR}\"${COLOR_RESET}"
echo -e "${COLOR_WHITE}source \"\$GITD_INSTALL/src/${shell_type}/gitd.${shell_type}\"${COLOR_RESET}"
echo -e "${COLOR_GRAY}# === GITD END ===${COLOR_RESET}"
fi
echo ""
echo -e "${COLOR_CYAN}${ICON_PACKAGE}${COLOR_RESET} Quick start:"
echo ""
echo -e " ${COLOR_WHITE}gitd https://github.com/user/repo${COLOR_RESET}"
echo -e " ${COLOR_WHITE}gitd -s https://github.com/user/repo${COLOR_RESET} # with setup"
echo ""
}
# =============================================================================
# MAIN
# =============================================================================
main() {
setup_colors
# Handle flags
case "${1:-}" in
--version|-v)
echo "gitd installer v${GITD_VERSION}"
exit 0
;;
--help|-h)
echo "Usage: ./install.sh [options]"
echo ""
echo "Options:"
echo " --quick, -q Quick install with defaults"
echo " --uninstall Remove gitd"
echo " --upgrade Upgrade existing installation"
echo " --version, -v Show version"
echo " --help, -h Show this help"
exit 0
;;
--quick|-q)
show_banner
check_dependencies
install_quick
exit 0
;;
--uninstall)
show_banner
uninstall
exit 0
;;
--upgrade)
show_banner
upgrade_existing
exit 0
;;
esac
# Interactive mode
clear
show_banner
check_dependencies
# Check for existing installation
if [[ -d "$GITD_INSTALL_DIR" ]]; then
msg_warning "Existing installation detected at $GITD_INSTALL_DIR"
echo ""
local upgrade_choice
upgrade_choice=$(select_menu "What would you like to do?" \
"Upgrade existing installation" \
"Fresh install (overwrites existing)" \
"Uninstall" \
"Exit")
clear
show_banner
case "$upgrade_choice" in
0) upgrade_existing; exit 0 ;;
1) ;; # Continue with install
2) uninstall; exit 0 ;;
*) exit 0 ;;
esac
fi
# Main menu
local choice
choice=$(select_menu "Installation Mode" \
"Quick Install (recommended)" \
"Custom Install" \
"Exit")
clear
show_banner
case "$choice" in
0) install_quick ;;
1) install_custom ;;
*) msg_info "Installation cancelled"; exit 0 ;;
esac
}
# Run
main "$@"