From 4c7d0b57bd52dd0ca2de772476f1902e422189e3 Mon Sep 17 00:00:00 2001 From: imbytecat Date: Fri, 3 Apr 2026 15:49:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(base):=20=E5=A2=9E=E5=BC=BA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=81=A5=E5=A3=AE=E6=80=A7=E4=B8=8E=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 pacman.conf 管理(Color + ILoveCandy + ParallelDownloads) - dev 模块改用 decman 原生 user/mimic_login 替代手拼 su - - dev 模块异常处理改为收集汇总,不再静默吞掉 - install.sh 改用 mktemp + trap 清理临时目录 - 移除 AGENTS.md 中不存在的 wsl.py 引用 --- AGENTS.md | 1 - modules/base.py | 3 +++ modules/dev.py | 24 ++++++++++++------------ scripts/install.sh | 8 ++++---- system/etc/pacman.conf | 26 ++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 system/etc/pacman.conf diff --git a/AGENTS.md b/AGENTS.md index 9d3d174..fe98d07 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,7 +18,6 @@ │ ├── dev.py # 开发模块(语言运行时 + 编辑器 + 工具链) │ ├── docker.py # Docker 模块(packages + systemd units) │ ├── locale.py # locale 模块(files + on_change hook) -│ ├── wsl.py # WSL 模块(WSL 特定适配) │ └── zsh.py # Zsh 模块(shell + oh-my-zsh + 插件) ├── system/etc/ # 系统配置文件源 → 部署到 /etc/ ├── home/ # 用户配置文件源 → 部署到 ~/ diff --git a/modules/base.py b/modules/base.py index 467822b..1f18699 100644 --- a/modules/base.py +++ b/modules/base.py @@ -10,6 +10,9 @@ class BaseModule(Module): def files(self): return { + "/etc/pacman.conf": File( + source_file="./system/etc/pacman.conf", + ), "/etc/pacman.d/mirrorlist": File( source_file="./system/etc/pacman.d/mirrorlist", ), diff --git a/modules/dev.py b/modules/dev.py index 6b48f0d..384b226 100644 --- a/modules/dev.py +++ b/modules/dev.py @@ -1,5 +1,3 @@ -import shlex - import decman from decman import File, Module from decman.plugins.pacman import packages as pacman_packages @@ -46,17 +44,19 @@ class DevModule(Module): } def after_update(self, store): + failures: list[str] = [] for pkg in BUN_GLOBAL_PACKAGES: try: - decman.prg( - ["su", "-", self.user, "-c", shlex.join(["bun", "add", "-g", pkg])] - ) - except Exception: - print(f"警告:安装 {pkg} 失败,跳过") + decman.prg(["bun", "add", "-g", pkg], user=self.user, mimic_login=True) + except Exception as e: + failures.append(f"bun: {pkg} ({e})") for pkg in GO_INSTALL_PACKAGES: try: - decman.prg( - ["su", "-", self.user, "-c", shlex.join(["go", "install", pkg])] - ) - except Exception: - print(f"警告:安装 {pkg} 失败,跳过") + decman.prg(["go", "install", pkg], user=self.user, mimic_login=True) + except Exception as e: + failures.append(f"go: {pkg} ({e})") + if failures: + print(f"\n⚠ {len(failures)} 个全局包安装失败:") + for f in failures: + print(f" - {f}") + print() diff --git a/scripts/install.sh b/scripts/install.sh index 1fed2a6..0eeb1d5 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -26,10 +26,10 @@ fi echo "==> 安装 decman..." if ! command -v decman &> /dev/null; then - rm -rf /tmp/decman - git clone https://aur.archlinux.org/decman.git /tmp/decman - (cd /tmp/decman && makepkg -si --noconfirm) - rm -rf /tmp/decman + _tmpdir=$(mktemp -d) + trap 'rm -rf "$_tmpdir"' EXIT + git clone https://aur.archlinux.org/decman.git "$_tmpdir" + (cd "$_tmpdir" && makepkg -si --noconfirm) fi echo "==> 应用系统配置..." diff --git a/system/etc/pacman.conf b/system/etc/pacman.conf new file mode 100644 index 0000000..c1f126a --- /dev/null +++ b/system/etc/pacman.conf @@ -0,0 +1,26 @@ +# +# /etc/pacman.conf +# + +[options] +HoldPkg = pacman glibc +Architecture = auto + +Color +ILoveCandy +VerbosePkgLists +ParallelDownloads = 5 + +CheckSpace + +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional + +[core] +Include = /etc/pacman.d/mirrorlist + +[extra] +Include = /etc/pacman.d/mirrorlist + +# [multilib] +# Include = /etc/pacman.d/mirrorlist