From edd8ce32456ea8f890f289eedc26510000aea78c Mon Sep 17 00:00:00 2001 From: sususu98 Date: Fri, 12 Dec 2025 13:56:34 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E5=AE=89=E8=A3=85=EF=BC=8C=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E6=80=A7=E5=AE=89=E8=A3=85=E6=89=80=E6=9C=89=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 install_sys_dep 改为 install_sys_deps,支持批量安装, 例如 `apt-get install -y curl unzip jq` 而非逐个安装。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- setup.sh | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/setup.sh b/setup.sh index ea74ae5..8a3ca5e 100755 --- a/setup.sh +++ b/setup.sh @@ -103,45 +103,53 @@ get_sys_pkg_manager() { } # ========== 安装系统依赖 ========== -install_sys_dep() { - local dep=$1 +install_sys_deps() { + local deps=("$@") local pkg_mgr=$(get_sys_pkg_manager) if [[ -z "$pkg_mgr" ]]; then - error "无法检测系统包管理器,请手动安装 $dep" + error "无法检测系统包管理器,请手动安装: ${deps[*]}" return 1 fi - info "正在安装 $dep..." + info "正在安装: ${deps[*]} ..." case "$pkg_mgr" in apt) - apt-get update -qq && apt-get install -y "$dep" + apt-get update -qq && apt-get install -y "${deps[@]}" ;; yum) - yum install -y "$dep" + yum install -y "${deps[@]}" ;; dnf) - dnf install -y "$dep" + dnf install -y "${deps[@]}" ;; apk) - apk add "$dep" + apk add "${deps[@]}" ;; brew) - brew install "$dep" + brew install "${deps[@]}" ;; pacman) - pacman -S --noconfirm "$dep" + pacman -S --noconfirm "${deps[@]}" ;; esac - if command_exists "$dep"; then - success "$dep 安装成功!" - return 0 - else - error "$dep 安装失败" + # 验证所有依赖是否安装成功 + local failed=() + for dep in "${deps[@]}"; do + if command_exists "$dep"; then + success "$dep 安装成功!" + else + failed+=("$dep") + fi + done + + if [[ ${#failed[@]} -gt 0 ]]; then + error "以下依赖安装失败: ${failed[*]}" return 1 fi + return 0 } # ========== 检测并安装系统依赖 ========== @@ -205,12 +213,10 @@ check_system_deps() { return 1 fi - # 自动安装依赖 - for dep in "${missing_deps[@]}"; do - if ! install_sys_dep "$dep"; then - return 1 - fi - done + # 一次性安装所有缺失的依赖 + if ! install_sys_deps "${missing_deps[@]}"; then + return 1 + fi return 0 }