Files
dotfiles/run_onchange_install-packages.sh

50 lines
1.8 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
echo "检测到 pacman开始安装 Arch/Manjaro 包..."
echo "更新系统包..."
$SUDO pacman -Syu --noconfirm
echo "安装 Bash 常用命令增强/替代工具..."
$SUDO pacman -S --noconfirm zoxide exa bat fd ripgrep btop tldr fzf
echo "安装其他常用工具..."
$SUDO pacman -S --noconfirm git vim tmux fish fastfetch thefuck
echo "Arch/Manjaro 包安装完成!"
elif command -v apt >/dev/null 2>&1; then
echo "检测到 apt开始安装 Debian/Ubuntu 包..."
echo "更新包索引..."
$SUDO apt update -y || true
echo "安装 Bash 常用命令增强/替代工具..."
$SUDO apt install -y zoxide exa bat fd-find ripgrep btop tldr fzf
echo "安装其他常用工具..."
$SUDO apt install -y git vim tmux fish fastfetch thefuck
echo "Debian/Ubuntu 包安装完成!"
elif command -v dnf >/dev/null 2>&1; then
echo "检测到 dnf开始安装 Fedora 包..."
echo "更新包元数据..."
$SUDO dnf makecache -y || true
echo "安装 Bash 常用命令增强/替代工具..."
$SUDO dnf install -y zoxide exa bat fd-find ripgrep btop tldr fzf
echo "安装其他常用工具..."
$SUDO dnf install -y git vim tmux fish fastfetch thefuck
echo "Fedora 包安装完成!"
else
echo "未检测到 apt / pacman / dnf跳过安装。" >&2
fi