-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_dev_env.sh
More file actions
163 lines (143 loc) · 6 KB
/
setup_dev_env.sh
File metadata and controls
163 lines (143 loc) · 6 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
#!/bin/bash
# Function to display a message
function echo_message() {
echo ""
echo "======================================"
echo "$1"
echo "======================================"
echo ""
}
# Function to handle errors
function handle_error() {
echo ""
echo "======================================"
echo "Error occurred during: $1"
echo "Exiting script."
echo "======================================"
exit 1
}
# Function to install common dependencies
function install_dependencies() {
echo_message "Installing curl, git, unzip, and xz-utils..."
sudo apt install -y curl git unzip xz-utils || handle_error "installing curl, git, unzip, and xz-utils"
}
# Function to install or upgrade Node.js and npm
function install_nodejs() {
echo_message "Installing or upgrading Node.js and npm..."
read -p "Enter the version of Node.js to install (default is 16): " NODE_VERSION
NODE_VERSION=${NODE_VERSION:-16}
curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | sudo -E bash - || handle_error "setting up Node.js repository"
sudo apt install -y nodejs || handle_error "installing Node.js and npm"
node -v || handle_error "verifying Node.js installation"
npm -v || handle_error "verifying npm installation"
}
# Function to install or upgrade create-react-app
function install_react() {
install_nodejs
echo_message "Installing or upgrading create-react-app globally..."
sudo npm install -g create-react-app || handle_error "installing create-react-app"
create-react-app --version || handle_error "verifying create-react-app installation"
}
# Function to install or upgrade Flutter
function install_flutter() {
echo_message "Installing or upgrading Dart SDK..."
sudo apt install -y apt-transport-https || handle_error "installing apt-transport-https"
sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -' || handle_error "adding Google signing key"
sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list' || handle_error "adding Dart repository"
sudo apt update -y || handle_error "updating package list"
sudo apt install -y dart || handle_error "installing Dart SDK"
export PATH="$PATH:/usr/lib/dart/bin"
echo 'export PATH="$PATH:/usr/lib/dart/bin"' >> ~/.bashrc
echo_message "Installing or upgrading Flutter..."
read -p "Enter the version of Flutter to install (default is stable): " FLUTTER_VERSION
FLUTTER_VERSION=${FLUTTER_VERSION:-stable}
curl -O https://storage.googleapis.com/flutter_infra_release/releases/$FLUTTER_VERSION/linux/flutter_linux_$FLUTTER_VERSION-latest.tar.xz || handle_error "downloading Flutter"
tar xf flutter_linux_$FLUTTER_VERSION-latest.tar.xz || handle_error "extracting Flutter"
sudo mv flutter /opt/flutter || handle_error "moving Flutter to /opt directory"
export PATH="$PATH:/opt/flutter/bin"
echo 'export PATH="$PATH:/opt/flutter/bin"' >> ~/.bashrc
echo_message "Pre-caching Flutter binaries..."
flutter precache || handle_error "pre-caching Flutter binaries"
echo_message "Running flutter doctor..."
flutter doctor || handle_error "running flutter doctor"
}
# Function to install Snap if not already installed
function install_snap() {
if ! command -v snap &> /dev/null; then
echo_message "Installing Snap..."
sudo apt install -y snapd || handle_error "installing Snap"
fi
}
# Function to install or upgrade Android Studio
function install_android_studio() {
install_snap
echo_message "Installing or upgrading Android Studio..."
sudo snap install android-studio --classic || handle_error "installing Android Studio"
}
# Function to install or upgrade Visual Studio Code
function install_vscode() {
install_snap
echo_message "Installing or upgrading Visual Studio Code..."
sudo snap install --classic code || handle_error "installing Visual Studio Code"
}
# Function to install or upgrade Laravel
function install_laravel() {
echo_message "Installing or upgrading Laravel..."
install_nodejs
sudo apt install -y php php-cli php-mbstring unzip || handle_error "installing PHP dependencies"
curl -sS https://getcomposer.org/installer | php || handle_error "downloading Composer"
sudo mv composer.phar /usr/local/bin/composer || handle_error "moving Composer to bin directory"
composer global require laravel/installer || handle_error "installing Laravel"
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
laravel --version || handle_error "verifying Laravel installation"
}
# Update and upgrade the system
echo_message "Updating and upgrading the system..."
sudo apt update -y || handle_error "updating package list"
sudo apt upgrade -y || handle_error "upgrading packages"
# Prompt user for input
echo "Choose the development field name to setup (Node.js, React, Flutter, Android Studio, vscode, Laravel):"
read userInput
# Call the appropriate installation function
case $userInput in
"Node.js")
install_dependencies
install_nodejs
;;
"React")
install_dependencies
install_react
;;
"Flutter")
install_dependencies
install_flutter
;;
"Android Studio")
install_dependencies
install_android_studio
;;
"vscode")
install_dependencies
install_vscode
;;
"Laravel")
install_dependencies
install_laravel
;;
*)
echo_message "Invalid option selected. Please choose a valid development field name."
exit 1
;;
esac
# Verify installations
echo_message "Verifying installations..."
node -v || echo "Node.js not installed."
npm -v || echo "npm not installed."
create-react-app --version || echo "create-react-app not installed."
flutter --version || echo "Flutter not installed."
dart --version || echo "Dart SDK not installed."
code --version || echo "Visual Studio Code not installed."
android-studio --version || echo "Android Studio not installed."
laravel --version || echo "Laravel not installed."
echo_message "Development environment setup completed successfully!"