-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathInstall.sh
459 lines (423 loc) · 12.7 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
#!/bin/sh
tput sgr0; clear
## Load Seedbox Components
source <(wget -qO- https://raw.githubusercontent.com/jerry048/Seedbox-Components/main/seedbox_installation.sh)
# Check if Seedbox Components is successfully loaded
if [ $? -ne 0 ]; then
echo "Component ~Seedbox Components~ failed to load"
echo "Check connection with GitHub"
exit 1
fi
## Load loading animation
source <(wget -qO- https://raw.githubusercontent.com/Silejonu/bash_loading_animations/main/bash_loading_animations.sh)
# Check if bash loading animation is successfully loaded
if [ $? -ne 0 ]; then
fail "Component ~Bash loading animation~ failed to load"
fail_exit "Check connection with GitHub"
fi
# Run BLA::stop_loading_animation if the script is interrupted
trap BLA::stop_loading_animation SIGINT
## Install function
install_() {
info_2 "$2"
BLA::start_loading_animation "${BLA_classic[@]}"
$1 1> /dev/null 2> $3
if [ $? -ne 0 ]; then
fail_3 "FAIL"
else
info_3 "Successful"
export $4=1
fi
BLA::stop_loading_animation
}
## Installation environment Check
info "Checking Installation Environment"
# Check Root Privilege
if [ $(id -u) -ne 0 ]; then
fail_exit "This script needs root permission to run"
fi
# Linux Distro Version check
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
OS=SuSe
elif [ -f /etc/redhat-release ]; then
OS=Redhat
else
OS=$(uname -s)
VER=$(uname -r)
fi
if [[ ! "$OS" =~ "Debian" ]] && [[ ! "$OS" =~ "Ubuntu" ]]; then #Only Debian and Ubuntu are supported
fail "$OS $VER is not supported"
info "Only Debian 10+ and Ubuntu 20.04+ are supported"
exit 1
fi
if [[ "$OS" =~ "Debian" ]]; then #Debian 10+ are supported
if [[ ! "$VER" =~ "10" ]] && [[ ! "$VER" =~ "11" ]] && [[ ! "$VER" =~ "12" ]]; then
fail "$OS $VER is not supported"
info "Only Debian 10+ are supported"
exit 1
fi
fi
if [[ "$OS" =~ "Ubuntu" ]]; then #Ubuntu 20.04+ are supported
if [[ ! "$VER" =~ "20" ]] && [[ ! "$VER" =~ "22" ]] && [[ ! "$VER" =~ "23" ]]; then
fail "$OS $VER is not supported"
info "Only Ubuntu 20.04+ is supported"
exit 1
fi
fi
## Read input arguments
while getopts "u:p:c:q:l:rbvx3oh" opt; do
case ${opt} in
u ) # process option username
username=${OPTARG}
;;
p ) # process option password
password=${OPTARG}
;;
c ) # process option cache
cache=${OPTARG}
#Check if cache is a number
while true
do
if ! [[ "$cache" =~ ^[0-9]+$ ]]; then
warn "Cache must be a number"
need_input "Please enter a cache size (in MB):"
read cache
else
break
fi
done
#Converting the cache to qBittorrent's unit (MiB)
qb_cache=$cache
;;
q ) # process option cache
qb_install=1
qb_ver=("qBittorrent-${OPTARG}")
;;
l ) # process option libtorrent
lib_ver=("libtorrent-${OPTARG}")
#Check if qBittorrent version is specified
if [ -z "$qb_ver" ]; then
warn "You must choose a qBittorrent version for your libtorrent install"
qb_ver_choose
fi
;;
r ) # process option autoremove
autoremove_install=1
;;
b ) # process option autobrr
autobrr_install=1
;;
v ) # process option vertex
vertex_install=1
;;
x ) # process option bbr
unset bbrv3_install
bbrx_install=1
;;
3 ) # process option bbr
unset bbrx_install
bbrv3_install=1
;;
o ) # process option port
if [[ -n "$qb_install" ]]; then
need_input "Please enter qBittorrent port:"
read qb_port
while true
do
if ! [[ "$qb_port" =~ ^[0-9]+$ ]]; then
warn "Port must be a number"
need_input "Please enter qBittorrent port:"
read qb_port
else
break
fi
done
need_input "Please enter qBittorrent incoming port:"
read qb_incoming_port
while true
do
if ! [[ "$qb_incoming_port" =~ ^[0-9]+$ ]]; then
warn "Port must be a number"
need_input "Please enter qBittorrent incoming port:"
read qb_incoming_port
else
break
fi
done
fi
if [[ -n "$autobrr_install" ]]; then
need_input "Please enter autobrr port:"
read autobrr_port
while true
do
if ! [[ "$autobrr_port" =~ ^[0-9]+$ ]]; then
warn "Port must be a number"
need_input "Please enter autobrr port:"
read autobrr_port
else
break
fi
done
fi
if [[ -n "$vertex_install" ]]; then
need_input "Please enter vertex port:"
read vertex_port
while true
do
if ! [[ "$vertex_port" =~ ^[0-9]+$ ]]; then
warn "Port must be a number"
need_input "Please enter vertex port:"
read vertex_port
else
break
fi
done
fi
;;
h ) # process option help
info "Help:"
info "Usage: ./Install.sh -u <username> -p <password> -c <Cache Size(unit:MiB)> -q <qBittorrent version> -l <libtorrent version> -b -v -r -3 -x -p"
info "Example: ./Install.sh -u jerry048 -p 1LDw39VOgors -c 3072 -q 4.3.9 -l v1.2.19 -b -v -r -3"
source <(wget -qO- https://raw.githubusercontent.com/jerry048/Seedbox-Components/main/Torrent%20Clients/qBittorrent/qBittorrent_install.sh)
seperator
info "Options:"
need_input "1. -u : Username"
need_input "2. -p : Password"
need_input "3. -c : Cache Size for qBittorrent (unit:MiB)"
echo -e "\n"
need_input "4. -q : qBittorrent version"
need_input "Available qBittorrent versions:"
tput sgr0; tput setaf 7; tput dim; history -p "${qb_ver_list[@]}"; tput sgr0
echo -e "\n"
need_input "5. -l : libtorrent version"
need_input "Available qBittorrent versions:"
tput sgr0; tput setaf 7; tput dim; history -p "${lib_ver_list[@]}"; tput sgr0
echo -e "\n"
need_input "6. -r : Install autoremove-torrents"
need_input "7. -b : Install autobrr"
need_input "8. -v : Install vertex"
need_input "9. -x : Install BBRx"
need_input "10. -3 : Install BBRv3"
need_input "11. -p : Specify ports for qBittorrent, autobrr and vertex"
need_input "12. -h : Display help message"
exit 0
;;
\? )
info "Help:"
info_2 "Usage: ./Install.sh -u <username> -p <password> -c <Cache Size(unit:MiB)> -q <qBittorrent version> -l <libtorrent version> -b -v -r -3 -x -p"
info_2 "Example ./Install.sh -u jerry048 -p 1LDw39VOgors -c 3072 -q 4.3.9 -l v1.2.19 -b -v -r -3"
exit 1
;;
esac
done
# System Update & Dependencies Install
info "Start System Update & Dependencies Install"
update
## Install Seedbox Environment
tput sgr0; clear
info "Start Installing Seedbox Environment"
echo -e "\n"
# qBittorrent
source <(wget -qO- https://raw.githubusercontent.com/jerry048/Seedbox-Components/main/Torrent%20Clients/qBittorrent/qBittorrent_install.sh)
# Check if qBittorrent install is successfully loaded
if [ $? -ne 0 ]; then
fail_exit "Component ~qBittorrent install~ failed to load"
fi
if [[ ! -z "$qb_install" ]]; then
## Check if all the required arguments are specified
#Check if username is specified
if [ -z "$username" ]; then
warn "Username is not specified"
need_input "Please enter a username:"
read username
fi
#Check if password is specified
if [ -z "$password" ]; then
warn "Password is not specified"
need_input "Please enter a password:"
read password
fi
## Create user if it does not exist
if ! id -u $username > /dev/null 2>&1; then
useradd -m -s /bin/bash $username
# Check if the user is created successfully
if [ $? -ne 0 ]; then
warn "Failed to create user $username"
return 1
fi
fi
chown -R $username:$username /home/$username
#Check if cache is specified
if [ -z "$cache" ]; then
warn "Cache is not specified"
need_input "Please enter a cache size (in MB):"
read cache
#Check if cache is a number
while true
do
if ! [[ "$cache" =~ ^[0-9]+$ ]]; then
warn "Cache must be a number"
need_input "Please enter a cache size (in MB):"
read cache
else
break
fi
done
qb_cache=$cache
fi
#Check if qBittorrent version is specified
if [ -z "$qb_ver" ]; then
warn "qBittorrent version is not specified"
qb_ver_check
fi
#Check if libtorrent version is specified
if [ -z "$lib_ver" ]; then
warn "libtorrent version is not specified"
lib_ver_check
fi
#Check if qBittorrent port is specified
if [ -z "$qb_port" ]; then
qb_port=8080
fi
#Check if qBittorrent incoming port is specified
if [ -z "$qb_incoming_port" ]; then
qb_incoming_port=45000
fi
## qBittorrent & libtorrent compatibility check
qb_install_check
## qBittorrent install
install_ "install_qBittorrent_ $username $password $qb_ver $lib_ver $qb_cache $qb_port $qb_incoming_port" "Installing qBittorrent" "/tmp/qb_error" qb_install_success
fi
# autobrr Install
if [[ ! -z "$autobrr_install" ]]; then
install_ install_autobrr_ "Installing autobrr" "/tmp/autobrr_error" autobrr_install_success
fi
# vertex Install
if [[ ! -z "$vertex_install" ]]; then
install_ install_vertex_ "Installing vertex" "/tmp/vertex_error" vertex_install_success
fi
# autoremove-torrents Install
if [[ ! -z "$autoremove_install" ]]; then
install_ install_autoremove-torrents_ "Installing autoremove-torrents" "/tmp/autoremove_error" autoremove_install_success
fi
seperator
## Tunning
info "Start Doing System Tunning"
install_ tuned_ "Installing tuned" "/tmp/tuned_error" tuned_success
install_ set_txqueuelen_ "Setting txqueuelen" "/tmp/txqueuelen_error" txqueuelen_success
install_ set_file_open_limit_ "Setting File Open Limit" "/tmp/file_open_limit_error" file_open_limit_success
# Check for Virtual Environment since some of the tunning might not work on virtual machine
systemd-detect-virt > /dev/null
if [ $? -eq 0 ]; then
warn "Virtualization is detected, skipping some of the tunning"
install_ disable_tso_ "Disabling TSO" "/tmp/tso_error" tso_success
else
install_ set_disk_scheduler_ "Setting Disk Scheduler" "/tmp/disk_scheduler_error" disk_scheduler_success
install_ set_ring_buffer_ "Setting Ring Buffer" "/tmp/ring_buffer_error" ring_buffer_success
fi
install_ set_initial_congestion_window_ "Setting Initial Congestion Window" "/tmp/initial_congestion_window_error" initial_congestion_window_success
install_ kernel_settings_ "Setting Kernel Settings" "/tmp/kernel_settings_error" kernel_settings_success
# BBRx
if [[ ! -z "$bbrx_install" ]]; then
# Check if Tweaked BBR is already installed
if [[ ! -z "$(lsmod | grep bbrx)" ]]; then
warn echo "Tweaked BBR is already installed"
else
install_ install_bbrx_ "Installing BBRx" "/tmp/bbrx_error" bbrx_install_success
fi
fi
# BBRv3
if [[ ! -z "$bbrv3_install" ]]; then
install_ install_bbrv3_ "Installing BBRv3" "/tmp/bbrv3_error" bbrv3_install_success
fi
## Configue Boot Script
info "Start Configuing Boot Script"
touch /root/.boot-script.sh && chmod +x /root/.boot-script.sh
cat << EOF > /root/.boot-script.sh
#!/bin/bash
sleep 120s
source <(wget -qO- https://raw.githubusercontent.com/jerry048/Seedbox-Components/main/seedbox_installation.sh)
# Check if Seedbox Components is successfully loaded
if [ \$? -ne 0 ]; then
exit 1
fi
set_txqueuelen_
# Check for Virtual Environment since some of the tunning might not work on virtual machine
systemd-detect-virt > /dev/null
if [ \$? -eq 0 ]; then
disable_tso_
else
set_disk_scheduler_
set_ring_buffer_
fi
set_initial_congestion_window_
EOF
# Configure the script to run during system startup
cat << EOF > /etc/systemd/system/boot-script.service
[Unit]
Description=boot-script
After=network.target
[Service]
Type=simple
ExecStart=/root/.boot-script.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable boot-script.service
seperator
## Finalizing the install
info "Seedbox Installation Complete"
publicip=$(curl -s https://ipinfo.io/ip)
# Display Username and Password
# qBittorrent
if [[ ! -z "$qb_install_success" ]]; then
info "qBittorrent installed"
boring_text "qBittorrent WebUI: http://$publicip:$qb_port"
boring_text "qBittorrent Username: $username"
boring_text "qBittorrent Password: $password"
echo -e "\n"
fi
# autoremove-torrents
if [[ ! -z "$autoremove_install_success" ]]; then
info "autoremove-torrents installed"
boring_text "Config at /home/$username/.config.yml"
boring_text "Please read https://autoremove-torrents.readthedocs.io/en/latest/config.html for configuration"
echo -e "\n"
fi
# autobrr
if [[ ! -z "$autobrr_install_success" ]]; then
info "autobrr installed"
boring_text "autobrr WebUI: http://$publicip:$autobrr_port"
echo -e "\n"
fi
# vertex
if [[ ! -z "$vertex_install_success" ]]; then
info "vertex installed"
boring_text "vertex WebUI: http://$publicip:$vertex_port"
boring_text "vertex Username: $username"
boring_text "vertex Password: $password"
echo -e "\n"
fi
# BBR
if [[ ! -z "$bbrx_install_success" ]]; then
info "BBRx successfully installed, please reboot for it to take effect"
fi
if [[ ! -z "$bbrv3_install_success" ]]; then
info "BBRv3 successfully installed, please reboot for it to take effect"
fi
exit 0