forked from eooce/ssh_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh_tool.sh
6433 lines (5614 loc) · 245 KB
/
ssh_tool.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
# 定义颜色
re='\e[0m'
red='\e[1;91m'
white='\e[1;97m'
green='\e[1;32m'
yellow='\e[1;33m'
purple='\e[1;35m'
skyblue='\e[1;96m'
[[ $EUID -ne 0 ]] && echo -e "${red}注意: 请在root用户下运行脚本${re}" && sleep 2 && exit 1
# 创建快捷指令
add_alias() {
config_file=$1
alias_names=("k" "K")
[ ! -f "$config_file" ] || touch "$config_file"
for alias_name in "${alias_names[@]}"; do
if ! grep -q "alias $alias_name=" "$config_file"; then
echo "Adding alias $alias_name to $config_file"
echo "alias $alias_name='cd ~ && ./ssh_tool.sh'" >> "$config_file"
fi
done
. "$config_file"
}
config_files=("/root/.bashrc" "/root/.profile" "/root/.bash_profile")
for config_file in "${config_files[@]}"; do
add_alias "$config_file"
done
# 获取当前服务器ipv4和ipv6
ip_address() {
ipv4_address=$(curl -s ipv4.ip.sb)
ipv6_address=$(curl -s --max-time 2 ipv6.ip.sb)
}
# 安装依赖包
install() {
if [ $# -eq 0 ]; then
echo -e "${red}未提供软件包参数!${re}"
return 1
fi
for package in "$@"; do
if command -v "$package" &>/dev/null; then
echo -e "${green}${package}已经安装了!${re}"
continue
fi
echo -e "${yellow}正在安装 ${package}...${re}"
if command -v apt &>/dev/null; then
apt install -y "$package"
elif command -v dnf &>/dev/null; then
dnf install -y "$package"
elif command -v yum &>/dev/null; then
yum install -y "$package"
elif command -v apk &>/dev/null; then
apk add "$package"
else
echo -e"${red}暂不支持你的系统!${re}"
return 1
fi
done
return 0
}
# 安装nodejs
install_nodejs(){
if command -v node &>/dev/null; then
# 获取当前已安装nodejs版本
installed_version=$(node --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
echo -e "${green}系统中已经安装Nodejs,版本:${red}${installed_version}${re}"
else
echo -e "${yellow}系统中未安装nodejs,正在为你安装...${re}"
# 根据对应系统安装nodejs
if command -v apt &>/dev/null; then
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && install nodejs
elif command -v dnf &>/dev/null; then
dnf install -y nodejs npm
elif command -v yum &>/dev/null; then
curl -fsSL https://rpm.nodesource.com/setup_21.x | sudo bash - && install nodejs
elif command -v apk &>/dev/null; then
apk add nodejs npm
else
echo -e "${red}暂不支持你的系统!${re}"
return 1
fi
if [ $? -eq 0 ]; then
echo -e "${green}nodejs安装成功!${re}"
else
echo -e "${red}nodejs安装失败,尝试再次安装...${re}"
install nodejs npm
sleep 3
break_end
fi
fi
}
# 安装java
install_java() {
if command -v java &>/dev/null; then
# 检查安装版本
installed_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
echo -e "${green}系统中已经安装Java${yellow}${installed_version}${re}"
else
echo -e "${yellow}系统中未安装Java,正在为你安装...${re}"
local install_status=0
if command -v apt &>/dev/null; then
apt install -y openjdk-17-jdk
elif command -v yum &>/dev/null; then
yum install -y java-17-openjdk
elif command -v dnf &>/dev/null; then
dnf install -y java-17-openjdk
elif command -v apk &>/dev/null; then
apk add openjdk17
else
echo -e "${red}暂不支持你的系统!${re}"
exit 1
fi
# 检查是否安装成功
if [ $install_status -eq 0 ]; then
echo -e "${green}Java安装成功${re}"
sleep 2
break_end
else
echo -e "${red}Java安装失败,尝试为你再次安装...${re}"
install java-17-openjdk
sleep 3
break_end
fi
fi
}
# 卸载依赖包
remove() {
if [ $# -eq 0 ]; then
echo -e "${red}未提供软件包参数!${re}"
return 1
fi
for package in "$@"; do
if command -v apt &>/dev/null; then
apt remove -y "$package" && apt autoremove -y
elif command -v dnf &>/dev/null; then
dnf remove -y "$package" && dnf autoremove -y
elif command -v yum &>/dev/null; then
yum remove -y "$package" && yum autoremove -y
elif command -v apk &>/dev/null; then
apk del "$package"
else
echo -e "${red}暂不支持你的系统!${re}"
return 1
fi
done
return 0
}
# 初始安装依赖包
install_dependency() {
clear
install wget socat unzip tar
}
# 等待用户返回
break_end() {
echo -e "${green}执行完成${re}"
echo -e "${yellow}按任意键返回...${re}"
read -n 1 -s -r -p ""
echo ""
clear
}
# 返回主菜单
main_menu() {
cd ~
./ssh_tool.sh
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
ssh_tool
fi
else
echo ""
fi
}
# 定义安装 Docker 的函数
install_docker() {
if ! command -v docker &>/dev/null; then
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
else
echo "Docker 已经安装"
fi
}
iptables_open() {
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
}
install_ldnmp() {
cd /home/web && docker-compose up -d
clear
echo "正在配置LDNMP环境,请耐心稍等……"
# 定义要执行的命令
commands=(
"docker exec php apt update > /dev/null 2>&1"
"docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev libmagickwand-dev imagemagick > /dev/null 2>&1"
"docker exec php docker-php-ext-install mysqli pdo_mysql zip exif gd intl bcmath opcache > /dev/null 2>&1"
"docker exec php pecl install imagick > /dev/null 2>&1"
"docker exec php sh -c 'echo \"extension=imagick.so\" > /usr/local/etc/php/conf.d/imagick.ini' > /dev/null 2>&1"
"docker exec php pecl install redis > /dev/null 2>&1"
"docker exec php sh -c 'echo \"extension=redis.so\" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini' > /dev/null 2>&1"
"docker exec php sh -c 'echo \"upload_max_filesize=50M \\n post_max_size=50M\" > /usr/local/etc/php/conf.d/uploads.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"
"docker exec php74 apt update > /dev/null 2>&1"
"docker exec php74 apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev libmagickwand-dev imagemagick > /dev/null 2>&1"
"docker exec php74 docker-php-ext-install mysqli pdo_mysql zip gd intl bcmath opcache > /dev/null 2>&1"
"docker exec php74 pecl install imagick > /dev/null 2>&1"
"docker exec php74 sh -c 'echo \"extension=imagick.so\" > /usr/local/etc/php/conf.d/imagick.ini' > /dev/null 2>&1"
"docker exec php74 pecl install redis > /dev/null 2>&1"
"docker exec php74 sh -c 'echo \"extension=redis.so\" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini' > /dev/null 2>&1"
"docker exec php74 sh -c 'echo \"upload_max_filesize=50M \\n post_max_size=50M\" > /usr/local/etc/php/conf.d/uploads.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"
"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 php > /dev/null 2>&1"
"docker restart php74 > /dev/null 2>&1"
"docker restart nginx > /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
# 安排每日午夜运行脚本
echo "0 0 * * * cd ~ && ./auto_cert_renewal.sh" | crontab -
}
install_ssltls() {
docker stop nginx > /dev/null 2>&1
iptables_open
cd ~
certbot certonly --standalone -d $yuming --email [email protected] --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() {
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
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() {
ipv4_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 php
docker restart php74
docker restart nginx
}
docker_app() {
if docker inspect "$docker_name" &>/dev/null; then
clear
echo "$docker_name 已安装,访问地址: "
ipv4_address
echo "http:$ipv4_address:$docker_port"
echo ""
echo "应用操作"
echo "------------------------"
echo "1. 更新应用 2. 卸载应用"
echo "------------------------"
echo "0. 返回上一级选单"
echo "------------------------"
read -p $'\033[1;91m请输入你的选择: \033[0m' sub_choice
case $sub_choice in
1)
clear
docker rm -f "$docker_name"
docker rmi -f "$docker_img"
# 安装 Docker(请确保有 install_docker 函数)
install_docker
$docker_rum
clear
echo "$docker_name 已经安装完成"
echo "------------------------"
# 获取外部 IP 地址
ipv4_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 地址
ipv4_address
echo "您可以使用以下地址访问:"
echo "http:$ipv4_address:$docker_port"
$docker_use
$docker_passwd
;;
[Nn])
# 用户选择不安装
;;
*)
# 无效输入
;;
esac
fi
}
while true; do
clear
echo -e "\033[0;97m-----------------By'eooce-----------------\033[0m"
echo -e "\033[0;97m脚本地址: https://github.com/eooce/ssh_tool\033[0m"
echo ""
echo -e "${skyblue} ## ## ##### #### ###### #### #### ## ${re}"
echo -e "${skyblue} ## ## ## ## ## ## ## ## ## ## ## ${re}"
echo -e "${skyblue} ## ## ##### ####. ## ## ## ## ## ## ${re}"
echo -e "${skyblue} #### ## ## ## ## ## ## ## ## ${re}"
echo -e "${skyblue} ## ## #### ## #### #### ###### ${re}"
echo -e ""
echo -e " ${yellow}VPS一键脚本工具 v8.8.8${re}"
echo -e "${yellow}支持Ubuntu/Debian/CentOS/Alpine/Fedora/Rocky/Almalinux/Oracle-linux${re}"
echo -e ""
echo -e "${skyblue}快捷键已设置为${yellow}k,${skyblue}下次运行输入${yellow}k${skyblue}可快速启动此脚本${re}"
echo "-------------------------------------------------------------------"
echo -e "${green} 1. 本机信息 5. BBR管理 ${re}"
echo -e "${green} 2. 系统更新 6. Docker管理 ▶${re}"
echo -e "${green} 3. 系统清理 7. WARP管理 ▶解锁ChatGPT/Netflix${re}"
echo -e "${green} 4. 组件管理 ▶${purple} 8. LDNMP建站 ▶${re}"
echo "-------------------------------------------------------------------"
echo -e "${green} 9. 面板工具 ▶ 13. 测试脚本合集 ▶${re}"
echo -e "${green}10. 系统工具 ▶ 14. 甲骨文云合集 ▶${re}"
echo -e "${green}11. 我的工作区 ▶ 15. 常用环境管理 ▶${re}"
echo -e "${purple}12. 节点搭建合集 ▶ 16. 开设NAT小鸡 ▶${re}"
echo "-------------------------------------------------------------------"
echo -e "${green}00. 脚本更新${red} 88. 退出脚本${re}"
echo -e "${yellow}-------------------------------------------------------------------${re}"
read -p $'\033[1;91m请输入你的选择: \033[0m' choice
case $choice in
1)
clear
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 'Model name' | sed -e 's/Model name[[:space:]]*: //')
fi
cpu_usage=$(top -bn1 | grep 'Cpu(s)' | awk '{print $2 + $4}')
cpu_usage_percent=$(printf "%.2f" "$cpu_usage")%
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 "%d/%dGB (%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
clear
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 -e "${white}系统信息查询${re}"
echo "------------------------"
echo -e "${white}主机名: ${purple}${hostname}${re}"
echo -e "${white}运营商: ${purple}${isp_info}${re}"
echo "------------------------"
echo -e "${white}系统版本: ${purple}${os_info}${re}"
echo -e "${white}Linux版本: ${purple}${kernel_version}${re}"
echo "------------------------"
echo -e "${white}CPU架构: ${purple}${cpu_arch}${re}"
echo -e "${white}CPU型号: ${purple}${cpu_info}${re}"
echo -e "${white}CPU核心数: ${purple}${cpu_cores}${re}"
echo "------------------------"
echo -e "${white}CPU占用: ${purple}${cpu_usage_percent}${re}"
echo -e "${white}物理内存: ${purple}${mem_info}${re}"
echo -e "${white}虚拟内存: ${purple}${swap_info}${re}"
echo -e "${white}硬盘占用: ${purple}${disk_info}${re}"
echo "------------------------"
echo -e "${purple}$output${re}"
echo "------------------------"
echo -e "${white}网络拥堵算法: ${purple}${congestion_algorithm} ${queue_algorithm}${re}"
echo "------------------------"
echo -e "${white}公网IPv4地址: ${purple}${ipv4_address}${re}"
echo -e "${white}公网IPv6地址: ${purple}${ipv6_address}${re}"
echo "------------------------"
echo -e "${white}地理位置: ${purple}${country} $city${re}"
echo -e "${white}系统时间: ${purple}${current_time}${re}"
echo "------------------------"
echo -e "${white}系统运行时长: ${purple}${runtime}${re}"
echo
;;
2)
clear
update_system() {
if command -v apt &>/dev/null; then
apt-get update && apt-get upgrade -y
elif command -v dnf &>/dev/null; then
dnf check-update && dnf upgrade -y
elif command -v yum &>/dev/null; then
yum check-update && yum upgrade -y
elif command -v apk &>/dev/null; then
apk update && apk upgrade
else
echo -e "${red}不支持的Linux发行版${re}"
return 1
fi
return 0
}
update_system
;;
3)
clear
clean_system() {
if command -v apt &>/dev/null; then
apt autoremove --purge -y && apt clean -y && apt autoclean -y
apt remove --purge $(dpkg -l | awk '/^rc/ {print $2}') -y
# 清理包配置文件
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
elif command -v yum &>/dev/null; then
yum autoremove -y && yum clean all
# 清理日志
journalctl --vacuum-time=1s
journalctl --vacuum-size=50M
# 移除不再需要的内核
yum remove $(rpm -q kernel | grep -v $(uname -r)) -y
elif command -v dnf &>/dev/null; then
dnf autoremove -y && dnf clean all
# 清理日志
journalctl --vacuum-time=1s
journalctl --vacuum-size=50M
# 移除不再需要的内核
dnf remove $(rpm -q kernel | grep -v $(uname -r)) -y
elif command -v apk &>/dev/null; then
apk autoremove -y
apk clean
# 清理包配置文件
apk del $(apk info -e | grep '^r' | awk '{print $1}') -y
# 清理日志文件
journalctl --vacuum-time=1s
journalctl --vacuum-size=50M
# 移除不再需要的内核
apk del $(apk info -vv | grep -E 'linux-[0-9]' | grep -v $(uname -r) | awk '{print $1}') -y
else
echo -e "${red}暂不支持你的系统!${re}"
exit 1
fi
}
clean_system
;;
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 "15. screen后台会话工具"
echo "16. masscan端口快速扫描工具"
echo "------------------------"
echo "21. cmatrix 黑客帝国屏保"
echo "22. sl 跑火车屏保"
echo "------------------------"
echo "26. 俄罗斯方块小游戏"
echo "27. 贪吃蛇小游戏 "
echo "28. 太空入侵者小游戏"
echo "------------------------"
echo "31. 全部安装"
echo -e "${red}32. 全部卸载${re}"
echo "------------------------"
echo -e "${yellow}41. 安装指定工具${re}"
echo -e "${red}42. 卸载指定工具${re}"
echo "------------------------"
echo -e "${skyblue} 0. 返回主菜单${re}"
echo "------------------------"
read -p $'\033[1;91m请输入你的选择: \033[0m' 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 ~
;;
15)
clear
# 检测 CentOS 系统
if [ -f /etc/os-release ]; then
os_name=$(grep '^ID=' /etc/os-release | cut -d= -f2)
elif command -v lsb_release > /dev/null 2>&1; then
# 如果 os-release 文件不存在,则使用 lsb_release
os_name=$(lsb_release -i | cut -f2)
else
echo "无法确定操作系统类型。"
exit 1
fi
os_name=$(echo $os_name | tr -d '"')
if [ "$os_name" = "centos" ]; then
yum install epel-release -y
yum install screen -y
else
install screen
fi
cd ~
;;
16)
clear
install masscan
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)
main_menu
;;
*)
echo "无效的输入!"
;;
esac
break_end
done
;;
5)
clear
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
;;
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 -e "${red}8. 卸载Dcoker环境${re}"
echo "------------------------"
echo -e "${skyblue} 0. 返回主菜单${re}"
echo "------------------------"
read -p $'\033[1;91m请输入你的选择: \033[0m' sub_choice
case $sub_choice in
1)
clear
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
;;
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
echo ""