-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·351 lines (314 loc) · 12 KB
/
install.sh
File metadata and controls
executable file
·351 lines (314 loc) · 12 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
#!/usr/bin/env bash
# Installation script for git, make, docker, AWS CLI, and Terraform
# Get machine architecture
ARCH=$(uname -m)
if [[ "$ARCH" == "x86_64" ]] || [[ "$ARCH" == "amd64" ]]; then
ARCH="amd64"
elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
ARCH="arm64"
elif [[ "$ARCH" == "armv6l" ]]; then
ARCH="armv6l"
elif [[ "$ARCH" == "i386" ]]; then
ARCH="386"
else
echo "$ARCH is an unsupported architecture."
exit 1
fi
OS_TYPE=$(uname)
INSTALL_MODE="${1:-full}" # "local" = Docker only, "full" = Docker + AWS CLI + Terraform
if [[ "$INSTALL_MODE" == "local" ]] || [[ "$INSTALL_MODE" == "--local" ]]; then
INSTALL_MODE="local"
TOTAL_MACOS_STEPS=3
TOTAL_LINUX_STEPS=3
else
INSTALL_MODE="full"
TOTAL_MACOS_STEPS=5
TOTAL_LINUX_STEPS=5
fi
STEP=1
SUCCESS="false"
# Detect current shell
CURRENT_SHELL=$(ps -p $$ -o comm=)
if [ "$OS_TYPE" = "Darwin" ] && [ -z "$SKIP_SHEBANG_CHECK" ]; then
if [ "$CURRENT_SHELL" != "zsh" ]; then
if [ -x "/bin/zsh" ]; then
export SKIP_SHEBANG_CHECK=1
echo "macOS detected. Current shell: $CURRENT_SHELL. Switching to zsh interpreter......"
exec /bin/zsh "$0" "$@"
else
echo "Error: /bin/zsh not found. Please ensure zsh is installed." >&2
exit 1
fi
fi
fi
# Check Shell
SHELL_NAME=$(basename "$SHELL")
if [[ "$SHELL_NAME" == "zsh" ]]; then
echo "The current shell is $SHELL_NAME. The installation will proceed based on $SHELL_NAME."
elif [[ "$SHELL_NAME" == "bash" ]]; then
echo "The current shell is $SHELL_NAME. The installation will proceed based on $SHELL_NAME."
else
echo "The current shell is $SHELL_NAME. $SHELL_NAME is an unsupported shell."
exit 1
fi
# Set Config File
if [ "$SHELL_NAME" = "zsh" ]; then
CONFIG_FILE="$HOME/.zshrc"
PROFILE_FILE="$HOME/.zshrc"
elif [ "$SHELL_NAME" = "bash" ]; then
CONFIG_FILE="$HOME/.bashrc"
PROFILE_FILE="$HOME/.profile"
fi
# Function to display completion message
function display_completion_message {
if [[ "$SUCCESS" == "true" ]]; then
echo ""
echo "All steps are complete."
echo ""
exit 0
else
echo ""
echo "Installation was interrupted. Completed $((STEP - 1)) steps."
echo ""
echo "Please source your profile to apply changes:"
echo -e "\033[1;32msource $CONFIG_FILE\033[0m"
exit 1
fi
}
# Use trap to display message on script exit, whether successful or due to an error
trap display_completion_message EXIT
trap "echo 'Process interrupted!'; exit 1" INT
if [[ "$OS_TYPE" == "Darwin" ]]; then
# 1. Install Git
echo "[$STEP/$TOTAL_MACOS_STEPS] Installing Git..."
if ! command -v git &> /dev/null; then
echo "git not found, installing..."
# Install Homebrew first if not available
if ! command -v brew &> /dev/null; then
echo "Homebrew not found, installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
export PATH="/opt/homebrew/bin:$PATH"
fi
brew install git
else
echo "git is already installed."
fi
STEP=$((STEP + 1))
echo
# 2. Install Make (part of Xcode Command Line Tools)
echo "[$STEP/$TOTAL_MACOS_STEPS] Installing Make (Xcode Command Line Tools)..."
if ! command -v make &> /dev/null; then
echo "make not found, installing Xcode Command Line Tools..."
xcode-select --install
else
echo "make is already installed."
fi
STEP=$((STEP + 1))
echo
# 3. Install Docker
echo "[$STEP/$TOTAL_MACOS_STEPS] Installing Docker..."
if ! command -v docker &> /dev/null; then
echo "Docker not found, installing..."
if ! command -v brew &> /dev/null; then
echo "Homebrew not found, installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
export PATH="/opt/homebrew/bin:$PATH"
fi
brew install --cask docker
else
echo "Docker is already installed."
fi
# Start Docker Daemon
echo "Starting Docker Daemon..."
if ! docker ps > /dev/null 2>&1; then
echo "🚫 Docker is not running. Starting Docker Desktop..."
open -a Docker
# Wait for Docker to initialize
while ! docker ps > /dev/null 2>&1; do
echo "⏳ Waiting for Docker to start..."
sleep 2
done
echo "✅ Docker is now running!"
else
echo "✅ Docker is already running."
fi
STEP=$((STEP + 1))
echo
if [[ "$INSTALL_MODE" == "full" ]]; then
# 4. Install AWS CLI
echo "[$STEP/$TOTAL_MACOS_STEPS] Installing AWS CLI..."
if command -v aws &> /dev/null; then
current_version=$(aws --version | cut -d/ -f2 | cut -d' ' -f1)
if [[ $current_version == 2* ]]; then
echo "AWS CLI v$current_version is already installed and meets the version requirement."
else
echo "AWS CLI v$current_version is installed but does not meet the version requirement. Updating..."
if ! command -v brew &> /dev/null; then
echo "Homebrew not found, installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
export PATH="/opt/homebrew/bin:$PATH"
fi
brew upgrade awscli
fi
else
echo "AWS CLI not found, installing..."
if ! command -v brew &> /dev/null; then
echo "Homebrew not found, installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
export PATH="/opt/homebrew/bin:$PATH"
fi
brew install awscli
fi
STEP=$((STEP + 1))
echo
# 5. Install Terraform
echo "[$STEP/$TOTAL_MACOS_STEPS] Installing Terraform..."
if ! command -v terraform &> /dev/null; then
echo "Terraform not found, installing..."
if ! command -v brew &> /dev/null; then
echo "Homebrew not found, installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
export PATH="/opt/homebrew/bin:$PATH"
fi
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
else
echo "Terraform is already installed."
fi
STEP=$((STEP + 1))
echo
fi
SUCCESS="true"
elif [[ "$OS_TYPE" == "Linux" ]]; then
# Update package lists and upgrade existing packages
echo "Updating package lists and upgrading existing packages..."
sudo apt-get update -y
sudo apt-get upgrade -y
echo
if ! command -v sudo &> /dev/null; then
echo "sudo not found, installing..."
apt-get install -y sudo
fi
# 1. Install Git
echo "[$STEP/$TOTAL_LINUX_STEPS] Installing Git..."
if ! command -v git &> /dev/null; then
echo "git not found, installing..."
sudo apt-get install -y git
else
echo "git is already installed."
fi
STEP=$((STEP + 1))
echo
# 2. Install Make (part of build-essential)
echo "[$STEP/$TOTAL_LINUX_STEPS] Installing Make (build-essential)..."
if ! command -v make &> /dev/null; then
echo "make not found, installing build-essential..."
sudo apt-get install -y build-essential
else
echo "make is already installed."
fi
STEP=$((STEP + 1))
echo
# 3. Install Docker
echo "[$STEP/$TOTAL_LINUX_STEPS] Installing Docker..."
if ! command -v docker &> /dev/null; then
echo "Installing Docker..."
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
else
echo "Docker is already installed."
fi
# Configure Docker to work without sudo
echo "Configuring Docker to work without sudo..."
sudo usermod -aG docker ${USER}
sudo chmod 666 /var/run/docker.sock
# Start Docker Daemon
echo "Starting Docker Daemon..."
if ! docker ps > /dev/null 2>&1; then
echo "Docker is not running. Starting Docker service..."
sudo systemctl start docker
sudo systemctl enable docker
# Wait for Docker to initialize
while ! docker ps > /dev/null 2>&1; do
echo "⏳ Waiting for Docker to start..."
sleep 2
done
echo "✅ Docker is now running!"
echo "Note: You may need to log out and back in for Docker group permissions to take effect."
else
echo "✅ Docker is already running."
fi
STEP=$((STEP + 1))
echo
if [[ "$INSTALL_MODE" == "full" ]]; then
# 4. Install AWS CLI
echo "[$STEP/$TOTAL_LINUX_STEPS] Installing AWS CLI..."
if command -v aws &> /dev/null && version=$(aws --version | cut -d/ -f2 | cut -d' ' -f1) && [[ $version == 2* ]]; then
echo "AWS CLI v2 is already installed (version $version)"
else
echo "Installing AWS CLI v2..."
if ! command -v unzip &> /dev/null; then
sudo apt-get install -y unzip
fi
if [ "$ARCH" = "arm64" ]; then
curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
else
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
fi
unzip awscliv2.zip
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
rm -rf aws awscliv2.zip
fi
STEP=$((STEP + 1))
echo
# 5. Install Terraform
echo "[$STEP/$TOTAL_LINUX_STEPS] Installing Terraform..."
if ! command -v terraform &> /dev/null; then
echo "Terraform not found, installing..."
sudo apt-get install -y gnupg software-properties-common
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt-get update -y
sudo apt-get install -y terraform
fi
STEP=$((STEP + 1))
echo
fi
SUCCESS="true"
else
echo "Unsupported OS: $OS_TYPE"
exit 1
fi
# Function to check if a command exists and display its version
function check_command_version {
CMD=$1
VERSION_CMD=$2
if command -v "$CMD" &> /dev/null; then
CURRENT_VERSION=$(eval $VERSION_CMD 2>&1 | head -n 1)
echo "✅ $CMD is installed. Current version: $CURRENT_VERSION"
else
echo "❌ $CMD is not installed."
fi
}
if [[ "$SUCCESS" == "true" ]]; then
echo ""
echo "🎉 All required tools are installed and ready to use!"
echo ""
# Check all installed tools
echo "Installed tools:"
check_command_version git "git --version"
check_command_version make "make --version"
check_command_version docker "docker --version"
if [[ "$INSTALL_MODE" == "full" ]]; then
check_command_version aws "aws --version"
check_command_version terraform "terraform --version"
fi
else
echo "Some tools failed to install. Please check the output above for details."
exit 1
fi