-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathinstall.sh
More file actions
2155 lines (1839 loc) · 70.1 KB
/
Copy pathinstall.sh
File metadata and controls
2155 lines (1839 loc) · 70.1 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
VERSION="6.0.0"
# Customer customization: change this block for white-label builds.
APP_NAME="RustMinerSystem"
APP_ID="rustminersystem"
DOWNLOAD_HOST="https://github.com/EvilGenius-dot/RustMinerSystem/raw/main/linux"
CLI_DOWNLOAD_URL="https://github.com/EvilGenius-dot/RustMinerSystem/raw/refs/heads/main/CLI/RustMinerSystemCLI-0.1.0"
SERVICE_NAME="rustservice"
PROCESS_WAIT_INTERVAL="0.1"
PROCESS_WAIT_STEPS_PER_SECOND=10
PROCESS_WAIT_INTERVAL_SUPPORTED=""
PATH_RUST="/root/${APP_ID}"
PATH_EXEC="${APP_ID}"
DOWNLOAD_EXEC_PREFIX="${PATH_EXEC}"
ORIGIN_EXEC="${DOWNLOAD_EXEC_PREFIX}-${VERSION}"
CLI_EXEC_NAME="RustMinerSystemCLI-0.1.0"
CLI_COMMAND_NAME="rustminer"
CLI_LINK_PATH="/usr/local/bin/${CLI_COMMAND_NAME}"
CLI_LAUNCHER_MARKER="Generated by RustMinerSystem install.sh"
CONFIG_FILE_NAME="rust-config"
SYSCTL_TAG="${APP_ID}"
INSTALL_DIR_GUARD="${APP_ID}"
PATH_CONFIG="${PATH_RUST}/${CONFIG_FILE_NAME}"
PATH_NOHUP="${PATH_RUST}/nohup.out"
PATH_ERR="${PATH_RUST}/err.log"
PATH_CUE="${PATH_RUST}/cue"
PATH_D_1="${PATH_RUST}/0.d1"
PATH_D_2="${PATH_RUST}/0.d1-shm"
PATH_D_3="${PATH_RUST}/0.d1-wal"
PATH_CLI="${PATH_RUST}/${CLI_EXEC_NAME}"
PATH_CLI_TMP="${PATH_RUST}/${CLI_EXEC_NAME}.tmp"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
BOLD="\033[1m"
RESET="\033[0m"
# -----------------------------------------------------------------------------
# Language text
# -----------------------------------------------------------------------------
select_language() {
clear
echo "Please select your language / 请选择语言:"
echo "1. English"
echo "2. 中文"
read -p "$(echo -e "[1-2]:")" lang_choice
}
load_language() {
case "$lang_choice" in
1)
prompt_install="1. Install"
prompt_update="2. Update"
prompt_target_version="3. Install version"
prompt_start="4. Start"
prompt_stop="5. Stop"
prompt_restart="6. Restart"
prompt_port="7. Change port"
prompt_ulimit="8. Raise Linux connection limit"
prompt_https="9. HTTPS access"
prompt_enable_web_ui="10. Enable WEB access"
prompt_disable_web_ui="11. Disable WEB access"
prompt_auto_start="12. Enable autostart"
prompt_disable_auto_start="13. Disable autostart"
prompt_service_log="14. View systemd service log"
prompt_status="15. View runtime log"
prompt_error_log="16. View error log"
prompt_clear_log="17. Clear logs"
prompt_web_port="18. View WEB port"
prompt_uninstall="19. Uninstall"
prompt_reset_pwd="20. Reset account password"
prompt_runtime_status="21. View runtime status"
prompt_install_cli="22. Install CLI tool"
prompt_uninstall_cli="23. Uninstall CLI tool"
prompt_control_api="24. Enable/disable API"
prompt_choose_menu="Please choose [1-24]: "
prompt_choose_short="Please choose"
prompt_root_no="Please run this script as root!"
prompt_error_command="Invalid command entered. Please try again."
prompt_set_port="Enter the port number: "
prompt_https_question="Enable HTTPS backend access? After enabling it, the backend must be accessed with https://. After disabling it, use http://."
prompt_https_off="1. Disabled"
prompt_https_on="2. Enabled"
prompt_https_choose="Please choose [1-2]: "
prompt_https_invalid="Invalid input, HTTPS is enabled by default."
prompt_enter_version="Please enter the version number: "
prompt_confirm_uninstall="Type YES to confirm uninstall: "
prompt_confirm_cli_install="Please choose whether to continue CLI installation [1-2]: "
prompt_confirm_cli_uninstall="Type YES to confirm CLI uninstall: "
prompt_confirm_web_ui_change="Please choose whether to continue [1-2]: "
prompt_control_api_question="Enable the control API? RustMinerSystem will restart after this change."
prompt_control_api_off="1. Disable API"
prompt_control_api_on="2. Enable API"
prompt_control_api_choose="Please choose [1-2]: "
menu_group_install="Install & Update"
menu_group_runtime="Runtime Control"
menu_group_settings="Settings"
menu_group_logs="Log Management"
menu_group_maintenance="Maintenance"
menu_group_cli="CLI Tool"
menu_tip="Tip: Linux connection limit changes require a server restart to take effect."
msg_install_start="Start installation: "
msg_disable_firewall="Disable firewall"
msg_unknown_os_firewall="Unknown operating system, failed to disable firewall"
msg_starting="Start program"
msg_already_running="Program is already running, please do not start it again."
msg_start_failed="Program startup failure!!!"
msg_started_title="Program started successfully"
msg_version_label="Version"
msg_backend_url="Backend access URL"
msg_default_username="Default username"
msg_default_password="Default password"
msg_tip_label="Tip"
msg_public_firewall_tip="For public backend access, remember to open the provider firewall."
msg_default_security_tip="If you are using the default password and port, please change the account password and web access port in the web settings."
msg_http_tip="Current backend uses HTTP. Do not access it with HTTPS. To use HTTPS, run this script and choose 9."
msg_https_tip="Current backend uses HTTPS. Do not access it with HTTP. To use HTTP, run this script and choose 9."
msg_delete_config="Delete configuration files"
msg_password_reset_done="Password reset completed, changed to default account/password: qzpm19kkx xloqslz913"
msg_terminating="Terminating process..."
msg_process_not_found="Not found"
msg_process_label="process"
msg_process_terminated="Terminated"
msg_stopping_process="Stopping process"
msg_stop_timeout="Process did not stop within timeout"
msg_enable_autostart="Set up automatic startup"
msg_disable_autostart="Disable automatic startup..."
msg_failed="Failed"
msg_config_missing="Environment variable configuration file not found, creating one now"
msg_config_updated="Updated configuration file"
msg_config_added="Added configuration to file"
msg_config_changed="Configuration changed"
msg_change_limit="Modify system connection limit"
msg_limit_changed_restart="Connection limit has been changed to 65535, please restart the server for the change to take effect"
msg_current_limit="Current connection limit:"
msg_change_done_restart="Modification completed, please restart the server for the change to take effect"
msg_running_detected="Detected running"
msg_must_stop_before_install=", it must be stopped before continuing with the installation."
msg_enter_stop_running="Enter 1 to stop the running"
msg_or_cancel_install="and continue with the installation, enter 2 to cancel the installation."
msg_cancel_install="Cancel installation"
msg_invalid_cancel_install="Invalid input, cancelling installation."
msg_create_dir="Creating directory"
msg_dir_exists="Directory already exists, no need to create it again, continuing with the installation."
msg_downloading="Downloading..."
msg_download_program="Downloading program"
msg_download_source="Download source"
msg_download_target="Save as"
msg_download_complete="Download completed"
msg_uninstall_done="Uninstall completed"
msg_cli_install_start="Installing CLI tool"
msg_cli_download_program="Downloading CLI tool"
msg_cli_main_missing="RustMinerSystem is not installed. Please choose 1 to install RustMinerSystem first, then install the CLI tool."
msg_cli_already_installed="rustminer CLI is already installed."
msg_cli_command_exists="rustminer command already exists and is not managed by this script"
msg_cli_install_done_title="CLI tool installed successfully"
msg_cli_install_done_run="Run rustminer to open the CLI tool. Use rustminer start, rustminer stop, or rustminer restart to control RustMinerSystem."
msg_cli_install_done_path="CLI path"
msg_cli_install_done_link="Command launcher"
msg_cli_install_done_doc="CLI guide/documentation"
msg_cli_install_warning_title="Before installing the CLI tool, RustMinerSystem WEB access must be disabled."
msg_cli_install_warning_detail="After WEB access is disabled, the web page will be unreachable and statistics can only be viewed through the CLI tool. To enable or disable WEB access later, run this install script and choose the WEB access option."
msg_cli_install_continue="1. Continue installation and switch to CLI mode"
msg_cli_install_cancel="2. Cancel"
msg_cli_install_cancelled="CLI installation cancelled."
msg_cli_launching="Opening CLI tool..."
msg_cli_not_installed="rustminer CLI is not installed."
msg_cli_uninstall_done="CLI tool uninstalled"
msg_web_ui_change_notice_title="Changing WEB access will restart RustMinerSystem."
msg_web_ui_change_notice_detail="If WEB access is disabled, the web page will be unreachable; use the rustminer CLI to access statistics. If the CLI is not installed, install it from this script's menu."
msg_web_ui_change_continue="1. Continue and restart RustMinerSystem"
msg_web_ui_change_cancel="2. Cancel"
msg_web_ui_change_cancelled="WEB access change cancelled."
msg_web_ui_enabled="WEB access has been enabled."
msg_web_ui_disabled="WEB access has been disabled."
msg_web_ui_disabled_start_tip="WEB access is disabled. Run rustminer to open the CLI tool, or enable WEB access from this install script."
msg_control_api_enabled="API has been enabled."
msg_control_api_disabled="API has been disabled."
msg_control_api_current_status="Current API status"
msg_control_api_status_enabled="Enabled"
msg_control_api_status_disabled="Disabled"
msg_tail_hint="Press CTRL+C to stop viewing logs"
msg_service_log="Viewing systemd service log"
msg_journalctl_missing="journalctl was not found. This system may not use systemd."
msg_service_status_label="Service status"
msg_status_running="Running"
msg_status_stopped="Not started"
msg_status_abnormal="Abnormal"
msg_status_unavailable="systemd unavailable"
msg_missing_dependency="Missing required command(s)"
msg_missing_downloader="Missing downloader: please install wget or curl."
msg_invalid_port="Invalid port. Please enter a number from 1 to 65535."
msg_port_in_use="Port is already in use, please choose another one."
msg_invalid_version="Invalid version. Use only letters, numbers, dot, dash, or underscore."
msg_uninstall_cancelled="Uninstall cancelled."
msg_invalid_remove_path="Unsafe remove path detected, operation cancelled"
msg_limit_global_done="Global network and file descriptor optimization completed."
msg_limit_reboot_required="Please restart the server for all changes to fully take effect."
msg_limit_sysctl_missing="sysctl was not found, failed to apply network optimization."
msg_clear_logs="Cleaning up logs"
msg_clear_done="Cleanup completed"
msg_current_web_port="Current WEB access port is"
msg_enter_release_version="Enter the published version number to install:"
msg_version_example="Enter the specified version number, for example 3.5.0"
;;
2)
prompt_install="1. 安装"
prompt_update="2. 更新"
prompt_target_version="3. 安装指定版本"
prompt_start="4. 启动软件"
prompt_stop="5. 停止软件"
prompt_restart="6. 重启软件"
prompt_port="7. 修改端口"
prompt_ulimit="8. 解除系统连接数限制"
prompt_https="9. 设置HTTPS访问"
prompt_enable_web_ui="10. 开启WEB访问"
prompt_disable_web_ui="11. 关闭WEB访问"
prompt_auto_start="12. 设置开机启动"
prompt_disable_auto_start="13. 关闭开机启动"
prompt_service_log="14. 查看systemd服务日志"
prompt_status="15. 查看运行日志"
prompt_error_log="16. 查看错误日志"
prompt_clear_log="17. 清理日志"
prompt_web_port="18. 查看WEB端口"
prompt_uninstall="19. 卸载"
prompt_reset_pwd="20. 重置账号密码"
prompt_runtime_status="21. 查看运行状态"
prompt_install_cli="22. 安装命令行工具"
prompt_uninstall_cli="23. 卸载命令行工具"
prompt_control_api="24. 开启/关闭API"
prompt_choose_menu="请选择 [1-24]:"
prompt_choose_short="请选择"
prompt_root_no="请使用root用户运行此脚本!"
prompt_error_command="输入了错误的指令, 请重新输入。"
prompt_set_port="请输入要设置的端口号:"
prompt_https_question="是否开启HTTPS后台访问? 请注意, 开启后后台地址必须使用https://访问, 关闭后必须使用http://访问。"
prompt_https_off="1. 不开启"
prompt_https_on="2. 开启"
prompt_https_choose="请选择 [1-2]:"
prompt_https_invalid="输入错误, 默认开启。"
prompt_enter_version="请输入版本号:"
prompt_confirm_uninstall="请输入 YES 确认卸载:"
prompt_confirm_cli_install="请选择是否继续安装命令行工具 [1-2]:"
prompt_confirm_cli_uninstall="请输入 YES 确认卸载命令行工具:"
prompt_confirm_web_ui_change="请选择是否继续 [1-2]:"
prompt_control_api_question="是否开启控制API?修改后 RustMinerSystem 将自动重启。"
prompt_control_api_off="1. 关闭API"
prompt_control_api_on="2. 开启API"
prompt_control_api_choose="请选择 [1-2]:"
menu_group_install="安装更新"
menu_group_runtime="运行控制"
menu_group_settings="配置设置"
menu_group_logs="日志管理"
menu_group_maintenance="维护操作"
menu_group_cli="命令行工具"
menu_tip="提示:解除系统连接数限制需要重启服务器后生效。"
msg_install_start="开始安装: "
msg_disable_firewall="关闭防火墙"
msg_unknown_os_firewall="未知的操作系统, 关闭防火墙失败"
msg_starting="启动程序"
msg_already_running="程序已经启动,请不要重复启动。"
msg_start_failed="程序启动失败!!!"
msg_started_title="程序启动成功"
msg_version_label="版本号"
msg_backend_url="后台访问地址"
msg_default_username="默认用户名"
msg_default_password="默认密码"
msg_tip_label="提示"
msg_public_firewall_tip="公网访问管理后台, 请记得打开运营商后台防火墙。"
msg_default_security_tip="如果您是默认密码及默认端口, 请及时在网页设置中修改账号密码及web访问端口。"
msg_http_tip="当前后台为HTTP协议访问, 请不要使用HTTPS访问, 如需使用HTTPS, 请运行脚本选择9进行设置。"
msg_https_tip="当前后台为HTTPS协议访问, 请不要使用HTTP访问, 如需使用HTTP, 请运行脚本选择9进行设置。"
msg_delete_config="删除配置文件"
msg_password_reset_done="重置密码完成, 已修改为默认账号密码 qzpm19kkx xloqslz913"
msg_terminating="终止进程..."
msg_process_not_found="未发现"
msg_process_label="进程"
msg_process_terminated="终止"
msg_stopping_process="停止进程"
msg_stop_timeout="进程在等待时间内未停止"
msg_enable_autostart="设置开机启动"
msg_disable_autostart="关闭开机启动..."
msg_failed="失败"
msg_config_missing="未发现环境变量配置文件, 开始创建"
msg_config_updated="已更新配置文件"
msg_config_added="已添加配置到文件"
msg_config_changed="配置已修改"
msg_change_limit="修改系统连接数限制"
msg_limit_changed_restart="连接数限制已修改为65535,重启服务器后生效"
msg_current_limit="当前连接数限制:"
msg_change_done_restart="修改完成, 重启服务器后生效"
msg_running_detected="发现正在运行的"
msg_must_stop_before_install=", 需要停止才可继续安装。"
msg_enter_stop_running="输入1停止正在运行的"
msg_or_cancel_install="并且继续安装, 输入2取消安装。"
msg_cancel_install="取消安装"
msg_invalid_cancel_install="输入错误, 取消安装。"
msg_create_dir="开始创建目录"
msg_dir_exists="目录已存在, 无需重复创建, 继续执行安装。"
msg_downloading="开始下载..."
msg_download_program="下载程序"
msg_download_source="下载地址"
msg_download_target="保存位置"
msg_download_complete="下载完成"
msg_uninstall_done="卸载完成"
msg_cli_install_start="安装命令行工具"
msg_cli_download_program="下载命令行工具"
msg_cli_main_missing="RustMinerSystem 尚未安装,请先选择 1 安装 RustMinerSystem,再安装命令行工具。"
msg_cli_already_installed="rustminer 命令行工具已安装。"
msg_cli_command_exists="rustminer 命令已存在,且不是由此脚本管理"
msg_cli_install_done_title="命令行工具安装成功"
msg_cli_install_done_run="运行 rustminer 命令即可打开命令行工具;运行 rustminer start、rustminer stop、rustminer restart 可启动、停止、重启 RustMinerSystem。"
msg_cli_install_done_path="命令行工具路径"
msg_cli_install_done_link="命令启动脚本"
msg_cli_install_done_doc="命令行工具说明/使用文档"
msg_cli_install_warning_title="安装命令行工具前,需要关闭 RustMinerSystem 的 WEB 访问。"
msg_cli_install_warning_detail="关闭 WEB 访问后,网页将不可达,统计数据仅可通过命令行工具查看。如需再次开启或关闭 WEB 访问,请重新运行安装脚本并选择对应的 WEB 访问功能。"
msg_cli_install_continue="1. 继续安装并切换到命令行模式"
msg_cli_install_cancel="2. 取消"
msg_cli_install_cancelled="已取消安装命令行工具。"
msg_cli_launching="正在打开命令行工具..."
msg_cli_not_installed="rustminer 命令行工具未安装。"
msg_cli_uninstall_done="命令行工具已卸载"
msg_web_ui_change_notice_title="开启或关闭 WEB 访问会重启 RustMinerSystem。"
msg_web_ui_change_notice_detail="关闭 WEB 访问后,网页端将不可访问;可使用 rustminer 命令行工具访问统计数据。如需安装命令行工具,请在本安装脚本菜单中选择安装命令行工具。"
msg_web_ui_change_continue="1. 继续并重启 RustMinerSystem"
msg_web_ui_change_cancel="2. 取消"
msg_web_ui_change_cancelled="已取消修改 WEB 访问。"
msg_web_ui_enabled="WEB 访问已开启。"
msg_web_ui_disabled="WEB 访问已关闭。"
msg_web_ui_disabled_start_tip="当前 WEB 访问已关闭。运行 rustminer 可打开命令行工具,如需网页访问请在安装脚本中开启 WEB 访问。"
msg_control_api_enabled="API 已开启。"
msg_control_api_disabled="API 已关闭。"
msg_control_api_current_status="当前 API 状态"
msg_control_api_status_enabled="已开启"
msg_control_api_status_disabled="未开启"
msg_tail_hint="按 CTRL+C 退出日志查看"
msg_service_log="查看systemd服务日志"
msg_journalctl_missing="未找到journalctl,当前系统可能不是systemd。"
msg_service_status_label="服务状态"
msg_status_running="运行中"
msg_status_stopped="未启动"
msg_status_abnormal="异常"
msg_status_unavailable="systemd不可用"
msg_missing_dependency="缺少必要命令"
msg_missing_downloader="缺少下载工具:请安装 wget 或 curl。"
msg_invalid_port="端口无效,请输入 1 到 65535 之间的数字。"
msg_port_in_use="端口已被占用,请选择其他端口。"
msg_invalid_version="版本号无效,只允许字母、数字、点、横线或下划线。"
msg_uninstall_cancelled="已取消卸载。"
msg_invalid_remove_path="检测到不安全的删除路径,已取消操作"
msg_limit_global_done="全局网络与文件描述符优化已完成。"
msg_limit_reboot_required="请重启服务器,让所有配置完全生效。"
msg_limit_sysctl_missing="未找到sysctl,无法应用网络优化。"
msg_clear_logs="清理日志"
msg_clear_done="清理完成"
msg_current_web_port="当前WEB访问端口"
msg_enter_release_version="输入已发布的版本来进行安装:"
msg_version_example="请输入指定的版本号, 例如 3.5.0"
;;
*)
echo "Invalid language selected / 无效的选择"
exit 1
;;
esac
}
# -----------------------------------------------------------------------------
# Menu and entry helpers
# -----------------------------------------------------------------------------
require_root() {
[ "$(id -u)" != "0" ] && { echo "$prompt_root_no"; exit 1; }
}
is_systemd_available() {
command -v systemctl >/dev/null 2>&1 && [ -d /run/systemd/system ]
}
detect_system() {
OS_ID="unknown"
OS_LIKE=""
OS_NAME="$(uname -s)"
INIT_SYSTEM="unknown"
if [ -r /etc/os-release ]; then
OS_ID=$(sh -c '. /etc/os-release; printf "%s" "${ID:-unknown}"')
OS_LIKE=$(sh -c '. /etc/os-release; printf "%s" "${ID_LIKE:-}"')
OS_NAME=$(sh -c '. /etc/os-release; printf "%s" "${PRETTY_NAME:-${ID:-unknown}}"')
fi
if is_systemd_available; then
INIT_SYSTEM="systemd"
elif command -v rc-service >/dev/null 2>&1 && command -v rc-update >/dev/null 2>&1; then
INIT_SYSTEM="openrc"
elif command -v service >/dev/null 2>&1; then
INIT_SYSTEM="sysv"
fi
}
check_dependencies() {
local missing=""
local cmd
for cmd in pgrep sed grep mkdir chmod touch tail awk find; do
if ! command -v "$cmd" >/dev/null 2>&1; then
missing="${missing} ${cmd}"
fi
done
if [ -n "$missing" ]; then
echo "${msg_missing_dependency}:${missing}"
return 1
fi
if ! command -v wget >/dev/null 2>&1 && ! command -v curl >/dev/null 2>&1; then
echo "$msg_missing_downloader"
return 1
fi
}
download_file() {
local url="$1"
local output="$2"
printf "%s: %s\n" "$msg_download_source" "$url"
printf "%s: %s\n" "$msg_download_target" "$output"
if command -v wget >/dev/null 2>&1; then
if wget --help 2>&1 | grep -q -- "--show-progress"; then
wget --show-progress --progress=bar:force:noscroll "$url" -O "$output"
else
wget "$url" -O "$output"
fi
elif command -v curl >/dev/null 2>&1; then
curl -fL --progress-bar "$url" -o "$output"
else
return 1
fi
local result=$?
if [ "$result" -eq 0 ]; then
echo "$msg_download_complete"
fi
return "$result"
}
is_valid_port() {
local port="$1"
[[ "$port" =~ ^[0-9]+$ ]] && [ "$port" -ge 1 ] && [ "$port" -le 65535 ]
}
is_port_available() {
local port="$1"
if command -v ss >/dev/null 2>&1; then
! ss -ltn "sport = :${port}" 2>/dev/null | grep -q ":${port}"
elif command -v netstat >/dev/null 2>&1; then
! netstat -ltn 2>/dev/null | grep -q "[.:]${port}[[:space:]]"
else
return 0
fi
}
generate_port() {
local port
for _ in {1..20}; do
port=$((RANDOM % 45536 + 20000))
if is_port_available "$port"; then
echo "$port"
return 0
fi
done
echo "63521"
}
is_valid_version() {
local version="$1"
[[ "$version" =~ ^[A-Za-z0-9._-]+$ ]]
}
safe_remove_install_dir() {
if [ -z "$PATH_RUST" ] || [ "$PATH_RUST" = "/" ] || [[ "$PATH_RUST" != *"$INSTALL_DIR_GUARD"* ]]; then
echo "${msg_invalid_remove_path}: $PATH_RUST"
return 1
fi
rm -rf -- "$PATH_RUST"
}
safe_remove_data_file() {
local target="$1"
if [ -n "$target" ] && [[ "$target" == "$PATH_RUST"/* ]]; then
rm -f -- "$target"
fi
}
get_service_status() {
local active_state
if ! is_systemd_available; then
service_status_color="$YELLOW"
service_status_text="$msg_status_unavailable"
return
fi
active_state=$(systemctl is-active "${SERVICE_NAME}.service" 2>/dev/null)
case "$active_state" in
active)
service_status_color="$GREEN"
service_status_text="$msg_status_running"
;;
inactive|unknown|"")
service_status_color="$YELLOW"
service_status_text="$msg_status_stopped"
;;
*)
service_status_color="$RED"
service_status_text="$msg_status_abnormal"
;;
esac
}
print_menu_section() {
local group="$1"
shift
local left
local right
printf "\n%b%s%b\n" "${BOLD}${BLUE}" "$group" "$RESET"
while [ "$#" -gt 0 ]; do
left="$1"
shift
right=""
if [ "$#" -gt 0 ]; then
right="$1"
shift
fi
if [ -n "$right" ]; then
printf " %-34s %s\n" "$left" "$right"
else
printf " %s\n" "$left"
fi
done
}
show_main_menu() {
get_service_status
printf "%b\n" "${BOLD}${BLUE}+----------------------------------------------------------------+${RESET}"
printf "%b %s %s%b\n" "$BOLD" "$APP_NAME" "$VERSION" "$RESET"
printf " %b●%b %s: %b%s%b\n" "$service_status_color" "$RESET" "$msg_service_status_label" "$service_status_color" "$service_status_text" "$RESET"
printf "%b\n" "${BOLD}${BLUE}+----------------------------------------------------------------+${RESET}"
print_menu_section "$menu_group_install" "$prompt_install" "$prompt_update" "$prompt_target_version"
print_menu_section "$menu_group_runtime" "$prompt_start" "$prompt_stop" "$prompt_restart"
print_menu_section "$menu_group_settings" "$prompt_port" "$prompt_ulimit" "$prompt_https" "$prompt_enable_web_ui" "$prompt_disable_web_ui" "$prompt_auto_start" "$prompt_disable_auto_start" "$prompt_control_api"
print_menu_section "$menu_group_logs" "$prompt_service_log" "$prompt_status" "$prompt_error_log" "$prompt_clear_log" "$prompt_web_port"
print_menu_section "$menu_group_maintenance" "$prompt_uninstall" "$prompt_reset_pwd" "$prompt_runtime_status"
print_menu_section "$menu_group_cli" "$prompt_install_cli" "$prompt_uninstall_cli"
printf "\n%b\n" "${BOLD}${BLUE}+----------------------------------------------------------------+${RESET}"
printf "%b%s%b\n" "$YELLOW" "$menu_tip" "$RESET"
}
show_start_success() {
local access_url="$1"
local protocol_tip="$2"
echo ""
echo ""
echo -e "|----------------------------------------------------------------|"
echo -e " ${msg_started_title}, ${msg_version_label}: ${BOLD}${BLUE}${VERSION}${RESET} "
echo -e ""
echo -e "${msg_backend_url}: ${BOLD}${GREEN}${access_url}${RESET}"
echo -e "${msg_default_username}: ${BOLD}${GREEN}qzpm19kkx${RESET}"
echo -e "${msg_default_password}: ${BOLD}${GREEN}xloqslz913${RESET}"
echo -e ""
echo -e "${msg_tip_label}: ${BOLD}${BLUE}${msg_public_firewall_tip}${RESET}"
echo -e "${msg_tip_label}: ${BOLD}${BLUE}${msg_default_security_tip}${RESET}"
echo -e "${msg_tip_label}: ${BOLD}${BLUE}${protocol_tip}${RESET}"
echo "|----------------------------------------------------------------|"
}
show_start_cli_mode_success() {
echo ""
echo ""
echo -e "|----------------------------------------------------------------|"
echo -e " ${msg_started_title}, ${msg_version_label}: ${BOLD}${BLUE}${VERSION}${RESET} "
echo -e ""
echo -e "${msg_tip_label}: ${BOLD}${BLUE}${msg_web_ui_disabled_start_tip}${RESET}"
echo "|----------------------------------------------------------------|"
}
# -----------------------------------------------------------------------------
# Business functions
# -----------------------------------------------------------------------------
update() {
stop
installapp "$VERSION"
}
check_process() {
pgrep -x "$1" >/dev/null 2>&1
}
is_fast_process_wait_supported() {
if [ -n "$PROCESS_WAIT_INTERVAL_SUPPORTED" ]; then
[ "$PROCESS_WAIT_INTERVAL_SUPPORTED" = "1" ]
return
fi
if sleep "$PROCESS_WAIT_INTERVAL" 2>/dev/null; then
PROCESS_WAIT_INTERVAL_SUPPORTED="1"
return 0
fi
PROCESS_WAIT_INTERVAL_SUPPORTED="0"
return 1
}
wait_for_process_started() {
local process_name="$1"
local timeout="${2:-10}"
local interval="1"
local max_attempts="$timeout"
local attempts=0
if check_process "$process_name"; then
return 0
fi
if is_fast_process_wait_supported; then
interval="$PROCESS_WAIT_INTERVAL"
max_attempts=$((timeout * PROCESS_WAIT_STEPS_PER_SECOND))
fi
while [ "$attempts" -lt "$max_attempts" ]; do
if check_process "$process_name"; then
return 0
fi
sleep "$interval"
attempts=$((attempts + 1))
done
return 1
}
wait_for_process_stopped() {
local process_name="$1"
local timeout="${2:-10}"
local interval="1"
local max_attempts="$timeout"
local attempts=0
if ! check_process "$process_name"; then
return 0
fi
if is_fast_process_wait_supported; then
interval="$PROCESS_WAIT_INTERVAL"
max_attempts=$((timeout * PROCESS_WAIT_STEPS_PER_SECOND))
fi
while [ "$attempts" -lt "$max_attempts" ]; do
if ! check_process "$process_name"; then
return 0
fi
sleep "$interval"
attempts=$((attempts + 1))
done
return 1
}
set_port() {
read -p "$(echo -e "$prompt_set_port")" choose
if ! is_valid_port "$choose"; then
echo "$msg_invalid_port"
return 1
fi
if ! is_port_available "$choose"; then
echo "$msg_port_in_use"
return 1
fi
setConfig START_PORT "$choose"
stop
start
}
set_https_admin() {
set_https
stop
start
}
set_web_ui() {
local enabled="$1"
local choose
printf "%b%s%b\n" "$YELLOW" "$msg_web_ui_change_notice_title" "$RESET"
printf "%b%s%b\n" "$YELLOW" "$msg_web_ui_change_notice_detail" "$RESET"
echo "$msg_web_ui_change_continue"
echo "$msg_web_ui_change_cancel"
read -p "$(echo -e "$prompt_confirm_web_ui_change")" choose
case "$choose" in
1)
;;
2)
echo "$msg_web_ui_change_cancelled"
return 1
;;
*)
echo "$msg_invalid_cancel_install"
return 1
;;
esac
stop
setConfig ENABLE_WEB_UI "$enabled"
start
if [ "$enabled" = "1" ]; then
echo "$msg_web_ui_enabled"
else
echo "$msg_web_ui_disabled"
fi
}
enable_web_ui_access() {
set_web_ui 1
}
disable_web_ui_access() {
set_web_ui 0
}
set_control_api() {
local choose
local enabled
local current_status
if [ "$(getConfig "ENABLE_CONTROL_API")" = "1" ]; then
current_status="$msg_control_api_status_enabled"
else
current_status="$msg_control_api_status_disabled"
fi
printf "%s: %s\n" "$msg_control_api_current_status" "$current_status"
echo "$prompt_control_api_question"
echo "$prompt_control_api_off"
echo "$prompt_control_api_on"
read -p "$(echo -e "$prompt_control_api_choose")" choose
case "$choose" in
1)
enabled=0
;;
2)
enabled=1
;;
*)
echo "$prompt_error_command"
return 1
;;
esac
stop
setConfig ENABLE_CONTROL_API "$enabled"
start
if [ "$enabled" = "1" ]; then
echo "$msg_control_api_enabled"
else
echo "$msg_control_api_disabled"
fi
}
set_https() {
echo "$prompt_https_question"
echo "$prompt_https_off"
echo "$prompt_https_on"
read -p "$(echo -e "$prompt_https_choose")" choose
case $choose in
1)
setConfig ENABLE_WEB_TLS 0
;;
2)
setConfig ENABLE_WEB_TLS 1
return
;;
*)
setConfig ENABLE_WEB_TLS 1
echo "$prompt_https_invalid"
return
;;
esac
}
get_ip(){
local IP=""
if command -v curl >/dev/null 2>&1; then
IP=$(curl -fsSL --max-time 2 https://ipv4.icanhazip.com 2>/dev/null | tr -d '[:space:]')
fi
if [ -z "$IP" ] && command -v wget >/dev/null 2>&1; then
IP=$(wget -qO- -t1 -T2 ipv4.icanhazip.com | tr -d '[:space:]')
fi
if [ -z "$IP" ] && command -v ip >/dev/null 2>&1; then
IP=$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i=="src") print $(i+1)}' | head -n 1)
fi
if [ -z "$IP" ] && command -v hostname >/dev/null 2>&1; then
IP=$(hostname -I 2>/dev/null | awk '{print $1}')
fi
echo "$IP"
}
ensure_runtime_files() {
mkdir -p "$PATH_RUST"
chmod 755 "$PATH_RUST"
[ -f "$PATH_NOHUP" ] || touch "$PATH_NOHUP"
[ -f "$PATH_ERR" ] || touch "$PATH_ERR"
chmod 640 "$PATH_NOHUP" "$PATH_ERR"
}
create_systemd_service() {
ensure_runtime_files
cat > "/etc/systemd/system/${SERVICE_NAME}.service" <<EOF
[Unit]
Description=$APP_NAME
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=$PATH_RUST/
ExecStart=/bin/sh -c 'exec "\$1" >> "\$2" 2>> "\$3"' sh "$PATH_RUST/$PATH_EXEC" "$PATH_NOHUP" "$PATH_ERR"
Restart=always
RestartSec=3
LimitNOFILE=65535
TimeoutStopSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
}
remove_service_file() {
if is_systemd_available; then
systemctl disable --now "${SERVICE_NAME}.service" >/dev/null 2>&1
rm -f -- "/etc/systemd/system/${SERVICE_NAME}.service"
systemctl daemon-reload
else
sed -i "/${PATH_EXEC}/d" /etc/rc.local 2>/dev/null || true
fi
}
sysctl_key_path() {
local key="$1"
echo "/proc/sys/${key//./\/}"
}
cleanup_global_network_optimization() {
local keys=(
fs.file-max fs.inotify.max_user_instances
net.ipv4.tcp_congestion_control net.core.default_qdisc
net.ipv4.tcp_fin_timeout net.ipv4.tcp_fastopen net.ipv4.tcp_fastopen_blackhole_timeout_sec
net.ipv4.tcp_max_orphans net.ipv4.tcp_tw_reuse net.ipv4.ip_local_port_range
net.ipv4.tcp_rmem net.ipv4.tcp_wmem net.ipv4.tcp_no_metrics_save
net.ipv4.tcp_mtu_probing net.ipv4.tcp_notsent_lowat
net.ipv4.tcp_syn_retries net.ipv4.tcp_synack_retries
net.ipv4.tcp_keepalive_time net.ipv4.tcp_keepalive_intvl net.ipv4.tcp_keepalive_probes
net.core.somaxconn net.core.rmem_max net.core.wmem_max
net.core.rmem_default net.core.wmem_default
net.core.netdev_max_backlog net.core.netdev_budget
net.ipv4.tcp_max_tw_buckets net.ipv4.tcp_max_syn_backlog net.ipv4.tcp_slow_start_after_idle
vm.swappiness vm.dirty_ratio vm.dirty_background_ratio
)
local files=("/etc/sysctl.conf")
local f
local key
sed -i '/ulimit -SHn/d' /etc/profile 2>/dev/null || true
touch /etc/sysctl.conf
if [ -d /etc/sysctl.d ]; then
while IFS= read -r f; do
[ -f "$f" ] && files+=("$f")
done < <(find /etc/sysctl.d -maxdepth 1 -name "*.conf" 2>/dev/null)
fi
for f in "${files[@]}"; do
[ -f "$f" ] || continue
sed -i "/^# === ${SYSCTL_TAG} network optimization begin ===/,/^# === ${SYSCTL_TAG} network optimization end ===/d" "$f"
for key in "${keys[@]}"; do
sed -i "/^[[:space:]]*${key}[[:space:]]*=/d" "$f"
done
done
rm -f "/etc/sysctl.d/99-${SYSCTL_TAG}-optimize.conf" /etc/sysctl.d/99-tcpmux-optimize.conf 2>/dev/null || true
}
apply_sysctl_setting() {
local key="$1"
local value="$2"
local output_file="$3"
local available
[ -e "$(sysctl_key_path "$key")" ] || return 1
if [ "$key" = "net.ipv4.tcp_congestion_control" ]; then
available=$(sysctl -n net.ipv4.tcp_available_congestion_control 2>/dev/null || true)
[[ "$available" == *"$value"* ]] || return 1
fi
if sysctl -w "${key}=${value}" >/dev/null 2>&1; then
echo "${key} = ${value}" >> "$output_file"
return 0
fi
return 1
}
apply_global_network_optimization() {
local sysctl_file="/etc/sysctl.conf"
local applied_count=0
if ! command -v sysctl >/dev/null 2>&1; then
echo "$msg_limit_sysctl_missing"
return 1
fi
cleanup_global_network_optimization
{
echo ""
echo "# === ${SYSCTL_TAG} network optimization begin ==="
echo "# Generated by install.sh. Menu 8 cleans these keys before writing again."
echo "# File descriptors and TCP backlog"
} >> "$sysctl_file"
apply_sysctl_setting fs.file-max 1048576 "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting fs.inotify.max_user_instances 8192 "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting net.core.default_qdisc fq "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting net.ipv4.tcp_congestion_control bbr "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting net.ipv4.tcp_fastopen 3 "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting net.ipv4.tcp_fastopen_blackhole_timeout_sec 0 "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting net.ipv4.tcp_fin_timeout 15 "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting net.ipv4.tcp_max_orphans 262144 "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting net.ipv4.tcp_tw_reuse 1 "$sysctl_file" && applied_count=$((applied_count + 1))
apply_sysctl_setting net.ipv4.tcp_max_tw_buckets 2000000 "$sysctl_file" && applied_count=$((applied_count + 1))