-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-env.sh
More file actions
executable file
·2532 lines (2229 loc) · 88.9 KB
/
setup-env.sh
File metadata and controls
executable file
·2532 lines (2229 loc) · 88.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
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
# File: setup-env.sh
# Author: Michael Brown
# Version: 1.1.0
# Date: February 6, 2026
# Description: Menu-driven development environment setup script for Ubuntu/Debian systems
# Installs and configures common dev tools including Python, Node.js, Git, curl, wget,
# make/build tools, Docker, Docker Compose, zip/unzip, Golang, PHP, AWS/Azure/GCloud CLIs,
# Terraform, OpenSSL, OpenSSH, Composer, Laravel deps, Vim, and Postman CLI
################################################################################################
#### HOW TO USE THIS SCRIPT - Examples and Quick Reference
################################################################################################
# BASIC USAGE:
# Make the script executable first:
# chmod +x setup-env.sh
#
# Run in interactive menu mode (shows a numbered menu with options):
# Simply run the script without any parameters - this starts the interactive menu
# ./setup-env.sh
#
# Run with command line options:
# ./setup-env.sh # Starts the interactive menu
# ./setup-env.sh --github-clone # Clone a GitHub repo via HTTPS
# ./setup-env.sh --install-python # Install Python only
# ./setup-env.sh --install-nodejs # Install Node.js only
# ./setup-env.sh --install-npm # Install npm only
# ./setup-env.sh --install-git # Install Git only
# ./setup-env.sh --install-curl # Install curl only
# ./setup-env.sh --install-wget # Install wget only
# ./setup-env.sh --install-make # Install make/build tools only
# ./setup-env.sh --install-docker # Install Docker only
# ./setup-env.sh --install-docker-compose # Install Docker Compose only
# ./setup-env.sh --install-zip # Install zip/unzip only
# ./setup-env.sh --install-golang # Install Golang only
# ./setup-env.sh --install-php # Install PHP only
# ./setup-env.sh --install-aws # Install AWS CLI only
# ./setup-env.sh --install-azure # Install Azure CLI only
# ./setup-env.sh --install-gcloud # Install Google Cloud SDK only
# ./setup-env.sh --install-terraform # Install Terraform only
# ./setup-env.sh --install-openssl # Install OpenSSL only
# ./setup-env.sh --install-openssh # Install OpenSSH server only
# ./setup-env.sh --install-composer # Install Composer only
# ./setup-env.sh --install-laravel-deps # Install Laravel dependencies
# ./setup-env.sh --install-vim # Install Vim only
# ./setup-env.sh --install-postman # Install Postman CLI only
# ./setup-env.sh --system-update # Run system update and cleanup
# ./setup-env.sh --install-packages pkg1 pkg2 ... # Install a list of packages
# ./setup-env.sh --help # Show help information
# COMMON SCENARIOS:
#
# 1. Interactive installation (menu-driven):
# ./setup-env.sh
# Then select options 1-26 from the menu (you can enter multiple numbers separated by spaces)
#
# 2. Install specific tools:
# ./setup-env.sh --install-python
# ./setup-env.sh --install-docker
# 3. Install Laravel dependencies:
# ./setup-env.sh --install-laravel-deps
# MENU OPTIONS EXPLAINED:
# When you run ./setup-env.sh, you'll see a menu with these options.
# You can select one option or multiple options by entering numbers separated by spaces (e.g., 3 5 9 11 19).
# Menu labels are dynamic and may show Install/Update with color based on status.
# Green = installed and up to date; Yellow = installed but update available.
# 1. Install Python - Installs Python 3 and pip
# 2. Install Node.js - Installs Node.js runtime
# 3. Install npm - Installs npm package manager
# 4. Install Golang - Installs Go programming language
# 5. Install PHP - Installs PHP and common extensions
# 6. Install Composer - Installs Composer
# 7. Install Laravel Deps - Installs Laravel dependencies
# 8. Install make - Installs build-essential (make, gcc, g++)
# 9. Install Docker - Installs Docker Engine
# 10. Install Docker Compose - Installs Docker Compose (standalone)
# 11. Install AWS CLI - Installs AWS CLI
# 12. Install Azure CLI - Installs Azure CLI
# 13. Install Google Cloud SDK - Installs Google Cloud SDK
# 14. Install Terraform - Installs Terraform
# 15. Install wget - Installs wget for file downloads
# 16. Install zip/unzip - Installs zip and unzip utilities
# 17. Install Git - Installs Git version control
# 18. Install curl - Installs curl for HTTP requests
# 19. Install OpenSSL - Installs OpenSSL
# 20. Install Postman CLI - Installs Postman CLI
# 21. Install Vim - Installs Vim editor
# 22. Clone GitHub Repo (HTTPS) - Clone a GitHub repository
# 23. Set Git Identity - Configure git user.name and user.email
# 24. Show Installed Versions - Display versions of installed tools
# 25. CLI Options - Show command line options
# 26. Help - Show usage information
# 0. Exit - Quit the script
################################################################################################
#### Configurable Variables
################################################################################################
# Define script version
SCRIPT_VERSION="1.1.0"
# Enable or disable logging (true/false)
LOGGING_ENABLED=false
LOGFILE="/var/log/dev-setup-script.log"
# Quiet mode (suppress non-essential output)
QUIET_MODE=false
# Non-interactive mode (skip pauses for CLI usage)
NON_INTERACTIVE=false
# Git global identity
GIT_USER_NAME="gitmikebrown"
GIT_USER_EMAIL="123339553+gitmikebrown@users.noreply.github.com"
# Cache for detected package manager
DETECTED_PKG_MANAGER=""
# Terminal colors
COLOR_GREEN="\033[0;32m"
COLOR_RED="\033[0;31m"
COLOR_BLUE="\033[0;34m"
COLOR_PURPLE="\033[0;35m"
COLOR_YELLOW="\033[0;33m"
COLOR_GRAY="\033[0;90m"
COLOR_RESET="\033[0m"
################################################################################################
#### Detect Package Manager
################################################################################################
function detectPackageManager() {
# Return cached value if already detected
if [ -n "$DETECTED_PKG_MANAGER" ]; then
echo "$DETECTED_PKG_MANAGER"
return
fi
# Detect package manager and cache the result
if command -v apt >/dev/null 2>&1; then
DETECTED_PKG_MANAGER="apt"
elif command -v yum >/dev/null 2>&1; then
DETECTED_PKG_MANAGER="yum"
elif command -v dnf >/dev/null 2>&1; then
DETECTED_PKG_MANAGER="dnf"
else
DETECTED_PKG_MANAGER="unknown"
fi
echo "$DETECTED_PKG_MANAGER"
}
################################################################################################
#### Ensure Script is Run as Root
################################################################################################
function checkRoot() {
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or use sudo."
exit 1
fi
}
################################################################################################
#### Logging Function
################################################################################################
function log() {
if [ "$LOGGING_ENABLED" = true ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOGFILE"
fi
}
################################################################################################
#### Quiet Mode Handling
################################################################################################
function terminalOutput() {
if [ "$QUIET_MODE" = false ]; then
local text="$1"
if [[ "$text" =~ ^[=]{10,}$ ]]; then
printf "%b\n" "${COLOR_GREEN}${text}${COLOR_RESET}"
elif [[ "$text" =~ ^\ (WARNING|Warning|CAUTION|Caution|DANGER|Danger) ]]; then
printf "%b\n" "${COLOR_RED}${text}${COLOR_RESET}"
elif [[ "$text" =~ ^\ (Installing|Installed|Dev\ Environment\ Setup|Database\ Setup|Help) ]]; then
printf "%b\n" "${COLOR_GREEN}${text}${COLOR_RESET}"
else
printf "%b\n" "$text"
fi
fi
}
################################################################################################
#### Utility Functions
################################################################################################
function isWSL(){
if grep -qiE "(microsoft|wsl)" /proc/version 2>/dev/null; then
return 0
fi
if grep -qiE "(microsoft|wsl)" /proc/sys/kernel/osrelease 2>/dev/null; then
return 0
fi
if [ -n "${WSL_DISTRO_NAME-}" ] || [ -n "${WSL_INTEROP-}" ]; then
return 0
fi
return 1
}
function warnWslDocker(){
if isWSL; then
terminalOutput "This looks like a WSL environment."
terminalOutput "Docker Engine inside WSL is not recommended for most users."
terminalOutput "Install Docker Desktop on Windows and enable this distro instead."
terminalOutput "Docker Desktop: Settings > Resources > WSL Integration > Enable integration."
terminalOutput "Then select this distro (or enable default WSL distro integration)."
terminalOutput ""
fi
}
function promptInput(){
local prompt="$1"
local varName="$2"
printf "%b" "${COLOR_YELLOW}${prompt}${COLOR_RESET}"
if [ -n "$varName" ]; then
read -r "$varName"
else
read -r
fi
}
function pause(){
if [ "$NON_INTERACTIVE" = true ]; then
return
fi
local prompt="${1:-Press [Enter] to return to the menu...}"
promptInput "$prompt"
}
function confirm(){
promptInput "$1 [y/N]: " response
[[ "$response" =~ ^[Yy]$ ]]
}
function ensurePackages() {
local pkgManager
pkgManager=$(detectPackageManager)
if [ "$#" -eq 0 ]; then
return 0
fi
if [ "$pkgManager" = "apt" ]; then
sudo apt update
sudo apt install -y "$@"
elif [ "$pkgManager" = "yum" ]; then
sudo yum install -y "$@"
elif [ "$pkgManager" = "dnf" ]; then
sudo dnf install -y "$@"
else
terminalOutput "Error: Unsupported package manager"
log "Package installation failed - unsupported package manager"
return 1
fi
}
################################################################################################
#### Installation Functions
################################################################################################
function installPython() {
local pkgManager
pkgManager=$(detectPackageManager)
terminalOutput "======================================"
terminalOutput " Installing Python"
terminalOutput "======================================"
log "Starting Python installation"
if [ "$pkgManager" = "apt" ]; then
sudo apt update
sudo apt install -y python3 python3-pip python3-venv python3-dev
elif [ "$pkgManager" = "yum" ]; then
sudo yum install -y python3 python3-pip python3-devel
elif [ "$pkgManager" = "dnf" ]; then
sudo dnf install -y python3 python3-pip python3-devel
else
terminalOutput "Error: Unsupported package manager"
log "Python installation failed - unsupported package manager"
pause
return 1
fi
terminalOutput "Python installation complete!"
python3 --version
pip3 --version
log "Python installation complete"
pause
}
function installNodeJS() {
local pkgManager
pkgManager=$(detectPackageManager)
terminalOutput "======================================"
terminalOutput " Installing Node.js and npm"
terminalOutput "======================================"
log "Starting Node.js installation"
ensurePackages curl
if [ "$pkgManager" = "apt" ]; then
# Install Node.js LTS via NodeSource repository
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
elif [ "$pkgManager" = "yum" ]; then
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs
elif [ "$pkgManager" = "dnf" ]; then
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo dnf install -y nodejs
else
terminalOutput "Error: Unsupported package manager"
log "Node.js installation failed - unsupported package manager"
pause
return 1
fi
terminalOutput "Node.js installation complete!"
node --version
if ! command -v npm >/dev/null 2>&1; then
ensurePackages npm
fi
npm --version
log "Node.js installation complete"
pause
}
function installNpm() {
terminalOutput "======================================"
terminalOutput " Installing npm"
terminalOutput "======================================"
log "Starting npm installation"
ensurePackages npm
terminalOutput "npm installation complete!"
npm --version
log "npm installation complete"
pause
}
function installGit() {
local pkgManager
pkgManager=$(detectPackageManager)
terminalOutput "======================================"
terminalOutput " Installing Git"
terminalOutput "======================================"
log "Starting Git installation"
if [ "$pkgManager" = "apt" ]; then
sudo apt update
sudo apt install -y git
elif [ "$pkgManager" = "yum" ]; then
sudo yum install -y git
elif [ "$pkgManager" = "dnf" ]; then
sudo dnf install -y git
else
terminalOutput "Error: Unsupported package manager"
log "Git installation failed - unsupported package manager"
pause
return 1
fi
terminalOutput "Git installation complete!"
git --version
if ! setGitIdentity; then
pause
return
fi
log "Git installation complete"
pause
}
function setGitIdentity() {
local targetUser="$USER"
local targetHome="$HOME"
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
targetUser="$SUDO_USER"
targetHome=$(getent passwd "$targetUser" | cut -d: -f6)
if [ -z "$targetHome" ]; then
targetHome="$HOME"
fi
fi
local gitConfigCmd=(git config --global)
if [ "$targetUser" != "$USER" ]; then
gitConfigCmd=(sudo -u "$targetUser" env HOME="$targetHome" git config --global)
fi
if [ "$NON_INTERACTIVE" = true ]; then
"${gitConfigCmd[@]}" user.name "$GIT_USER_NAME"
"${gitConfigCmd[@]}" user.email "$GIT_USER_EMAIL"
return 0
fi
if ! confirm "Would you like to set your Git identity now?"; then
terminalOutput "Skipped Git identity setup. You can set it later with:"
terminalOutput " git config --global user.name \"Your Name\""
terminalOutput " git config --global user.email \"you@example.com\""
terminalOutput "To change the defaults, edit GIT_USER_NAME/GIT_USER_EMAIL near the top of this script."
log "Git identity setup skipped"
return 1
fi
local gitName="$GIT_USER_NAME"
local gitEmail="$GIT_USER_EMAIL"
terminalOutput ""
terminalOutput "Git identity defaults:"
terminalOutput " Name: $gitName"
terminalOutput " Email: $gitEmail"
if confirm "Is this your info?"; then
"${gitConfigCmd[@]}" user.name "$gitName"
"${gitConfigCmd[@]}" user.email "$gitEmail"
return 0
fi
terminalOutput "You can update it now or later with:"
terminalOutput " git config --global user.name \"Your Name\""
terminalOutput " git config --global user.email \"you@example.com\""
terminalOutput "To change the defaults, edit GIT_USER_NAME/GIT_USER_EMAIL near the top of this script."
promptInput "Enter your name (leave blank to skip): " gitNameInput
promptInput "Enter your email (leave blank to skip): " gitEmailInput
if [ -n "$gitNameInput" ]; then
gitName="$gitNameInput"
fi
if [ -n "$gitEmailInput" ]; then
gitEmail="$gitEmailInput"
fi
if [ -n "$gitNameInput" ] || [ -n "$gitEmailInput" ]; then
if [ -n "$gitName" ]; then
"${gitConfigCmd[@]}" user.name "$gitName"
fi
if [ -n "$gitEmail" ]; then
"${gitConfigCmd[@]}" user.email "$gitEmail"
fi
fi
return 0
}
function setGitIdentityMenu() {
clear
terminalOutput "======================================"
terminalOutput " Set Git Identity"
terminalOutput "======================================"
if ! command -v git >/dev/null 2>&1; then
terminalOutput "Git is not installed."
if confirm "Install Git now?"; then
installGit
else
terminalOutput "Canceled."
fi
return 0
fi
setGitIdentity
pause
}
function cloneGitHubRepo() {
terminalOutput "======================================"
terminalOutput " GitHub Repo Clone (Beginner Friendly)"
terminalOutput "======================================"
terminalOutput "This will copy a GitHub repository to your computer."
terminalOutput "Tip: Type 'q' at any prompt to cancel."
if ! command -v git >/dev/null 2>&1; then
terminalOutput "Git is not installed."
if confirm "Install Git now?"; then
installGit
else
terminalOutput "Canceled."
return 1
fi
fi
local repoUrl=""
local repoName=""
local defaultDir=""
local targetDir=""
local targetPath=""
local confirmAction=""
local action=""
local targetUser="$USER"
local targetHome="$HOME"
local cloneMethod=""
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
targetUser="$SUDO_USER"
targetHome=$(getent passwd "$targetUser" | cut -d: -f6)
if [ -z "$targetHome" ]; then
targetHome="$HOME"
fi
fi
terminalOutput "First, choose how to sign in to GitHub:"
terminalOutput " 1) HTTPS (recommended for beginners)"
terminalOutput " - You will use a Personal Access Token (PAT) instead of a password."
terminalOutput " - Create one at: https://github.com/settings/tokens/new"
terminalOutput " - For private repos, select 'repo'. For public only, 'public_repo'."
terminalOutput " 2) SSH (advanced)"
terminalOutput " - You need an SSH key added to GitHub first."
terminalOutput " - Docs: https://docs.github.com/authentication/connecting-to-github-with-ssh"
terminalOutput ""
while true; do
promptInput "Select [1-2]: " cloneMethod
if [ "$cloneMethod" = "q" ] || [ "$cloneMethod" = "Q" ]; then
terminalOutput "Canceled."
return 0
fi
if [ "$cloneMethod" = "1" ] || [ "$cloneMethod" = "2" ]; then
break
fi
terminalOutput "Invalid option. Please enter 1 or 2."
done
if [ "$cloneMethod" = "2" ]; then
terminalOutput ""
terminalOutput "SSH key setup:"
terminalOutput "- GitHub needs your public key before SSH will work."
terminalOutput "- We can generate a key now and show it to you."
if ! command -v ssh-keygen >/dev/null 2>&1; then
ensurePackages openssh-client
fi
local sshDir="$targetHome/.ssh"
local sshKey="$sshDir/id_ed25519_github"
local sshPub="$sshKey.pub"
local existingPub=""
for key in "$sshDir"/*.pub; do
if [ -f "$key" ]; then
existingPub="$key"
break
fi
done
if [ -n "$existingPub" ]; then
terminalOutput "Found an existing SSH public key. We will reuse it."
sshPub="$existingPub"
elif confirm "Generate a new SSH key now?"; then
sudo -u "$targetUser" env HOME="$targetHome" mkdir -p "$sshDir"
sudo -u "$targetUser" env HOME="$targetHome" ssh-keygen -t ed25519 -C "$targetUser@$(hostname)" -f "$sshKey" -N ""
sudo -u "$targetUser" env HOME="$targetHome" chmod 700 "$sshDir"
sudo -u "$targetUser" env HOME="$targetHome" chmod 600 "$sshKey" 2>/dev/null || true
sudo -u "$targetUser" env HOME="$targetHome" chmod 644 "$sshPub" 2>/dev/null || true
else
terminalOutput "Skipping SSH key generation. SSH clone may fail without a key."
fi
if [ -f "$sshPub" ]; then
terminalOutput ""
terminalOutput "Add this public key to GitHub (Settings > SSH and GPG keys):"
terminalOutput "https://github.com/settings/ssh/new"
terminalOutput ""
terminalOutput "----- BEGIN PUBLIC KEY -----"
cat "$sshPub"
terminalOutput "----- END PUBLIC KEY -----"
terminalOutput ""
fi
fi
while true; do
if [ "$cloneMethod" = "1" ]; then
terminalOutput ""
terminalOutput "Step 1: Paste the HTTPS URL of the repo."
terminalOutput "You can copy it from the green 'Code' button on GitHub (HTTPS tab)."
promptInput "HTTPS URL: " repoUrl
else
terminalOutput ""
terminalOutput "Step 1: Paste the SSH URL of the repo."
terminalOutput "You can copy it from the green 'Code' button on GitHub (SSH tab)."
promptInput "SSH URL: " repoUrl
fi
if [ "$repoUrl" = "q" ] || [ "$repoUrl" = "Q" ]; then
terminalOutput "Canceled."
return 0
fi
if [ -z "$repoUrl" ]; then
terminalOutput "Please enter a URL or 'q' to cancel."
continue
fi
if [ "$cloneMethod" = "1" ]; then
if [[ "$repoUrl" != https://* ]]; then
terminalOutput "URL must start with https://"
continue
fi
else
if [[ "$repoUrl" != git@* && "$repoUrl" != ssh://* ]]; then
terminalOutput "URL must be an SSH format (git@... or ssh://...)"
continue
fi
fi
break
done
repoName=$(basename "$repoUrl")
repoName=${repoName%.git}
if [ -z "$repoName" ]; then
terminalOutput "Could not determine repo name from URL."
return 1
fi
defaultDir="$repoName"
while true; do
promptInput "Target folder [${defaultDir}]: " targetDir
if [ "$targetDir" = "q" ] || [ "$targetDir" = "Q" ]; then
terminalOutput "Canceled."
return 0
fi
if [ -z "$targetDir" ]; then
targetDir="$defaultDir"
fi
if [[ "$targetDir" != /* ]]; then
targetPath="$targetHome/$targetDir"
else
targetPath="$targetDir"
fi
if [ -e "$targetPath" ]; then
terminalOutput "Target path '$targetPath' already exists. Choose another folder or 'q' to cancel."
targetDir=""
continue
fi
break
done
terminalOutput ""
terminalOutput "Step 2: Choose where to save it."
terminalOutput "Default is your home folder with the repo name."
terminalOutput ""
terminalOutput "About to clone:"
terminalOutput " URL: $repoUrl"
terminalOutput " Dest: $targetPath"
if [ "$cloneMethod" = "1" ]; then
terminalOutput ""
terminalOutput "Step 3: When Git asks for login:"
terminalOutput "- Username: your GitHub username"
terminalOutput "- Password: your GitHub Personal Access Token (PAT)"
terminalOutput "If you do not have a PAT yet, create one here:"
terminalOutput " https://github.com/settings/tokens/new"
fi
while true; do
promptInput "Continue? [y/N]: " confirmAction
if ! [[ "$confirmAction" =~ ^[Yy]$ ]]; then
terminalOutput "Canceled."
return 0
fi
if [ "$targetUser" != "$USER" ]; then
if sudo -u "$targetUser" env HOME="$targetHome" git clone "$repoUrl" "$targetPath"; then
terminalOutput "Clone complete."
terminalOutput "Next steps:"
terminalOutput " cd \"$targetPath\""
terminalOutput " git status"
terminalOutput ""
terminalOutput "Tip: If prompted for credentials, use a GitHub token or sign in via VS Code."
return 0
fi
elif git clone "$repoUrl" "$targetPath"; then
terminalOutput "Clone complete."
terminalOutput "Next steps:"
terminalOutput " cd \"$targetPath\""
terminalOutput " git status"
terminalOutput ""
terminalOutput "Tip: If prompted for credentials, use a GitHub token or sign in via VS Code."
return 0
fi
terminalOutput "Clone failed. Choose an option:"
terminalOutput " 1) Retry clone"
terminalOutput " 2) Change URL"
terminalOutput " 3) Change target folder"
terminalOutput " 4) Cancel"
promptInput "Select [1-4]: " action
case "$action" in
1) ;;
2)
repoUrl=""
while true; do
if [ "$cloneMethod" = "1" ]; then
promptInput "Enter the HTTPS repo URL (e.g., https://github.com/owner/repo.git): " repoUrl
else
promptInput "Enter the SSH repo URL (e.g., git@github.com:owner/repo.git): " repoUrl
fi
if [ "$repoUrl" = "q" ] || [ "$repoUrl" = "Q" ]; then
terminalOutput "Canceled."
return 0
fi
if [ -z "$repoUrl" ]; then
terminalOutput "Please enter a URL or 'q' to cancel."
continue
fi
if [ "$cloneMethod" = "1" ]; then
if [[ "$repoUrl" != https://* ]]; then
terminalOutput "URL must start with https://"
continue
fi
else
if [[ "$repoUrl" != git@* && "$repoUrl" != ssh://* ]]; then
terminalOutput "URL must be an SSH format (git@... or ssh://...)"
continue
fi
fi
break
done
repoName=$(basename "$repoUrl")
repoName=${repoName%.git}
if [ -z "$repoName" ]; then
terminalOutput "Could not determine repo name from URL."
return 1
fi
defaultDir="$repoName"
targetDir=""
targetPath=""
while true; do
promptInput "Target folder [${defaultDir}]: " targetDir
if [ "$targetDir" = "q" ] || [ "$targetDir" = "Q" ]; then
terminalOutput "Canceled."
return 0
fi
if [ -z "$targetDir" ]; then
targetDir="$defaultDir"
fi
if [[ "$targetDir" != /* ]]; then
targetPath="$targetHome/$targetDir"
else
targetPath="$targetDir"
fi
if [ -e "$targetPath" ]; then
terminalOutput "Target path '$targetPath' already exists. Choose another folder or 'q' to cancel."
targetDir=""
continue
fi
break
done
;;
3)
targetDir=""
while true; do
promptInput "Target folder [${defaultDir}]: " targetDir
if [ "$targetDir" = "q" ] || [ "$targetDir" = "Q" ]; then
terminalOutput "Canceled."
return 0
fi
if [ -z "$targetDir" ]; then
targetDir="$defaultDir"
fi
if [[ "$targetDir" != /* ]]; then
targetPath="$targetHome/$targetDir"
else
targetPath="$targetDir"
fi
if [ -e "$targetPath" ]; then
terminalOutput "Target path '$targetPath' already exists. Choose another folder or 'q' to cancel."
targetDir=""
continue
fi
break
done
;;
4)
terminalOutput "Canceled."
return 0
;;
*)
terminalOutput "Invalid option."
;;
esac
done
}
function installCurl() {
local pkgManager
pkgManager=$(detectPackageManager)
terminalOutput "======================================"
terminalOutput " Installing curl"
terminalOutput "======================================"
log "Starting curl installation"
if [ "$pkgManager" = "apt" ]; then
sudo apt update
sudo apt install -y curl
elif [ "$pkgManager" = "yum" ]; then
sudo yum install -y curl
elif [ "$pkgManager" = "dnf" ]; then
sudo dnf install -y curl
else
terminalOutput "Error: Unsupported package manager"
log "curl installation failed - unsupported package manager"
pause
return 1
fi
terminalOutput "curl installation complete!"
curl --version
log "curl installation complete"
pause
}
function installMake() {
local pkgManager
pkgManager=$(detectPackageManager)
terminalOutput "======================================"
terminalOutput " Installing make and build tools"
terminalOutput "======================================"
log "Starting build-essential installation"
if [ "$pkgManager" = "apt" ]; then
sudo apt update
sudo apt install -y build-essential
elif [ "$pkgManager" = "yum" ]; then
sudo yum groupinstall -y "Development Tools"
sudo yum install -y make gcc gcc-c++
elif [ "$pkgManager" = "dnf" ]; then
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y make gcc gcc-c++
else
terminalOutput "Error: Unsupported package manager"
log "build-essential installation failed - unsupported package manager"
pause
return 1
fi
terminalOutput "make and build tools installation complete!"
make --version
gcc --version
log "build-essential installation complete"
pause
}
function runSystemUpdate() {
local pkgManager
pkgManager=$(detectPackageManager)
terminalOutput "======================================"
terminalOutput " Running System Update"
terminalOutput "======================================"
log "Starting system update"
if [ "$pkgManager" = "apt" ]; then
sudo apt -y -qq update
sudo apt -y -qq upgrade
sudo apt -y -qq dist-upgrade
sudo apt -y -qq autoremove
sudo apt -y -qq autoclean
elif [ "$pkgManager" = "yum" ]; then
sudo yum -y update
sudo yum -y autoremove || true
elif [ "$pkgManager" = "dnf" ]; then
sudo dnf -y upgrade
sudo dnf -y autoremove || true
else
terminalOutput "Error: Unsupported package manager"
log "System update failed - unsupported package manager"
return 1
fi
terminalOutput "System update complete!"
log "System update complete"
}
function installDocker() {
local pkgManager
pkgManager=$(detectPackageManager)
terminalOutput "======================================"
terminalOutput " Installing Docker"
terminalOutput "======================================"
log "Starting Docker installation"
if [ "$pkgManager" = "apt" ]; then
# Remove old versions
sudo apt remove -y docker docker-engine docker.io containerd runc 2>/dev/null
# Install prerequisites
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
# Add Docker's official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Set up repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker Engine
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Add current user to docker group
sudo usermod -aG docker $SUDO_USER 2>/dev/null || sudo usermod -aG docker $USER
elif [ "$pkgManager" = "yum" ]; then
# Remove old versions
sudo yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine 2>/dev/null
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $SUDO_USER 2>/dev/null || sudo usermod -aG docker $USER
elif [ "$pkgManager" = "dnf" ]; then
# Remove old versions
sudo dnf remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine 2>/dev/null
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $SUDO_USER 2>/dev/null || sudo usermod -aG docker $USER
else
terminalOutput "Error: Unsupported package manager"
log "Docker installation failed - unsupported package manager"
pause
return 1
fi
terminalOutput "Docker installation complete!"
terminalOutput "Note: You may need to log out and back in for Docker group changes to take effect."
docker --version
log "Docker installation complete"
pause
}
function installZip() {
local pkgManager
pkgManager=$(detectPackageManager)
terminalOutput "======================================"
terminalOutput " Installing zip and unzip"
terminalOutput "======================================"
log "Starting zip/unzip installation"
if [ "$pkgManager" = "apt" ]; then
sudo apt update
sudo apt install -y zip unzip
elif [ "$pkgManager" = "yum" ]; then
sudo yum install -y zip unzip
elif [ "$pkgManager" = "dnf" ]; then
sudo dnf install -y zip unzip
else
terminalOutput "Error: Unsupported package manager"
log "zip/unzip installation failed - unsupported package manager"
pause
return 1
fi
terminalOutput "zip and unzip installation complete!"
zip --version
log "zip/unzip installation complete"
pause
}
function installGolang() {
terminalOutput "======================================"