forked from mahdiMGF2/mirzabot
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
2766 lines (2714 loc) · 121 KB
/
install.sh
File metadata and controls
2766 lines (2714 loc) · 121 KB
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Checking Root Access
if [[ $EUID -ne 0 ]]; then
echo -e "\033[31m[ERROR]\033[0m Please run this script as \033[1mroot\033[0m."
exit 1
fi
# Function to update the script itself automatically
function self_update_script() {
local MASTER_PATH="/root/install.sh"
local BIN_LINK="/usr/local/bin/mirzapro"
local URL="https://raw.githubusercontent.com/mahdiMGF2/mirza_pro/main/install.sh"
local TEMP_FILE="/tmp/mirza_pro_update.sh"
echo -e "\e[33mChecking for updates...\033[0m"
wget -q -O "$TEMP_FILE" "$URL"
if [ -s "$TEMP_FILE" ]; then
if [ -f "$MASTER_PATH" ]; then
LOCAL_HASH=$(md5sum "$MASTER_PATH" | awk '{print $1}')
else
LOCAL_HASH="not_installed"
fi
REMOTE_HASH=$(md5sum "$TEMP_FILE" | awk '{print $1}')
if [ "$LOCAL_HASH" != "$REMOTE_HASH" ]; then
if [ "$LOCAL_HASH" == "not_installed" ]; then
echo -e "\e[32mFirst run detected. Installing script to system...\033[0m"
else
echo -e "\e[32mNew version found! Updating...\033[0m"
fi
mv "$TEMP_FILE" "$MASTER_PATH"
chmod +x "$MASTER_PATH"
rm -f "$BIN_LINK"
ln -s "$MASTER_PATH" "$BIN_LINK"
chmod +x "$BIN_LINK"
echo -e "\e[32mProcess updated. Restarting...\033[0m"
sleep 1
exec bash "$MASTER_PATH" "$@"
else
echo -e "\e[32mScript is up to date.\033[0m"
rm -f "$TEMP_FILE"
if [ ! -f "$BIN_LINK" ]; then
ln -s "$MASTER_PATH" "$BIN_LINK"
chmod +x "$BIN_LINK"
fi
fi
else
echo -e "\e[91mWarning: Could not check for updates (Connection failed).\033[0m"
if [ ! -f "$MASTER_PATH" ]; then
echo -e "\e[91mCritical: Cannot install script for the first time without internet.\033[0m"
exit 1
fi
rm -f "$TEMP_FILE"
fi
}
# Execute the update check immediately upon script start
self_update_script
# Check SSL certificate status and days remaining
check_ssl_status() {
# First get domain from config file
if [ -f "/var/www/html/mirzaprobotconfig/config.php" ]; then
domain=$(grep '^\$domainhosts' "/var/www/html/mirzaprobotconfig/config.php" | cut -d"'" -f2 | cut -d'/' -f1)
if [ -n "$domain" ] && [ -f "/etc/letsencrypt/live/$domain/cert.pem" ]; then
expiry_date=$(openssl x509 -enddate -noout -in "/etc/letsencrypt/live/$domain/cert.pem" | cut -d= -f2)
current_date=$(date +%s)
expiry_timestamp=$(date -d "$expiry_date" +%s)
days_remaining=$(( ($expiry_timestamp - $current_date) / 86400 ))
if [ $days_remaining -gt 0 ]; then
echo -e "\033[32m✅ SSL Certificate: $days_remaining days remaining (Domain: $domain)\033[0m"
else
echo -e "\033[31m❌ SSL Certificate: Expired (Domain: $domain)\033[0m"
fi
else
echo -e "\033[33m⚠️ SSL Certificate: Not found for domain $domain\033[0m"
fi
else
echo -e "\033[33m⚠️ Cannot check SSL: Config file not found\033[0m"
fi
}
# Check bot installation status
check_bot_status() {
if [ -f "/var/www/html/mirzaprobotconfig/config.php" ]; then
echo -e "\033[32m✅ Bot is installed\033[0m"
check_ssl_status
else
echo -e "\033[31m❌ Bot is not installed\033[0m"
fi
}
# Display Logo
function show_logo() {
clear
echo -e "\033[1;34m"
echo "================================================================================="
echo ""
echo "███╗ ███╗██╗██████╗ ███████╗ █████╗ ██████╗ █████╗ ███╗ ██╗███████╗██╗ "
echo "████╗ ████║██║██╔══██╗╚══███╔╝██╔══██╗ ██╔══██╗██╔══██╗████╗ ██║██╔════╝██║ "
echo "██╔████╔██║██║██████╔╝ ███╔╝ ███████║ ██████╔╝███████║██╔██╗ ██║█████╗ ██║ "
echo "██║╚██╔╝██║██║██╔══██╗ ███╔╝ ██╔══██║ ██╔═══╝ ██╔══██║██║╚██╗██║██╔══╝ ██║ "
echo "██║ ╚═╝ ██║██║██║ ██║███████╗██║ ██║ ██║ ██║ ██║██║ ╚████║███████╗█████╗"
echo "╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚════╝"
echo ""
echo "================================================================================="
echo -e "\033[0m"
echo ""
echo -e "\033[1;36m+-------------------+---------------------------------------------------+\033[0m"
echo -e "\033[1;36m| Version |\033[0m \033[33m0.4 (Pro)\033[0m"
echo -e "\033[1;36m+-------------------+---------------------------------------------------+\033[0m"
echo -e "\033[1;36m| Telegram Channel |\033[0m \033[34mhttps://t.me/mirzapanel\033[0m"
echo -e "\033[1;36m+-------------------+---------------------------------------------------+\033[0m"
echo -e "\033[1;36m| Telegram Group |\033[0m \033[34mhttps://t.me/mirzapanelgroup\033[0m"
echo -e "\033[1;36m+-------------------+---------------------------------------------------+\033[0m"
echo ""
echo -e "\033[1;36mInstallation Status:\033[0m"
check_bot_status
echo ""
}
# Display Menu
function show_menu() {
show_logo
echo -e "\033[1;36m1)\033[0m Install MirzaPro Bot"
echo -e "\033[1;36m2)\033[0m Update MirzaPro Bot"
echo -e "\033[1;36m3)\033[0m Remove MirzaPro Bot"
# echo -e "\033[1;36m4)\033[0m Export Database"
# echo -e "\033[1;36m5)\033[0m Import Database"
# echo -e "\033[1;36m6)\033[0m Configure Automated Backup"
# echo -e "\033[1;36m7)\033[0m Renew SSL Certificates"
# echo -e "\033[1;36m8)\033[0m Change Domain"
# echo -e "\033[1;36m9)\033[0m Additional Bot Management"
echo -e "\033[1;36m10)\033[0m Migrate Free to Pro (Beta)"
echo -e "\033[1;36m11)\033[0m Exit"
echo ""
read -p "Select an option [1-10]: " option
case $option in
1) install_bot ;;
2) update_bot ;;
3) remove_bot ;;
# 4) export_database ;;
# 5) import_database ;;
# 6) auto_backup ;;
# 7) renew_ssl ;;
# 8) change_domain ;;
# 9) manage_additional_bots ;;
10) migrate_to_pro ;;
11)
echo -e "\033[32mExiting...\033[0m"
exit 0
;;
*)
echo -e "\033[31mInvalid option. Please try again.\033[0m"
show_menu
;;
esac
}
# Check if Marzban is installed
function check_marzban_installed() {
if [ -f "/opt/marzban/docker-compose.yml" ]; then
return 0 # Marzban installed
else
return 1 # Marzban not installed
fi
}
# Detect database type for Marzban
function detect_database_type() {
COMPOSE_FILE="/opt/marzban/docker-compose.yml"
if [ ! -f "$COMPOSE_FILE" ]; then
echo "unknown" # File not found, cannot determine database type
return 1
fi
if grep -q "^[[:space:]]*mysql:" "$COMPOSE_FILE"; then
echo "mysql"
return 0
elif grep -q "^[[:space:]]*mariadb:" "$COMPOSE_FILE"; then
echo "mariadb"
return 1
else
echo "sqlite" # Assume SQLite if neither MySQL nor MariaDB is found
return 1
fi
}
# Find a free port between 3300 and 3330
function find_free_port() {
for port in {3300..3330}; do
if ! ss -tuln | grep -q ":$port "; then
echo "$port"
return 0
fi
done
echo -e "\033[31m[ERROR] No free port found between 3300 and 3330.\033[0m"
exit 1
}
# Function to fix update issues by changing mirrors
function fix_update_issues() {
echo -e "\e[33mTrying to fix update issues by changing mirrors...\033[0m"
# Backup original sources.list
cp /etc/apt/sources.list /etc/apt/sources.list.backup
# Detect Ubuntu version
if [ -f /etc/os-release ]; then
. /etc/apt/sources.list
VERSION_ID=$(cat /etc/os-release | grep VERSION_ID | cut -d '"' -f2)
UBUNTU_CODENAME=$(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d '=' -f2)
else
echo -e "\e[91mCould not detect Ubuntu version.\033[0m"
return 1
fi
# Try different mirrors
MIRRORS=(
"archive.ubuntu.com"
"us.archive.ubuntu.com"
"fr.archive.ubuntu.com"
"de.archive.ubuntu.com"
"mirrors.digitalocean.com"
"mirrors.linode.com"
)
for mirror in "${MIRRORS[@]}"; do
echo -e "\e[33mTrying mirror: $mirror\033[0m"
# Create new sources.list
cat > /etc/apt/sources.list << EOF
deb http://$mirror/ubuntu/ $UBUNTU_CODENAME main restricted universe multiverse
deb http://$mirror/ubuntu/ $UBUNTU_CODENAME-updates main restricted universe multiverse
deb http://$mirror/ubuntu/ $UBUNTU_CODENAME-security main restricted universe multiverse
EOF
# Try updating
if apt-get update 2>/dev/null; then
echo -e "\e[32mSuccessfully updated using mirror: $mirror\033[0m"
return 0
fi
done
# If all mirrors fail, restore original sources.list
mv /etc/apt/sources.list.backup /etc/apt/sources.list
echo -e "\e[91mAll mirrors failed. Restored original sources.list\033[0m"
return 1
}
# Install Function for Mirza Pro
function install_bot() {
echo -e "\e[32mInstalling Mirza Pro script ... \033[0m\n"
# Check if Marzban is installed and redirect to appropriate function
if check_marzban_installed; then
echo -e "\033[41m[IMPORTANT WARNING]\033[0m \033[1;33mMarzban detected. Proceeding with Marzban-compatible installation.\033[0m"
install_bot_with_marzban "$@" # Pass any arguments (e.g., -v beta)
return 0
fi
# Function to add the Ondřej Surý PPA for PHP
add_php_ppa() {
sudo add-apt-repository -y ppa:ondrej/php || {
echo -e "\e[91mError: Failed to add PPA ondrej/php.\033[0m"
return 1
}
}
# 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 || {
echo -e "\e[91mError: Failed to add PPA ondrej/php with locale override.\033[0m"
return 1
}
}
# 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 ! add_php_ppa_with_locale; then
echo "Failed to add PPA even with locale override. Exiting..."
exit 1
fi
fi
# Try normal update/upgrade first
if ! (sudo apt update && sudo apt upgrade -y); then
echo -e "\e[93mUpdate/upgrade failed. Attempting to fix using alternative mirrors...\033[0m"
if fix_update_issues; then
# Try update/upgrade again after fixing mirrors
if sudo apt update && sudo apt upgrade -y; then
echo -e "\e[92mThe server was successfully updated after fixing mirrors...\033[0m\n"
else
echo -e "\e[91mError: Failed to update even after trying alternative mirrors.\033[0m"
exit 1
fi
else
echo -e "\e[91mError: Failed to update/upgrade packages and mirror fix failed.\033[0m"
exit 1
fi
else
echo -e "\e[92mThe server was successfully updated ...\033[0m\n"
fi
sudo apt-get install software-properties-common || {
echo -e "\e[91mError: Failed to install software-properties-common.\033[0m"
exit 1
}
sudo apt install -y git unzip curl || {
echo -e "\e[91mError: Failed to install required packages.\033[0m"
exit 1
}
DEBIAN_FRONTEND=noninteractive sudo apt install -y php8.2 php8.2-fpm php8.2-mysql || {
echo -e "\e[91mError: Failed to install PHP 8.2 and related packages.\033[0m"
exit 1
}
# List of required packages
PKG=(
lamp-server^
libapache2-mod-php
mysql-server
apache2
php-mbstring
php-zip
php-gd
php-json
php-curl
)
# Installing required packages with error handling
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 -e "\e[91mError installing $i. Exiting...\033[0m"
exit 1
fi
fi
done
echo -e "\n\e[92mPackages Installed, Continuing ...\033[0m\n"
# phpMyAdmin Configuration
echo 'phpmyadmin phpmyadmin/dbconfig-install boolean true' | sudo debconf-set-selections
echo 'phpmyadmin phpmyadmin/app-password-confirm password mirzahipass' | sudo debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/admin-pass password mirzahipass' | sudo debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/app-pass password mirzahipass' | sudo debconf-set-selections
echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | sudo debconf-set-selections
sudo apt-get install phpmyadmin -y || {
echo -e "\e[91mError: Failed to install phpMyAdmin.\033[0m"
exit 1
}
# Check and remove existing phpMyAdmin configuration
if [ -f /etc/apache2/conf-available/phpmyadmin.conf ]; then
sudo rm -f /etc/apache2/conf-available/phpmyadmin.conf && echo -e "\e[92mRemoved existing phpMyAdmin configuration.\033[0m"
fi
# Create symbolic link for phpMyAdmin - will be included in VirtualHost
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf || {
echo -e "\e[91mError: Failed to create symbolic link for phpMyAdmin configuration.\033[0m"
exit 1
}
# Additional package installations with error handling
sudo apt-get install -y php-soap || {
echo -e "\e[91mError: Failed to install php-soap.\033[0m"
exit 1
}
sudo apt-get install libapache2-mod-php || {
echo -e "\e[91mError: Failed to install libapache2-mod-php.\033[0m"
exit 1
}
sudo systemctl enable mysql.service || {
echo -e "\e[91mError: Failed to enable MySQL service.\033[0m"
exit 1
}
sudo systemctl start mysql.service || {
echo -e "\e[91mError: Failed to start MySQL service.\033[0m"
exit 1
}
sudo systemctl enable apache2 || {
echo -e "\e[91mError: Failed to enable Apache2 service.\033[0m"
exit 1
}
sudo systemctl start apache2 || {
echo -e "\e[91mError: Failed to start Apache2 service.\033[0m"
exit 1
}
sudo apt-get install ufw -y || {
echo -e "\e[91mError: Failed to install UFW.\033[0m"
exit 1
}
ufw allow 'Apache' || {
echo -e "\e[91mError: Failed to allow Apache in UFW.\033[0m"
exit 1
}
sudo systemctl restart apache2 || {
echo -e "\e[91mError: Failed to restart Apache2 service after UFW update.\033[0m"
exit 1
}
sudo apt-get install -y git || {
echo -e "\e[91mError: Failed to install Git.\033[0m"
exit 1
}
sudo apt-get install -y wget || {
echo -e "\e[91mError: Failed to install Wget.\033[0m"
exit 1
}
sudo apt-get install -y unzip || {
echo -e "\e[91mError: Failed to install Unzip.\033[0m"
exit 1
}
sudo apt install curl -y || {
echo -e "\e[91mError: Failed to install cURL.\033[0m"
exit 1
}
sudo apt-get install -y php-ssh2 || {
echo -e "\e[91mError: Failed to install php-ssh2.\033[0m"
exit 1
}
sudo apt-get install -y libssh2-1-dev libssh2-1 || {
echo -e "\e[91mError: Failed to install libssh2.\033[0m"
exit 1
}
sudo apt install jq -y || {
echo -e "\e[91mError: Failed to install jq.\033[0m"
exit 1
}
sudo systemctl restart apache2.service || {
echo -e "\e[91mError: Failed to restart Apache2 service.\033[0m"
exit 1
}
# Check and remove existing directory before cloning Git repository
# CHANGED: Folder name to mirzaprobotconfig
BOT_DIR="/var/www/html/mirzaprobotconfig"
if [ -d "$BOT_DIR" ]; then
echo -e "\e[93mDirectory $BOT_DIR already exists. Removing...\033[0m"
sudo rm -rf "$BOT_DIR" || {
echo -e "\e[91mError: Failed to remove existing directory $BOT_DIR.\033[0m"
exit 1
}
fi
# Create bot directory
sudo mkdir -p "$BOT_DIR"
if [ ! -d "$BOT_DIR" ]; then
echo -e "\e[91mError: Failed to create directory $BOT_DIR.\033[0m"
exit 1
fi
# CHANGED: Always download from main branch (No releases for Pro)
ZIP_URL="https://github.com/mahdiMGF2/mirza_pro/archive/refs/heads/main.zip"
echo -e "\033[33mDownloading Mirza Pro from Main Branch...\033[0m"
# Download and extract the repository
TEMP_DIR="/tmp/mirzaprobot"
mkdir -p "$TEMP_DIR"
wget -O "$TEMP_DIR/bot.zip" "$ZIP_URL" || {
echo -e "\e[91mError: Failed to download the specified version.\033[0m"
exit 1
}
unzip "$TEMP_DIR/bot.zip" -d "$TEMP_DIR"
# Find the extracted directory dynamically (usually mirza_pro-main)
EXTRACTED_DIR=$(find "$TEMP_DIR" -mindepth 1 -maxdepth 1 -type d)
mv "$EXTRACTED_DIR"/* "$BOT_DIR" || {
echo -e "\e[91mError: Failed to move extracted files.\033[0m"
exit 1
}
rm -rf "$TEMP_DIR"
sudo chown -R www-data:www-data "$BOT_DIR"
sudo chmod -R 755 "$BOT_DIR"
echo -e "\n\033[33mMirza Pro config and script have been installed successfully.\033[0m"
wait
if [ ! -d "/root/confmirza" ]; then
sudo mkdir /root/confmirza || {
echo -e "\e[91mError: Failed to create /root/confmirza directory.\033[0m"
exit 1
}
sleep 1
touch /root/confmirza/dbrootmirza.txt || {
echo -e "\e[91mError: Failed to create dbrootmirza.txt.\033[0m"
exit 1
}
sudo chmod -R 777 /root/confmirza/dbrootmirza.txt || {
echo -e "\e[91mError: Failed to set permissions for dbrootmirza.txt.\033[0m"
exit 1
}
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 -e "\e[91mError: Failed to alter MySQL user. Attempting recovery...\033[0m"
# Enable skip-grant-tables at the end of the file
sudo sed -i '$ a skip-grant-tables' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo systemctl restart mysql
# Access MySQL to reset the root user
sudo mysql <<EOF
DROP USER IF EXISTS 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY '${passs}';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EOF
# Disable skip-grant-tables
sudo sed -i '/skip-grant-tables/d' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo systemctl restart mysql
# Retry MySQL login with the new credentials
echo "SELECT 1" | mysql -u$userrr -p$passs 2>/dev/null || {
echo -e "\e[91mError: Recovery failed. MySQL login still not working.\033[0m"
exit 1
}
}
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
while [[ ! "$domainname" =~ ^[a-zA-Z0-9.-]+$ ]]; do
echo -e "\e[91mInvalid domain format. Please try again.\033[0m"
read -p "Enter the domain: " domainname
done
DOMAIN_NAME="$domainname"
PATHS=$(cat /root/confmirza/dbrootmirza.txt | grep '$path' | cut -d"'" -f2)
sudo ufw allow 80 || {
echo -e "\e[91mError: Failed to allow port 80 in UFW.\033[0m"
exit 1
}
sudo ufw allow 443 || {
echo -e "\e[91mError: Failed to allow port 443 in UFW.\033[0m"
exit 1
}
echo -e "\033[33mDisable apache2\033[0m"
wait
sudo systemctl stop apache2 || {
echo -e "\e[91mError: Failed to stop Apache2.\033[0m"
exit 1
}
sudo systemctl disable apache2 || {
echo -e "\e[91mError: Failed to disable Apache2.\033[0m"
exit 1
}
sudo apt install letsencrypt -y || {
echo -e "\e[91mError: Failed to install letsencrypt.\033[0m"
exit 1
}
sudo systemctl enable certbot.timer || {
echo -e "\e[91mError: Failed to enable certbot timer.\033[0m"
exit 1
}
sudo certbot certonly --standalone --agree-tos --preferred-challenges http -d $DOMAIN_NAME || {
echo -e "\e[91mError: Failed to generate SSL certificate.\033[0m"
exit 1
}
sudo apt install python3-certbot-apache -y || {
echo -e "\e[91mError: Failed to install python3-certbot-apache.\033[0m"
exit 1
}
sudo certbot --apache --agree-tos --preferred-challenges http -d $DOMAIN_NAME || {
echo -e "\e[91mError: Failed to configure SSL with Certbot.\033[0m"
exit 1
}
echo " "
echo -e "\033[33mEnable apache2\033[0m"
wait
sudo systemctl enable apache2 || {
echo -e "\e[91mError: Failed to enable Apache2.\033[0m"
exit 1
}
sudo systemctl start apache2 || {
echo -e "\e[91mError: Failed to start Apache2.\033[0m"
exit 1
}
# Create Apache VirtualHost configuration for port 80
VHOST_FILE="/etc/apache2/sites-available/${DOMAIN_NAME}.conf"
sudo tee "$VHOST_FILE" > /dev/null <<EOF
<VirtualHost *:80>
ServerName $DOMAIN_NAME
DocumentRoot $BOT_DIR
<Directory $BOT_DIR>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Include phpMyAdmin configuration
Include /etc/apache2/conf-available/phpmyadmin.conf
ErrorLog \${APACHE_LOG_DIR}/${DOMAIN_NAME}-error.log
CustomLog \${APACHE_LOG_DIR}/${DOMAIN_NAME}-access.log combined
</VirtualHost>
EOF
# Create Apache VirtualHost configuration for port 443 (HTTPS)
VHOST_SSL_FILE="/etc/apache2/sites-available/${DOMAIN_NAME}-ssl.conf"
sudo tee "$VHOST_SSL_FILE" > /dev/null <<EOF
<VirtualHost *:443>
ServerName $DOMAIN_NAME
DocumentRoot $BOT_DIR
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/$DOMAIN_NAME/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/$DOMAIN_NAME/privkey.pem
<Directory $BOT_DIR>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Include phpMyAdmin configuration
Include /etc/apache2/conf-available/phpmyadmin.conf
ErrorLog \${APACHE_LOG_DIR}/${DOMAIN_NAME}-error.log
CustomLog \${APACHE_LOG_DIR}/${DOMAIN_NAME}-access.log combined
</VirtualHost>
EOF
# Enable the new virtual hosts
sudo a2ensite "${DOMAIN_NAME}.conf" || {
echo -e "\e[91mError: Failed to enable VirtualHost for port 80.\033[0m"
exit 1
}
sudo a2ensite "${DOMAIN_NAME}-ssl.conf" || {
echo -e "\e[91mError: Failed to enable VirtualHost for port 443.\033[0m"
exit 1
}
# --- FIX: REMOVE DEFAULT APACHE CONFIGS COMPLETELY ---
echo -e "\e[33mRemoving default Apache configurations to prevent conflicts...\033[0m"
# 1. Disable sites
sudo a2dissite 000-default.conf 2>/dev/null || true
sudo a2dissite 000-default-le-ssl.conf 2>/dev/null || true
sudo a2dissite default-ssl.conf 2>/dev/null || true
# 2. Remove symbolic links in sites-enabled (Forceful cleanup)
sudo rm -f /etc/apache2/sites-enabled/000-default.conf
sudo rm -f /etc/apache2/sites-enabled/000-default-le-ssl.conf
sudo rm -f /etc/apache2/sites-enabled/default-ssl.conf
# 3. Remove original files in sites-available (Optional but requested)
# This ensures they can never be enabled again by mistake
sudo rm -f /etc/apache2/sites-available/000-default.conf
sudo rm -f /etc/apache2/sites-available/000-default-le-ssl.conf
sudo rm -f /etc/apache2/sites-available/default-ssl.conf
sleep 3
# Enable SSL module
sudo a2enmod ssl || {
echo -e "\e[91mError: Failed to enable SSL module.\033[0m"
exit 1
}
# Restart Apache to apply new configuration
sudo systemctl restart apache2 || {
echo -e "\e[91mError: Failed to restart Apache2 with new configuration.\033[0m"
exit 1
}
clear
printf "\e[33m[+] \e[36mBot Token: \033[0m"
read YOUR_BOT_TOKEN
while [[ ! "$YOUR_BOT_TOKEN" =~ ^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$ ]]; do
echo -e "\e[91mInvalid bot token format. Please try again.\033[0m"
printf "\e[33m[+] \e[36mBot Token: \033[0m"
read YOUR_BOT_TOKEN
done
printf "\e[33m[+] \e[36mChat id: \033[0m"
read YOUR_CHAT_ID
while [[ ! "$YOUR_CHAT_ID" =~ ^-?[0-9]+$ ]]; do
echo -e "\e[91mInvalid chat ID format. Please try again.\033[0m"
printf "\e[33m[+] \e[36mChat id: \033[0m"
read YOUR_CHAT_ID
done
YOUR_DOMAIN="$DOMAIN_NAME"
while true; do
printf "\e[33m[+] \e[36musernamebot: \033[0m"
read YOUR_BOTNAME
if [ "$YOUR_BOTNAME" != "" ]; then
break
else
echo -e "\e[91mError: Bot username cannot be empty. Please enter a valid username.\033[0m"
fi
done
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 || {
echo -e "\e[91mError: MySQL connection failed.\033[0m"
exit 1
}
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)
# CHANGED: Updated DB name to mirzaprobot to avoid conflict
if [[ $(mysql -u root -p$ROOT_PASSWORD -e "SHOW DATABASES LIKE 'mirzaprobot'") ]]; then
clear
echo -e "\n\e[91mYou have already created the database\033[0m\n"
else
dbname=mirzaprobot
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
# Create Database
mysql -u root -p$ROOT_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $dbname;"
# Create User (Remote Access) with restricted privileges
mysql -u root -p$ROOT_PASSWORD -e "CREATE USER IF NOT EXISTS '$dbuser'@'%' IDENTIFIED WITH mysql_native_password BY '$dbpass'; GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'%'; FLUSH PRIVILEGES;"
# Create User (Local Access) with restricted privileges
mysql -u root -p$ROOT_PASSWORD -e "CREATE USER IF NOT EXISTS '$dbuser'@'localhost' IDENTIFIED WITH mysql_native_password BY '$dbpass'; GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'localhost'; FLUSH PRIVILEGES;" || {
echo -e "\e[91mError: Failed to create database or user.\033[0m"
exit 1
}
echo -e "\n\e[95mDatabase Created.\033[0m"
clear
ASAS="$"
wait
sleep 1
# CHANGED: Path to mirzaprobotconfig
file_path="/var/www/html/mirzaprobotconfig/config.php"
if [ -f "$file_path" ]; then
rm "$file_path" || {
echo -e "\e[91mError: Failed to delete old config.php.\033[0m"
exit 1
}
echo -e "File deleted successfully."
else
echo -e "File not found."
fi
sleep 1
secrettoken=$(openssl rand -base64 10 | tr -dc 'a-zA-Z0-9' | cut -c1-8)
# CHANGED: Generate config.php with new Pro structure
cat <<EOF > /var/www/html/mirzaprobotconfig/config.php
<?php
${ASAS}dbname = '$dbname';
${ASAS}usernamedb = '$dbuser';
${ASAS}passworddb = '$dbpass';
${ASAS}connect = mysqli_connect("localhost", ${ASAS}usernamedb, ${ASAS}passworddb, ${ASAS}dbname);
if (${ASAS}connect->connect_error) { die("error" . ${ASAS}connect->connect_error); }
mysqli_set_charset(${ASAS}connect, "utf8mb4");
${ASAS}options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ];
${ASAS}dsn = "mysql:host=localhost;dbname=${ASAS}dbname;charset=utf8mb4";
try { ${ASAS}pdo = new PDO(${ASAS}dsn, ${ASAS}usernamedb, ${ASAS}passworddb, ${ASAS}options); } catch (\PDOException ${ASAS}e) { error_log("Database connection failed: " . ${ASAS}e->getMessage()); }
${ASAS}APIKEY = '${YOUR_BOT_TOKEN}';
${ASAS}adminnumber = '${YOUR_CHAT_ID}';
${ASAS}domainhosts = '${YOUR_DOMAIN}';
${ASAS}usernamebot = '${YOUR_BOTNAME}';
${ASAS}new_marzban = true;
?>
EOF
sleep 1
# CHANGED: Update URL path in webhook and table setup
curl -F "url=https://${YOUR_DOMAIN}/index.php" \
-F "secret_token=${secrettoken}" \
"https://api.telegram.org/bot${YOUR_BOT_TOKEN}/setWebhook" || {
echo -e "\e[91mError: Failed to set webhook for bot.\033[0m"
exit 1
}
MESSAGE="✅ The Mirza Pro bot is installed! for start the bot send /start command."
curl -s -X POST "https://api.telegram.org/bot${YOUR_BOT_TOKEN}/sendMessage" -d chat_id="${YOUR_CHAT_ID}" -d text="$MESSAGE" || {
echo -e "\e[91mError: Failed to send message to Telegram.\033[0m"
exit 1
}
sleep 3
sudo systemctl start apache2 || {
echo -e "\e[91mError: Failed to start Apache2.\033[0m"
exit 1
}
sleep 5
url="https://${YOUR_DOMAIN}/table.php"
curl -k --max-time 10 $url > /dev/null 2>&1 || {
echo -e "\e[93mWarning: Could not reach URL immediately, but installation may still be successful.\033[0m"
}
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 Pro 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
# Add executable permission and link (This is handled by self_update_script as well, but kept for completeness)
chmod +x /root/install.sh
ln -sf /root/install.sh /usr/local/bin/mirzapro
# Trigger self-update to ensure next run uses latest
self_update_script
}
# function install_bot_with_marzban() {
# # Display warning and confirmation
# echo -e "\033[41m[IMPORTANT WARNING]\033[0m \033[1;33mMarzban panel is detected on your server. Please make sure to backup the Marzban database before installing Mirza Bot.\033[0m"
# read -p "Are you sure you want to install Mirza Bot alongside Marzban? (y/n): " confirm
# if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
# echo -e "\e[91mInstallation aborted by user.\033[0m"
# exit 0
# fi
# # Check database type
# echo -e "\e[32mChecking Marzban database type...\033[0m"
# DB_TYPE=$(detect_database_type)
# if [ "$DB_TYPE" != "mysql" ]; then
# echo -e "\e[91mError: Your database is $DB_TYPE. To install Mirza Bot, you must use MySQL.\033[0m"
# echo -e "\e[93mPlease configure Marzban to use MySQL and try again.\033[0m"
# exit 1
# fi
# echo -e "\e[92mMySQL detected. Proceeding with installation...\033[0m"
# # Check if port 80 is free before proceeding
# echo -e "\e[32mChecking port availability...\033[0m"
# if sudo ss -tuln | grep -q ":80 "; then
# echo -e "\e[91mError: Port 80 is already in use. Please free port 80 and run the script again.\033[0m"
# exit 1
# fi
# if sudo ss -tuln | grep -q ":88 "; then
# echo -e "\e[91mError: Port 88 is already in use. Please free port 88 and run the script again.\033[0m"
# exit 1
# fi
# echo -e "\e[92mPorts 80 and 88 are free. Proceeding with installation...\033[0m"
# # Try normal update/upgrade first
# if ! (sudo apt update && sudo apt upgrade -y); then
# echo -e "\e[93mUpdate/upgrade failed. Attempting to fix using alternative mirrors...\033[0m"
# if fix_update_issues; then
# # Try update/upgrade again after fixing mirrors
# if sudo apt update && sudo apt upgrade -y; then
# echo -e "\e[92mSystem updated successfully after fixing mirrors...\033[0m\n"
# else
# echo -e "\e[91mError: Failed to update even after trying alternative mirrors.\033[0m"
# exit 1
# fi
# else
# echo -e "\e[91mError: Failed to update/upgrade system and mirror fix failed.\033[0m"
# exit 1
# fi
# else
# echo -e "\e[92mSystem updated successfully...\033[0m\n"
# fi
# sudo apt-get install software-properties-common || {
# echo -e "\e[91mError: Failed to install software-properties-common.\033[0m"
# exit 1
# }
# # Install MySQL client if not already installed
# echo -e "\e[32mChecking and installing MySQL client...\033[0m"
# if ! command -v mysql &>/dev/null; then
# sudo apt install -y mysql-client || {
# echo -e "\e[91mError: Failed to install MySQL client. Please install it manually and try again.\033[0m"
# exit 1
# }
# echo -e "\e[92mMySQL client installed successfully.\033[0m"
# else
# echo -e "\e[92mMySQL client is already installed.\033[0m"
# fi
# # Add Ondřej Surý PPA for PHP 8.2
# sudo apt install -y software-properties-common || {
# echo -e "\e[91mError: Failed to install software-properties-common.\033[0m"
# exit 1
# }
# sudo add-apt-repository -y ppa:ondrej/php || {
# echo -e "\e[91mError: Failed to add PPA ondrej/php. Trying with locale override...\033[0m"
# sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php || {
# echo -e "\e[91mError: Failed to add PPA even with locale override.\033[0m"
# exit 1
# }
# }
# sudo apt update || {
# echo -e "\e[91mError: Failed to update package list after adding PPA.\033[0m"
# exit 1
# }
# # Install all required packages
# sudo apt install -y git unzip curl wget jq || {
# echo -e "\e[91mError: Failed to install basic tools.\033[0m"
# exit 1
# }
# # Install Apache if not installed
# if ! dpkg -s apache2 &>/dev/null; then
# sudo apt install -y apache2 || {
# echo -e "\e[91mError: Failed to install Apache2.\033[0m"
# exit 1
# }
# fi
# # Install PHP 8.2 and all necessary modules (including PDO)
# DEBIAN_FRONTEND=noninteractive sudo apt install -y php8.2 php8.2-fpm php8.2-mysql php8.2-mbstring php8.2-zip php8.2-gd php8.2-curl php8.2-soap php8.2-ssh2 libssh2-1-dev libssh2-1 php8.2-pdo || {
# echo -e "\e[91mError: Failed to install PHP 8.2 and modules.\033[0m"
# exit 1
# }
# # Install additional Apache module
# sudo apt install -y libapache2-mod-php8.2 || {
# echo -e "\e[91mError: Failed to install libapache2-mod-php8.2.\033[0m"
# exit 1
# }
# sudo apt install -y python3-certbot-apache || {
# echo -e "\e[91mError: Failed to install Certbot for Apache.\033[0m"
# exit 1
# }
# sudo systemctl enable certbot.timer || {
# echo -e "\e[91mError: Failed to enable certbot timer.\033[0m"
# exit 1
# }
# # Install UFW if not present
# if ! dpkg -s ufw &>/dev/null; then
# sudo apt install -y ufw || {
# echo -e "\e[91mError: Failed to install UFW.\033[0m"
# exit 1
# }
# fi
# # Check Marzban and use its MySQL (Docker-based)
# ENV_FILE="/opt/marzban/.env"
# if [ ! -f "$ENV_FILE" ]; then
# echo -e "\e[91mError: Marzban .env file not found. Cannot proceed without Marzban configuration.\033[0m"
# exit 1
# fi
# # Get MySQL root password from .env
# MYSQL_ROOT_PASSWORD=$(grep "MYSQL_ROOT_PASSWORD=" "$ENV_FILE" | cut -d'=' -f2 | tr -d '[:space:]' | sed 's/"//g')
# ROOT_USER="root"
# # Check if MYSQL_ROOT_PASSWORD is empty or invalid
# if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
# echo -e "\e[93mWarning: Could not retrieve MySQL root password from Marzban .env file.\033[0m"
# read -s -p "Please enter the MySQL root password manually: " MYSQL_ROOT_PASSWORD
# echo
# fi
# # Dynamically find the MySQL container
# MYSQL_CONTAINER=$(docker ps -q --filter "name=mysql" --no-trunc)
# if [ -z "$MYSQL_CONTAINER" ]; then
# echo -e "\e[91mError: Could not find a running MySQL container. Ensure Marzban is running with Docker.\033[0m"
# echo -e "\e[93mRunning containers:\033[0m"
# docker ps
# exit 1
# fi
# echo "Testing MySQL connection..."
# # Read MySQL root password from .env
# if [ -f "/opt/marzban/.env" ]; then
# MYSQL_ROOT_PASSWORD=$(grep -E '^MYSQL_ROOT_PASSWORD=' /opt/marzban/.env | cut -d '=' -f2- | tr -d '" \n\r')
# if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
# echo -e "\e[93mWarning: MYSQL_ROOT_PASSWORD not found in .env. Please enter it manually.\033[0m"
# read -s -p "Enter MySQL root password: " MYSQL_ROOT_PASSWORD
# echo
# fi
# else
# echo -e "\e[93mWarning: .env file not found. Please enter MySQL root password manually.\033[0m"
# read -s -p "Enter MySQL root password: " MYSQL_ROOT_PASSWORD
# echo
# fi
# ROOT_USER="root"
# echo -e "\e[32mUsing MySQL container: $(docker inspect -f '{{.Name}}' "$MYSQL_CONTAINER" | cut -c2-)\033[0m"
# # Try connecting directly to host first (for mysql:latest with network_mode: host)
# mysql -u "$ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" -h 127.0.0.1 -P 3306 -e "SELECT 1;" 2>/tmp/mysql_error.log
# if [ $? -eq 0 ]; then
# echo -e "\e[92mMySQL connection successful (direct host method).\033[0m"
# else
# # If direct connection fails, try inside container (for mysql:lts)
# if [ -n "$MYSQL_CONTAINER" ]; then
# echo -e "\e[93mDirect connection failed, trying inside container...\033[0m"
# docker exec "$MYSQL_CONTAINER" bash -c "echo 'SELECT 1;' | mysql -u '$ROOT_USER' -p'$MYSQL_ROOT_PASSWORD'" 2>/tmp/mysql_error.log
# if [ $? -eq 0 ]; then
# echo -e "\e[92mMySQL connection successful (container method).\033[0m"
# else
# echo -e "\e[91mError: Failed to connect to MySQL using both methods.\033[0m"
# echo -e "\e[93mPassword used: '$MYSQL_ROOT_PASSWORD'\033[0m"
# echo -e "\e[93mError details:\033[0m"
# cat /tmp/mysql_error.log
# echo -e "\e[93mPlease ensure MySQL is running and the root password is correct.\033[0m"
# read -s -p "Enter the correct MySQL root password: " NEW_PASSWORD
# echo
# MYSQL_ROOT_PASSWORD="$NEW_PASSWORD"
# # Retry with new password (direct method first)
# mysql -u "$ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" -h 127.0.0.1 -P 3306 -e "SELECT 1;" 2>/tmp/mysql_error.log || {
# docker exec "$MYSQL_CONTAINER" bash -c "echo 'SELECT 1;' | mysql -u '$ROOT_USER' -p'$MYSQL_ROOT_PASSWORD'" 2>/tmp/mysql_error.log || {
# echo -e "\e[91mError: Still can't connect with new password.\033[0m"
# echo -e "\e[93mError details:\033[0m"
# cat /tmp/mysql_error.log
# exit 1
# }
# }
# echo -e "\e[92mMySQL connection successful with new password.\033[0m"
# fi
# else
# echo -e "\e[91mError: No MySQL container found and direct connection failed.\033[0m"
# echo -e "\e[93mPassword used: '$MYSQL_ROOT_PASSWORD'\033[0m"
# echo -e "\e[93mError details:\033[0m"
# cat /tmp/mysql_error.log
# exit 1
# fi
# fi
# # Ask for database username and password like Marzban
# clear
# echo -e "\e[33mConfiguring Mirza Bot database credentials...\033[0m"
# default_dbuser=$(openssl rand -base64 12 | tr -dc 'a-zA-Z' | head -c8)
# printf "\e[33m[+] \e[36mDatabase username (default: $default_dbuser): \033[0m"
# read dbuser
# if [ -z "$dbuser" ]; then
# dbuser="$default_dbuser"
# fi
# default_dbpass=$(openssl rand -base64 12 | tr -dc 'a-zA-Z0-9' | head -c12)
# printf "\e[33m[+] \e[36mDatabase password (default: $default_dbpass): \033[0m"
# read -s dbpass
# echo
# if [ -z "$dbpass" ]; then
# dbpass="$default_dbpass"
# fi
# dbname="mirzabot"
# # Create database and user inside Docker container
# docker exec "$MYSQL_CONTAINER" bash -c "mysql -u '$ROOT_USER' -p'$MYSQL_ROOT_PASSWORD' -e \"CREATE DATABASE IF NOT EXISTS $dbname; CREATE USER IF NOT EXISTS '$dbuser'@'%' IDENTIFIED BY '$dbpass'; GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'%'; FLUSH PRIVILEGES;\"" || {
# echo -e "\e[91mError: Failed to create database or user in Marzban MySQL container.\033[0m"
# exit 1
# }
# echo -e "\e[92mDatabase '$dbname' created successfully.\033[0m"
# # Bot directory setup
# BOT_DIR="/var/www/html/mirzabotconfig"
# if [ -d "$BOT_DIR" ]; then
# echo -e "\e[93mDirectory $BOT_DIR already exists. Removing...\033[0m"
# sudo rm -rf "$BOT_DIR" || {
# echo -e "\e[91mError: Failed to remove existing directory $BOT_DIR.\033[0m"
# exit 1
# }
# fi
# sudo mkdir -p "$BOT_DIR" || {
# echo -e "\e[91mError: Failed to create directory $BOT_DIR.\033[0m"
# exit 1
# }
# # Download bot files
# ZIP_URL=$(curl -s https://api.github.com/repos/mahdiMGF2/botmirzapanel/releases/latest | grep "zipball_url" | cut -d '"' -f 4)
# if [[ "$1" == "-v" && "$2" == "beta" ]] || [[ "$1" == "-beta" ]] || [[ "$1" == "-" && "$2" == "beta" ]]; then
# ZIP_URL="https://github.com/mahdiMGF2/botmirzapanel/archive/refs/heads/main.zip"