forked from mahdiMGF2/botmirzapanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
305 lines (241 loc) · 10.1 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
#!/bin/bash
if [ "$(id -u)" -ne 0 ]; then
echo -e "\033[33mPlease run as root\033[0m"
exit
fi
wait
# Check if the OS is Ubuntu 22.04
OS=$(lsb_release -si)
VERSION=$(lsb_release -sr)
if [ "$OS" != "Ubuntu" ] || [ "$VERSION" != "22.04" ]; then
echo -e "\033[31mThis script can only be run on Ubuntu 22.04\033[0m"
exit 1
fi
echo -e "\e[32mInstalling mirza script ... \033[0m\n"
# Function to add the Ondřej Surý PPA for PHP
add_php_ppa() {
sudo add-apt-repository -y ppa:ondrej/php
}
# Function to add the Ondřej Surý PPA for PHP with locale override
add_php_ppa_with_locale() {
sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
}
# Try adding the PPA with the system's default locale settings
if ! add_php_ppa; then
echo "Failed to add PPA with default locale, retrying with locale override..."
# If it fails, add the PPA with a locale override
if ! add_php_ppa_with_locale; then
echo "Failed to add PPA even with locale override. Exiting..."
exit 1
fi
fi
sudo apt update && apt upgrade -y
echo -e "\e[92mThe server was successfully updated ...\033[0m\n"
DEBIAN_FRONTEND=noninteractive sudo apt install -y php8.2 php8.2-fpm php8.2-mysql
PKG=(
lamp-server^
libapache2-mod-php
mysql-server
apache2
php-mbstring
php-zip
php-gd
php-json
php-curl
)
for i in "${PKG[@]}"; do
dpkg -s $i &> /dev/null
if [ $? -eq 0 ]; then
echo "$i is already installed"
else
if ! DEBIAN_FRONTEND=noninteractive sudo apt install -y $i; then
echo "Error installing $i. Exiting..."
exit 1
fi
fi
done
echo -e "\n\e[92mPackages Installed Continuing ...\033[0m\n"
echo 'phpmyadmin phpmyadmin/dbconfig-install boolean true' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/app-password-confirm password mirzahipass' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/admin-pass password mirzahipass' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/app-pass password mirzahipass' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | debconf-set-selections
sudo apt-get install phpmyadmin -y
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin.conf
sudo systemctl restart apache2
wait
sudo apt-get install -y php-soap
sudo apt-get install libapache2-mod-php
sudo systemctl enable mysql.service
sudo systemctl start mysql.service
sudo systemctl enable apache2
sudo systemctl start apache2
wait
sudo apt-get install ufw -y
ufw allow 'Apache'
sudo systemctl restart apache2
sudo apt-get install -y git
sudo apt-get install -y wget
sudo apt-get install -y unzip
sudo apt install curl -y
sudo apt-get install -y php-ssh2
sudo apt-get install -y libssh2-1-dev libssh2-1
sudo systemctl restart apache2.service
wait
git clone https://github.com/mahdiMGF2/botmirzapanel.git /var/www/html/mirzabotconfig
sudo chown -R www-data:www-data /var/www/html/mirzabotconfig/
sudo chmod -R 755 /var/www/html/mirzabotconfig/
echo -e "\n\033[33mmirza config and script have been installed successfully\033[0m"
wait
if [ ! -d "/root/confmirza" ]; then
sudo mkdir /root/confmirza
sleep 1
touch /root/confmirza/dbrootmirza.txt
sudo chmod -R 777 /root/confmirza/dbrootmirza.txt
sleep 1
randomdbpasstxt=$(openssl rand -base64 10 | tr -dc 'a-zA-Z0-9' | cut -c1-8)
ASAS="$"
echo "${ASAS}user = 'root';" >> /root/confmirza/dbrootmirza.txt
echo "${ASAS}pass = '${randomdbpasstxt}';" >> /root/confmirza/dbrootmirza.txt
echo "${ASAS}path = '${RANDOM_NUMBER}';" >> /root/confmirza/dbrootmirza.txt
sleep 1
passs=$(cat /root/confmirza/dbrootmirza.txt | grep '$pass' | cut -d"'" -f2)
userrr=$(cat /root/confmirza/dbrootmirza.txt | grep '$user' | cut -d"'" -f2)
sudo mysql -u $userrr -p$passs -e "alter user '$userrr'@'localhost' identified with mysql_native_password by '$passs';FLUSH PRIVILEGES;"
echo "SELECT 1" | mysql -u$userrr -p$passs 2>/dev/null
echo "Folder created successfully!"
else
echo "Folder already exists."
fi
clear
echo " "
echo -e "\e[32m SSL \033[0m\n"
read -p "Enter the domain: " domainname
if [ "$domainname" = "" ]; then
wait
else
# variables
DOMAIN_NAME="$domainname"
PATHS=$(cat /root/confmirza/dbrootmirza.txt | grep '$path' | cut -d"'" -f2)
sudo ufw allow 80
sudo ufw allow 443
echo -e "\033[33mDisable apache2\033[0m"
wait
sudo systemctl stop apache2
sudo systemctl disable apache2
sudo apt install letsencrypt -y
sudo systemctl enable certbot.timer
sudo certbot certonly --standalone --agree-tos --preferred-challenges http -d $DOMAIN_NAME
sudo apt install python3-certbot-apache -y
sudo certbot --apache --agree-tos --preferred-challenges http -d $DOMAIN_NAME
wait
echo " "
echo -e "\033[33mEnable apache2\033[0m"
wait
sudo systemctl enable apache2
sudo systemctl start apache2
ROOT_PASSWORD=$(cat /root/confmirza/dbrootmirza.txt | grep '$pass' | cut -d"'" -f2)
ROOT_USER="root"
echo "SELECT 1" | mysql -u$ROOT_USER -p$ROOT_PASSWORD 2>/dev/null
if [ $? -eq 0 ]; then
wait
randomdbpass=$(openssl rand -base64 10 | tr -dc 'a-zA-Z0-9' | cut -c1-8)
randomdbdb=$(openssl rand -base64 10 | tr -dc 'a-zA-Z' | cut -c1-8)
if [[ $(mysql -u root -p$ROOT_PASSWORD -e "SHOW DATABASES LIKE 'mirzabot'") ]]; then
clear
echo -e "\n\e[91mYou have already created the database\033[0m\n"
else
dbname=mirzabot
clear
echo -e "\n\e[32mPlease enter the database username!\033[0m"
printf "[+] Default user name is \e[91m${randomdbdb}\e[0m ( let it blank to use this user name ): "
read dbuser
if [ "$dbuser" = "" ]; then
dbuser=$randomdbdb
fi
echo -e "\n\e[32mPlease enter the database password!\033[0m"
printf "[+] Default password is \e[91m${randomdbpass}\e[0m ( let it blank to use this password ): "
read dbpass
if [ "$dbpass" = "" ]; then
dbpass=$randomdbpass
fi
mysql -u root -p$ROOT_PASSWORD -e "CREATE DATABASE $dbname;" -e "CREATE USER '$dbuser'@'%' IDENTIFIED WITH mysql_native_password BY '$dbpass';GRANT ALL PRIVILEGES ON * . * TO '$dbuser'@'%';FLUSH PRIVILEGES;" -e "CREATE USER '$dbuser'@'localhost' IDENTIFIED WITH mysql_native_password BY '$dbpass';GRANT ALL PRIVILEGES ON * . * TO '$dbuser'@'localhost';FLUSH PRIVILEGES;"
echo -e "\n\e[95mDatabase Created.\033[0m"
clear
printf "\n\e[33m[+] \e[36mBot Token: \033[0m"
read YOUR_BOT_TOKEN
printf "\e[33m[+] \e[36mChat id: \033[0m"
read YOUR_CHAT_ID
printf "\e[33m[+] \e[36mDomain: \033[0m"
read YOUR_DOMAIN
printf "\e[33m[+] \e[36musernamebot: \033[0m"
read YOUR_BOTNAME
echo " "
if [ "$YOUR_BOT_TOKEN" = "" ] || [ "$YOUR_DOMAIN" = "" ] || [ "$YOUR_CHAT_ID" = "" ] || [ "$YOUR_BOTNAME" = "" ]; then
exit
fi
ASAS="$"
wait
sleep 1
file_path="/var/www/html/mirzabotconfig/config.php"
if [ -f "$file_path" ]; then
rm "$file_path"
echo -e "File deleted successfully."
else
echo -e "File not found."
fi
sleep 1
echo -e "<?php" >> /var/www/html/mirzabotconfig/config.php
echo -e "${ASAS}APIKEY = '${YOUR_BOT_TOKEN}';" >> /var/www/html/mirzabotconfig/config.php
echo -e "${ASAS}usernamedb = '${dbuser}';" >> /var/www/html/mirzabotconfig/config.php
echo -e "${ASAS}passworddb = '${dbpass}';" >> /var/www/html/mirzabotconfig/config.php
echo -e "${ASAS}dbname = '${dbname}';" >> /var/www/html/mirzabotconfig/config.php
echo -e "${ASAS}domainhosts = '${YOUR_DOMAIN}/mirzabotconfig';" >> /var/www/html/mirzabotconfig/config.php
echo -e "${ASAS}adminnumber = '${YOUR_CHAT_ID}';" >> /var/www/html/mirzabotconfig/config.php
echo -e "${ASAS}usernamebot = '${YOUR_BOTNAME}';" >> /var/www/html/mirzabotconfig/config.php
echo -e "${ASAS}connect = mysqli_connect('localhost', \$usernamedb, \$passworddb, \$dbname);" >> /var/www/html/mirzabotconfig/config.php
echo -e "if (${ASAS}connect->connect_error) {" >> /var/www/html/mirzabotconfig/config.php
echo -e "die(' The connection to the database failed:' . ${ASAS}connect->connect_error);" >> /var/www/html/mirzabotconfig/config.php
echo -e "}" >> /var/www/html/mirzabotconfig/config.php
echo -e "mysqli_set_charset(${ASAS}connect, 'utf8mb4');" >> /var/www/html/mirzabotconfig/config.php
text_to_save=$(cat <<EOF
\$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
\$dsn = "mysql:host=localhost;dbname=${ASAS}dbname;charset=utf8mb4";
try {
\$pdo = new PDO(\$dsn, \$usernamedb, \$passworddb, \$options);
} catch (\PDOException \$e) {
throw new \PDOException(\$e->getMessage(), (int)\$e->getCode());
}
EOF
)
echo -e "$text_to_save" >> /var/www/html/mirzabotconfig/config.php
echo -e "?>" >> /var/www/html/mirzabotconfig/config.php
sleep 1
curl -F "url=https://${YOUR_DOMAIN}/mirzabotconfig/index.php" "https://api.telegram.org/bot${YOUR_BOT_TOKEN}/setWebhook"
MESSAGE="✅ The bot is installed! for start bot send comment /start"
curl -s -X POST "https://api.telegram.org/bot${YOUR_BOT_TOKEN}/sendMessage" -d chat_id="${YOUR_CHAT_ID}" -d text="$MESSAGE"
sleep 1
sudo systemctl start apache2
url="https://${YOUR_DOMAIN}/mirzabotconfig/table.php"
curl $url
clear
echo " "
echo -e "\e[102mDomain Bot: https://${YOUR_DOMAIN}\033[0m"
echo -e "\e[104mDatabase address: https://${YOUR_DOMAIN}/phpmyadmin\033[0m"
echo -e "\e[33mDatabase name: \e[36m${dbname}\033[0m"
echo -e "\e[33mDatabase username: \e[36m${dbuser}\033[0m"
echo -e "\e[33mDatabase password: \e[36m${dbpass}\033[0m"
echo " "
echo -e "Mirza Bot"
fi
elif [ "$ROOT_PASSWORD" = "" ] || [ "$ROOT_USER" = "" ]; then
echo -e "\n\e[36mThe password is empty.\033[0m\n"
else
echo -e "\n\e[36mThe password is not correct.\033[0m\n"
fi
fi