-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·789 lines (718 loc) · 24.9 KB
/
install.sh
File metadata and controls
executable file
·789 lines (718 loc) · 24.9 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
#!/bin/bash
set -e
# Parse command line arguments
VERBOSE=false
UNINSTALL=false
CUSTOM_PROFILE_DIR=""
CUSTOM_CONFIG_DIR=""
SKIP_CONFIRM=false
while [[ $# -gt 0 ]]; do
case $1 in
-v|--verbose)
VERBOSE=true
shift
;;
-u|--uninstall)
UNINSTALL=true
shift
;;
--profile-dir)
CUSTOM_PROFILE_DIR="$2"
shift 2
;;
--config-dir)
CUSTOM_CONFIG_DIR="$2"
shift 2
;;
-y|--yes)
SKIP_CONFIRM=true
shift
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -v, --verbose Enable verbose output"
echo " -u, --uninstall Remove profile setup and restore backups"
echo " --profile-dir DIR Use custom profile directory (default: script_dir/profile)"
echo " --config-dir DIR Use custom config directory (default: script_dir/config)"
echo " -y, --yes Skip confirmation prompts (assume yes)"
echo " -h, --help Show this help message"
echo ""
echo "Environment variables:"
echo " PROFILE_ROOT Override profile directory"
echo " CONFIG_ROOT Override config directory"
echo " INSTALL_PREFIX Override installation prefix (default: \$HOME)"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Set up paths with priority: command line > environment > defaults
THIS=$(readlink -f "$0")
ROOT=$(dirname "$THIS")
# Installation prefix (where profile files will be installed)
INSTALL_PREFIX="${INSTALL_PREFIX:-$HOME}"
# Profile directory
if [ -n "$CUSTOM_PROFILE_DIR" ]; then
PROFILE="$CUSTOM_PROFILE_DIR"
elif [ -n "$PROFILE_ROOT" ]; then
PROFILE="$PROFILE_ROOT"
else
PROFILE="$ROOT/profile"
fi
# Config directory
if [ -n "$CUSTOM_CONFIG_DIR" ]; then
CONFIG="$CUSTOM_CONFIG_DIR"
elif [ -n "$CONFIG_ROOT" ]; then
CONFIG="$CONFIG_ROOT"
else
CONFIG="$ROOT/config"
fi
# Oh My Zsh paths
ZSH="$INSTALL_PREFIX/.oh-my-zsh"
ZSH_CUSTOM="$ZSH/custom"
PAD=24
# Function to pad output text
pad_output() {
printf "%-${PAD}s" "$1"
}
# Function for verbose logging
log_verbose() {
if [ "$VERBOSE" = true ]; then
echo " [VERBOSE] $1"
fi
}
# Function to backup existing files
backup_file() {
local file="$1"
if [ -e "$file" ] && [ ! -L "$file" ]; then
local backup
backup="${file}.backup.$(date +%Y%m%d_%H%M%S)"
log_verbose "Creating backup: $file -> $backup"
cp -r "$file" "$backup"
echo " backed up to: $backup"
fi
}
# Function to restore latest backup
restore_backup() {
local file="$1"
local latest_backup=""
local backup
for backup in "${file}.backup."*; do
if [ -e "$backup" ]; then
latest_backup="$backup"
fi
done
if [ -n "$latest_backup" ]; then
log_verbose "Restoring backup: $latest_backup -> $file"
rm -rf "$file"
mv "$latest_backup" "$file"
echo " restored from: $latest_backup"
return 0
fi
return 1
}
# Function to remove symlink if it exists
remove_symlink() {
local file="$1"
if [ -L "$file" ]; then
log_verbose "Removing symlink: $file"
rm "$file"
echo " removed symlink: $file"
fi
}
# Function to create symlink safely
create_symlink() {
local source="$1"
local target="$2"
local target_name="$3"
if [ -L "$target" ]; then
local current_target
current_target=$(readlink "$target")
if [ "$current_target" = "$source" ]; then
log_verbose "Symlink already correct: $target -> $source"
echo " already linked correctly"
return 0
else
log_verbose "Updating symlink: $target ($current_target -> $source)"
rm "$target"
fi
elif [ -e "$target" ]; then
log_verbose "Replacing existing regular file/directory: $target"
rm -rf "$target"
fi
log_verbose "Creating symlink: $source -> $target"
ln -s "$source" "$target"
echo " created: $target_name"
}
# Function to check whether .zshrc is managed by this installer
is_managed_zshrc() {
local file="$1"
[ -f "$file" ] || return 1
if grep -q "^# managed-by: utility-scripts-install$" "$file"; then
return 0
fi
# Backward compatibility with the previous unmanaged template
if grep -q '^export PROFILE=' "$file" \
&& grep -q "^source \\\$PROFILE/zshrc.sh$" "$file"; then
return 0
fi
return 1
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to initialize git submodules
init_submodules() {
local submodule_path="$1"
local submodule_name="$2"
if [ ! -d "$submodule_path" ] || [ -z "$(ls -A "$submodule_path" 2>/dev/null)" ]; then
log_verbose "Initializing submodule: $submodule_name"
if [ "$VERBOSE" = true ]; then
git submodule update --init --recursive "$submodule_path"
else
git submodule update --init --recursive "$submodule_path" > /dev/null 2>&1
fi
return 0
else
log_verbose "Submodule already initialized: $submodule_name"
return 1
fi
}
# Function to check dependencies
check_dependencies() {
local missing_deps=()
if ! command_exists git; then
missing_deps+=("git")
fi
if ! command_exists curl; then
missing_deps+=("curl")
fi
if [ ${#missing_deps[@]} -gt 0 ]; then
echo "Error: Missing required dependencies: ${missing_deps[*]}"
echo "Please install the missing tools and try again."
echo ""
echo "On Ubuntu/Debian: sudo apt-get install ${missing_deps[*]}"
echo "On CentOS/RHEL: sudo yum install ${missing_deps[*]}"
echo "On macOS: brew install ${missing_deps[*]}"
exit 1
fi
log_verbose "All dependencies available: git, curl"
}
# Function to ask for confirmation
confirm() {
local message="$1"
if [ "$SKIP_CONFIRM" = true ]; then
log_verbose "Skipping confirmation: $message"
return 0
fi
echo -n "$message (y/N): "
read -r response
case "$response" in
[yY]|[yY][eE][sS])
return 0
;;
*)
return 1
;;
esac
}
# Function to validate paths exist
validate_paths() {
if [ ! -d "$PROFILE" ]; then
echo "Error: Profile directory does not exist: $PROFILE"
exit 1
fi
if [ ! -d "$CONFIG" ]; then
echo "Error: Config directory does not exist: $CONFIG"
exit 1
fi
log_verbose "Path validation successful"
}
# Uninstall function
uninstall() {
echo "Uninstalling profile setup..."
log_verbose "Starting uninstall process"
if ! confirm "This will remove dotfile symlinks and restore backups. Continue?"; then
echo "Uninstall cancelled."
exit 0
fi
OUTPUT="removing dircolors"
echo -n "$(pad_output "$OUTPUT"):"
remove_symlink "$INSTALL_PREFIX/.dircolors"
restore_backup "$INSTALL_PREFIX/.dircolors" || true
echo " Done"
OUTPUT="removing vim setup"
echo -n "$(pad_output "$OUTPUT"):"
remove_symlink "$INSTALL_PREFIX/.vimrc"
remove_symlink "$INSTALL_PREFIX/.vim"
restore_backup "$INSTALL_PREFIX/.vimrc" || true
restore_backup "$INSTALL_PREFIX/.vim" || true
echo " Done"
OUTPUT="removing zshrc"
echo -n "$(pad_output "$OUTPUT"):"
remove_symlink "$INSTALL_PREFIX/.zshrc"
if ! restore_backup "$INSTALL_PREFIX/.zshrc"; then
if is_managed_zshrc "$INSTALL_PREFIX/.zshrc"; then
rm -f "$INSTALL_PREFIX/.zshrc"
echo " removed managed file: $INSTALL_PREFIX/.zshrc"
fi
fi
echo " Done"
echo "Uninstall complete. Oh My Zsh, cargo/rustup, platformio, mise, gh, opencode, and claude installations were left intact."
echo "To remove them manually:"
echo " rm -rf $ZSH"
echo " rm -rf $HOME/.cargo"
echo " rm -rf $HOME/.rustup"
echo " rm -rf $HOME/.platformio"
echo " rm -rf $INSTALL_PREFIX/.local/share/mise"
echo " rm -f $INSTALL_PREFIX/.local/bin/mise"
echo " rm -rf $INSTALL_PREFIX/.opencode"
echo " rm -f $HOME/.local/bin/claude"
echo " rm -rf $HOME/.local/share/claude"
}
# ---------------------------------------------------------------------------
# Handle uninstall mode
if [ "$UNINSTALL" = true ]; then
uninstall
exit 0
fi
echo "Setting up utility scripts ..."
log_verbose "Verbose mode enabled"
log_verbose "Script location: $THIS"
# Check dependencies before proceeding
check_dependencies
# Validate paths exist
validate_paths
OUTPUT="source directory"
echo "$(pad_output "$OUTPUT"): $ROOT"
OUTPUT="profile directory"
echo "$(pad_output "$OUTPUT"): $PROFILE"
OUTPUT="config directory"
echo "$(pad_output "$OUTPUT"): $CONFIG"
OUTPUT="destination"
echo "$(pad_output "$OUTPUT"): $INSTALL_PREFIX"
# Ask for confirmation before proceeding
echo ""
if ! confirm "Proceed with profile installation?"; then
echo "Installation cancelled."
exit 0
fi
# ---------------------------------------------------------------------------
OUTPUT="setting up dircolors"
echo -n "$(pad_output "$OUTPUT"):"
backup_file "$INSTALL_PREFIX/.dircolors"
create_symlink "$CONFIG/dircolors" "$INSTALL_PREFIX/.dircolors" ".dircolors"
# ---------------------------------------------------------------------------
OUTPUT="setting up vim"
echo -n "$(pad_output "$OUTPUT"):"
backup_file "$INSTALL_PREFIX/.vimrc"
backup_file "$INSTALL_PREFIX/.vim"
create_symlink "$PROFILE/vimrc" "$INSTALL_PREFIX/.vimrc" ".vimrc"
create_symlink "$PROFILE/vim" "$INSTALL_PREFIX/.vim" ".vim"
echo ""
# ---------------------------------------------------------------------------
COLORSCHEME_REPO="https://github.com/rafi/awesome-vim-colorschemes.git"
COLORSCHEME_DIR="$PROFILE/vim/awesome-vim-colorschemes"
COLORSCHEME_COLORS_LINK="$PROFILE/vim/colors"
OUTPUT="initializing vim themes"
echo -n "$(pad_output "$OUTPUT"):"
if [ -d "$COLORSCHEME_DIR/.git" ]; then
log_verbose "awesome-vim-colorschemes already present"
echo " exists"
else
log_verbose "Cloning awesome-vim-colorschemes from $COLORSCHEME_REPO"
# Try submodule first; if it doesn't populate the repo, fall back to direct clone
git submodule update --init --recursive "$COLORSCHEME_DIR" > /dev/null 2>&1 || true
if [ ! -d "$COLORSCHEME_DIR/.git" ]; then
log_verbose "Submodule init did not populate repo; cloning directly"
if [ "$VERBOSE" = true ]; then
git clone "$COLORSCHEME_REPO" "$COLORSCHEME_DIR"
else
git clone -q "$COLORSCHEME_REPO" "$COLORSCHEME_DIR"
fi
fi
echo " Done"
fi
OUTPUT="linking vim colors"
echo -n "$(pad_output "$OUTPUT"):"
if [ -L "$COLORSCHEME_COLORS_LINK" ] && [ "$(readlink "$COLORSCHEME_COLORS_LINK")" = "$COLORSCHEME_DIR/colors" ]; then
log_verbose "vim/colors symlink already correct"
echo " exists"
elif [ -e "$COLORSCHEME_COLORS_LINK" ] && [ ! -L "$COLORSCHEME_COLORS_LINK" ]; then
log_verbose "vim/colors exists as real directory, skipping symlink"
echo " exists (real dir)"
else
ln -sf "$COLORSCHEME_DIR/colors" "$COLORSCHEME_COLORS_LINK"
log_verbose "Created symlink: vim/colors -> awesome-vim-colorschemes/colors"
echo " Done"
fi
# ---------------------------------------------------------------------------
OUTPUT="installing oh my zsh"
echo -n "$(pad_output "$OUTPUT"):"
if [ ! -d "$ZSH" ]; then
if confirm "Install Oh My Zsh?"; then
log_verbose "Cloning Oh My Zsh repository to $ZSH"
if [ "$VERBOSE" = true ]; then
git clone -c core.eol=lf -c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 https://github.com/ohmyzsh/ohmyzsh.git "$ZSH"
else
git clone -c core.eol=lf -c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 https://github.com/ohmyzsh/ohmyzsh.git "$ZSH" > /dev/null 2>&1
fi
echo " Done"
else
echo " Skipped"
fi
else
log_verbose "Oh My Zsh already exists at $ZSH"
echo " exists"
fi
# ---------------------------------------------------------------------------
OUTPUT="installing p10k theme"
echo -n "$(pad_output "$OUTPUT"):"
if [ ! -d "$ZSH_CUSTOM/themes/powerlevel10k" ]; then
if [ -d "$ZSH" ] && confirm "Install Powerlevel10k theme?"; then
log_verbose "Cloning Powerlevel10k theme to $ZSH_CUSTOM/themes/powerlevel10k"
if [ "$VERBOSE" = true ]; then
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$ZSH_CUSTOM"/themes/powerlevel10k
else
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$ZSH_CUSTOM"/themes/powerlevel10k > /dev/null 2>&1
fi
echo " Done"
else
echo " Skipped"
fi
else
log_verbose "Powerlevel10k theme already exists"
echo " exists"
fi
# ---------------------------------------------------------------------------
OUTPUT="installing mise"
echo -n "$(pad_output "$OUTPUT"):"
if command_exists mise; then
log_verbose "mise already installed"
echo " exists"
else
if confirm "Install mise (polyglot runtime manager)?"; then
log_verbose "Installing mise from https://mise.run"
if [ "$VERBOSE" = true ]; then
curl https://mise.run | sh
else
curl -sSL https://mise.run | sh
fi
echo " Done"
else
echo " Skipped"
fi
fi
MISE_CMD=""
if command_exists mise; then
MISE_CMD=$(command -v mise)
elif [ -x "$INSTALL_PREFIX/.local/bin/mise" ]; then
MISE_CMD="$INSTALL_PREFIX/.local/bin/mise"
fi
OUTPUT="installing node"
echo -n "$(pad_output "$OUTPUT"):"
if command_exists node; then
log_verbose "node already installed"
echo " exists"
elif [ -n "$MISE_CMD" ]; then
if confirm "Install Node.js (node@latest) via mise globally?"; then
log_verbose "Installing node@latest via mise ($MISE_CMD)"
if [ "$VERBOSE" = true ]; then
if "$MISE_CMD" use -g node@latest; then
:
else
echo " Failed"
echo "Error: Node.js installation via mise failed."
echo "Try again manually with:"
echo " $MISE_CMD use -g node@latest"
exit 1
fi
else
if "$MISE_CMD" use -g node@latest > /dev/null 2>&1; then
:
else
echo " Failed"
echo "Error: Node.js installation via mise failed."
echo "Try again manually with:"
echo " $MISE_CMD use -g node@latest"
exit 1
fi
fi
if [ -d "$INSTALL_PREFIX/.local/bin" ] && [[ ":$PATH:" != *":$INSTALL_PREFIX/.local/bin:"* ]]; then
PATH="$INSTALL_PREFIX/.local/bin:$PATH"
export PATH
fi
eval "$("$MISE_CMD" activate bash)"
echo " Done"
else
echo " Skipped"
fi
else
echo " Skipped"
echo "Error: mise is required to install Node.js. Install mise first."
fi
OUTPUT="installing gh"
echo -n "$(pad_output "$OUTPUT"):"
if command_exists gh; then
log_verbose "gh already installed"
echo " exists"
else
if confirm "Install GitHub CLI (gh)?"; then
if command_exists brew; then
log_verbose "Installing gh with Homebrew"
if [ "$VERBOSE" = true ]; then
brew install gh
else
brew install gh > /dev/null 2>&1
fi
echo " Done"
elif command_exists apt-get; then
log_verbose "Installing gh with apt-get"
if sudo apt-get update && sudo apt-get install -y gh; then
echo " Done"
else
echo " Failed"
echo "Error: GitHub CLI installation via apt-get failed."
echo "Try again manually with:"
echo " sudo apt-get update && sudo apt-get install -y gh"
exit 1
fi
elif command_exists dnf; then
log_verbose "Installing gh with dnf"
if sudo dnf install -y gh; then
echo " Done"
else
echo " Failed"
echo "Error: GitHub CLI installation via dnf failed."
echo "Try again manually with:"
echo " sudo dnf install -y gh"
exit 1
fi
elif command_exists yum; then
log_verbose "Installing gh with yum"
if sudo yum install -y gh; then
echo " Done"
else
echo " Failed"
echo "Error: GitHub CLI installation via yum failed."
echo "Try again manually with:"
echo " sudo yum install -y gh"
exit 1
fi
elif command_exists winget; then
log_verbose "Installing gh with winget"
if winget install --id GitHub.cli -e; then
echo " Done"
else
echo " Failed"
echo "Error: GitHub CLI installation via winget failed."
echo "Try again manually with:"
echo " winget install --id GitHub.cli -e"
exit 1
fi
else
echo " Failed"
echo "Error: Could not find a supported package manager for GitHub CLI."
echo "Install manually with one of:"
echo " brew install gh"
echo " sudo apt-get install gh"
echo " sudo dnf install gh"
echo " sudo yum install gh"
echo " winget install --id GitHub.cli -e"
exit 1
fi
else
echo " Skipped"
fi
fi
OUTPUT="installing claude"
echo -n "$(pad_output "$OUTPUT"):"
if command_exists claude; then
log_verbose "claude already installed"
echo " exists"
else
if confirm "Install Claude Code (native installer)?"; then
log_verbose "Installing Claude Code from https://claude.ai/install.sh"
if [ "$VERBOSE" = true ]; then
if curl -fsSL https://claude.ai/install.sh | bash; then
echo " Done"
else
echo " Failed"
echo "Error: Claude Code installation failed."
echo "Try again manually with:"
echo " curl -fsSL https://claude.ai/install.sh | bash"
exit 1
fi
else
if curl -fsSL https://claude.ai/install.sh | bash > /dev/null 2>&1; then
echo " Done"
else
echo " Failed"
echo "Error: Claude Code installation failed."
echo "Try again manually with:"
echo " curl -fsSL https://claude.ai/install.sh | bash"
exit 1
fi
fi
else
echo " Skipped"
fi
fi
OUTPUT="installing cargo"
echo -n "$(pad_output "$OUTPUT"):"
if command_exists cargo; then
log_verbose "cargo already installed"
echo " exists"
else
if confirm "Install Rust (cargo) via rustup?"; then
log_verbose "Installing rustup from https://sh.rustup.rs"
if curl -fsSL https://sh.rustup.rs | sh -s -- -y --no-modify-path; then
echo " Done"
else
echo " Failed"
echo "Error: rustup installation failed."
echo "Try again manually with:"
echo " curl -fsSL https://sh.rustup.rs | sh -s -- -y --no-modify-path"
exit 1
fi
else
echo " Skipped"
fi
fi
OUTPUT="installing platformio"
echo -n "$(pad_output "$OUTPUT"):"
if command_exists pio || command_exists pio.exe; then
log_verbose "platformio already installed"
echo " exists"
else
if confirm "Install PlatformIO Core?"; then
if command_exists python3; then
log_verbose "Installing PlatformIO Core from official installer"
PLATFORMIO_INSTALLER=$(mktemp "${TMPDIR:-/tmp}/get-platformio.XXXXXX.py")
if curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py \
-o "$PLATFORMIO_INSTALLER"; then
if python3 "$PLATFORMIO_INSTALLER"; then
rm -f "$PLATFORMIO_INSTALLER"
echo " Done"
else
rm -f "$PLATFORMIO_INSTALLER"
echo " Failed"
echo "Error: PlatformIO Core installation failed."
echo "Try again manually with:"
echo " curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -o /tmp/get-platformio.py"
echo " python3 /tmp/get-platformio.py"
exit 1
fi
else
rm -f "$PLATFORMIO_INSTALLER"
echo " Failed"
echo "Error: Failed to download PlatformIO installer."
echo "Try again manually with:"
echo " curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -o /tmp/get-platformio.py"
echo " python3 /tmp/get-platformio.py"
exit 1
fi
else
echo " Failed"
echo "Error: python3 is required to install PlatformIO Core."
exit 1
fi
else
echo " Skipped"
fi
fi
OUTPUT="installing opencode"
echo -n "$(pad_output "$OUTPUT"):"
if command_exists opencode; then
log_verbose "opencode already installed"
echo " exists"
else
if confirm "Install opencode (AI coding assistant)?"; then
log_verbose "Installing opencode from https://opencode.ai/install"
if [ "$VERBOSE" = true ]; then
curl -fsSL https://opencode.ai/install | bash
else
curl -fsSL https://opencode.ai/install | bash
fi
echo " Done"
else
echo " Skipped"
fi
fi
OUTPUT="writing"
FILE="$INSTALL_PREFIX/.zshrc"
echo "$(pad_output "$OUTPUT"): $FILE"
backup_file "$FILE"
log_verbose "Writing new .zshrc configuration"
cat > "$FILE" <<- EOD
# managed-by: utility-scripts-install
export PROFILE="$PROFILE"
source \$PROFILE/zshrc.sh
EOD
OUTPUT=""
echo "Installation complete!"
echo "--------------------------------------------------------------------------------"
# Check for Cloudflare credentials
CLOUDFLARE_CREDS="$INSTALL_PREFIX/.config/cloudflare/credentials"
if [ ! -f "$CLOUDFLARE_CREDS" ]; then
if command -v flarectl &> /dev/null; then
echo ""
echo "Note: flarectl is installed but Cloudflare credentials not found."
echo ""
echo "To configure Cloudflare API integration:"
echo " 1. Create the directory: mkdir -p ~/.config/cloudflare"
echo " 2. Create credentials file: touch ~/.config/cloudflare/credentials"
echo " 3. Set secure permissions: chmod 600 ~/.config/cloudflare/credentials"
echo " 4. Add your token: echo 'export CF_API_TOKEN=your_token_here' > ~/.config/cloudflare/credentials"
echo ""
echo "See README.md for detailed instructions on creating a Cloudflare API token."
echo "--------------------------------------------------------------------------------"
fi
else
# Verify permissions
PERM=$(stat -f '%A' "$CLOUDFLARE_CREDS" 2>/dev/null || stat -c '%a' "$CLOUDFLARE_CREDS" 2>/dev/null)
if [ "$PERM" != "600" ]; then
echo ""
echo "Warning: Cloudflare credentials file has insecure permissions ($PERM)"
echo " Run: chmod 600 $CLOUDFLARE_CREDS"
echo "--------------------------------------------------------------------------------"
fi
fi
# Offer to source the new configuration
if [ -f "$INSTALL_PREFIX/.zshrc" ]; then
echo "Your new shell configuration is ready."
echo ""
if confirm "Source the new .zshrc configuration now?"; then
if [ -n "$ZSH_VERSION" ]; then
# We're already in zsh, source the config
log_verbose "Sourcing new .zshrc configuration"
source "$INSTALL_PREFIX/.zshrc"
echo "Configuration loaded successfully!"
else
# We're in a different shell, start zsh
log_verbose "Starting new zsh session"
echo "Starting new zsh session..."
exec zsh
fi
else
echo "To use your new configuration:"
echo " source $INSTALL_PREFIX/.zshrc"
echo " # OR restart your terminal"
fi
else
echo "Note: .zshrc was not created. Please restart your terminal to use the new profile setup."
fi