From 301d93c31ff2db4486b7c85cd0540d046d2b38a3 Mon Sep 17 00:00:00 2001 From: ert Date: Sun, 21 Dec 2025 01:03:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=80=E4=B8=8B=EF=BC=8C?= =?UTF-8?q?=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 46 +++++++++++++-- TODO.md | 16 ++++-- linux_tool.sh | 152 ++++++++++++++++++++++++++++---------------------- 3 files changed, 136 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 5c00de0..3caea03 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Ubuntu 命令行工具 +# Linux 命令行工具 -一个适用于Ubuntu的多功能命令行工具,提供系统管理、网络配置和rinetd管理等功能。 +一个适用于多种Linux发行版的多功能命令行工具,提供系统管理、网络配置和rinetd管理等功能,支持Ubuntu、Debian、CentOS等系统。 ## 功能特点 @@ -24,15 +24,34 @@ - 添加中转配置 - 修改中转配置 - 删除中转配置 + - 配置修改后自动重启rinetd服务 -### 4. 网络工具 +### 4. 系统配置 +- 查看CPU使用率 +- 查看内存使用率 +- 查看磁盘使用率 +- 查看系统负载 +- 查看登录用户信息 +- 查看系统服务状态 + +### 5. 网络工具 - 网络测速 (speedtest-cli) - 端口扫描 (nmap) - 查看网络连接 (netstat/ss) - DNS测试 (dig) - 路由追踪 (traceroute) +- Ping测试 +- 域名解析测试 +- 网络流量监控 +- 查看MAC地址 +- 查看ARP表 - 自动安装缺失的网络工具 +### 6. 其他功能 +- 多语言支持(中文/英文) +- 脚本自动更新 +- 支持多种Linux发行版 + ## 安装和使用 ### 自动安装运行(推荐) @@ -69,12 +88,13 @@ sudo ./linux_tool.sh ## 注意事项 - 建议使用sudo权限运行脚本,因为部分功能需要管理员权限 -- 系统更新功能会自动处理不同Ubuntu版本的更新 -- rinetd配置修改后需要重启rinetd才能生效 +- 系统更新功能会自动检测并适应不同Linux发行版 +- rinetd配置修改后会自动重启服务,无需手动操作 - 使用前请确保了解各功能的作用,避免误操作 -## 支持的Ubuntu版本 +## 支持的Linux发行版 +### Ubuntu - Ubuntu 14.04 LTS (Trusty Tahr) - Ubuntu 16.04 LTS (Xenial Xerus) - Ubuntu 18.04 LTS (Bionic Beaver) @@ -83,6 +103,20 @@ sudo ./linux_tool.sh - Ubuntu 24.04 LTS (Noble Numbat) - Ubuntu 24.10 (Oracular Oriole) +### Debian +- Debian 8 LTS (Jessie) +- Debian 9 LTS (Stretch) +- Debian 10 LTS (Buster) +- Debian 11 LTS (Bullseye) +- Debian 12 LTS (Bookworm) +- Debian 13 (Trixie) +- Debian 14 (Forky) + +### 其他支持的系统 +- CentOS 6/7 (yum) +- CentOS 8+ / Fedora (dnf) +- 其他使用apt/yum/dnf包管理器的Linux发行版 + ## 许可证 MIT License \ No newline at end of file diff --git a/TODO.md b/TODO.md index c54fc67..402164d 100644 --- a/TODO.md +++ b/TODO.md @@ -15,15 +15,19 @@ - [x] 实现脚本的自动更新功能 - [x] 添加更多系统版本的支持 - [x] 支持更多网络工具的集成 - -## 待优化 - [x] 添加更多网络工具功能 - [x] 优化脚本性能 - [x] 添加更多系统配置选项 - [x] 实现脚本的多语言支持 +- [x] 支持多种Linux发行版 +- [x] rinetd配置修改后自动重启服务 ## 未来改进方向 -- 添加更多语言支持 -- 实现配置文件保存功能 -- 添加更多系统管理工具 -- 优化用户界面和交互体验 \ No newline at end of file +- [ ] 添加更多语言支持 +- [ ] 实现配置文件保存功能 +- [ ] 添加更多系统管理工具 +- [ ] 优化用户界面和交互体验 +- [ ] 支持更多包管理器 +- [ ] 添加更多安全相关功能 +- [ ] 实现批量操作功能 +- [ ] 添加定时任务功能 \ No newline at end of file diff --git a/linux_tool.sh b/linux_tool.sh index 171b526..95352ad 100755 --- a/linux_tool.sh +++ b/linux_tool.sh @@ -661,10 +661,10 @@ system_config() { show_menu() { clear echo -e "${CYAN}==========================================${NC}" - echo -e "${GREEN} $(__) title ${NC}" + echo -e "${GREEN} $(__ title) ${NC}" echo -e "${CYAN}==========================================${NC}" - echo -e "${PURPLE} $(__) copyright ${NC}" - echo -e "${BLUE} $(__) website ${NC}" + echo -e "${PURPLE} $(__ copyright) ${NC}" + echo -e "${BLUE} $(__ website) ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}$(__ menu_1)${NC}" echo -e "${YELLOW}$(__ menu_2)${NC}" @@ -755,7 +755,8 @@ modify_max_connections() { read -n 1 } -# 支持的Ubuntu版本列表 +# 支持的Linux发行版和版本 +# Ubuntu declare -A SUPPORTED_UBUNTU_VERSIONS=( ["trusty"]="14.04 LTS" ["xenial"]="16.04 LTS" @@ -766,6 +767,17 @@ declare -A SUPPORTED_UBUNTU_VERSIONS=( ["oracular"]="24.10" ) +# Debian +declare -A SUPPORTED_DEBIAN_VERSIONS=( + ["jessie"]="8 LTS" + ["stretch"]="9 LTS" + ["buster"]="10 LTS" + ["bullseye"]="11 LTS" + ["bookworm"]="12 LTS" + ["trixie"]="13" + ["forky"]="14" +) + # 系统更新功能 system_update() { clear @@ -773,84 +785,92 @@ system_update() { echo -e "${GREEN} 系统更新 ${NC}" echo -e "${CYAN}==========================================${NC}" - # 获取当前系统信息 - OS_NAME=$(lsb_release -i | cut -f2) - CURRENT_VERSION=$(lsb_release -c | cut -f2) - CURRENT_RELEASE=$(lsb_release -r | cut -f2) + # 检测Linux发行版 + if command -v lsb_release &> /dev/null; then + OS_NAME=$(lsb_release -i | cut -f2) + CURRENT_VERSION=$(lsb_release -c | cut -f2) + CURRENT_RELEASE=$(lsb_release -r | cut -f2) + elif [ -f /etc/os-release ]; then + source /etc/os-release + OS_NAME=$NAME + CURRENT_VERSION=$VERSION_CODENAME + CURRENT_RELEASE=$VERSION_ID + else + echo -e "${RED}无法检测系统版本!${NC}" + log_message "ERROR" "无法检测系统版本" + read -n 1 -p "按任意键返回菜单..." + return 1 + fi echo -e "${YELLOW}当前系统: ${OS_NAME} ${CURRENT_RELEASE} (${CURRENT_VERSION})${NC}" - # 检查是否为Ubuntu系统 - if [ "$OS_NAME" != "Ubuntu" ]; then - echo -e "${RED}警告:当前系统不是Ubuntu,部分功能可能无法正常使用!${NC}" - echo -e "${YELLOW}继续执行更新?(y/n): ${NC}" - read -n 1 confirm - if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then - echo -e "${YELLOW}取消更新。${NC}" - read -n 1 -p "按任意键返回菜单..." - return 1 - fi + # 确定包管理器 + if command -v apt-get &> /dev/null; then + PM="apt" + elif command -v yum &> /dev/null; then + PM="yum" + elif command -v dnf &> /dev/null; then + PM="dnf" + else + echo -e "${RED}不支持的包管理器!${NC}" + log_message "ERROR" "不支持的包管理器" + read -n 1 -p "按任意键返回菜单..." + return 1 fi - echo -e "${YELLOW}支持的Ubuntu版本:${NC}" - for version in "${!SUPPORTED_UBUNTU_VERSIONS[@]}"; do - echo -e " - ${version}: ${SUPPORTED_UBUNTU_VERSIONS[$version]}" - done + echo -e "${YELLOW}包管理器: ${PM}${NC}" - echo -e "\n${YELLOW}1. 自动选择系统版本更新${NC}" - echo -e "${YELLOW}2. 手动选择系统版本更新${NC}" - echo -n -e "${PURPLE}请输入您的选择 [1-2]: ${NC}" + # 显示支持的版本 + if [[ "$OS_NAME" == *"Ubuntu"* ]]; then + echo -e "${YELLOW}支持的Ubuntu版本:${NC}" + for version in "${!SUPPORTED_UBUNTU_VERSIONS[@]}"; do + echo -e " - ${version}: ${SUPPORTED_UBUNTU_VERSIONS[$version]}" + done + elif [[ "$OS_NAME" == *"Debian"* ]]; then + echo -e "${YELLOW}支持的Debian版本:${NC}" + for version in "${!SUPPORTED_DEBIAN_VERSIONS[@]}"; do + echo -e " - ${version}: ${SUPPORTED_DEBIAN_VERSIONS[$version]}" + done + fi + + echo -e "\n${YELLOW}1. 自动更新${NC}" + echo -n -e "${PURPLE}请输入您的选择 [1]: ${NC}" read update_choice case $update_choice in 1) - echo -e "${YELLOW}正在使用当前系统版本 ${CURRENT_VERSION} 进行更新...${NC}" + echo -e "${YELLOW}正在执行系统更新...${NC}" log_message "INFO" "开始系统更新,当前版本: ${CURRENT_VERSION}" - # 根据Ubuntu版本选择更新命令 - if [ "$OS_NAME" == "Ubuntu" ] && [[ " ${!SUPPORTED_UBUNTU_VERSIONS[@]} " =~ " $CURRENT_VERSION " ]]; then - sudo apt-get update - sudo apt-get upgrade -y - sudo apt-get dist-upgrade -y - sudo apt-get autoremove -y - else - # 通用更新命令,适用于其他Ubuntu版本或Linux发行版 - sudo apt-get update || sudo apt update - sudo apt-get upgrade -y || sudo apt upgrade -y - sudo apt-get dist-upgrade -y || sudo apt full-upgrade -y - sudo apt-get autoremove -y || sudo apt autoremove -y - fi + case $PM in + apt) + # apt包管理器 (Debian/Ubuntu) + sudo apt-get update + sudo apt-get upgrade -y + sudo apt-get dist-upgrade -y + sudo apt-get autoremove -y + ;; + yum) + # yum包管理器 (CentOS 6/7) + sudo yum update -y + sudo yum upgrade -y + ;; + dnf) + # dnf包管理器 (CentOS 8+, Fedora) + sudo dnf update -y + sudo dnf upgrade -y + ;; + *) + echo -e "${RED}不支持的包管理器!${NC}" + log_message "ERROR" "不支持的包管理器: $PM" + read -n 1 -p "按任意键返回菜单..." + return 1 + ;; + esac echo -e "${GREEN}系统更新完成!${NC}" log_message "INFO" "系统更新完成" ;; - 2) - echo -n -e "${PURPLE}请输入要更新的系统版本代号(如:jammy, focal): ${NC}" - read selected_version - - if [ "$selected_version" == "$CURRENT_VERSION" ]; then - echo -e "${YELLOW}正在使用选择的系统版本 ${selected_version} 进行更新...${NC}" - log_message "INFO" "开始系统更新,使用选择的版本: ${selected_version}" - - sudo apt-get update - sudo apt-get upgrade -y - sudo apt-get dist-upgrade -y - sudo apt-get autoremove -y - - echo -e "${GREEN}系统更新完成!${NC}" - log_message "INFO" "系统更新完成" - else - # 检查选择的版本是否受支持 - if [[ " ${!SUPPORTED_UBUNTU_VERSIONS[@]} " =~ " $selected_version " ]]; then - echo -e "${RED}错误:选择的系统版本 ${selected_version} 与当前系统版本 ${CURRENT_VERSION} 不匹配!${NC}" - echo -e "${YELLOW}当前系统版本: ${CURRENT_VERSION} (${SUPPORTED_UBUNTU_VERSIONS[$CURRENT_VERSION]:-未知版本})${NC}" - echo -e "${YELLOW}选择的版本: ${selected_version} (${SUPPORTED_UBUNTU_VERSIONS[$selected_version]})${NC}" - else - echo -e "${RED}错误:选择的系统版本 ${selected_version} 不是受支持的Ubuntu版本!${NC}" - fi - log_message "ERROR" "选择的系统版本无效: ${selected_version}" - fi - ;; *) echo -e "${RED}无效的选择!${NC}" log_message "WARNING" "无效的更新选择: ${update_choice}"