检查必需依赖

This commit is contained in:
starry
2025-09-03 06:22:01 +08:00
committed by GitHub
parent b1d3caa38f
commit c907107173

View File

@@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
# 自用修改版脚本鸣谢https://github.com/Devmiston/sing-box # 自用修改版脚本鸣谢https://github.com/Devmiston/sing-box
# 建议先安装curl wget jq lsof后再执行此脚本
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m' CYAN='\033[0;36m'
YELLOW='\033[0;33m' YELLOW='\033[0;33m'
NC='\033[0m' NC='\033[0m'
@@ -42,6 +42,53 @@ short_ids=()
# SingBox版本控制 - 留空使用最新版本,指定版本如:"1.12.4" # SingBox版本控制 - 留空使用最新版本,指定版本如:"1.12.4"
SINGBOX_VERSION="" SINGBOX_VERSION=""
# 检查必需依赖并自动安装
function check_dependencies() {
local missing_deps=()
# 检查wget
if ! command -v wget >/dev/null 2>&1; then
missing_deps+=("wget")
fi
# 检查jq
if ! command -v jq >/dev/null 2>&1; then
missing_deps+=("jq")
fi
if [[ ${#missing_deps[@]} -eq 0 ]]; then
return 0
fi
echo "检测到缺少必需依赖: ${missing_deps[*]}"
echo "正在尝试自动安装..."
# 检测包管理器并安装
if command -v apt >/dev/null 2>&1; then
apt update >/dev/null 2>&1
apt install -y "${missing_deps[@]}" >/dev/null 2>&1
elif command -v yum >/dev/null 2>&1; then
yum install -y "${missing_deps[@]}" >/dev/null 2>&1
elif command -v dnf >/dev/null 2>&1; then
dnf install -y "${missing_deps[@]}" >/dev/null 2>&1
elif command -v pacman >/dev/null 2>&1; then
pacman -S --noconfirm "${missing_deps[@]}" >/dev/null 2>&1
else
echo -e "${RED}未检测到支持的包管理器,请手动安装: ${missing_deps[*]}${NC}"
exit 1
fi
# 验证安装结果
for dep in "${missing_deps[@]}"; do
if ! command -v "$dep" >/dev/null 2>&1; then
echo -e "${RED}安装 $dep 失败,请手动安装${NC}"
exit 1
fi
done
echo -e "${GREEN}依赖安装完成${NC}"
}
# 检查防火墙以及放行端口 # 检查防火墙以及放行端口
function check_firewall_configuration() { function check_firewall_configuration() {
local os_name=$(uname -s) local os_name=$(uname -s)
@@ -6090,6 +6137,9 @@ echo "╚═══════════════════════
esac esac
} }
# 检查必需依赖
check_dependencies
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
main_menu main_menu
else else