fix: 修复模块收敛性、异常处理和引导脚本健壮性
- dev: 异常捕获改为 except Exception 适配 decman 自定义异常 - docker/zsh/wsl: on_enable 改为 after_update + 状态检查确保收敛 - docker/zsh: subprocess 失败时 early return 避免误触发 - wsl: systemctl 调用加 try/except 防止 systemd 不可用时崩溃 - zsh: shell 路径改为精确解析 passwd 字段 - docker: decorator 别名统一为 pacman_packages - install.sh: 开头验证 sudo 权限、mkdir -p 确保父目录、[ 改 [[ - wsl-init.sh: pacman -Sy 改 -Syu 避免 partial upgrade、已有用户补 wheel 组
This commit is contained in:
+8
-2
@@ -42,6 +42,12 @@ class DevModule(Module):
|
||||
|
||||
def after_update(self, store):
|
||||
for pkg in BUN_GLOBAL_PACKAGES:
|
||||
decman.prg(["su", "-", self.user, "-c", f"bun add -g {pkg}"])
|
||||
try:
|
||||
decman.prg(["su", "-", self.user, "-c", f"bun add -g {pkg}"])
|
||||
except Exception:
|
||||
print(f"警告:安装 {pkg} 失败,跳过")
|
||||
for pkg in GO_INSTALL_PACKAGES:
|
||||
decman.prg(["su", "-", self.user, "-c", f"go install {pkg}"])
|
||||
try:
|
||||
decman.prg(["su", "-", self.user, "-c", f"go install {pkg}"])
|
||||
except Exception:
|
||||
print(f"警告:安装 {pkg} 失败,跳过")
|
||||
|
||||
+13
-5
@@ -1,6 +1,8 @@
|
||||
import subprocess
|
||||
|
||||
import decman
|
||||
from decman import Module
|
||||
from decman.plugins.pacman import packages
|
||||
from decman.plugins.pacman import packages as pacman_packages
|
||||
from decman.plugins.systemd import units
|
||||
|
||||
|
||||
@@ -9,13 +11,19 @@ class DockerModule(Module):
|
||||
super().__init__("docker")
|
||||
self.user = user
|
||||
|
||||
@packages
|
||||
def packages(self) -> set[str]:
|
||||
@pacman_packages
|
||||
def pacman_packages(self) -> set[str]:
|
||||
return {"docker", "docker-compose"}
|
||||
|
||||
@units
|
||||
def units(self) -> set[str]:
|
||||
return {"docker.socket"}
|
||||
|
||||
def on_enable(self, store):
|
||||
decman.prg(["gpasswd", "-a", self.user, "docker"])
|
||||
def after_update(self, store):
|
||||
result = subprocess.run(
|
||||
["id", "-nG", self.user], capture_output=True, text=True
|
||||
)
|
||||
if result.returncode != 0:
|
||||
return
|
||||
if "docker" not in result.stdout.split():
|
||||
decman.prg(["gpasswd", "-a", self.user, "docker"])
|
||||
|
||||
+17
-2
@@ -1,3 +1,5 @@
|
||||
import subprocess
|
||||
|
||||
import decman
|
||||
from decman import Module
|
||||
|
||||
@@ -6,5 +8,18 @@ class WslModule(Module):
|
||||
def __init__(self):
|
||||
super().__init__("wsl")
|
||||
|
||||
def on_enable(self, store):
|
||||
decman.prg(["systemctl", "mask", "systemd-networkd-wait-online.service"])
|
||||
def after_update(self, store):
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["systemctl", "is-enabled", "systemd-networkd-wait-online.service"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.stdout.strip() != "masked":
|
||||
decman.prg(
|
||||
["systemctl", "mask", "systemd-networkd-wait-online.service"]
|
||||
)
|
||||
except Exception:
|
||||
print(
|
||||
"警告:systemd 不可用,跳过 mask systemd-networkd-wait-online.service"
|
||||
)
|
||||
|
||||
+12
-2
@@ -1,3 +1,5 @@
|
||||
import subprocess
|
||||
|
||||
import decman
|
||||
from decman import File, Module
|
||||
from decman.plugins.aur import packages as aur_packages
|
||||
@@ -38,5 +40,13 @@ class ZshModule(Module):
|
||||
"oh-my-zsh-git",
|
||||
}
|
||||
|
||||
def on_enable(self, store):
|
||||
decman.prg(["chsh", "-s", "/usr/bin/zsh", self.user])
|
||||
def after_update(self, store):
|
||||
result = subprocess.run(
|
||||
["getent", "passwd", self.user], capture_output=True, text=True
|
||||
)
|
||||
if result.returncode != 0:
|
||||
return
|
||||
# passwd 格式: name:x:uid:gid:gecos:home:shell
|
||||
shell = result.stdout.strip().split(":")[-1]
|
||||
if shell != "/usr/bin/zsh":
|
||||
decman.prg(["chsh", "-s", "/usr/bin/zsh", self.user])
|
||||
|
||||
Reference in New Issue
Block a user