-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmac_flutter.sh
280 lines (239 loc) · 9.18 KB
/
mac_flutter.sh
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
#!/bin/zsh
#
# Setup script for macOS Flutter development
# Copyright (C) 2019-2024 ZL Asica
# Define color codes for output
red=$(tput setaf 1) # Error messages
green=$(tput setaf 2) # Success messages
blue=$(tput setaf 4) # Prompts and questions
magenta=$(tput setaf 5) # Titles
cyan=$(tput setaf 6) # Info messages
plain=$(tput sgr0) # Reset color
divider="*********************************************************************"
# Function to display error messages and exit
error_exit() {
local msg_key="$1"
echo -e "${red}${messages[${lang}_$msg_key]}${plain}" >&2
echo -e "${red}[---] If you encounter any issues, \nlease report them at: https://github.com/ZL-Asica/server-setup-scripts/issues${plain}" >&2
exit 1
}
# Check Xcode
xcode_install() {
if test ! $(which xcode-select); then
echo -e "${blue}[+] Installing Xcode...${plain}"
xcode-select --install
# Wait for the installation to complete
until test $(which xcode-select); do
sleep 5
done
else
echo -e "${green}[+++] Xcode already installed. Skipping...${plain}"
fi
}
# Check homebrew
homebrew_install() {
if test ! $(which brew); then
echo -e "${blue}[+] Installing Homebrew...${plain}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add homebrew to the path
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
# Activate the changes
source ~/.zshrc
else
echo -e "${green}[+++] Homebrew already installed. Skipping...${plain}"
fi
}
# rbenv, [email protected], cocoapods
ruby_install() {
# Check rbenv
if test ! $(which rbenv); then
echo -e "${blue}[+] Installing rbenv...${plain}"
brew install rbenv
# Add rbenv to the path
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
# Activate the changes
source ~/.zshrc
else
echo -e "${green}[+++] rbenv already installed. Skipping...${plain}"
fi
# Check ruby
if test ! $(which ruby); then
echo -e "${blue}[+] Installing [email protected]...${plain}"
rbenv install 3.3.0
rbenv global 3.3.0
else
echo -e "${green}[+++] [email protected] already installed. Skipping...${plain}"
fi
# Check cocoapods
if test ! $(which pod); then
echo -e "${blue}[+] Installing cocoapods...${plain}"
gem install cocoapods
else
echo -e "${green}[+++] cocoapods already installed. Skipping...${plain}"
fi
}
# Install Flutter Through fvm
flutter_install() {
# Check flutter first
if test ! $(which flutter); then
echo -e "${blue}[+] Installing Flutter...${plain}"
# Check fvm
if test ! $(which fvm); then
echo -e "${blue}[+] Installing fvm(Flutter version manager)...${plain}"
# Install fvm
brew install fvm
else
echo -e "${green}[+++] fvm already installed. Skipping...${plain}"
fi
fvm install stable
# Set the global flutter version
fvm global stable
# Add fvm to the path
echo 'export PATH=$PATH:"$HOME/fvm/default/bin"' >> ~/.zshrc
# Activate the changes
source ~/.zshrc
else
echo -e "${green}[+++] Flutter already installed. Skipping...${plain}"
fi
}
# Install openjdk@17
openjdk_install() {
# directly install without check
echo -e "${blue}[+] Installing openjdk@17...${plain}"
brew install openjdk@17
# Add openjdk to the path
echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc
echo 'export JAVA_HOME="/opt/homebrew/opt/openjdk@17"' >> ~/.zshrc
# Activate the changes
source ~/.zshrc
}
# Install Android Studio Command Line Tools
android_studio_install() {
if test ! $(which sdkmanager); then
echo -e "${blue}[+] Installing Android Studio Command Line Tools...${plain}"
# Download latest version into $HOME/
curl -o ~/android-studio.zip https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip
# Create the directory
mkdir -p ~/android-studio/cmdline-tools/latest/
# Unzip the file contents into the directory
unzip ~/android-studio.zip -d ~/android-studio/cmdline-tools/latest/
# Delete the zip file
rm ~/android-studio.zip
# Set the environment variable to the path
echo 'export ANDROID_HOME="$HOME/android-studio"' >> ~/.zshrc
echo 'export PATH=$PATH:"$ANDROID_HOME/cmdline-tools/latest/bin"' >> ~/.zshrc
echo 'export PATH=$PATH:"$ANDROID_HOME/emulator"' >> ~/.zshrc
echo 'export PATH=$PATH:"$ANDROID_HOME/platform-tools"' >> ~/.zshrc
# Activate the changes
source ~/.zshrc
# Install the latest platform tools
sdkmanager "platform-tools" "build-tools;34.0.0" "platforms;android-34"
sdkmanager "system-images;android-34;google_apis;arm64-v8a"
avdmanager create avd -n android-34- -k "system-images;android-34;google_apis;arm64-v8a" --abi google_apis/arm64-v8a
# Config flutter
flutter config --android-sdk ~/android-studio
# Accept the licenses
flutter doctor --android-licenses
else
echo -e "${green}[+++] Android Studio Command Line Tools already installed. Skipping...${plain}"
fi
}
# Xcode setup
xcode_setup() {
# Check ios-deploy
if test ! $(which ios-deploy); then
echo -e "${blue}[+] Installing ios-deploy...${plain}"
brew install ios-deploy
else
echo -e "${green}[+++] ios-deploy already installed. Skipping...${plain}"
fi
echo -e "${blue}[+] Setting up Xcode...You will need to enter your password.${plain}"
# check if Xcode is installed and set the path
if test ! $(which xcodebuild); then
sudo sh -c 'xcode-select -s /Applications/Xcode.app/Contents/Developer && xcodebuild -runFirstLaunch'
fi
# Check the first launch
if test ! -d /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform; then
xcodebuild -downloadPlatform iOS
fi
# wait for the installation to complete
until test -d /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform; do
sleep 5
done
# Accept the Xcode license
sudo xcodebuild -license accept
}
# Endding message
ending_message() {
# Run flutter doctor
flutter doctor
echo -e "${divider}"
echo -e "${green}Flutter enviroment setup completed!${plain}"
echo -e "${green}Please ${magenta}restart your terminal${green} to apply the changes.${plain}"
echo -e "${divider}"
# Remind them to install Visual Studio Code with the Flutter extension
echo -e "${green}Please install ${magenta}Visual Studio Code${green} with the ${magenta}Flutter extension.${plain}"
echo -e "${blue}If you have Visual Studio Code opened, please restart it.${plain}"
echo -e "${green}https://code.visualstudio.com/${plain}"
echo -e "${divider}"
# Give a star
echo -e "${green}If you find this script helpful, please give it a star on GitHub.${plain}"
echo -e "${blue}https://github.com/ZL-Asica/server-setup-scripts/${plain}"
}
main() {
# Ensure the script is run not as root
if [ "$EUID" -eq 0 ]; then
echo -e "${red}Please run this script as a regular user, not as root.${plain}"
error_exit "root"
fi
# Make sure is macOS
if [ "$(uname)" != "Darwin" ]; then
echo -e "${red}This script is only for macOS.${plain}"
error_exit "macos"
fi
# Ask for user's permission to start the installation
echo -e "${blue}This script will install the following (if not installed yet):${plain}"
echo -e "${cyan}1. Xcode${plain}"
echo -e "${cyan}2. Homebrew${plain}"
echo -e "${cyan}3. rbenv, [email protected], cocoapods${plain}"
echo -e "${cyan}4. Flutter${plain}"
echo -e "${cyan}5. openjdk@17${plain}"
echo -e "${cyan}6. Android Studio Command Line Tools${plain}"
echo -e "${cyan}7. Andrios SDK - platform-tools, build-tools;30.0.3, platforms;android-30${plain}"
echo -e "${divider}"
read -p "$(echo -e "${blue}Do you want to continue? (y/n)${plain}")" -n 1 -r
# Check for Xcode
xcode_install
# Check for Homebrew
homebrew_install
# Check for rbenv, [email protected], cocoapods
ruby_install
# Install Flutter Through fvm
flutter_install
# Install openjdk@17
openjdk_install
# Install Android Studio Command Line Tools
android_studio_install
# Xcode setup
xcode_setup
# Ending message
ending_message
}
# ----------------------------------------------------------
# Start of the script
# ----------------------------------------------------------
# Move focus to the top of the terminal without clearing the screen
printf '\033c'
# Welcome message
echo "" # New line for better readability
echo -e "${magenta}"
cat << "EOF"
______ _ _
|__ / | / \ ___(_) ___ __ _
/ /| | / _ \ / __| |/ __/ _` |
/ /_| |___ / ___ \\__ \ | (_| (_| |
/____|_____| /_/ \_\___/_|\___\__,_|
EOF
echo -e "${magenta}macOS Flutter enviroment setup script - ZL Asica${plain}"
echo -e "https://github.com/ZL-Asica/server-setup-scripts/blob/main/mac_flutter.sh"
main