├── .gitignore
├── README.md
├── proxy-to-https
├── README.md
├── execute.sh
├── generate-server-pem.sh
├── manage-hosts.sh
└── port-forward.sh
└── setup
├── execute.sh
├── setup-base-tools.sh
├── setup-dev-env.sh
└── setup-docker.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | server.pem
2 | server.key
3 | server.csr
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | ## `proxy-to-https`
4 | Local service proxy to Any domain
5 | ### 1. Start your local service, and got the `local_port_number`
6 | ### 2. Run the following commands
7 | - Change your current directory to `proxy-to-https`
8 | ```powershell
9 | cd ./proxy-to-https
10 | ```
11 | - Make all files executable
12 | ```powershell
13 | chmod +x ./*
14 | ```
15 | - Execute the following command
16 | ```powershell
17 | ./execute.sh your_domain
18 | ```
19 |
20 | Or you can configure an `alias` in a `.zshrc` or `.bashrc` file.
21 | ### 3. Open your browser, and visit `your_domain`
22 |
23 | ## `setup`
24 | This suite of scripts is designed to streamline the setup of a comprehensive frontend development environment on macOS. It automates the installation and configuration of essential tools, development environment settings, and optional Docker-related packages, ensuring a consistent and efficient setup process for developers.
25 |
26 | ### Run the following commands
27 | - Change your current directory to `setup`
28 | ```powershell
29 | cd ./setup
30 | ```
31 | - Make all files executable
32 | ```powershell
33 | chmod +x ./*
34 | ```
35 | - Execute the following command
36 | ```powershell
37 | ./execute.sh
38 | ```
39 |
40 | Or you can configure an `alias` in a `.zshrc` or `.bashrc` file.
--------------------------------------------------------------------------------
/proxy-to-https/README.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | ## `proxy-to-https`
4 | Local service proxy to Any domain
5 | > following below instructions, if you never used shell
6 | ### 1. Start your local service, and got the `local_port_number`
7 | ### 2. Run the following commands
8 | - Change your current directory to `proxy-to-https`
9 | ```powershell
10 | cd ./proxy-to-https
11 | ```
12 | - Make all files executable
13 | ```powershell
14 | chmod +x ./*
15 | ```
16 | - Add a new host to your `/etc/hosts` file
17 | ```powershell
18 | ./manage-hosts.sh add 127.0.0.1 your_domain
19 | ```
20 | - Proxy your local service port to default port `80` or `443`, and make a `server.pem` file
21 | > port `80` is the default port for http
22 | ```powershell
23 | ./port-forward.sh 80 your_local_port_number
24 | ```
25 |
26 | If you want to use https, you need to run the following commands
27 | > port `443` is the default port for https
28 | ```powershell
29 | ./port-forward.sh 443 your_local_port_number
30 | ```
31 |
32 | Or you can configure an alias in a `.zshrc` or `.bashrc` file.
33 | ### 3. Open your browser, and visit `your_domain`
34 |
--------------------------------------------------------------------------------
/proxy-to-https/execute.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # -----------------------------------------------------------------------------
3 | # File: execute.sh
4 | # Description: This script generates a self-signed certificate for a given domain.
5 | # Usage: ./execute.sh
6 | # Compatibility: GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
7 | # -----------------------------------------------------------------------------
8 |
9 | # Retrieve arguments
10 | domain="$1"
11 |
12 | # Get the directory of the script
13 | path=$(dirname "$0")
14 |
15 | $path/manage-hosts.sh add 127.0.0.1 "$domain"
16 |
17 | $path/port-forward.sh 443 8000
18 | # ./port-forward.sh 80 8000
19 |
20 | # Function to be executed when Ctrl+C is pressed
21 | callback() {
22 | $path/manage-hosts.sh remove "$domain"
23 | # chmod -x ./*
24 | trap - SIGINT
25 | trap - EXIT
26 | }
27 |
28 | # Set the trap for SIGINT (Ctrl+C) and EXIT signals
29 | trap callback SIGINT
30 | trap callback EXIT
31 |
--------------------------------------------------------------------------------
/proxy-to-https/generate-server-pem.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # -----------------------------------------------------------------------------
3 | # File: generate-server-pem.sh
4 | # Description: A script to generate a self-signed SSL certificate (server.pem).
5 | # If openssl is not installed, it will attempt to install it.
6 | # Usage: ./generate-server-pem.sh
7 | # Compatibility: Designed for Linux and macOS. Windows support via WSL.
8 | # -----------------------------------------------------------------------------
9 |
10 | # Function to display usage information
11 | display_usage() {
12 | echo "Usage: $0"
13 | echo "This script generates a self-signed SSL certificate (server.pem)."
14 | echo "If openssl is not installed, it will attempt to install it."
15 | echo "Example:"
16 | echo " ./generate-server-pem.sh"
17 | exit 1
18 | }
19 |
20 | # Function to install openssl based on the operating system
21 | install_openssl() {
22 | echo "Info: openssl is not installed. Attempting to install it now..."
23 |
24 | if [[ "$OSTYPE" == "linux-gnu"* ]]; then
25 | # Linux (Debian/Ubuntu)
26 | if command -v apt-get &> /dev/null; then
27 | sudo apt-get update
28 | sudo apt-get install -y openssl
29 | # Linux (Red Hat/CentOS/Fedora)
30 | elif command -v yum &> /dev/null; then
31 | sudo yum install -y openssl
32 | elif command -v dnf &> /dev/null; then
33 | sudo dnf install -y openssl
34 | else
35 | echo "Error: Unable to determine package manager. Please install openssl manually."
36 | exit 1
37 | fi
38 | elif [[ "$OSTYPE" == "darwin"* ]]; then
39 | # macOS
40 | if command -v brew &> /dev/null; then
41 | brew install openssl
42 | else
43 | echo "Error: Homebrew is not installed. Please install Homebrew and then run this script again."
44 | exit 1
45 | fi
46 | else
47 | echo "Error: Unsupported operating system. Please install openssl manually."
48 | exit 1
49 | fi
50 |
51 | # Check if openssl was installed successfully
52 | if ! command -v openssl &> /dev/null; then
53 | echo "Error: Failed to install openssl. Please install it manually."
54 | exit 1
55 | fi
56 |
57 | echo "Info: openssl has been installed successfully."
58 | }
59 |
60 | # Define the output file name
61 | OUTPUT_FILE="server.pem"
62 |
63 | # Check if the output file already exists
64 | if [ -f "$OUTPUT_FILE" ]; then
65 | echo "Error: $OUTPUT_FILE already exists. Please delete it or choose a different name."
66 | exit 1
67 | fi
68 |
69 | # Check if openssl is installed, and install it if not
70 | if ! command -v openssl &> /dev/null; then
71 | install_openssl
72 | fi
73 |
74 | # Generate a private key
75 | echo "Info: Generating private key (server.key)..."
76 | if ! openssl genrsa -out server.key 4096; then
77 | echo "Error: Failed to generate private key."
78 | exit 1
79 | fi
80 |
81 | # Generate a self-signed certificate
82 | echo "Info: Generating self-signed certificate (server.crt)..."
83 | # The -subj option sets the subject of the certificate, which is the domain name of the server.
84 | # The -days option sets the number of days the certificate is valid for.
85 | # The -out option specifies the output file name.
86 | # The -key option specifies the private key file name.
87 | # The -x509 option specifies that the certificate should be self-signed.
88 | if ! openssl req -new -key server.key -x509 -days 3653 -out server.crt -subj "/CN=portal-content-nexus-uat.derbysoft-test.com"; then
89 | echo "Error: Failed to generate self-signed certificate."
90 | rm server.key
91 | exit 1
92 | fi
93 |
94 | # Combine the private key and certificate into a single PEM file
95 | echo "Info: Combining private key and certificate into $OUTPUT_FILE..."
96 | if ! cat server.key server.crt > "$OUTPUT_FILE"; then
97 | echo "Error: Failed to combine key and certificate."
98 | rm server.key server.crt
99 | exit 1
100 | fi
101 |
102 | # Clean up intermediate files
103 | echo "Info: Cleaning up intermediate files..."
104 | if ! rm server.key server.crt; then
105 | echo "Warning: Failed to remove intermediate files."
106 | fi
107 |
108 | # Check if the PEM file was created successfully
109 | if [ -f "$OUTPUT_FILE" ]; then
110 | echo "Info: Successfully generated $OUTPUT_FILE."
111 | else
112 | echo "Error: Failed to generate $OUTPUT_FILE."
113 | exit 1
114 | fi
--------------------------------------------------------------------------------
/proxy-to-https/manage-hosts.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # -----------------------------------------------------------------------------
3 | # File: manage-hosts.sh
4 | # Description: A script to manage host entries in the system's hosts file.
5 | # It supports adding, removing, and removing all entries for a domain.
6 | # Usage:
7 | # - Add a host entry: ./manage-hosts.sh add
8 | # - Remove a host entry: ./manage-hosts.sh remove
9 | # - Remove all entries for a domain: ./manage-hosts.sh remove-all
10 | # Dependencies: Requires sudo privileges to modify the hosts file.
11 | # Compatibility: Designed for Linux and macOS. Windows support via WSL.
12 | # -----------------------------------------------------------------------------
13 |
14 | # Function to display usage information
15 | display_usage() {
16 | echo "Usage: $0 [ | ]"
17 | echo "Actions:"
18 | echo " add Add a host entry"
19 | echo " remove Remove a host entry"
20 | echo " remove-all Remove all entries for a domain"
21 | exit 1
22 | }
23 |
24 | # Function to add a host entry
25 | add_host() {
26 | local ip="$1"
27 | local domain="$2"
28 | local hosts_path="$3"
29 |
30 | # Check if the host entry already exists
31 | while IFS= read -r line; do
32 | if [[ "$line" == "$ip $domain" ]]; then
33 | echo "Warning: Host entry for $domain already exists."
34 | return
35 | fi
36 | done < "$hosts_path"
37 |
38 | # Add the host entry
39 | echo "$ip $domain" | sudo tee -a "$hosts_path" > /dev/null
40 | echo "Info: Added host entry: $ip $domain"
41 | }
42 |
43 | # Function to remove a host entry
44 | remove_host() {
45 | local domain="$1"
46 | local hosts_path="$2"
47 | local temp_file=$(mktemp)
48 |
49 | # Check if the host entry exists
50 | local found=false
51 | while IFS= read -r line; do
52 | if [[ "$line" == *" $domain" ]]; then
53 | found=true
54 | fi
55 | done < "$hosts_path"
56 |
57 | if [ "$found" = false ]; then
58 | echo "Warning: No host entry found for $domain."
59 | return
60 | fi
61 |
62 | # Remove the host entry
63 | while IFS= read -r line; do
64 | if [[ "$line" != *" $domain" ]]; then
65 | echo "$line" >> "$temp_file"
66 | fi
67 | done < "$hosts_path"
68 |
69 | sudo mv "$temp_file" "$hosts_path"
70 | echo "Info: Removed host entry for $domain"
71 | }
72 |
73 | # Function to remove all entries for a domain
74 | remove_all_hosts_for_domain() {
75 | local domain_pattern="$1"
76 | local hosts_path="$2"
77 | local temp_file=$(mktemp)
78 |
79 | # Check if any entries for the domain exist
80 | local found=false
81 | while IFS= read -r line; do
82 | if [[ "$line" == *" $domain_pattern" ]]; then
83 | found=true
84 | fi
85 | done < "$hosts_path"
86 |
87 | if [ "$found" = false ]; then
88 | echo "Warning: No host entries found for domain pattern: $domain_pattern"
89 | return
90 | fi
91 |
92 | # Remove all entries for the domain
93 | while IFS= read -r line; do
94 | if [[ "$line" != *" $domain_pattern" ]]; then
95 | echo "$line" >> "$temp_file"
96 | fi
97 | done < "$hosts_path"
98 |
99 | sudo mv "$temp_file" "$hosts_path"
100 | echo "Info: Removed all host entries for domain pattern: $domain_pattern"
101 | }
102 |
103 | # Main function to handle script actions
104 | main() {
105 | # Check if the correct number of arguments is provided
106 | if [ $# -lt 1 ]; then
107 | display_usage
108 | fi
109 |
110 | local action="$1"
111 | local ip=""
112 | local domain=""
113 |
114 | # Determine the action and retrieve arguments
115 | case "$action" in
116 | add)
117 | if [ $# -ne 3 ]; then
118 | display_usage
119 | fi
120 | ip="$2"
121 | domain="$3"
122 | ;;
123 | remove)
124 | if [ $# -ne 2 ]; then
125 | display_usage
126 | fi
127 | domain="$2"
128 | ;;
129 | remove-all)
130 | if [ $# -ne 2 ]; then
131 | display_usage
132 | fi
133 | domain="$2"
134 | ;;
135 | *)
136 | display_usage
137 | ;;
138 | esac
139 |
140 | # Determine the hosts file path based on the operating system
141 | local hosts_path=""
142 | if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "darwin"* ]]; then
143 | hosts_path="/etc/hosts"
144 | elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
145 | hosts_path="C:\Windows\System32\drivers\etc\hosts"
146 | else
147 | echo "Error: Unsupported operating system."
148 | exit 1
149 | fi
150 |
151 | # Execute the requested action
152 | case "$action" in
153 | add)
154 | add_host "$ip" "$domain" "$hosts_path"
155 | ;;
156 | remove)
157 | remove_host "$domain" "$hosts_path"
158 | ;;
159 | remove-all)
160 | remove_all_hosts_for_domain "$domain" "$hosts_path"
161 | ;;
162 | esac
163 | }
164 |
165 | # Execute the main function with the provided arguments
166 | main "$@"
--------------------------------------------------------------------------------
/proxy-to-https/port-forward.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # -----------------------------------------------------------------------------
3 | # File: port-forward.sh
4 | # Description: A script to set up HTTPS to HTTP port forwarding using socat.
5 | # It forwards traffic from an HTTPS port to an HTTP port.
6 | # If server.pem is not found, it will attempt to generate it.
7 | # Usage: ./port-forward.sh
8 | # Example: ./port-forward.sh 443 8000
9 | # Dependencies: Requires socat to be installed.
10 | # Compatibility: Designed for Linux and macOS. Windows support via WSL.
11 | # -----------------------------------------------------------------------------
12 |
13 | # Function to display usage information
14 | display_usage() {
15 | echo "Usage: $0 "
16 | echo "This script sets up HTTPS to HTTP port forwarding using socat."
17 | echo "It forwards traffic from an HTTPS port to an HTTP port."
18 | echo "Example:"
19 | echo " ./port-forward.sh 443 8000"
20 | exit 1
21 | }
22 |
23 | # Function to install socat based on the operating system
24 | install_socat() {
25 | echo "Info: socat is not installed. Attempting to install it now..."
26 |
27 | if [[ "$OSTYPE" == "linux-gnu"* ]]; then
28 | # Linux (Debian/Ubuntu)
29 | if command -v apt-get &> /dev/null; then
30 | sudo apt-get update
31 | sudo apt-get install -y socat
32 | # Linux (Red Hat/CentOS/Fedora)
33 | elif command -v yum &> /dev/null; then
34 | sudo yum install -y socat
35 | elif command -v dnf &> /dev/null; then
36 | sudo dnf install -y socat
37 | else
38 | echo "Error: Unable to determine package manager. Please install socat manually."
39 | exit 1
40 | fi
41 | elif [[ "$OSTYPE" == "darwin"* ]]; then
42 | # macOS
43 | if command -v brew &> /dev/null; then
44 | brew install socat
45 | else
46 | echo "Error: Homebrew is not installed. Please install Homebrew and then run this script again."
47 | exit 1
48 | fi
49 | else
50 | echo "Error: Unsupported operating system. Please install socat manually."
51 | exit 1
52 | fi
53 |
54 | # Check if socat was installed successfully
55 | if ! command -v socat &> /dev/null; then
56 | echo "Error: Failed to install socat. Please install it manually."
57 | exit 1
58 | fi
59 |
60 | echo "Info: socat has been installed successfully."
61 | }
62 |
63 | # Get the directory of the script
64 | path=$(dirname "$0")
65 |
66 | # Function to check and generate server.pem if needed
67 | generate_server_pem() {
68 | if [ ! -f "server.pem" ]; then
69 | echo "Info: server.pem not found. Generating it now..."
70 | $path/generate-server-pem.sh
71 | if [ $? -ne 0 ]; then
72 | echo "Error: Failed to generate server.pem. Please check generate-server-pem.sh."
73 | exit 1
74 | fi
75 | fi
76 | }
77 |
78 | # Check if the correct number of arguments is provided
79 | if [ $# -ne 2 ]; then
80 | display_usage
81 | fi
82 |
83 | # Retrieve arguments
84 | https_port="$1"
85 | http_port="$2"
86 |
87 | # Validate port numbers
88 | if ! [[ "$https_port" =~ ^[0-9]+$ ]] || ! [[ "$http_port" =~ ^[0-9]+$ ]]; then
89 | echo "Error: Port numbers must be valid integers."
90 | display_usage
91 | fi
92 |
93 | if [ "$https_port" -lt 1 ] || [ "$https_port" -gt 65535 ] || [ "$http_port" -lt 1 ] || [ "$http_port" -gt 65535 ]; then
94 | echo "Error: Port numbers must be between 1 and 65535."
95 | display_usage
96 | fi
97 |
98 | # Check if socat is installed, and install it if not
99 | if ! command -v socat &> /dev/null; then
100 | install_socat
101 | fi
102 |
103 | # Generate server.pem if needed
104 | generate_server_pem
105 |
106 | # Set up port forwarding
107 | echo "Info: Setting up HTTPS to HTTP port forwarding from $https_port to $http_port..."
108 | socat -v openssl-listen:"$https_port",reuseaddr,fork,cert=server.pem,verify=0 tcp:127.0.0.1:"$http_port"
109 |
110 | # Check if socat started successfully
111 | if [ $? -ne 0 ]; then
112 | echo "Error: Failed to set up port forwarding."
113 | exit 1
114 | fi
115 |
116 | echo "Info: HTTPS to HTTP port forwarding from $https_port to $http_port is now active."
117 | echo "Info: Press Ctrl+C to stop the forwarding."
118 |
119 | # Keep the script running until the user interrupts
120 | while true; do
121 | sleep 1
122 | done
--------------------------------------------------------------------------------
/setup/execute.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # -----------------------------------------------------------------------------
3 | # File: main-setup.sh
4 | # Description: This script orchestrates the setup of a frontend development environment
5 | # by invoking specialized scripts for base tools, development environment
6 | # configuration, and optional Docker-related packages.
7 | # Usage: ./main-setup.sh
8 | # Compatibility: GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin20.6.0)
9 | # -----------------------------------------------------------------------------
10 |
11 | # Exit on error
12 | set -e
13 |
14 | # Define color variables for formatted output
15 | RED='\033[0;31m'
16 | GREEN='\033[0;32m'
17 | YELLOW='\033[0;33m'
18 | NC='\033[0m' # End of color
19 |
20 | # Get the directory of the script
21 | path=$(dirname "$0")
22 |
23 | echo -e "${GREEN}Starting frontend development environment setup...${NC}"
24 |
25 | # Call the script to install base tools
26 | echo -e "${YELLOW}Installing base tools...${NC}"
27 | source $path/setup-base-tools.sh
28 |
29 | # Call the script to configure the development environment
30 | echo -e "${YELLOW}Configuring development environment...${NC}"
31 | source $path/setup-dev-env.sh
32 |
33 | # Ask the user if they want to install Docker-related packages
34 | read -p "Would you like to install Docker-related packages? (y/n): " install_docker
35 | if [[ "$install_docker" == "y" || "$install_docker" == "Y" ]]; then
36 | echo -e "${YELLOW}Installing Docker-related packages...${NC}"
37 | source $path/setup-docker.sh
38 | else
39 | echo -e "${YELLOW}Skipping installation of Docker-related packages.${NC}"
40 | fi
41 |
42 | echo -e "${GREEN}Frontend development environment setup completed!${NC}"
43 | echo -e "${YELLOW}Please restart your terminal to apply all changes.${NC}"
--------------------------------------------------------------------------------
/setup/setup-base-tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # -----------------------------------------------------------------------------
3 | # File: setup-base-tools.sh
4 | # Description: This script installs essential development tools and applications
5 | # required for a basic development setup on macOS.
6 | # Usage: source ./setup-base-tools.sh
7 | # Compatibility: GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin20.6.0)
8 | # -----------------------------------------------------------------------------
9 |
10 | # Exit on error
11 | set -e
12 |
13 | # Define color variables for formatted output
14 | RED='\033[0;31m'
15 | GREEN='\033[0;32m'
16 | YELLOW='\033[0;33m'
17 | NC='\033[0m' # No Color
18 |
19 | echo -e "${GREEN}Starting installation of base tools...${NC}"
20 |
21 | # Check if Homebrew is installed; if not, install it
22 | if ! command -v brew &> /dev/null; then
23 | echo -e "${YELLOW}Homebrew not detected, installing...${NC}"
24 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
25 | echo -e "${GREEN}Homebrew installation completed!${NC}"
26 | else
27 | echo -e "${GREEN}Homebrew is installed, updating...${NC}"
28 | brew update
29 | fi
30 |
31 | # Install common development tools
32 | echo -e "${GREEN}Installing common development tools...${NC}"
33 | # Git: Version control system for code management
34 | brew install git
35 | # Yarn: JavaScript package manager for installing and managing project dependencies
36 | brew install yarn
37 | # Zsh: Alternative command-line shell with enhanced features
38 | brew install zsh
39 | # Tmux: Terminal multiplexer for running multiple terminal sessions in one window
40 | brew install tmux
41 | # Wget: Command-line download tool for retrieving files from the web
42 | brew install wget
43 | # Curl: Command-line tool for making network requests
44 | brew install curl
45 |
46 | # Install VS Code
47 | echo -e "${GREEN}Installing VS Code...${NC}"
48 | # Visual Studio Code: Popular code editor supporting multiple programming languages and plugins
49 | brew install --cask visual-studio-code
50 |
51 | # Install Google Chrome
52 | echo -e "${GREEN}Installing Google Chrome...${NC}"
53 | # Google Chrome: Popular web browser for testing and debugging web applications
54 | brew install --cask google-chrome
55 |
56 | # Install Firefox
57 | echo -e "${GREEN}Installing Firefox...${NC}"
58 | # Firefox: Another popular web browser for testing and debugging web applications
59 | brew install --cask firefox
60 |
61 | # Install Postman
62 | echo -e "${GREEN}Installing Postman...${NC}"
63 | # Postman: API testing tool for sending HTTP requests and testing APIs
64 | brew install --cask postman
65 |
66 | # Install Oh My Zsh (optional)
67 | echo -e "${GREEN}Installing Oh My Zsh...${NC}"
68 | # Oh My Zsh: Zsh extension framework with many pre-configured themes and plugins
69 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
70 |
71 | echo -e "${GREEN}Base tools installation completed!${NC}"
--------------------------------------------------------------------------------
/setup/setup-dev-env.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # -----------------------------------------------------------------------------
3 | # File: setup-dev-env.sh
4 | # Description: This script configures the development environment by installing
5 | # Node.js versions, configuring nvm, and installing VS Code extensions.
6 | # Usage: source ./setup-dev-env.sh
7 | # Compatibility: GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin20.6.0)
8 | # -----------------------------------------------------------------------------
9 |
10 | # Exit on error
11 | set -e
12 |
13 | # Define color variables for formatted output
14 | RED='\033[0;31m'
15 | GREEN='\033[0;32m'
16 | YELLOW='\033[0;33m'
17 | NC='\033[0m' # No Color
18 |
19 | echo -e "${GREEN}Starting development environment setup...${NC}"
20 |
21 | # Install nvm using the official script
22 | echo -e "${GREEN}Installing nvm using the official script...${NC}"
23 | # nvm: Node.js version management tool for installing and switching between multiple Node.js versions
24 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
25 |
26 | # Configure nvm environment variables
27 | echo -e "${GREEN}Configuring nvm environment variables...${NC}"
28 | # Set nvm installation path
29 | export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
30 | # Load nvm
31 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
32 | # Load nvm bash_completion
33 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
34 |
35 | # Add nvm configuration to bash_profile and zshrc
36 | echo "export NVM_DIR=\"$([ -z \"\${XDG_CONFIG_HOME-}\" ] && printf %s \"\${HOME}/.nvm\" || printf %s \"\${XDG_CONFIG_HOME}/nvm\")\"" >>~/.bash_profile
37 | echo "[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm" >>~/.bash_profile
38 | echo "[ -s \"\$NVM_DIR/bash_completion\" ] && \\. \"\$NVM_DIR/bash_completion\" # This loads nvm bash_completion" >>~/.bash_profile
39 |
40 | echo "export NVM_DIR=\"$([ -z \"\${XDG_CONFIG_HOME-}\" ] && printf %s \"\${HOME}/.nvm\" || printf %s \"\${XDG_CONFIG_HOME}/nvm\")\"" >>~/.zshrc
41 | echo "[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm" >>~/.zshrc
42 | echo "[ -s \"\$NVM_DIR/bash_completion\" ] && \\. \"\$NVM_DIR/bash_completion\" # This loads nvm bash_completion" >>~/.zshrc
43 |
44 | # Install multiple Node.js versions
45 | echo -e "${GREEN}Installing multiple Node.js versions...${NC}"
46 | # Node.js 14.x: Long-term support version suitable for stable projects
47 | nvm install 14
48 | # Node.js 16.x: Current stable version suitable for most projects
49 | nvm install 16
50 | # Node.js 18.x
51 | nvm install 18
52 | # Node.js 20.x
53 | nvm install 20
54 |
55 | # Set default Node.js version
56 | echo -e "${GREEN}Setting default Node.js version to 16...${NC}"
57 | nvm alias default 16
58 |
59 | # Function to check if VS Code is installed
60 | check_vscode_installed() {
61 | if ! command -v code &>/dev/null; then
62 | echo -e "${RED}VS Code is not installed. Please install VS Code first.${NC}"
63 | return 1
64 | fi
65 | return 0
66 | }
67 |
68 | if check_vscode_installed; then
69 | # Install VS Code extensions (optional)
70 | echo -e "${GREEN}Installing VS Code extensions...${NC}"
71 | # ESLint: Code analysis tool for identifying and fixing issues in JavaScript code
72 | code --install-extension dbaeumer.vscode-eslint
73 | # Prettier: Code formatting tool for maintaining consistent code style
74 | code --install-extension esbenp.prettier-vscode
75 | # Path Intellisense: Path autocompletion for efficient file path input
76 | code --install-extension christian-kohler.path-intellisense
77 | # EditorConfig: Tool for maintaining consistent code formatting settings
78 | code --install-extension editorconfig.editorconfig
79 | # VS Code ESLint: ESLint plugin for VS Code
80 | code --install-extension dbaeumer.vscode-eslint
81 | # TypeScript and TSLint plugins: Support for TypeScript development and code analysis
82 | code --install-extension ms-vscode.vscode-typescript-tslint-plugin
83 | # Material Icon Theme: Aesthetic icon theme for VS Code
84 | code --install-extension PKief.material-icon-theme
85 | # Material Theme: Aesthetic theme for VS Code
86 | code --install-extension equinusocio.vsc-material-theme
87 | else
88 | echo -e "${YELLOW}Skipping installation of VS Code extensions.${NC}"
89 | fi
90 |
91 | echo -e "${GREEN}Development environment setup completed!${NC}"
92 |
--------------------------------------------------------------------------------
/setup/setup-docker.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # -----------------------------------------------------------------------------
3 | # File: setup-docker.sh
4 | # Description: This script installs Docker-related packages, including Docker,
5 | # Docker Desktop, and Insomnia for API testing.
6 | # Usage: source ./setup-docker.sh
7 | # Compatibility: GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin20.6.0)
8 | # -----------------------------------------------------------------------------
9 |
10 | # Exit on error
11 | set -e
12 |
13 | # Define color variables for formatted output
14 | RED='\033[0;31m'
15 | GREEN='\033[0;32m'
16 | YELLOW='\033[0;33m'
17 | NC='\033[0m' # No Color
18 |
19 | echo -e "${GREEN}Starting installation of Docker-related packages...${NC}"
20 |
21 | # Install Docker-related packages
22 | echo -e "${GREEN}Installing Docker-related packages...${NC}"
23 | # Docker: Containerization platform for developing, deploying, and running applications
24 | brew install --cask docker
25 | # Docker Desktop: Desktop version of Docker for simplified container management
26 | brew install --cask docker-desktop
27 | # Docker Edge: Test version of Docker with the latest features
28 | brew install --cask docker-edge
29 | # Insomnia: API client for sending HTTP requests and testing APIs
30 | brew install --cask insomnia
31 |
32 | echo -e "${GREEN}Docker-related packages installation completed!${NC}"
--------------------------------------------------------------------------------