From 2baa4fdc45e5b69136d19d5475db30d8dc036c36 Mon Sep 17 00:00:00 2001 From: Erystasius Date: Wed, 1 Apr 2026 23:06:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=84=9A=E6=9C=AC=E4=BB=A5?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=AD=98=E5=9C=A8=E7=9A=84=E5=8C=85=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=99=A8=E8=87=AA=E5=8A=A8=E5=AE=89=E8=A3=85=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=8C=85=EF=BC=8C=E6=94=AF=E6=8C=81=20apt=E3=80=81pac?= =?UTF-8?q?man=20=E5=92=8C=20dnf=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_onchange_install-packages.sh | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 run_onchange_install-packages.sh diff --git a/run_onchange_install-packages.sh b/run_onchange_install-packages.sh new file mode 100644 index 0000000..bdb4cfd --- /dev/null +++ b/run_onchange_install-packages.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -euo pipefail + +# 按存在的包管理器安装依赖包。 +# 说明: +# - 不使用 chezmoi 的 .tmpl 模板语法;通过运行时检测 apt/pacman/dnf。 +# - 脚本尽量保持幂等(包已安装会自动跳过)。 + +SUDO="" +if [ "$(id -u)" -ne 0 ]; then + if command -v sudo >/dev/null 2>&1; then + SUDO="sudo" + else + echo "需要 sudo 权限才能安装包(当前非 root,且找不到 sudo)。" >&2 + exit 1 + fi +fi + +if command -v pacman >/dev/null 2>&1; then + # Arch/Manjaro:先同步并升级系统,再安装所需包 + $SUDO pacman -Syu --noconfirm + $SUDO pacman -S --noconfirm exa zoxide dust bat btop fd ripgrep fzf tldr +elif command -v apt >/dev/null 2>&1; then + # Debian/Ubuntu:更新索引后再安装 + $SUDO apt update -y || true + $SUDO apt install -y fzf zoxide ripgrep bat fd-find btop exa +elif command -v dnf >/dev/null 2>&1; then + # Fedora:更新元数据后再安装 + $SUDO dnf makecache -y || true + $SUDO dnf install -y exa zoxide dust bat btop fd-find ripgrep fzf tldr +else + echo "未检测到 apt / pacman / dnf,跳过安装。" >&2 +fi +