-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
366 lines (285 loc) · 9.57 KB
/
install.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
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#!/bin/bash
WHITE='\033[0;37m'
NC='\033[0m'
show_menu() {
clear
echo -e "${WHITE}"
echo "SCRIPT: Transfer Me v0.1.0"
echo "USAGE: This script transfers your desired directories to your destination server."
echo "------------------------------"
echo "Select an option:"
echo "1) Transfer Marzban Directories"
echo "2) Transfer X-UI Directories"
echo "3) Transfer Hiddify Directories"
echo "4) Transfer Custom Directories"
echo "5) Exit"
echo -e "${NC}"
read -p "Enter your choice [1-5]: " choice
case $choice in
1)
transfer_marzban_directories
;;
2)
transfer_xui_directories
;;
3)
transfer_hiddify_directories
;;
4)
transfer_custom_directories
;;
5)
echo "Exiting..."
exit 0
;;
*)
echo "Invalid choice, please enter a number between 1 and 5."
show_menu
;;
esac
}
transfer_marzban_directories() {
#!/bin/bash
WHITE='\033[0;37m'
NC='\033[0m'
display_warning() {
clear
echo -e "${WHITE}"
echo "----------------------------------------"
echo " WARNING: $1"
echo "----------------------------------------"
echo -e "${NC}"
}
MESSAGE="First, make sure Marzban is installed on your destination server."
display_warning "$MESSAGE"
read -p "Enter the destination server IP address: " SERVER_IP
read -p "Enter the SSH port (default 22): " SERVER_PORT
SERVER_PORT=${SERVER_PORT:-22}
read -sp "Enter the SSH password: " SERVER_PASSWORD
echo
if ! command -v zip &> /dev/null; then
echo "Installing zip package..."
sudo apt-get update && sudo apt-get install -y zip
else
echo "Zip is already installed."
fi
if ! command -v sshpass &> /dev/null; then
echo "Installing sshpass..."
sudo apt-get update && sudo apt-get install -y sshpass
else
echo "sshpass is already installed."
fi
BASE_DIR="/opt"
BASE_DIR2="/var/lib"
echo "Zipping contents of $BASE_DIR/marzban..."
(cd "$BASE_DIR" && zip -r marzban.zip marzban/)
echo "Zipping contents of $BASE_DIR2/marzban..."
(cd "$BASE_DIR2" && zip -r marzban.zip marzban/)
echo "Transferring /opt/marzban.zip to the server..."
sshpass -p "$SERVER_PASSWORD" scp -P $SERVER_PORT /opt/marzban.zip root@$SERVER_IP:/opt/marzban.zip
echo "Transferring /var/lib/marzban.zip to the server..."
sshpass -p "$SERVER_PASSWORD" scp -P $SERVER_PORT /var/lib/marzban.zip root@$SERVER_IP:/var/lib/marzban.zip
sshpass -p "$SERVER_PASSWORD" ssh -T -p "$SERVER_PORT" root@"$SERVER_IP" << 'EOF'
BASE_DIR="/opt"
BASE_DIR2="/var/lib"
# Install unzip if not installed
if ! command -v unzip &> /dev/null; then
echo "Installing unzip package..."
apt-get update && apt-get install -y unzip
else
echo "Unzip is already installed."
fi
echo "Removing /opt/marzban directory..."
rm -rf /opt/marzban
echo "Removing /var/lib/marzban directory..."
rm -rf /var/lib/marzban
echo "Unzipping /opt/marzban.zip..."
(cd "$BASE_DIR" && unzip -o marzban.zip)
echo "Unzipping /var/lib/marzban.zip..."
(cd "$BASE_DIR2" && unzip -o marzban.zip)
echo "Removing /opt/marzban.zip file..."
rm -rf /opt/marzban.zip
echo "Removing /var/lib/marzban.zip file..."
rm -rf /var/lib/marzban.zip
EOF
echo -e "\033[97mMarzban directories are transferred successfully.\033[0m"
}
transfer_xui_directories() {
#!/bin/bash
WHITE='\033[0;37m'
NC='\033[0m'
display_warning() {
clear
echo -e "${WHITE}"
echo "----------------------------------------"
echo " WARNING: $1"
echo "----------------------------------------"
echo -e "${NC}"
}
MESSAGE="First, make sure X-UI is installed on your destination server."
display_warning "$MESSAGE"
read -p "Enter the destination server IP address: " SERVER_IP
read -p "Enter the SSH port (default 22): " SERVER_PORT
SERVER_PORT=${SERVER_PORT:-22}
read -sp "Enter the SSH password: " SERVER_PASSWORD
echo
if ! command -v zip &> /dev/null; then
echo "Installing zip package..."
sudo apt-get update && sudo apt-get install -y zip
else
echo "Zip is already installed."
fi
if ! command -v sshpass &> /dev/null; then
echo "Installing sshpass..."
sudo apt-get update && sudo apt-get install -y sshpass
else
echo "sshpass is already installed."
fi
BASE_DIR="/etc"
echo "Zipping contents of $BASE_DIR/x-ui..."
(cd "$BASE_DIR" && zip -r x-ui.zip x-ui/)
echo "Transferring /etc/x-ui.zip to the server..."
sshpass -p "$SERVER_PASSWORD" scp -P $SERVER_PORT /etc/x-ui.zip root@$SERVER_IP:/etc/x-ui.zip
sshpass -p "$SERVER_PASSWORD" ssh -T -p "$SERVER_PORT" root@"$SERVER_IP" << 'EOF'
BASE_DIR="/etc"
# Install unzip if not installed
if ! command -v unzip &> /dev/null; then
echo "Installing unzip package..."
apt-get update && apt-get install -y unzip
else
echo "Unzip is already installed."
fi
echo "Removing /etc/x-ui directory..."
rm -rf /etc/x-ui
echo "Unzipping /etc/x-ui.zip..."
(cd "$BASE_DIR" && unzip -o x-ui.zip)
echo "Removing /etc/x-ui.zip..."
rm -rf /etc/x-ui.zip
EOF
echo -e "\033[97mX-UI directories are transferred successfully.\033[0m"
}
transfer_hiddify_directories() {
#!/bin/bash
WHITE='\033[0;37m'
NC='\033[0m'
display_warning() {
clear
echo -e "${WHITE}"
echo "----------------------------------------"
echo " WARNING: $1"
echo "----------------------------------------"
echo -e "${NC}"
}
MESSAGE="First, make sure Hiddify is installed on your destination server."
display_warning "$MESSAGE"
read -p "Enter the destination server IP address: " SERVER_IP
read -p "Enter the SSH port (default 22): " SERVER_PORT
SERVER_PORT=${SERVER_PORT:-22}
read -sp "Enter the SSH password: " SERVER_PASSWORD
echo
if ! command -v zip &> /dev/null; then
echo "Installing zip package..."
sudo apt-get update && sudo apt-get install -y zip
else
echo "Zip is already installed."
fi
if ! command -v sshpass &> /dev/null; then
echo "Installing sshpass..."
sudo apt-get update && sudo apt-get install -y sshpass
else
echo "sshpass is already installed."
fi
BASE_DIR="/opt"
echo "Zipping contents of $BASE_DIR/hiddify-config..."
(cd "$BASE_DIR" && zip -r hiddify-config.zip hiddify-config/)
echo "Transferring /opt/hiddify-config.zip to the server..."
sshpass -p "$SERVER_PASSWORD" scp -P $SERVER_PORT /opt/hiddify-config.zip root@$SERVER_IP:/opt/hiddify-config.zip
sshpass -p "$SERVER_PASSWORD" ssh -T -p "$SERVER_PORT" root@"$SERVER_IP" << 'EOF'
BASE_DIR="/opt"
# Install unzip if not installed
if ! command -v unzip &> /dev/null; then
echo "Installing unzip package..."
apt-get update && apt-get install -y unzip
else
echo "Unzip is already installed."
fi
echo "Removing /opt/hiddify-config directory..."
rm /opt/hiddify-config
echo "Unzipping /opt/hiddify-config.zip..."
(cd "$BASE_DIR" && unzip -o hiddify-config.zip)
echo "Removing /opt/hiddify-config.zip file..."
rm -rf /opt/hiddify-config.zip
EOF
echo -e "\033[97mHiddify directories are transferred successfully.\033[0m"
}
transfer_custom_directories() {
#!/bin/bash
WHITE='\033[0;37m'
NC='\033[0m'
display_warning() {
clear
echo -e "${WHITE}"
echo "----------------------------------------"
echo " INFO: $1"
echo "----------------------------------------"
echo -e "${NC}"
}
MESSAGE="This section is for transferring custom directories."
display_warning "$MESSAGE"
read -p "Enter the destination server IP address: " SERVER_IP
read -p "Enter the SSH port (default 22): " SERVER_PORT
SERVER_PORT=${SERVER_PORT:-22}
read -sp "Enter the SSH password: " SERVER_PASSWORD
echo
read -p "Enter the first directory you want to transfer (example: /opt/marzban): " CUSTOM_DIR1
read -p "Enter the second directory you want to transfer (optional, press Enter to skip): " CUSTOM_DIR2
if ! command -v zip &> /dev/null; then
echo "Installing zip package..."
sudo apt-get update && sudo apt-get install -y zip
else
echo "Zip is already installed."
fi
if ! command -v sshpass &> /dev/null; then
echo "Installing sshpass..."
sudo apt-get update && sudo apt-get install -y sshpass
else
echo "sshpass is already installed."
fi
zip_and_transfer() {
local dir="$1"
local base_dir=$(dirname "$dir")
local dir_name=$(basename "$dir")
local zip_file="${dir_name}.zip"
echo "Zipping contents of $dir..."
(cd "$base_dir" && zip -r "$zip_file" "$dir_name/")
echo "Transferring $zip_file to the server..."
sshpass -p "$SERVER_PASSWORD" scp -P "$SERVER_PORT" "$base_dir/$zip_file" root@"$SERVER_IP":"$base_dir/$zip_file"
echo "Unzipping $zip_file on the server..."
sshpass -p "$SERVER_PASSWORD" ssh -T -p "$SERVER_PORT" root@"$SERVER_IP" << EOF
if ! command -v unzip &> /dev/null; then
echo "Installing unzip package..."
apt-get update && apt-get install -y unzip
else
echo "Unzip is already installed."
fi
echo "Removing $dir on the server..."
rm -rf "$dir"
echo "Unzipping $base_dir/$zip_file..."
(cd "$base_dir" && unzip -o "$zip_file")
echo "Deleting $zip_file on the server..."
rm -f "$base_dir/$zip_file"
EOF
}
if [ -n "$CUSTOM_DIR1" ]; then
zip_and_transfer "$CUSTOM_DIR1"
else
echo "No first custom directory specified."
fi
if [ -n "$CUSTOM_DIR2" ]; then
zip_and_transfer "$CUSTOM_DIR2"
else
echo "No second custom directory specified."
fi
echo -e "\033[97mCustom directories are transferred successfully.\033[0m"
}
show_menu