-
Notifications
You must be signed in to change notification settings - Fork 269
/
kejilion.sh
5376 lines (4662 loc) · 188 KB
/
kejilion.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
ln -sf ~/kejilion.sh /usr/local/bin/k
ip_address() {
ipv4_address=$(curl -s ipv4.ip.sb)
ipv6_address=$(curl -s --max-time 1 ipv6.ip.sb)
}
install() {
if [ $# -eq 0 ]; then
echo "未提供软件包参数!"
return 1
fi
for package in "$@"; do
if ! command -v "$package" &>/dev/null; then
if command -v apt &>/dev/null; then
apt update -y && apt install -y "$package"
elif command -v yum &>/dev/null; then
yum -y update && yum -y install "$package"
elif command -v apk &>/dev/null; then
apk update && apk add "$package"
else
echo "未知的包管理器!"
return 1
fi
fi
done
return 0
}
install_dependency() {
clear
install wget socat unzip tar
}
remove() {
if [ $# -eq 0 ]; then
echo "未提供软件包参数!"
return 1
fi
for package in "$@"; do
if command -v apt &>/dev/null; then
apt purge -y "$package"
elif command -v yum &>/dev/null; then
yum remove -y "$package"
elif command -v apk &>/dev/null; then
apk del "$package"
else
echo "未知的包管理器!"
return 1
fi
done
return 0
}
break_end() {
echo -e "\033[0;32m操作完成\033[0m"
echo "按任意键继续..."
read -n 1 -s -r -p ""
echo ""
clear
}
kejilion() {
k
exit
}
check_port() {
# 定义要检测的端口
PORT=443
# 检查端口占用情况
result=$(ss -tulpn | grep ":$PORT")
# 判断结果并输出相应信息
if [ -n "$result" ]; then
is_nginx_container=$(docker ps --format '{{.Names}}' | grep 'nginx')
# 判断是否是Nginx容器占用端口
if [ -n "$is_nginx_container" ]; then
echo ""
else
clear
echo -e "\e[1;31m端口 $PORT 已被占用,无法安装环境,卸载以下程序后重试!\e[0m"
echo "$result"
break_end
kejilion
fi
else
echo ""
fi
}
install_add_docker() {
if [ -f "/etc/alpine-release" ]; then
apk update
apk add docker docker-compose
rc-update add docker default
service docker start
else
curl -fsSL https://get.docker.com | sh && ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin
systemctl start docker
systemctl enable docker
fi
}
install_docker() {
if ! command -v docker &>/dev/null; then
install_add_docker
else
echo "Docker 已经安装"
fi
}
iptables_open() {
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
ip6tables -P INPUT ACCEPT
ip6tables -P FORWARD ACCEPT
ip6tables -P OUTPUT ACCEPT
ip6tables -F
}
install_ldnmp() {
cd /home/web && docker-compose up -d
clear
echo "正在配置LDNMP环境,请耐心稍等……"
# 定义要执行的命令
commands=(
"docker exec nginx chmod -R 777 /var/www/html"
"docker restart nginx > /dev/null 2>&1"
"docker exec php apt update > /dev/null 2>&1"
"docker exec php apk update > /dev/null 2>&1"
"docker exec php74 apt update > /dev/null 2>&1"
"docker exec php74 apk update > /dev/null 2>&1"
# php安装包管理
"curl -sL https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o /usr/local/bin/install-php-extensions > /dev/null 2>&1"
"docker exec php mkdir -p /usr/local/bin/ > /dev/null 2>&1"
"docker exec php74 mkdir -p /usr/local/bin/ > /dev/null 2>&1"
"docker cp /usr/local/bin/install-php-extensions php:/usr/local/bin/ > /dev/null 2>&1"
"docker cp /usr/local/bin/install-php-extensions php74:/usr/local/bin/ > /dev/null 2>&1"
"docker exec php chmod +x /usr/local/bin/install-php-extensions > /dev/null 2>&1"
"docker exec php74 chmod +x /usr/local/bin/install-php-extensions > /dev/null 2>&1"
# php安装扩展
"docker exec php install-php-extensions mysqli > /dev/null 2>&1"
"docker exec php install-php-extensions pdo_mysql > /dev/null 2>&1"
"docker exec php install-php-extensions gd intl zip > /dev/null 2>&1"
"docker exec php install-php-extensions exif > /dev/null 2>&1"
"docker exec php install-php-extensions bcmath > /dev/null 2>&1"
"docker exec php install-php-extensions opcache > /dev/null 2>&1"
"docker exec php install-php-extensions imagick redis > /dev/null 2>&1"
# php配置参数
"docker exec php sh -c 'echo \"upload_max_filesize=50M \" > /usr/local/etc/php/conf.d/uploads.ini' > /dev/null 2>&1"
"docker exec php sh -c 'echo \"post_max_size=50M \" > /usr/local/etc/php/conf.d/post.ini' > /dev/null 2>&1"
"docker exec php sh -c 'echo \"memory_limit=256M\" > /usr/local/etc/php/conf.d/memory.ini' > /dev/null 2>&1"
"docker exec php sh -c 'echo \"max_execution_time=1200\" > /usr/local/etc/php/conf.d/max_execution_time.ini' > /dev/null 2>&1"
"docker exec php sh -c 'echo \"max_input_time=600\" > /usr/local/etc/php/conf.d/max_input_time.ini' > /dev/null 2>&1"
# php重启
"docker exec php chmod -R 777 /var/www/html"
"docker restart php > /dev/null 2>&1"
# php7.4安装扩展
"docker exec php74 install-php-extensions mysqli > /dev/null 2>&1"
"docker exec php74 install-php-extensions pdo_mysql > /dev/null 2>&1"
"docker exec php74 install-php-extensions gd intl zip > /dev/null 2>&1"
"docker exec php74 install-php-extensions exif > /dev/null 2>&1"
"docker exec php74 install-php-extensions bcmath > /dev/null 2>&1"
"docker exec php74 install-php-extensions opcache > /dev/null 2>&1"
"docker exec php74 install-php-extensions imagick redis > /dev/null 2>&1"
# php7.4配置参数
"docker exec php74 sh -c 'echo \"upload_max_filesize=50M \" > /usr/local/etc/php/conf.d/uploads.ini' > /dev/null 2>&1"
"docker exec php74 sh -c 'echo \"post_max_size=50M \" > /usr/local/etc/php/conf.d/post.ini' > /dev/null 2>&1"
"docker exec php74 sh -c 'echo \"memory_limit=256M\" > /usr/local/etc/php/conf.d/memory.ini' > /dev/null 2>&1"
"docker exec php74 sh -c 'echo \"max_execution_time=1200\" > /usr/local/etc/php/conf.d/max_execution_time.ini' > /dev/null 2>&1"
"docker exec php74 sh -c 'echo \"max_input_time=600\" > /usr/local/etc/php/conf.d/max_input_time.ini' > /dev/null 2>&1"
# php7.4重启
"docker exec php74 chmod -R 777 /var/www/html"
"docker restart php74 > /dev/null 2>&1"
)
total_commands=${#commands[@]} # 计算总命令数
for ((i = 0; i < total_commands; i++)); do
command="${commands[i]}"
eval $command # 执行命令
# 打印百分比和进度条
percentage=$(( (i + 1) * 100 / total_commands ))
completed=$(( percentage / 2 ))
remaining=$(( 50 - completed ))
progressBar="["
for ((j = 0; j < completed; j++)); do
progressBar+="#"
done
for ((j = 0; j < remaining; j++)); do
progressBar+="."
done
progressBar+="]"
echo -ne "\r[$percentage%] $progressBar"
done
echo # 打印换行,以便输出不被覆盖
clear
echo "LDNMP环境安装完毕"
echo "------------------------"
# 获取nginx版本
nginx_version=$(docker exec nginx nginx -v 2>&1)
nginx_version=$(echo "$nginx_version" | grep -oP "nginx/\K[0-9]+\.[0-9]+\.[0-9]+")
echo -n "nginx : v$nginx_version"
# 获取mysql版本
dbrootpasswd=$(grep -oP 'MYSQL_ROOT_PASSWORD:\s*\K.*' /home/web/docker-compose.yml | tr -d '[:space:]')
mysql_version=$(docker exec mysql mysql -u root -p"$dbrootpasswd" -e "SELECT VERSION();" 2>/dev/null | tail -n 1)
echo -n " mysql : v$mysql_version"
# 获取php版本
php_version=$(docker exec php php -v 2>/dev/null | grep -oP "PHP \K[0-9]+\.[0-9]+\.[0-9]+")
echo -n " php : v$php_version"
# 获取redis版本
redis_version=$(docker exec redis redis-server -v 2>&1 | grep -oP "v=+\K[0-9]+\.[0-9]+")
echo " redis : v$redis_version"
echo "------------------------"
echo ""
}
install_certbot() {
install certbot
# 切换到一个一致的目录(例如,家目录)
cd ~ || exit
# 下载并使脚本可执行
curl -O https://raw.githubusercontent.com/kejilion/sh/main/auto_cert_renewal.sh
chmod +x auto_cert_renewal.sh
# 设置定时任务字符串
cron_job="0 0 * * * ~/auto_cert_renewal.sh"
# 检查是否存在相同的定时任务
existing_cron=$(crontab -l 2>/dev/null | grep -F "$cron_job")
# 如果不存在,则添加定时任务
if [ -z "$existing_cron" ]; then
(crontab -l 2>/dev/null; echo "$cron_job") | crontab -
echo "续签任务已添加"
else
echo "续签任务已存在,无需添加"
fi
}
install_ssltls() {
docker stop nginx > /dev/null 2>&1
iptables_open
cd ~
certbot certonly --standalone -d $yuming --email your@email.com --agree-tos --no-eff-email --force-renewal
cp /etc/letsencrypt/live/$yuming/cert.pem /home/web/certs/${yuming}_cert.pem
cp /etc/letsencrypt/live/$yuming/privkey.pem /home/web/certs/${yuming}_key.pem
docker start nginx > /dev/null 2>&1
}
default_server_ssl() {
install openssl
openssl req -x509 -nodes -newkey rsa:2048 -keyout /home/web/certs/default_server.key -out /home/web/certs/default_server.crt -days 5475 -subj "/C=US/ST=State/L=City/O=Organization/OU=Organizational Unit/CN=Common Name"
}
nginx_status() {
sleep 1
nginx_container_name="nginx"
# 获取容器的状态
container_status=$(docker inspect -f '{{.State.Status}}' "$nginx_container_name" 2>/dev/null)
# 获取容器的重启状态
container_restart_count=$(docker inspect -f '{{.RestartCount}}' "$nginx_container_name" 2>/dev/null)
# 检查容器是否在运行,并且没有处于"Restarting"状态
if [ "$container_status" == "running" ]; then
echo ""
else
rm -r /home/web/html/$yuming >/dev/null 2>&1
rm /home/web/conf.d/$yuming.conf >/dev/null 2>&1
rm /home/web/certs/${yuming}_key.pem >/dev/null 2>&1
rm /home/web/certs/${yuming}_cert.pem >/dev/null 2>&1
docker restart nginx >/dev/null 2>&1
dbrootpasswd=$(grep -oP 'MYSQL_ROOT_PASSWORD:\s*\K.*' /home/web/docker-compose.yml | tr -d '[:space:]')
docker exec mysql mysql -u root -p"$dbrootpasswd" -e "DROP DATABASE $dbname;" 2> /dev/null
echo -e "\e[1;31m检测到域名证书申请失败,请检测域名是否正确解析或更换域名重新尝试!\e[0m"
fi
}
add_yuming() {
ip_address
echo -e "先将域名解析到本机IP: \033[33m$ipv4_address $ipv6_address\033[0m"
read -p "请输入你解析的域名: " yuming
}
add_db() {
dbname=$(echo "$yuming" | sed -e 's/[^A-Za-z0-9]/_/g')
dbname="${dbname}"
dbrootpasswd=$(grep -oP 'MYSQL_ROOT_PASSWORD:\s*\K.*' /home/web/docker-compose.yml | tr -d '[:space:]')
dbuse=$(grep -oP 'MYSQL_USER:\s*\K.*' /home/web/docker-compose.yml | tr -d '[:space:]')
dbusepasswd=$(grep -oP 'MYSQL_PASSWORD:\s*\K.*' /home/web/docker-compose.yml | tr -d '[:space:]')
docker exec mysql mysql -u root -p"$dbrootpasswd" -e "CREATE DATABASE $dbname; GRANT ALL PRIVILEGES ON $dbname.* TO \"$dbuse\"@\"%\";"
}
reverse_proxy() {
ip_address
wget -O /home/web/conf.d/$yuming.conf https://raw.githubusercontent.com/kejilion/nginx/main/reverse-proxy.conf
sed -i "s/yuming.com/$yuming/g" /home/web/conf.d/$yuming.conf
sed -i "s/0.0.0.0/$ipv4_address/g" /home/web/conf.d/$yuming.conf
sed -i "s/0000/$duankou/g" /home/web/conf.d/$yuming.conf
docker restart nginx
}
restart_ldnmp() {
docker exec nginx chmod -R 777 /var/www/html
docker exec php chmod -R 777 /var/www/html
docker exec php74 chmod -R 777 /var/www/html
docker restart nginx
docker restart php
docker restart php74
}
docker_app() {
if docker inspect "$docker_name" &>/dev/null; then
clear
echo "$docker_name 已安装,访问地址: "
ip_address
echo "http:$ipv4_address:$docker_port"
echo ""
echo "应用操作"
echo "------------------------"
echo "1. 更新应用 2. 卸载应用"
echo "------------------------"
echo "0. 返回上一级选单"
echo "------------------------"
read -p "请输入你的选择: " sub_choice
case $sub_choice in
1)
clear
docker rm -f "$docker_name"
docker rmi -f "$docker_img"
$docker_rum
clear
echo "$docker_name 已经安装完成"
echo "------------------------"
# 获取外部 IP 地址
ip_address
echo "您可以使用以下地址访问:"
echo "http:$ipv4_address:$docker_port"
$docker_use
$docker_passwd
;;
2)
clear
docker rm -f "$docker_name"
docker rmi -f "$docker_img"
rm -rf "/home/docker/$docker_name"
echo "应用已卸载"
;;
0)
# 跳出循环,退出菜单
;;
*)
# 跳出循环,退出菜单
;;
esac
else
clear
echo "安装提示"
echo "$docker_describe"
echo "$docker_url"
echo ""
# 提示用户确认安装
read -p "确定安装吗?(Y/N): " choice
case "$choice" in
[Yy])
clear
# 安装 Docker(请确保有 install_docker 函数)
install_docker
$docker_rum
clear
echo "$docker_name 已经安装完成"
echo "------------------------"
# 获取外部 IP 地址
ip_address
echo "您可以使用以下地址访问:"
echo "http:$ipv4_address:$docker_port"
$docker_use
$docker_passwd
;;
[Nn])
# 用户选择不安装
;;
*)
# 无效输入
;;
esac
fi
}
cluster_python3() {
cd ~/cluster/
curl -sS -O https://raw.githubusercontent.com/kejilion/python-for-vps/main/cluster/$py_task
python3 ~/cluster/$py_task
}
tmux_run() {
# Check if the session already exists
tmux has-session -t $SESSION_NAME 2>/dev/null
# $? is a special variable that holds the exit status of the last executed command
if [ $? != 0 ]; then
# Session doesn't exist, create a new one
tmux new -s $SESSION_NAME
else
# Session exists, attach to it
tmux attach-session -t $SESSION_NAME
fi
}
while true; do
clear
echo -e "\033[96m_ _ ____ _ _ _ _ ____ _ _ "
echo "|_/ |___ | | | | | | |\ | "
echo "| \_ |___ _| | |___ | |__| | \| "
echo " "
echo -e "\033[96m科技lion一键脚本工具 v2.3.5 (支持Ubuntu/Debian/CentOS/Alpine系统)\033[0m"
echo -e "\033[96m-输入\033[93mk\033[96m可快速启动此脚本-\033[0m"
echo "------------------------"
echo "1. 系统信息查询"
echo "2. 系统更新"
echo "3. 系统清理"
echo "4. 常用工具 ▶"
echo "5. BBR管理 ▶"
echo "6. Docker管理 ▶ "
echo "7. WARP管理 ▶ "
echo "8. 测试脚本合集 ▶ "
echo "9. 甲骨文云脚本合集 ▶ "
echo -e "\033[33m10. LDNMP建站 ▶ \033[0m"
echo "11. 面板工具 ▶ "
echo "12. 我的工作区 ▶ "
echo "13. 系统工具 ▶ "
echo "14. VPS集群控制 ▶ "
echo "------------------------"
echo "p. 幻兽帕鲁开服脚本 ▶"
echo "------------------------"
echo "00. 脚本更新"
echo "------------------------"
echo "0. 退出脚本"
echo "------------------------"
read -p "请输入你的选择: " choice
case $choice in
1)
clear
# 函数: 获取IPv4和IPv6地址
ip_address
if [ "$(uname -m)" == "x86_64" ]; then
cpu_info=$(cat /proc/cpuinfo | grep 'model name' | uniq | sed -e 's/model name[[:space:]]*: //')
else
cpu_info=$(lscpu | grep 'BIOS Model name' | awk -F': ' '{print $2}' | sed 's/^[ \t]*//')
fi
if [ -f /etc/alpine-release ]; then
# Alpine Linux 使用以下命令获取 CPU 使用率
cpu_usage_percent=$(top -bn1 | grep '^CPU' | awk '{print " "$4}' | cut -c 1-2)
else
# 其他系统使用以下命令获取 CPU 使用率
cpu_usage_percent=$(top -bn1 | grep "Cpu(s)" | awk '{print " "$2}')
fi
cpu_cores=$(nproc)
mem_info=$(free -b | awk 'NR==2{printf "%.2f/%.2f MB (%.2f%%)", $3/1024/1024, $2/1024/1024, $3*100/$2}')
disk_info=$(df -h | awk '$NF=="/"{printf "%s/%s (%s)", $3, $2, $5}')
country=$(curl -s ipinfo.io/country)
city=$(curl -s ipinfo.io/city)
isp_info=$(curl -s ipinfo.io/org)
cpu_arch=$(uname -m)
hostname=$(hostname)
kernel_version=$(uname -r)
congestion_algorithm=$(sysctl -n net.ipv4.tcp_congestion_control)
queue_algorithm=$(sysctl -n net.core.default_qdisc)
# 尝试使用 lsb_release 获取系统信息
os_info=$(lsb_release -ds 2>/dev/null)
# 如果 lsb_release 命令失败,则尝试其他方法
if [ -z "$os_info" ]; then
# 检查常见的发行文件
if [ -f "/etc/os-release" ]; then
os_info=$(source /etc/os-release && echo "$PRETTY_NAME")
elif [ -f "/etc/debian_version" ]; then
os_info="Debian $(cat /etc/debian_version)"
elif [ -f "/etc/redhat-release" ]; then
os_info=$(cat /etc/redhat-release)
else
os_info="Unknown"
fi
fi
output=$(awk 'BEGIN { rx_total = 0; tx_total = 0 }
NR > 2 { rx_total += $2; tx_total += $10 }
END {
rx_units = "Bytes";
tx_units = "Bytes";
if (rx_total > 1024) { rx_total /= 1024; rx_units = "KB"; }
if (rx_total > 1024) { rx_total /= 1024; rx_units = "MB"; }
if (rx_total > 1024) { rx_total /= 1024; rx_units = "GB"; }
if (tx_total > 1024) { tx_total /= 1024; tx_units = "KB"; }
if (tx_total > 1024) { tx_total /= 1024; tx_units = "MB"; }
if (tx_total > 1024) { tx_total /= 1024; tx_units = "GB"; }
printf("总接收: %.2f %s\n总发送: %.2f %s\n", rx_total, rx_units, tx_total, tx_units);
}' /proc/net/dev)
current_time=$(date "+%Y-%m-%d %I:%M %p")
swap_used=$(free -m | awk 'NR==3{print $3}')
swap_total=$(free -m | awk 'NR==3{print $2}')
if [ "$swap_total" -eq 0 ]; then
swap_percentage=0
else
swap_percentage=$((swap_used * 100 / swap_total))
fi
swap_info="${swap_used}MB/${swap_total}MB (${swap_percentage}%)"
runtime=$(cat /proc/uptime | awk -F. '{run_days=int($1 / 86400);run_hours=int(($1 % 86400) / 3600);run_minutes=int(($1 % 3600) / 60); if (run_days > 0) printf("%d天 ", run_days); if (run_hours > 0) printf("%d时 ", run_hours); printf("%d分\n", run_minutes)}')
echo ""
echo "系统信息查询"
echo "------------------------"
echo "主机名: $hostname"
echo "运营商: $isp_info"
echo "------------------------"
echo "系统版本: $os_info"
echo "Linux版本: $kernel_version"
echo "------------------------"
echo "CPU架构: $cpu_arch"
echo "CPU型号: $cpu_info"
echo "CPU核心数: $cpu_cores"
echo "------------------------"
echo "CPU占用: $cpu_usage_percent%"
echo "物理内存: $mem_info"
echo "虚拟内存: $swap_info"
echo "硬盘占用: $disk_info"
echo "------------------------"
echo "$output"
echo "------------------------"
echo "网络拥堵算法: $congestion_algorithm $queue_algorithm"
echo "------------------------"
echo "公网IPv4地址: $ipv4_address"
echo "公网IPv6地址: $ipv6_address"
echo "------------------------"
echo "地理位置: $country $city"
echo "系统时间: $current_time"
echo "------------------------"
echo "系统运行时长: $runtime"
echo
;;
2)
clear
# Update system on Debian-based systems
if [ -f "/etc/debian_version" ]; then
apt update -y && DEBIAN_FRONTEND=noninteractive apt full-upgrade -y
fi
# Update system on Red Hat-based systems
if [ -f "/etc/redhat-release" ]; then
yum -y update
fi
# Update system on Alpine Linux
if [ -f "/etc/alpine-release" ]; then
apk update && apk upgrade
fi
;;
3)
clear
clean_debian() {
apt autoremove --purge -y
apt clean -y
apt autoclean -y
apt remove --purge $(dpkg -l | awk '/^rc/ {print $2}') -y
journalctl --rotate
journalctl --vacuum-time=1s
journalctl --vacuum-size=50M
apt remove --purge $(dpkg -l | awk '/^ii linux-(image|headers)-[^ ]+/{print $2}' | grep -v $(uname -r | sed 's/-.*//') | xargs) -y
}
clean_redhat() {
yum autoremove -y
yum clean all
journalctl --rotate
journalctl --vacuum-time=1s
journalctl --vacuum-size=50M
yum remove $(rpm -q kernel | grep -v $(uname -r)) -y
}
clean_alpine() {
apk del --purge $(apk info --installed | awk '{print $1}' | grep -v $(apk info --available | awk '{print $1}'))
apk autoremove
apk cache clean
rm -rf /var/log/*
rm -rf /var/cache/apk/*
}
# Main script
if [ -f "/etc/debian_version" ]; then
# Debian-based systems
clean_debian
elif [ -f "/etc/redhat-release" ]; then
# Red Hat-based systems
clean_redhat
elif [ -f "/etc/alpine-release" ]; then
# Alpine Linux
clean_alpine
fi
;;
4)
while true; do
clear
echo "▶ 安装常用工具"
echo "------------------------"
echo "1. curl 下载工具"
echo "2. wget 下载工具"
echo "3. sudo 超级管理权限工具"
echo "4. socat 通信连接工具 (申请域名证书必备)"
echo "5. htop 系统监控工具"
echo "6. iftop 网络流量监控工具"
echo "7. unzip ZIP压缩解压工具"
echo "8. tar GZ压缩解压工具"
echo "9. tmux 多路后台运行工具"
echo "10. ffmpeg 视频编码直播推流工具"
echo "11. btop 现代化监控工具"
echo "12. ranger 文件管理工具"
echo "13. gdu 磁盘占用查看工具"
echo "14. fzf 全局搜索工具"
echo "------------------------"
echo "21. cmatrix 黑客帝国屏保"
echo -e "22. sl 跑火车屏保 \033[33mNEW\033[0m"
echo "------------------------"
echo -e "26. 俄罗斯方块小游戏 \033[33mNEW\033[0m"
echo -e "27. 贪吃蛇小游戏 \033[33mNEW\033[0m"
echo -e "28. 太空入侵者小游戏 \033[33mNEW\033[0m"
echo "------------------------"
echo "31. 全部安装"
echo "32. 全部卸载"
echo "------------------------"
echo "41. 安装指定工具"
echo "42. 卸载指定工具"
echo "------------------------"
echo "0. 返回主菜单"
echo "------------------------"
read -p "请输入你的选择: " sub_choice
case $sub_choice in
1)
clear
install curl
clear
echo "工具已安装,使用方法如下:"
curl --help
;;
2)
clear
install wget
clear
echo "工具已安装,使用方法如下:"
wget --help
;;
3)
clear
install sudo
clear
echo "工具已安装,使用方法如下:"
sudo --help
;;
4)
clear
install socat
clear
echo "工具已安装,使用方法如下:"
socat -h
;;
5)
clear
install htop
clear
htop
;;
6)
clear
install iftop
clear
iftop
;;
7)
clear
install unzip
clear
echo "工具已安装,使用方法如下:"
unzip
;;
8)
clear
install tar
clear
echo "工具已安装,使用方法如下:"
tar --help
;;
9)
clear
install tmux
clear
echo "工具已安装,使用方法如下:"
tmux --help
;;
10)
clear
install ffmpeg
clear
echo "工具已安装,使用方法如下:"
ffmpeg --help
;;
11)
clear
install btop
clear
btop
;;
12)
clear
install ranger
cd /
clear
ranger
cd ~
;;
13)
clear
install gdu
cd /
clear
gdu
cd ~
;;
14)
clear
install fzf
cd /
clear
fzf
cd ~
;;
21)
clear
install cmatrix
clear
cmatrix
;;
22)
clear
install sl
clear
/usr/games/sl
;;
26)
clear
install bastet
clear
/usr/games/bastet
;;
27)
clear
install nsnake
clear
/usr/games/nsnake
;;
28)
clear
install ninvaders
clear
/usr/games/ninvaders
;;
31)
clear
install curl wget sudo socat htop iftop unzip tar tmux ffmpeg btop ranger gdu fzf cmatrix sl bastet nsnake ninvaders
;;
32)
clear
remove htop iftop unzip tmux ffmpeg btop ranger gdu fzf cmatrix sl bastet nsnake ninvaders
;;
41)
clear
read -p "请输入安装的工具名(wget curl sudo htop): " installname
install $installname
;;
42)
clear
read -p "请输入卸载的工具名(htop ufw tmux cmatrix): " removename
remove $removename
;;
0)
kejilion
;;
*)
echo "无效的输入!"
;;
esac
break_end
done
;;
5)
clear
if [ -f "/etc/alpine-release" ]; then
while true; do
clear
congestion_algorithm=$(sysctl -n net.ipv4.tcp_congestion_control)
queue_algorithm=$(sysctl -n net.core.default_qdisc)
echo "当前TCP阻塞算法: $congestion_algorithm $queue_algorithm"
echo ""
echo "BBR管理"
echo "------------------------"
echo "1. 开启BBRv3 2. 关闭BBRv3(会重启)"
echo "------------------------"
echo "0. 返回上一级选单"
echo "------------------------"
read -p "请输入你的选择: " sub_choice
case $sub_choice in
1)
cat > /etc/sysctl.conf << EOF
net.core.default_qdisc=fq_pie
net.ipv4.tcp_congestion_control=bbr
EOF
sysctl -p
;;
2)
sed -i '/net.core.default_qdisc=fq_pie/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_congestion_control=bbr/d' /etc/sysctl.conf
sysctl -p
reboot
;;
0)
break # 跳出循环,退出菜单
;;
*)
break # 跳出循环,退出菜单
;;
esac
done
else
install wget
wget --no-check-certificate -O tcpx.sh https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcpx.sh
chmod +x tcpx.sh
./tcpx.sh
fi
;;
6)
while true; do
clear
echo "▶ Docker管理器"
echo "------------------------"
echo "1. 安装更新Docker环境"
echo "------------------------"
echo "2. 查看Dcoker全局状态"
echo "------------------------"
echo "3. Dcoker容器管理 ▶"
echo "4. Dcoker镜像管理 ▶"
echo "5. Dcoker网络管理 ▶"
echo "6. Dcoker卷管理 ▶"
echo "------------------------"
echo "7. 清理无用的docker容器和镜像网络数据卷"
echo "------------------------"
echo "8. 卸载Dcoker环境"
echo "------------------------"
echo "0. 返回主菜单"
echo "------------------------"
read -p "请输入你的选择: " sub_choice
case $sub_choice in
1)
clear
install_add_docker
;;
2)
clear
echo "Dcoker版本"
docker --version
docker-compose --version
echo ""
echo "Dcoker镜像列表"
docker image ls
echo ""
echo "Dcoker容器列表"
docker ps -a
echo ""
echo "Dcoker卷列表"
docker volume ls
echo ""
echo "Dcoker网络列表"
docker network ls