-
Notifications
You must be signed in to change notification settings - Fork 3
/
installer.sh
282 lines (260 loc) · 11.1 KB
/
installer.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
281
282
#!/bin/bash
# use some sketchy colors for error
RED="\033[0;31m"
BOLD="\033[1m"
RESET="\033[0m"
# Detect if user is not running in root
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}error${RESET}: user is not running in root, please try again with sudo privileges"
exit 1
fi
# finally some good color
GREEN="\033[0;32m"
WHITE='\033[1;37m'
CYAN='\033[0;36m'
GRAY='\033[0;37m'
NC='\033[0m'
BG_YELLOW="\033[43m"
YELLOW="\033[0;33m"
clear
echo -e "${WHITE}"
echo " _ _ _ _____ _ _ _ "
echo " | | | | | | / ____| (_) | | "
echo " | |__| | ___ | | __ _| | | |_ ___ _ __ | |_ "
echo " | __ |/ _ \| |/ _\` | | | | |/ _ \ '_ \| __|"
echo " | | | | (_) | | (_| | |____| | | __/ | | | |_ "
echo " |_| |_|\___/|_|\__,_|\_____|_|_|\___|_| |_|\__|"
echo -e "${NC}"
echo -e "#################################################"
echo -e "# HolaClient Installation script @ v1.1"
echo -e "# "
echo -e "# https://holaclient.tech"
echo -e "# https://github.com/HolaClient"
echo -e "# https://discord.gg/CvqRH9TrYK"
echo -e "# "
echo -e "# Originally made by ${GREEN}${BOLD}ItzBenoitXD${NC}"
echo -e "# Your OS is $(lsb_release -is) version $(lsb_release -rs)"
echo -e "#################################################"
echo -e "${NC}"
echo "What would you like to do?"
echo "• [0] Install HolaClient and configure nginx with a SSL certificate"
echo "• [1] Install HolaClient"
echo "• [2] Update HolaClient"
echo "• [3] Install Dependencies"
echo "• [4] Configure nginx with a SSL certificate"
echo "• [5] Uninstall HolaClient"
read -p "Enter your choice (0-5): " choice
echo -e "${NC}"
if [[ $choice == "0" ]]; then
if [[ -d "/var/www/HolaClient" ]]; then
echo "${RED}error${RESET}: HolaClient is already installed! Please select option 5 to reinstall it."
exit 1
fi
read -p "Enter the HolaClient version you want to install (latest): " version
version=${version:-latest}
read -p "Enter your client area domain (client.example.com): " domain
read -p "Enter the port (2000): " port
port=${port:-2000}
echo ""
echo -e " ${YELLOW}${BG_YELLOW}${BOLD} WARN ${RESET} You may have a firewall that is blocking the port ${port}. Please add this port to your server"\'"s firewall if you have one. Continuing script."
echo ""
read -p "Enter your email ([email protected]): " email
email=${email:[email protected]}
echo ""
echo -e " ${YELLOW}${BG_YELLOW}${BOLD} WARN ${RESET} Below this message, you will see what settings you putted. To modify one/more settings or want to cancel the install, press Control+C now. Otherwise, the script will install HolaClient in 20 seconds."
echo ""
echo -e "HolaClient version: ${version}"
echo -e "HolaClient port: ${port}"
echo -e "Your email: ${email}"
echo -e "HolaClient Domain: $domain"
sleep 20
cd /var/www/
echo ""
echo "Updating system..."
sudo apt -y update > /dev/null 2>&1 && sudo apt -y upgrade > /dev/null 2>&1
echo "Installing Git..."
sudo apt -y install git > /dev/null 2>&1
echo "Installing NodeJS..."
sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash > /dev/null 2>&1
source ~/.nvm/nvm.sh > /dev/null 2>&1
nvm install 20 && nvm use 20 > /dev/null 2>&1
sudo apt-get install tee -y > /dev/null 2>&1
echo "Installing dependencies..."
sudo apt-get install -y gcc g++ make > /dev/null 2>&1
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - > /dev/null 2>&1
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list > /dev/null 2>&1
sudo apt-get update > /dev/null 2>&1 && sudo apt-get install yarn -y > /dev/null 2>&1
echo "Downloading HolaClient files..."
git clone --quiet --single-branch --branch "$version" https://github.com/HolaClient/HolaClient
cd HolaClient
echo "Installing Packages..."
npm i > /dev/null 2>&1
npm i -g pm2 > /dev/null 2>&1
pm2 start index.js --name "holaclient" > /dev/null 2>&1
echo "HolaClient installation completed successfully."
echo "Configuring Nginx..."
sudo apt install -y python3-certbot-nginx nginx > /dev/null 2>&1
ufw allow 80 > /dev/null && ufw allow 443 > /dev/null
certbot certonly --nginx -d "$domain" -m "$email"
sudo tee /etc/nginx/sites-enabled/holaclient.conf > /dev/null << EOL
server {
listen 80;
server_name $domain;
return 301 https://\$server_name\$request_uri;
}
server {
listen 443 ssl http2;
location /afkwspath {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass "http://$domain:$port/afkwspath";
}
server_name $domain;
ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;
ssl_session_cache shared:SSL:10m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://$domain:$port/;
proxy_buffering off;
proxy_set_header X-Real-IP \$remote_addr;
}
}
EOL
sudo systemctl restart nginx
echo "Nginx configuration with SSL completed successfully."
elif [[ $choice == "1" ]]; then
if [[ -d "/var/www/HolaClient" ]]; then
echo "HolaClient is already installed! Please select option 5 to reinstall it."
exit 1
fi
read -p "Enter the HolaClient version to install (latest): " version
version=${version:-latest}
cd /var/www/
echo ""
echo "Updating system..."
sudo apt -y update > /dev/null 2>&1 && sudo apt -y upgrade > /dev/null 2>&1
echo "Installing Git..."
sudo apt -y install git > /dev/null 2>&1
echo "Installing NodeJS..."
sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash > /dev/null 2>&1
source ~/.nvm/nvm.sh > /dev/null 2>&1
nvm install 20 && nvm use 20 > /dev/null 2>&1
sudo apt-get install tee -y > /dev/null 2>&1
echo "Installing dependencies..."
sudo apt-get install -y gcc g++ make > /dev/null 2>&1
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - > /dev/null 2>&1
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list > /dev/null 2>&1
sudo apt-get update > /dev/null 2>&1 && sudo apt-get install yarn -y > /dev/null 2>&1
echo "Downloading HolaClient files..."
git clone --quiet --single-branch --branch "$version" https://github.com/HolaClient/HolaClient
cd HolaClient
echo "Installing Packages..."
npm i > /dev/null 2>&1
npm i -g pm2 > /dev/null 2>&1
pm2 start index.js --name "holaclient" > /dev/null 2>&1
echo "HolaClient installation completed successfully."
elif [[ $choice == "2" ]]; then
if [ ! -d "/var/www/HolaClient" ]; then
echo "HolaClient is not installed, please Install it first!"
exit 1
fi
echo "Checking for updates in HolaClient..."
cd /var/www/HolaClient
latest_commit_github=$(git ls-remote https://github.com/HolaClient/HolaClient.git HEAD | cut -f 1)
current_commit_local=$(git rev-parse HEAD)
if [[ $latest_commit_github != $current_commit_local ]]; then
backup_dir="/var/www/HolaClient_backup_$(date +'%Y%m%d%H%M%S')"
echo "Updates found! Taking a backup of the current directory to $backup_dir..."
cp -r /var/www/HolaClient "$backup_dir"
echo "Updating HolaClient..."
git fetch origin
git pull origin latest
echo "HolaClient update completed successfully."
else
echo "HolaClient is already up to date."
fi
elif [[ $choice == "3" ]]; then
echo "Installing dependencies..."
cd /var/www/HolaClient
echo "Updating system..."
sudo apt -y update > /dev/null 2>&1 && sudo apt -y upgrade > /dev/null 2>&1
echo "Installing Git..."
sudo apt -y install git > /dev/null 2>&1
echo "Installing NodeJS..."
sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash > /dev/null 2>&1
source ~/.nvm/nvm.sh > /dev/null 2>&1
nvm install 20 && nvm use 20 > /dev/null 2>&1
sudo apt-get install tee -y > /dev/null 2>&1
echo "Installing dependencies..."
sudo apt-get install -y gcc g++ make > /dev/null 2>&1
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - > /dev/null 2>&1
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list > /dev/null 2>&1
sudo apt-get update > /dev/null 2>&1 && sudo apt-get install yarn -y > /dev/null 2>&1
echo "Dependencies installation completed successfully."
elif [[ $choice == "4" ]]; then
read -p "Enter your domain (client.example.com): " domain
read -p "Enter the port (2000): " port
port=${port:-2000}
read -p "Enter your email ([email protected]): " email
email=${email:[email protected]}
sudo apt install -y python3-certbot-nginx nginx > /dev/null 2>&1
ufw allow 80 > /dev/null && ufw allow 443 > /dev/null
certbot certonly --nginx -d "$domain" -m "$email"
sudo tee /etc/nginx/sites-enabled/holaclient.conf > /dev/null << EOL
server {
listen 80;
server_name $domain;
return 301 https://\$server_name\$request_uri;
}
server {
listen 443 ssl http2;
location /afkwspath {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass "http://$domain:$port/afkwspath";
}
server_name $domain;
ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;
ssl_session_cache shared:SSL:10m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://$domain:$port/;
proxy_buffering off;
proxy_set_header X-Real-IP \$remote_addr;
}
}
EOL
sudo systemctl restart nginx
echo "Nginx configuration with SSL completed successfully."
elif [[ $choice == "5" ]]; then
if [ ! -d "/var/www/HolaClient" ]; then
echo "HolaClient is not installed, please Install it first!"
exit 1
fi
read -p "Are you sure you want to uninstall HolaClient? This will delete all HolaClient files and configurations. (y/n): " confirm
if [[ $confirm == "y" ]]; then
echo "Uninstalling HolaClient..."
rm -r /var/www/HolaClient/node_modules
if [ ! -d "/etc/HolaClientBackups" ]; then
mkdir /etc/HolaClientBackups
fi
mkdir /etc/HolaClientBackups/$(date +'%Y%m%d%H%M')
mv /var/www/HolaClient /etc/HolaClientBackups/$(date +'%Y%m%d%H%M')
rm /etc/nginx/sites-enabled/holaclient.conf
pm2 delete holaclient > /dev/null
echo "HolaClient uninstallation completed successfully."
else
echo "Uninstallation canceled."
fi
else
echo "Invalid choice. Exiting..."
exit 1
fi