-
Notifications
You must be signed in to change notification settings - Fork 0
/
deb.install.sh
315 lines (270 loc) Β· 14.4 KB
/
deb.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
#!/bin/bash
##
# TorrentPier β Bull-powered BitTorrent tracker engine
#
# @copyright Copyright (c) 2024-present TorrentPier (https://torrentpier.com)
# @copyright Copyright (c) 2024-present Solovev Sergei <[email protected]>
#
# @link https://github.com/torrentpier/autoinstall for the canonical source repository
#
# @license https://github.com/torrentpier/autoinstall/blob/main/LICENSE MIT License
##
clear
# Arrays and variables used
suppOs=("debian" "ubuntu")
currOs=$(grep ^ID= /etc/os-release | awk -F= '{print $2}')
logsInst="/var/log/torrentpier_install.log"
saveFile="/root/torrentpier.cfg"
# TorrentPier auth
torrentPierUser="admin"
torrentPierPass="admin"
# User verification
if [ "$(whoami)" != "root" ]; then
echo "It needs to be run under the root user!" 2>&1 | tee -a "$logsInst"
exit 1
fi
# Checking for system support
foundOs=false
for os in "${suppOs[@]}"; do
if [[ "$os" == "$currOs" ]]; then
foundOs=true
break
fi
done
if $foundOs; then
# A function to check whether a string is an IP address
is_ip() {
local ip="$1"
# Checking the IP address format (4 numbers from 0 to 255, separated by dots)
if [[ "$ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
# Checking that each number is in the range from 0 to 255
IFS='.' read -r -a octets <<< "$ip"
for octet in "${octets[@]}"; do
if ((octet < 0 || octet > 255)); then
return 1
fi
done
return 0
else
return 1
fi
}
# A function to check whether a string is a domain name
is_domain() {
local domain="$1"
# Checking the format of the domain name (consisting of letters, numbers and hyphens separated by dots)
if [[ "$domain" =~ ^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$ ]]; then
return 0
else
return 1
fi
}
# The cycle of checking and requesting a domain name or IP address
while true; do
echo "Enter the domain name or IP address:"
read -r HOST
# Checking the entered value
if [ -n "$HOST" ]; then
if is_ip "$HOST" || is_domain "$HOST"; then
break
else
echo "Incorrect input. Please enter the correct domain name or IP address."
fi
else
echo "You have not entered a domain name or IP address. Please try again."
fi
done
# NGINX configuration file for TorrentPier
nginx_torrentpier="server {
listen 80;
server_name $HOST;
root /var/www/torrentpier;
index index.php;
charset utf-8;
location / {
try_files \$uri \$uri/ /index.php?\$args;
}
location ~ /\.(ht|en) {
return 404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}"
# NGINX configuration file for phpMyAdmin
nginx_phpmyadmin="server {
listen 9090;
server_name $HOST;
root /usr/share/phpmyadmin;
index index.php;
location / {
try_files \$uri \$uri/ /index.php;
}
location ~* ^/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/phpmyadmin;
}
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}"
# Packages for installation, TorrentPier, phpMyAdmin
pkgsList=("php-fpm" "php-mbstring" "php-bcmath" "php-intl" "php-tidy" "php-xml" "php-xmlwriter" "php-zip" "php-gd" "php-json" "php-curl" "nginx" "mariadb-server" "pwgen" "jq" "curl" "zip" "unzip" "cron")
# Updating tables and packages
echo "===================================" 2>&1 | tee -a "$logsInst" > /dev/null
echo "Updating tables and packages" | tee -a "$logsInst"
echo "===================================" 2>&1 | tee -a "$logsInst" > /dev/null
apt-get -y update 2>&1 | tee -a "$logsInst" > /dev/null
apt-get -y dist-upgrade 2>&1 | tee -a "$logsInst" > /dev/null
# Check and installation sudo
if ! dpkg-query -W -f='${Status}' "sudo" 2>/dev/null | grep -q "install ok installed"; then
echo "===================================" 2>&1 | tee -a "$logsInst" > /dev/null
echo "sudo not installed. Installation in progress..." | tee -a "$logsInst"
echo "===================================" 2>&1 | tee -a "$logsInst" > /dev/null
apt-get install -y sudo 2>&1 | tee -a "$logsInst" > /dev/null
fi
# Package installation cycle
for package in "${pkgsList[@]}"; do
# Checking for packages and installing packages
if ! dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q "install ok installed"; then
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo "$package not installed. Installation in progress..." | sudo tee -a "$logsInst"
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo apt-get install -y "$package" 2>&1 | sudo tee -a "$logsInst" > /dev/null
fi
done
passPma="$(pwgen -1Bs 12)"
dbSql="torrentpier_$(pwgen -1 8)"
userSql="torrentpier_$(pwgen -1 8)"
passSql="$(pwgen -1Bs 12)"
# Installation phpMyAdmin
if ! dpkg-query -W -f='${Status}' "phpmyadmin" 2>/dev/null | grep -q "install ok installed"; then
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo "phpMyAdmin not installed. Installation in progress..." | sudo tee -a "$logsInst"
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo debconf-set-selections <<EOF
phpmyadmin phpmyadmin/dbconfig-install boolean true
phpmyadmin phpmyadmin/mysql/app-pass password $passPma
phpmyadmin phpmyadmin/password-confirm password $passPma
phpmyadmin phpmyadmin/reconfigure-webserver multiselect
EOF
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y phpmyadmin 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo -e "$nginx_phpmyadmin" | sudo tee /etc/nginx/sites-available/00-phpmyadmin.conf 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo ln -s /etc/nginx/sites-available/00-phpmyadmin.conf /etc/nginx/sites-enabled/ 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Checking and running the NGINX configuration file
sudo nginx -t 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo systemctl restart nginx 2>&1 | sudo tee -a "$logsInst" > /dev/null
else
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo "phpMyAdmin is already installed on the system. The installation cannot continue." | sudo tee -a "$logsInst"
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
read -rp "Press Enter to complete..."
exit 1
fi
# Installation and setting Composer
if [ ! -f "/usr/local/bin/composer" ]; then
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo "Composer not installed. Installation in progress..." | sudo tee -a "$logsInst"
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
curl -sSL https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer 2>&1 | sudo tee -a "$logsInst" > /dev/null
fi
# Installation TorrentPier
if [ ! -d "/var/www/torrentpier" ]; then
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo "TorrentPier not installed. Installation in progress..." | sudo tee -a "$logsInst"
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Creating a temporary directory
sudo mkdir -p /tmp/torrentpier 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Downloading TorrentPier
curl -s https://api.github.com/repos/torrentpier/torrentpier/releases | jq -r 'map(select(.prerelease == true)) | .[0].zipball_url' | xargs -n 1 curl -L -o /tmp/torrentpier/torrentpier.zip 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo unzip -o /tmp/torrentpier/torrentpier.zip -d /tmp/torrentpier 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo mv /tmp/torrentpier/torrentpier-torrentpier-* /var/www/torrentpier 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Clearing the temporary folder
sudo rm -rf /tmp/torrentpier/* 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Installing composer dependencies
sudo COMPOSER_ALLOW_SUPERUSER=1 composer install --working-dir=/var/www/torrentpier 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Setting up the configuration file
sudo mv /var/www/torrentpier/.env.example /var/www/torrentpier/.env 2>&1 | sudo tee -a "$logsInst"
sed -i "s/APP_CRON_ENABLED=true/APP_CRON_ENABLED=false/g" /var/www/torrentpier/.env 2>&1 | sudo tee -a "$logsInst" > /dev/null
sed -i "s/DB_DATABASE=torrentpier/DB_DATABASE=$dbSql/g" /var/www/torrentpier/.env 2>&1 | sudo tee -a "$logsInst" > /dev/null
sed -i "s/DB_USERNAME=root/DB_USERNAME=$userSql/g" /var/www/torrentpier/.env 2>&1 | sudo tee -a "$logsInst" > /dev/null
sed -i "s/DB_PASSWORD=secret/DB_PASSWORD=$passSql/g" /var/www/torrentpier/.env 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Creating a user
sudo mysql -e "CREATE USER '$userSql'@'localhost' IDENTIFIED BY '$passSql';" 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Creating a database
sudo mysql -e "CREATE DATABASE $dbSql CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Granting privileges to the user on the database
sudo mysql -e "GRANT ALL PRIVILEGES ON $dbSql.* TO '$userSql'@'localhost';" 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Applying privilege changes
sudo mysql -e "FLUSH PRIVILEGES;" 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Import a database
{ sudo cat /var/www/torrentpier/install/sql/mysql.sql | sudo mysql --default-character-set=utf8mb4 -u "$userSql" -p"$passSql" "$dbSql"; } 2>&1 | sudo tee -a "$logsInst" > /dev/null
# We set the rights to directories and files
sudo chown -R www-data:www-data /var/www/torrentpier 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo find /var/www/torrentpier -type f -exec chmod 644 {} \; 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo find /var/www/torrentpier -type d -exec chmod 755 {} \; 2>&1 | sudo tee -a "$logsInst" > /dev/null
# Setting the CRON task
{ (sudo crontab -l; echo "* * * * * sudo -u www-data php /var/www/torrentpier/cron.php") | sudo crontab -; } 2>&1 | sudo tee -a "$logsInst" > /dev/null
else
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo "TorrentPier is already installed on the system. The installation cannot continue." | sudo tee -a "$logsInst"
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
read -rp "Press Enter to complete..."
exit 1
fi
# Setting up nginx
if dpkg-query -W -f='${Status}' "nginx" 2>/dev/null | grep -q "install ok installed"; then
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo "NGINX is not configured. The setup in progress..." | sudo tee -a "$logsInst"
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
# We remove the default one and create the TorrentPier config
sudo rm /etc/nginx/sites-enabled/default 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo -e "$nginx_torrentpier" | sudo tee /etc/nginx/sites-available/01-torrentpier.conf 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo ln -s /etc/nginx/sites-available/01-torrentpier.conf /etc/nginx/sites-enabled/ 2>&1 | sudo tee -a "$logsInst" > /dev/null
# We are testing and running the NGINX config
sudo nginx -t 2>&1 | sudo tee -a "$logsInst" > /dev/null
sudo systemctl restart nginx 2>&1 | sudo tee -a "$logsInst" > /dev/null
else
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
echo "NGINX is not installed. The installation cannot continue." | sudo tee -a "$logsInst"
echo "===================================" 2>&1 | sudo tee -a "$logsInst" > /dev/null
read -rp "Press Enter to complete..."
exit 1
fi
echo "" | sudo tee -a "$saveFile"
echo "Woah! TorrentPier successfully installed!" | sudo tee -a "$saveFile"
echo "" | sudo tee -a "$saveFile"
echo "===================================" | sudo tee -a "$saveFile"
echo "TorrentPier credentials:" | sudo tee -a "$saveFile"
echo "-> http://$HOST/" | sudo tee -a "$saveFile"
echo "-> Username: $torrentPierUser" | sudo tee -a "$saveFile"
echo "-> Password: $torrentPierPass" | sudo tee -a "$saveFile"
echo "===================================" | sudo tee -a "$saveFile"
echo "Database credentials:" | sudo tee -a "$saveFile"
echo "-> Database name: $dbSql" | sudo tee -a "$saveFile"
echo "-> Username: $userSql" | sudo tee -a "$saveFile"
echo "-> Password: $passSql" | sudo tee -a "$saveFile"
echo "===================================" | sudo tee -a "$saveFile"
echo "DO NOT USE IT IF YOU DO NOT KNOW WHAT IT IS INTENDED FOR" | sudo tee -a "$saveFile" > /dev/null
echo "phpMyAdmin credentials:" | sudo tee -a "$saveFile" > /dev/null
echo "-> http://$HOST:9090/phpmyadmin" | sudo tee -a "$saveFile" > /dev/null
echo "-> Username: phpmyadmin" | sudo tee -a "$saveFile" > /dev/null
echo "-> Password: $passPma" | sudo tee -a "$saveFile" > /dev/null
echo "===================================" | sudo tee -a "$saveFile" > /dev/null
echo "" | sudo tee -a $saveFile
echo "We are sure that you will be able to create the best tracker available!" | sudo tee -a $saveFile
echo "Good luck!" | sudo tee -a $saveFile
echo "" | sudo tee -a $saveFile
else
echo "Your system is not supported." 2>&1 | tee -a "$logsInst"
fi