Files
dotfiles/run_onchange_install-packages.sh
2026-04-02 04:38:48 +08:00

35 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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 git vim tmux
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 git vim tmux
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 git vim tmux
else
echo "未检测到 apt / pacman / dnf跳过安装。" >&2
fi