-
Notifications
You must be signed in to change notification settings - Fork 17
/
install-server.sh
2683 lines (2468 loc) · 86.5 KB
/
install-server.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
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
textcolor='\033[0;36m'
textcolor_light='\033[1;36m'
red='\033[1;31m'
clear='\033[0m'
check_os() {
if ! grep -q "bullseye" /etc/os-release && ! grep -q "bookworm" /etc/os-release && ! grep -q "jammy" /etc/os-release && ! grep -q "noble" /etc/os-release
then
echo ""
echo -e "${red}Error: only Debian 11/12 and Ubuntu 22.04/24.04 are supported${clear}"
echo ""
exit 1
fi
}
check_root() {
if [[ $EUID -ne 0 ]]
then
echo ""
echo -e "${red}Error: this script should be run as root, use \"sudo -i\" command${clear}"
echo ""
exit 1
fi
}
check_sbmanager() {
if [ -f /usr/local/bin/sbmanager ]
then
echo ""
echo -e "${red}Error: the script has already been run, no need to run it again${clear}"
echo ""
exit 1
fi
}
check_if_updated() {
if [[ "${language}" == "1" ]]
then
echo ""
echo -e "${textcolor}[?]${clear} Вы точно обновили систему и перезагрузили сервер перед запуском скрипта?"
echo "1 - Обновить и перезагрузить"
echo "2 - Продолжить (система была обновлена и перезагружена)"
read systemupdated
else
echo ""
echo -e "${textcolor}[?]${clear} Are you sure you have updated the system and rebooted the server before running the script?"
echo "1 - Update and reboot"
echo "2 - Continue (the system has been updated and rebooted)"
read systemupdated
fi
if [[ "${systemupdated}" == "1" ]]
then
echo ""
apt update && apt full-upgrade -y
sleep 1.5
echo ""
reboot
exit 0
fi
}
get_ip() {
serverip=$(curl -s ipinfo.io/ip)
if [[ ! $serverip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
then
serverip=$(curl -s 2ip.io)
fi
if [[ ! $serverip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
then
serverip=$(curl -s ifconfig.me)
fi
}
banner() {
echo ""
echo ""
echo "╔══╗ ╔═══ ╔══╗ ╦══╗ ╔═══ ══╦══"
echo "║ ║ ║ ║ ║ ║ ║ "
echo "╚══╗ ╠═══ ║ ╠╦═╝ ╠═══ ║ "
echo " ║ ║ ║ ║╚╗ ║ ║ "
echo "╚══╝ ╚═══ ╚══╝ ╩ ╚═ ╚═══ ╩ "
echo ""
echo "╔══╗ ╦ ╦╗ ╦ ╔══╗ ╦══╗ ╔══╗ ═╗ ╔"
echo "║ ║ ║╚╗ ║ ║ ║ ║ ║ ║ ╚╗╔╝"
echo "╚══╗ ║ ║ ║ ║ ║ ═╗ ══ ╠══╣ ║ ║ ╔╬╝ "
echo " ║ ║ ║ ╚╗║ ║ ║ ║ ║ ║ ║ ╔╝╚╗ "
echo "╚══╝ ╩ ╩ ╚╩ ╚══╝ ╩══╝ ╚══╝ ╝ ╚═"
}
enter_language() {
echo ""
echo ""
echo -e "${textcolor}Select the language:${clear}"
echo "1 - Russian"
echo "2 - English"
read language
echo ""
echo ""
}
start_message_ru() {
echo -e "${red}ВНИМАНИЕ!${clear}"
echo "Запускайте скрипт на чистой системе"
echo "Перед запуском скрипта рекомендуется выполнить следующие действия:"
echo -e "1) Обновить систему командой ${textcolor}apt update && apt full-upgrade -y${clear}"
echo -e "2) Перезагрузить сервер командой ${textcolor}reboot${clear}"
echo -e "3) При наличии своего сайта отправить папку с его файлами в ${textcolor}/root${clear} директорию сервера"
echo ""
echo -e "Если это сделано, то нажмите ${textcolor}Enter${clear}, чтобы продолжить"
echo -e "В противном случае нажмите ${textcolor}Ctrl + C${clear} для завершения работы скрипта"
read BigRedButton
}
start_message_en() {
echo -e "${red}ATTENTION!${clear}"
echo "Run the script on a newly installed system"
echo "Before running the script, it's recommended to do the following:"
echo -e "1) Update the system (${textcolor}apt update && apt full-upgrade -y${clear})"
echo -e "2) Reboot the server (${textcolor}reboot${clear})"
echo -e "3) If you have your own website then send the folder with its contents to the ${textcolor}/root${clear} directory of the server"
echo ""
echo -e "If it's done then press ${textcolor}Enter${clear} to continue"
echo -e "If not then press ${textcolor}Ctrl + C${clear} to exit the script"
read BigRedButton
}
start_message() {
if [[ "${language}" == "1" ]]
then
start_message_ru
else
start_message_en
fi
}
crop_domain() {
if [[ "$domain" == "https://"* ]]
then
domain=${domain#"https://"}
fi
if [[ "$domain" == "http://"* ]]
then
domain=${domain#"http://"}
fi
if [[ "$domain" == "www."* ]]
then
domain=${domain#"www."}
fi
if [[ "$domain" =~ "/" ]]
then
domain=$(echo "${domain}" | cut -d "/" -f 1)
fi
}
crop_redirect_domain() {
if [[ "$redirect" == "https://"* ]]
then
redirect=${redirect#"https://"}
fi
if [[ "$redirect" == "http://"* ]]
then
redirect=${redirect#"http://"}
fi
if [[ "$redirect" == "www."* ]]
then
redirect=${redirect#"www."}
fi
if [[ "$redirect" =~ "/" ]]
then
redirect=$(echo "${redirect}" | cut -d "/" -f 1)
fi
}
crop_site_link() {
if [[ "$sitelink" == "https://"* ]]
then
sitelink=${sitelink#"https://"}
fi
}
crop_trojan_path() {
if [[ "$trojanpath" == "/"* ]]
then
trojanpath=${trojanpath#"/"}
fi
}
crop_vless_path() {
if [[ "$vlesspath" == "/"* ]]
then
vlesspath=${vlesspath#"/"}
fi
}
crop_subscription_path() {
if [[ "$subspath" == "/"* ]]
then
subspath=${subspath#"/"}
fi
}
crop_rulesetpath() {
if [[ "$rulesetpath" == "/"* ]]
then
rulesetpath=${rulesetpath#"/"}
fi
}
edit_index() {
if [[ "$index" != "/"* ]]
then
index="/${index}"
fi
if [[ "$index" == *"/" ]]
then
index=${index%"/"}
fi
}
check_ssh_port_ru() {
while [[ ! $sshp =~ ^[0-9]+$ ]] || [ $sshp -eq 443 ] || [ $sshp -eq 10443 ] || [ $sshp -eq 11443 ] || [ $sshp -eq 40000 ] || [ $sshp -gt 65535 ]
do
if [[ ! $sshp =~ ^[0-9]+$ ]]
then
echo -e "${red}Ошибка: введённое значение не является числом${clear}"
elif [ $sshp -eq 443 ] || [ $sshp -eq 10443 ] || [ $sshp -eq 11443 ] || [ $sshp -eq 40000 ]
then
echo -e "${red}Ошибка: порты 443, 10443, 11443 и 40000 будут заняты${clear}"
elif [ $sshp -gt 65535 ]
then
echo -e "${red}Ошибка: номер порта не может быть больше 65535${clear}"
fi
echo ""
echo -e "${textcolor}[?]${clear} Введите новый номер порта SSH или 22 (не рекомендуется):"
read sshp
echo ""
done
}
check_ssh_port_en() {
while [[ ! $sshp =~ ^[0-9]+$ ]] || [ $sshp -eq 443 ] || [ $sshp -eq 10443 ] || [ $sshp -eq 11443 ] || [ $sshp -eq 40000 ] || [ $sshp -gt 65535 ]
do
if [[ ! $sshp =~ ^[0-9]+$ ]]
then
echo -e "${red}Error: this is not a number${clear}"
elif [ $sshp -eq 443 ] || [ $sshp -eq 10443 ] || [ $sshp -eq 11443 ] || [ $sshp -eq 40000 ]
then
echo -e "${red}Error: ports 443, 10443, 11443 and 40000 will be taken${clear}"
elif [ $sshp -gt 65535 ]
then
echo -e "${red}Error: port number can't be greater than 65535${clear}"
fi
echo ""
echo -e "${textcolor}[?]${clear} Enter new SSH port number or 22 (not recommended):"
read sshp
echo ""
done
}
check_username_ru() {
while [[ $username =~ " " ]] || [[ $username =~ '$' ]] || [[ -z $username ]]
do
if [[ $username =~ " " ]] || [[ $username =~ '$' ]]
then
echo -e "${red}Ошибка: имя пользователя не должно содержать пробелы и \$${clear}"
echo ""
elif [[ -z $username ]]
then
:
fi
echo -e "${textcolor}[?]${clear} Введите имя нового пользователя или root (не рекомендуется):"
read username
echo ""
done
}
check_username_en() {
while [[ $username =~ " " ]] || [[ $username =~ '$' ]] || [[ -z $username ]]
do
if [[ $username =~ " " ]] || [[ $username =~ '$' ]]
then
echo -e "${red}Error: username should not contain spaces and \$${clear}"
echo ""
elif [[ -z $username ]]
then
:
fi
echo -e "${textcolor}[?]${clear} Enter your username or root (not recommended):"
read username
echo ""
done
}
check_password_ru() {
while [[ $password =~ " " ]] || [[ -z $password ]]
do
if [[ $password =~ " " ]]
then
echo -e "${red}Ошибка: пароль не должен содержать пробелы${clear}"
echo ""
elif [[ -z $password ]]
then
:
fi
echo -e "${textcolor}[?]${clear} Введите пароль SSH для пользователя:"
read password
echo ""
done
}
check_password_en() {
while [[ $password =~ " " ]] || [[ -z $password ]]
do
if [[ $password =~ " " ]]
then
echo -e "${red}Error: password should not contain spaces${clear}"
echo ""
elif [[ -z $password ]]
then
:
fi
echo -e "${textcolor}[?]${clear} Enter new SSH password:"
read password
echo ""
done
}
get_test_response() {
testdomain=$(echo "${domain}" | rev | cut -d '.' -f 1-2 | rev)
if [[ "$cftoken" =~ [A-Z] ]]
then
test_response=$(curl --silent --request GET --url https://api.cloudflare.com/client/v4/zones --header "Authorization: Bearer ${cftoken}" --header "Content-Type: application/json")
else
test_response=$(curl --silent --request GET --url https://api.cloudflare.com/client/v4/zones --header "X-Auth-Key: ${cftoken}" --header "X-Auth-Email: ${email}" --header "Content-Type: application/json")
fi
}
check_cf_token_ru() {
echo "Проверка домена, API токена/ключа и почты..."
get_test_response
while [[ -z $(echo $test_response | grep "\"${testdomain}\"") ]] || [[ -z $(echo $test_response | grep "\"#dns_records:edit\"") ]] || [[ -z $(echo $test_response | grep "\"#dns_records:read\"") ]] || [[ -z $(echo $test_response | grep "\"#zone:read\"") ]]
do
domain=""
email=""
cftoken=""
echo ""
echo -e "${red}Ошибка: неправильно введён домен, API токен/ключ или почта${clear}"
echo ""
while [[ -z $domain ]]
do
echo -e "${textcolor}[?]${clear} Введите ваш домен:"
read domain
echo ""
done
crop_domain
while [[ -z $email ]]
do
echo -e "${textcolor}[?]${clear} Введите вашу почту, зарегистрированную на Cloudflare:"
read email
echo ""
done
while [[ -z $cftoken ]]
do
echo -e "${textcolor}[?]${clear} Введите ваш API токен Cloudflare (Edit zone DNS) или Cloudflare global API key:"
read cftoken
echo ""
done
echo "Проверка домена, API токена/ключа и почты..."
get_test_response
done
echo "Успешно!"
echo ""
}
check_cf_token_en() {
echo "Checking domain name, API token/key and email..."
get_test_response
while [[ -z $(echo $test_response | grep "\"${testdomain}\"") ]] || [[ -z $(echo $test_response | grep "\"#dns_records:edit\"") ]] || [[ -z $(echo $test_response | grep "\"#dns_records:read\"") ]] || [[ -z $(echo $test_response | grep "\"#zone:read\"") ]]
do
domain=""
email=""
cftoken=""
echo ""
echo -e "${red}Error: invalid domain name, API token/key or email${clear}"
echo ""
while [[ -z $domain ]]
do
echo -e "${textcolor}[?]${clear} Enter your domain name:"
read domain
echo ""
done
crop_domain
while [[ -z $email ]]
do
echo -e "${textcolor}[?]${clear} Enter your email registered on Cloudflare:"
read email
echo ""
done
while [[ -z $cftoken ]]
do
echo -e "${textcolor}[?]${clear} Enter your Cloudflare API token (Edit zone DNS) or Cloudflare global API key:"
read cftoken
echo ""
done
echo "Checking domain name, API token/key and email..."
get_test_response
done
echo "Success!"
echo ""
}
check_uuid_ru() {
while [[ ! $uuid =~ ^\{?[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}\}?$ ]] && [ ! -z "$uuid" ]
do
echo -e "${red}Ошибка: введённое значение не является UUID${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Введите UUID для VLESS или оставьте пустым для генерации случайного UUID:"
read uuid
[[ ! -z $uuid ]] && echo ""
done
}
check_uuid_en() {
while [[ ! $uuid =~ ^\{?[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}\}?$ ]] && [ ! -z "$uuid" ]
do
echo -e "${red}Error: this is not an UUID${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Enter your UUID for VLESS or leave this empty to generate a random UUID:"
read uuid
[[ ! -z $uuid ]] && echo ""
done
}
check_vless_path_ru() {
while [ "$trojanpath" = "$vlesspath" ] && [ ! -z "$vlesspath" ]
do
echo -e "${red}Ошибка: пути для Trojan и VLESS не должны совпадать${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Введите путь для VLESS или оставьте пустым для генерации случайного пути:"
read vlesspath
[[ ! -z $vlesspath ]] && echo ""
crop_vless_path
done
}
check_vless_path_en() {
while [ "$trojanpath" = "$vlesspath" ] && [ ! -z "$vlesspath" ]
do
echo -e "${red}Error: paths for Trojan and VLESS must be different${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Enter your path for VLESS or leave this empty to generate a random path:"
read vlesspath
[[ ! -z $vlesspath ]] && echo ""
crop_vless_path
done
}
check_subscription_path_ru() {
while ([ "$trojanpath" = "$subspath" ] || [ "$vlesspath" = "$subspath" ]) && [ ! -z "$subspath" ]
do
echo -e "${red}Ошибка: пути для Trojan, VLESS и подписки должны быть разными${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Введите путь для подписки или оставьте пустым для генерации случайного пути:"
read subspath
[[ ! -z $subspath ]] && echo ""
crop_subscription_path
done
}
check_subscription_path_en() {
while ([ "$trojanpath" = "$subspath" ] || [ "$vlesspath" = "$subspath" ]) && [ ! -z "$subspath" ]
do
echo -e "${red}Error: paths for Trojan, VLESS and subscription must be different${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Enter your subscription path or leave this empty to generate a random path:"
read subspath
[[ ! -z $subspath ]] && echo ""
crop_subscription_path
done
}
check_rulesetpath_ru() {
while ([ "$trojanpath" = "$rulesetpath" ] || [ "$vlesspath" = "$rulesetpath" ] || [ "$subspath" = "$rulesetpath" ]) && [ ! -z "$rulesetpath" ]
do
echo -e "${red}Ошибка: пути для Trojan, VLESS, подписки и наборов правил должны быть разными${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Введите путь для наборов правил (rule sets) или оставьте пустым для генерации случайного пути:"
read rulesetpath
[[ ! -z $rulesetpath ]] && echo ""
crop_rulesetpath
done
}
check_rulesetpath_en() {
while ([ "$trojanpath" = "$rulesetpath" ] || [ "$vlesspath" = "$rulesetpath" ] || [ "$subspath" = "$rulesetpath" ]) && [ ! -z "$rulesetpath" ]
do
echo -e "${red}Error: paths for Trojan, VLESS, subscription and rule sets must be different${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Enter your path for rule sets or leave this empty to generate a random path:"
read rulesetpath
[[ ! -z $rulesetpath ]] && echo ""
crop_rulesetpath
done
}
check_redirect_domain_ru() {
while [[ "$(curl -s -o /dev/null -w "%{http_code}" https://${redirect}/)" == "000" ]] || [[ -z $redirect ]]
do
if [[ -z $redirect ]]
then
:
else
echo -e "${red}Ошибка: домен введён неправильно или не имеет HTTPS${clear}"
echo ""
fi
echo -e "${textcolor}[?]${clear} Введите домен, на который будет идти перенаправление:"
read redirect
echo ""
crop_redirect_domain
done
}
check_redirect_domain_en() {
while [[ "$(curl -s -o /dev/null -w "%{http_code}" https://${redirect}/)" == "000" ]] || [[ -z $redirect ]]
do
if [[ -z $redirect ]]
then
:
else
echo -e "${red}Error: this domain is invalid or does not have HTTPS${clear}"
echo ""
fi
echo -e "${textcolor}[?]${clear} Enter the domain to which requests will be redirected:"
read redirect
echo ""
crop_redirect_domain
done
}
check_index_ru() {
while [ ! -f /root${index} ] || [ -z "$index" ]
do
echo -e "${red}Ошибка: файл /root${index} не существует${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Введите путь до index файла внутри папки вашего сайта (например, /site_folder/index.html):"
read index
echo ""
edit_index
done
}
check_index_en() {
while [ ! -f /root${index} ] || [ -z "$index" ]
do
echo -e "${red}Error: file /root${index} doesn't exist${clear}"
echo ""
echo -e "${textcolor}[?]${clear} Enter the path to the index file inside the folder of your website (e. g., /site_folder/index.html):"
read index
echo ""
edit_index
done
}
check_site_link_ru() {
while [[ "$(curl -s -o /dev/null -w "%{http_code}" https://${sitelink})" == "000" ]] || [[ -z $sitelink ]] || [ $(wget -q -O /dev/null https://${sitelink}; echo $?) -ne 0 ]
do
if [[ -z $sitelink ]]
then
:
else
echo -e "${red}Ошибка: сайт недоступен по данной ссылке или не имеет HTTPS${clear}"
echo ""
fi
echo -e "${textcolor}[?]${clear} Введите ссылку на главную страницу выбранного сайта:"
read sitelink
echo ""
crop_site_link
done
}
check_site_link_en() {
while [[ "$(curl -s -o /dev/null -w "%{http_code}" https://${sitelink})" == "000" ]] || [[ -z $sitelink ]] || [ $(wget -q -O /dev/null https://${sitelink}; echo $?) -ne 0 ]
do
if [[ -z $sitelink ]]
then
:
else
echo -e "${red}Error: the website is not available or does not have HTTPS${clear}"
echo ""
fi
echo -e "${textcolor}[?]${clear} Enter the link to the main page of the selected website:"
read sitelink
echo ""
crop_site_link
done
}
nginx_login() {
comment1="#"
comment2=""
comment3=""
redirect="${domain}"
sitedir="html"
index="index.html index.htm"
}
nginx_redirect() {
comment1=""
comment2="#"
comment3=""
sitedir="html"
index="index.html index.htm"
if [[ "${language}" == "1" ]]
then
echo -e "${textcolor}[?]${clear} Введите домен, на который будет идти перенаправление:"
read redirect
echo ""
crop_redirect_domain
check_redirect_domain_ru
else
echo -e "${textcolor}[?]${clear} Enter the domain to which requests will be redirected:"
read redirect
echo ""
crop_redirect_domain
check_redirect_domain_en
fi
}
nginx_copy_site() {
comment1=""
comment2=""
comment3="#"
redirect="${domain}"
if [[ "${language}" == "1" ]]
then
echo -e "${red}ВНИМАНИЕ!${clear}"
echo "Некоторые сайты могут содержать большие файлы или большое число страниц, которые могут занять много места на диске"
echo "Функционал некоторых сайтов может быть частично утрачен"
echo "Вы выбираете какой-либо сайт на свой страх и риск"
echo ""
echo -e "${textcolor}[?]${clear} Введите ссылку на главную страницу выбранного сайта:"
read sitelink
echo ""
crop_site_link
check_site_link_ru
else
echo -e "${red}ATTENTION!${clear}"
echo "Some websites might contain large files or large number of pages, which may take a lot of disk space"
echo "Some websites may partially lose their functionality"
echo "You choose the website at your own risk"
echo ""
echo -e "${textcolor}[?]${clear} Enter the link to the main page of the selected website:"
read sitelink
echo ""
crop_site_link
check_site_link_en
fi
}
nginx_site() {
comment1=""
comment2=""
comment3="#"
redirect="${domain}"
if [[ "${language}" == "1" ]]
then
echo -e "${textcolor}[?]${clear} Введите путь до index файла внутри папки вашего сайта (например, /site_folder/index.html):"
read index
echo ""
edit_index
check_index_ru
else
echo -e "${textcolor}[?]${clear} Enter the path to the index file inside the folder of your website (e. g., /site_folder/index.html):"
read index
echo ""
edit_index
check_index_en
fi
}
nginx_options() {
case $option in
2)
nginx_redirect
;;
3)
nginx_copy_site
;;
4)
nginx_site
;;
*)
nginx_login
esac
}
enter_ssh_data_ru() {
if [[ "${sshufw}" != "2" ]]
then
echo -e "${textcolor}[?]${clear} Введите новый номер порта SSH или 22 (рекомендуется номер более 1024):"
read sshp
echo ""
check_ssh_port_ru
echo -e "${textcolor}[?]${clear} Введите имя нового пользователя или root (рекомендуется не root):"
read username
echo ""
check_username_ru
echo -e "${textcolor}[?]${clear} Введите пароль SSH для пользователя (рекомендуется сложный пароль):"
read password
echo ""
check_password_ru
fi
}
enter_ssh_data_en() {
if [[ "${sshufw}" != "2" ]]
then
echo -e "${textcolor}[?]${clear} Enter new SSH port number or 22 (number above 1024 is recommended):"
read sshp
echo ""
check_ssh_port_en
echo -e "${textcolor}[?]${clear} Enter your username or root (non-root user is recommended):"
read username
echo ""
check_username_en
echo -e "${textcolor}[?]${clear} Enter new SSH password (a complex password is recommended):"
read password
echo ""
check_password_en
fi
}
enter_data_ru() {
echo ""
while [[ -z $domain ]]
do
echo -e "${textcolor}[?]${clear} Введите ваш домен:"
read domain
echo ""
done
crop_domain
while [[ -z $email ]]
do
echo -e "${textcolor}[?]${clear} Введите вашу почту, зарегистрированную на Cloudflare:"
read email
echo ""
done
while [[ -z $cftoken ]]
do
echo -e "${textcolor}[?]${clear} Введите ваш API токен Cloudflare (Edit zone DNS) или Cloudflare global API key:"
read cftoken
echo ""
done
check_cf_token_ru
echo -e "${textcolor}[?]${clear} Выберите вариант настройки прокси:"
echo "1 - Терминирование TLS на NGINX, протоколы Trojan и VLESS, транспорт WebSocket или HTTPUpgrade"
echo "2 - Терминирование TLS на HAProxy, протокол Trojan, выбор бэкенда Sing-Box или NGINX по паролю Trojan"
read variant
echo ""
if [[ "${variant}" == "1" ]]
then
echo -e "${textcolor}[?]${clear} Выберите транспорт:"
echo "1 - WebSocket"
echo "2 - HTTPUpgrade"
read transport
echo ""
fi
echo -e "${textcolor}[?]${clear} Выберите вариант настройки NGINX/HAProxy:"
echo "1 - Будет спрашивать логин и пароль вместо сайта"
echo "2 - Будет перенаправлять на другой домен"
echo "3 - Скопировать чужой сайт на свой сервер, тестовая опция"
echo "4 - Свой сайт (при наличии), тестовая опция"
read option;
echo ""
nginx_options
echo -e "${textcolor}[?]${clear} Введите пароль для Trojan или оставьте пустым для генерации случайного пароля:"
read trjpass
[[ ! -z $trjpass ]] && echo ""
if [[ "${variant}" == "1" ]]
then
echo -e "${textcolor}[?]${clear} Введите путь для Trojan или оставьте пустым для генерации случайного пути:"
read trojanpath
[[ ! -z $trojanpath ]] && echo ""
crop_trojan_path
echo -e "${textcolor}[?]${clear} Введите UUID для VLESS или оставьте пустым для генерации случайного UUID:"
read uuid
[[ ! -z $uuid ]] && echo ""
check_uuid_ru
echo -e "${textcolor}[?]${clear} Введите путь для VLESS или оставьте пустым для генерации случайного пути:"
read vlesspath
[[ ! -z $vlesspath ]] && echo ""
crop_vless_path
check_vless_path_ru
fi
echo -e "${textcolor}[?]${clear} Введите путь для подписки или оставьте пустым для генерации случайного пути:"
read subspath
[[ ! -z $subspath ]] && echo ""
crop_subscription_path
check_subscription_path_ru
echo -e "${textcolor}[?]${clear} Введите путь для наборов правил (rule sets) или оставьте пустым для генерации случайного пути:"
read rulesetpath
[[ ! -z $rulesetpath ]] && echo ""
crop_rulesetpath
check_rulesetpath_ru
echo -e "${textcolor}[?]${clear} Нужна ли настройка безопасности (SSH, UFW и unattended-upgrades)?"
echo "1 - Да (в случае нестандартных настроек у хостера или ошибки при вводе данных можно потерять доступ к серверу)"
echo "2 - Нет"
read sshufw
echo ""
enter_ssh_data_ru
}
enter_data_en() {
echo ""
while [[ -z $domain ]]
do
echo -e "${textcolor}[?]${clear} Enter your domain name:"
read domain
echo ""
done
crop_domain
while [[ -z $email ]]
do
echo -e "${textcolor}[?]${clear} Enter your email registered on Cloudflare:"
read email
echo ""
done
while [[ -z $cftoken ]]
do
echo -e "${textcolor}[?]${clear} Enter your Cloudflare API token (Edit zone DNS) or Cloudflare global API key:"
read cftoken
echo ""
done
check_cf_token_en
echo -e "${textcolor}[?]${clear} Select a proxy setup option:"
echo "1 - TLS termination on NGINX, Trojan and VLESS protocols, WebSocket or HTTPUpgrade transport"
echo "2 - TLS termination on HAProxy, Trojan protocol, Sing-Box or NGINX backend selection based on Trojan passwords"
read variant
echo ""
if [[ "${variant}" == "1" ]]
then
echo -e "${textcolor}[?]${clear} Select transport:"
echo "1 - WebSocket"
echo "2 - HTTPUpgrade"
read transport
echo ""
fi
echo -e "${textcolor}[?]${clear} Select NGINX/HAProxy setup option:"
echo "1 - Will show a login popup asking for username and password"
echo "2 - Will redirect to another domain"
echo "3 - Copy someone else's website to your server, experimental option"
echo "4 - Your own website (if you have one), experimental option"
read option;
echo ""
nginx_options
echo -e "${textcolor}[?]${clear} Enter your password for Trojan or leave this empty to generate a random password:"
read trjpass
[[ ! -z $trjpass ]] && echo ""
if [[ "${variant}" == "1" ]]
then
echo -e "${textcolor}[?]${clear} Enter your path for Trojan or leave this empty to generate a random path:"
read trojanpath
[[ ! -z $trojanpath ]] && echo ""
crop_trojan_path
echo -e "${textcolor}[?]${clear} Enter your UUID for VLESS or leave this empty to generate a random UUID:"
read uuid
[[ ! -z $uuid ]] && echo ""
check_uuid_en
echo -e "${textcolor}[?]${clear} Enter your path for VLESS or leave this empty to generate a random path:"
read vlesspath
[[ ! -z $vlesspath ]] && echo ""
crop_vless_path
check_vless_path_en
fi
echo -e "${textcolor}[?]${clear} Enter your subscription path or leave this empty to generate a random path:"
read subspath
[[ ! -z $subspath ]] && echo ""
crop_subscription_path
check_subscription_path_en
echo -e "${textcolor}[?]${clear} Enter your path for rule sets or leave this empty to generate a random path:"
read rulesetpath
[[ ! -z $rulesetpath ]] && echo ""
crop_rulesetpath
check_rulesetpath_en
echo -e "${textcolor}[?]${clear} Do you need security setup (SSH, UFW and unattended-upgrades)?"
echo "1 - Yes (in case of hoster's non-standard settings or a mistake while entering data, access to the server might be lost)"
echo "2 - No"
read sshufw
echo ""
enter_ssh_data_en
}
enter_data() {
if [[ "${language}" == "1" ]]
then
enter_data_ru
else
enter_data_en
fi
echo ""
echo ""
}
enable_bbr() {
echo -e "${textcolor_light}Setting up BBR...${clear}"
if [[ ! "$(sysctl net.core.default_qdisc)" == *"= fq" ]]
then
echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
fi
if [[ ! "$(sysctl net.ipv4.tcp_congestion_control)" == *"bbr" ]]
then
echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
fi
sysctl -p
echo ""
}
install_packages() {
echo -e "${textcolor_light}Installing packages...${clear}"
apt install sudo coreutils wget certbot python3-certbot-dns-cloudflare cron gnupg2 ca-certificates lsb-release openssl sed jq net-tools htop -y
if grep -q "bullseye" /etc/os-release || grep -q "bookworm" /etc/os-release
then
apt install debian-archive-keyring -y
else
apt install ubuntu-keyring -y
fi
if [[ "${sshufw}" != "2" ]]
then
apt install ufw unattended-upgrades -y
fi
if [ ! -d /usr/share/keyrings ]
then
mkdir /usr/share/keyrings
fi
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(grep "VERSION_CODENAME=" /etc/os-release | cut -d "=" -f 2) main" | tee /etc/apt/sources.list.d/cloudflare-client.list
apt-get update && apt-get install cloudflare-warp -y
#wget https://pkg.cloudflareclient.com/pool/$(grep "VERSION_CODENAME=" /etc/os-release | cut -d "=" -f 2)/main/c/cloudflare-warp/cloudflare-warp_2024.6.497-1_amd64.deb
#dpkg -i cloudflare-warp_2024.6.497-1_amd64.deb
#apt-mark hold cloudflare-warp
if [ ! -d /etc/apt/keyrings ]
then
mkdir /etc/apt/keyrings
fi
curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.asc
chmod a+r /etc/apt/keyrings/sagernet.asc
echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/sagernet.asc] https://deb.sagernet.org/ * *" | tee /etc/apt/sources.list.d/sagernet.list > /dev/null
apt-get update
apt-get install sing-box -y
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
if grep -q "bullseye" /etc/os-release || grep -q "bookworm" /etc/os-release
then
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
else
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
fi
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | tee /etc/apt/preferences.d/99nginx
apt update
apt install nginx -y
if [ ! -d /var/www ]
then
mkdir /var/www
fi
if [[ "${variant}" != "1" ]]
then
apt install haproxy -y
fi