Compare commits
18 Commits
77d51c65b3
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e411c4c97 | |||
| e94eda2a5f | |||
| ac66aadea2 | |||
| 04bf913d35 | |||
| d2b2c7376f | |||
| b84368259d | |||
| 3895221c48 | |||
| 27d4c68f23 | |||
| af42eb913f | |||
| 33f4beb72a | |||
| 193cbdb11b | |||
| 99f9608282 | |||
| b96e144e82 | |||
| 4182b3c300 | |||
| ff31160602 | |||
| 34e71deed0 | |||
| e34d7da3ea | |||
| e9a77f907e |
@@ -14,17 +14,17 @@
|
|||||||
.
|
.
|
||||||
├── source.py # decman 主配置入口
|
├── source.py # decman 主配置入口
|
||||||
├── modules/
|
├── modules/
|
||||||
│ ├── base.py # 基础模块(系统包 + 现代 CLI 工具 + 配置文件)
|
│ ├── base.py # 基础模块(系统包 + CLI 工具 + dotfiles)
|
||||||
│ ├── dev.py # 开发模块(语言运行时 + 编辑器 + 工具链)
|
│ ├── dev.py # 开发模块(语言运行时 + LSP + 工具链)
|
||||||
│ ├── docker.py # Docker 模块(packages + systemd units)
|
│ ├── docker.py # Docker 模块(packages + systemd units)
|
||||||
│ ├── locale.py # locale 模块(files + on_change hook)
|
│ ├── locale.py # locale 模块(on_change hook 示例)
|
||||||
│ └── zsh.py # Zsh 模块(shell + 插件 + 自动 chsh)
|
│ └── fish.py # Fish 模块(shell + fzf + 自动 chsh)
|
||||||
├── system/etc/ # 系统配置文件源 → 部署到 /etc/
|
├── system/etc/ # 系统配置文件源 → /etc/
|
||||||
├── home/ # 用户配置文件源 → 部署到 ~/
|
├── home/ # 用户配置文件源 → ~/(必须指定 owner)
|
||||||
├── scripts/
|
├── scripts/
|
||||||
│ ├── install.sh # 引导脚本(git → decman → 首次 sync)
|
│ ├── install.sh # 引导脚本(curl | bash)
|
||||||
│ └── wsl-init.sh # WSL 首次初始化(创建用户)
|
│ └── wsl-init.sh # WSL 首次初始化
|
||||||
└── pyproject.toml # 开发依赖(decman + 插件,仅用于类型检查)
|
└── pyproject.toml # 开发依赖(decman 插件,仅类型检查)
|
||||||
```
|
```
|
||||||
|
|
||||||
## 命令
|
## 命令
|
||||||
@@ -101,7 +101,7 @@ class DockerModule(Module):
|
|||||||
return {"docker.socket"}
|
return {"docker.socket"}
|
||||||
```
|
```
|
||||||
|
|
||||||
**模块组织原则**:所有 files / packages / units 声明都通过 Module 封装,按领域拆分(base / dev / docker / locale / zsh)。新增功能优先加到对应现有模块;跨领域、需要 lifecycle hook(`on_change` / `after_update`)或需要绑定 packages + systemd units 时再新建模块。
|
**模块组织原则**:所有 files / packages / units 声明都通过 Module 封装,按领域拆分(base / dev / docker / locale / fish)。新增功能优先加到对应现有模块;跨领域、需要 lifecycle hook(`on_change` / `after_update`)或需要绑定 packages + systemd units 时再新建模块。
|
||||||
|
|
||||||
### Shell 脚本
|
### Shell 脚本
|
||||||
|
|
||||||
@@ -121,6 +121,19 @@ class DockerModule(Module):
|
|||||||
- 示例:`feat(docker): 添加 Docker 支持并重排声明顺序`
|
- 示例:`feat(docker): 添加 Docker 支持并重排声明顺序`
|
||||||
- 分支:直接在 `main` 上工作
|
- 分支:直接在 `main` 上工作
|
||||||
|
|
||||||
|
## 关键依赖关系
|
||||||
|
|
||||||
|
`.config/fish/config.fish` 别名与包的绑定(修改前务必检查):
|
||||||
|
|
||||||
|
| 别名 | 依赖包 | 位置 |
|
||||||
|
|------|--------|------|
|
||||||
|
| `rm="gomi"` | `gomi-bin` (AUR) | `base.py` |
|
||||||
|
| `cat="bat"` | `bat` | `base.py` |
|
||||||
|
| `ls="eza"` | `eza` | `base.py` |
|
||||||
|
| `vi="nvim"` | `neovim` | `dev.py` |
|
||||||
|
| `lg="lazygit"` | `lazygit` | `dev.py` |
|
||||||
|
| `x="ouch decompress"` | `ouch` | `base.py` |
|
||||||
|
|
||||||
## Agent 须知
|
## Agent 须知
|
||||||
|
|
||||||
1. **decman 是唯一真相**:不要手动装包,加到 `source.py` 或模块里,跑 `sudo decman`。
|
1. **decman 是唯一真相**:不要手动装包,加到 `source.py` 或模块里,跑 `sudo decman`。
|
||||||
@@ -131,9 +144,9 @@ class DockerModule(Module):
|
|||||||
|
|
||||||
4. **用户配置**:源文件放 `home/`,必须指定 `owner=USERNAME`。
|
4. **用户配置**:源文件放 `home/`,必须指定 `owner=USERNAME`。
|
||||||
|
|
||||||
5. **Runs as root**:`sudo decman` 以 root 执行 `source.py`。`SUDO_USER` 是调用 sudo 的原始用户名,不要 fallback。
|
5. **环境变量**:`sudo decman` 以 root 执行,`SUDO_USER` 是原始用户名。配置内不要 fallback 到 `os.getenv("USER")`。
|
||||||
|
|
||||||
6. **开发环境**:`pyproject.toml` + `uv sync` 管理开发依赖(decman、decman-pacman、decman-systemd),仅用于 IDE 类型检查,不影响运行时。
|
6. **开发依赖**:`pyproject.toml` 仅用 uv 管理类型检查依赖,不影响运行时。修改依赖后运行 `uv sync`。
|
||||||
|
|
||||||
7. **幂等性**:所有脚本和配置必须可安全重复执行。
|
7. **幂等性**:所有脚本和配置必须可安全重复执行。
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
fish_add_path "$HOME/go/bin" "$HOME/.bun/bin"
|
||||||
|
|
||||||
|
set -gx EDITOR nvim
|
||||||
|
set -gx VISUAL nvim
|
||||||
|
set -gx PAGER less
|
||||||
|
set -gx MANPAGER "sh -c 'col -bx | bat -l man -p'"
|
||||||
|
|
||||||
|
set -g fish_greeting
|
||||||
|
|
||||||
|
function __prepend_sudo
|
||||||
|
set -l buffer (commandline)
|
||||||
|
if test -z "$buffer"
|
||||||
|
commandline -f up-line
|
||||||
|
set buffer (commandline)
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -n "$buffer"
|
||||||
|
if not string match -qr '^sudo\b' -- "$buffer"
|
||||||
|
commandline -r "sudo $buffer"
|
||||||
|
end
|
||||||
|
commandline -f end-of-line repaint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
bind escape,escape __prepend_sudo # Fish 4.0+ 语法:双击 Escape 添加 sudo
|
||||||
|
bind ctrl-space accept-autosuggestion # Fish 4.0+ 语法
|
||||||
|
|
||||||
|
set -gx FZF_DEFAULT_OPTS '--height=50% --layout=reverse --border --preview-window=right:60%'
|
||||||
|
set -gx FZF_DEFAULT_COMMAND 'fd --type f --hidden --follow --exclude .git'
|
||||||
|
set -gx FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND"
|
||||||
|
set -gx FZF_ALT_C_COMMAND 'fd --type d --hidden --follow --exclude .git'
|
||||||
|
|
||||||
|
alias ..='cd ..'
|
||||||
|
alias ...='cd ../..'
|
||||||
|
|
||||||
|
function ls
|
||||||
|
command eza --icons --group-directories-first --git $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
function l
|
||||||
|
command eza -la --icons --group-directories-first --git $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
function ll
|
||||||
|
command eza -l --icons --group-directories-first --git $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
function la
|
||||||
|
command eza -lA --icons --group-directories-first --git $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
function lt
|
||||||
|
command eza --tree --level=2 --icons --group-directories-first --git $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
alias cat='bat --paging=never'
|
||||||
|
alias rm='gomi'
|
||||||
|
alias lg='lazygit'
|
||||||
|
alias vi='nvim'
|
||||||
|
alias x='ouch decompress'
|
||||||
|
|
||||||
|
if set -q WSL_DISTRO_NAME
|
||||||
|
alias pbcopy='clip.exe'
|
||||||
|
alias pbpaste='powershell.exe -noprofile -c Get-Clipboard'
|
||||||
|
|
||||||
|
function keep_current_path --on-event fish_prompt
|
||||||
|
printf '\e]9;9;%s\e\\' (wslpath -w "$PWD")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if status is-interactive
|
||||||
|
zoxide init fish --cmd cd | source
|
||||||
|
mise activate fish | source
|
||||||
|
|
||||||
|
set -g direnv_fish_mode eval_after_arrow
|
||||||
|
direnv hook fish | source
|
||||||
|
|
||||||
|
fzf --fish | source
|
||||||
|
|
||||||
|
set -gx ATUIN_NOBIND true
|
||||||
|
atuin init fish | source
|
||||||
|
bind \cr _atuin_search
|
||||||
|
bind up _atuin_bind_up
|
||||||
|
|
||||||
|
starship init fish | source
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -f ~/.config/fish/config.local.fish
|
||||||
|
source ~/.config/fish/config.local.fish
|
||||||
|
end
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
function yy
|
||||||
|
set -l tmp (mktemp -t yazi-cwd.XXXXXX)
|
||||||
|
command yazi $argv --cwd-file="$tmp"
|
||||||
|
|
||||||
|
if set -l cwd (command cat -- "$tmp")
|
||||||
|
if test -n "$cwd" -a "$cwd" != "$PWD"
|
||||||
|
builtin cd -- "$cwd"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
command rm -f -- "$tmp"
|
||||||
|
end
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
[settings]
|
[settings]
|
||||||
trusted_config_paths = ["/"]
|
trusted_config_paths = ["/"]
|
||||||
|
|
||||||
|
[tools]
|
||||||
|
usage = "latest"
|
||||||
|
|||||||
-94
@@ -1,94 +0,0 @@
|
|||||||
# ── PATH ──
|
|
||||||
export PATH="$HOME/go/bin:$HOME/.bun/bin:$PATH"
|
|
||||||
|
|
||||||
# ── 默认编辑器与分页器 ──
|
|
||||||
export EDITOR=nvim
|
|
||||||
export VISUAL=nvim
|
|
||||||
export PAGER=less
|
|
||||||
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
|
|
||||||
|
|
||||||
# ── Shell 选项 ──
|
|
||||||
setopt AUTO_CD # 输目录名直接 cd
|
|
||||||
setopt INTERACTIVE_COMMENTS # 允许交互式 # 注释
|
|
||||||
setopt NO_BEEP # 关蜂鸣
|
|
||||||
|
|
||||||
# ── 补全系统(必须在 fzf-tab 之前)──
|
|
||||||
# 每天重建一次 zcompdump,其余启动直接复用,节省启动时间
|
|
||||||
autoload -Uz compinit
|
|
||||||
if [[ -n ~/.zcompdump(#qN.mh+24) ]]; then
|
|
||||||
compinit
|
|
||||||
else
|
|
||||||
compinit -C
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ── 外部插件 ──
|
|
||||||
source /usr/share/zsh/plugins/fzf-tab-git/fzf-tab.plugin.zsh
|
|
||||||
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
|
|
||||||
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh # 必须最后
|
|
||||||
|
|
||||||
# ── 双击 ESC 自动加 sudo ──
|
|
||||||
sudo-command-line() {
|
|
||||||
[[ -z $BUFFER ]] && zle up-history
|
|
||||||
[[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
|
|
||||||
zle end-of-line
|
|
||||||
}
|
|
||||||
zle -N sudo-command-line
|
|
||||||
bindkey '\e\e' sudo-command-line
|
|
||||||
|
|
||||||
# ── Ctrl+Space 接受自动建议 ──
|
|
||||||
bindkey '^ ' autosuggest-accept
|
|
||||||
|
|
||||||
# ── FZF 默认行为(fd 联动 + 现代 UI)──
|
|
||||||
export FZF_DEFAULT_OPTS='--height=50% --layout=reverse --border --preview-window=right:60%'
|
|
||||||
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
|
|
||||||
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
|
|
||||||
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
|
|
||||||
|
|
||||||
# ── 工具初始化(顺序重要)──
|
|
||||||
eval "$(starship init zsh)"
|
|
||||||
eval "$(zoxide init --cmd cd zsh)" # cd 直接被 zoxide 接管,cdi 自动可用
|
|
||||||
eval "$(mise activate zsh)"
|
|
||||||
eval "$(direnv hook zsh)"
|
|
||||||
eval "$(fzf --zsh)" # Ctrl+T 搜文件, Alt+C 搜目录
|
|
||||||
eval "$(atuin init zsh)" # 必须在 fzf 之后,接管 Ctrl+R
|
|
||||||
|
|
||||||
# ── 别名 ──
|
|
||||||
# 导航
|
|
||||||
alias ..="cd .."
|
|
||||||
alias ...="cd ../.."
|
|
||||||
|
|
||||||
# 文件列表(公共参数提取,DRY)
|
|
||||||
_EZA_BASE=(--icons --group-directories-first --git)
|
|
||||||
alias ls="eza ${_EZA_BASE}"
|
|
||||||
alias ll="eza -la ${_EZA_BASE}"
|
|
||||||
alias la="eza -a ${_EZA_BASE}"
|
|
||||||
alias lt="eza --tree --level=2 ${_EZA_BASE}"
|
|
||||||
|
|
||||||
# 工具
|
|
||||||
alias cat="bat --paging=never"
|
|
||||||
alias rm="gomi"
|
|
||||||
alias lg="lazygit"
|
|
||||||
alias vi="nvim"
|
|
||||||
alias x="ouch decompress" # 万能解压(zip/tar/gz/bz2/xz/zst/7z/rar)
|
|
||||||
|
|
||||||
# 网络
|
|
||||||
alias http="xh"
|
|
||||||
|
|
||||||
# ── yazi wrapper:退出时自动 cd 到最后目录 ──
|
|
||||||
function yy() {
|
|
||||||
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
|
|
||||||
yazi "$@" --cwd-file="$tmp"
|
|
||||||
if cwd="$(command cat -- "$tmp")" && [[ -n "$cwd" && "$cwd" != "$PWD" ]]; then
|
|
||||||
builtin cd -- "$cwd"
|
|
||||||
fi
|
|
||||||
command rm -f -- "$tmp"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ── WSL 剪贴板 ──
|
|
||||||
if [[ -n "$WSL_DISTRO_NAME" ]]; then
|
|
||||||
alias pbcopy="clip.exe"
|
|
||||||
alias pbpaste="powershell.exe -noprofile -c Get-Clipboard"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ── Local ──
|
|
||||||
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local
|
|
||||||
+4
-3
@@ -8,7 +8,7 @@ class BaseModule(Module):
|
|||||||
super().__init__("base")
|
super().__init__("base")
|
||||||
self.user = user
|
self.user = user
|
||||||
|
|
||||||
def files(self):
|
def files(self) -> dict[str, File]:
|
||||||
return {
|
return {
|
||||||
"/etc/pacman.conf": File(
|
"/etc/pacman.conf": File(
|
||||||
source_file="./system/etc/pacman.conf",
|
source_file="./system/etc/pacman.conf",
|
||||||
@@ -34,11 +34,14 @@ class BaseModule(Module):
|
|||||||
def pacman_packages(self) -> set[str]:
|
def pacman_packages(self) -> set[str]:
|
||||||
return {
|
return {
|
||||||
"7zip",
|
"7zip",
|
||||||
|
"adobe-source-han-sans-cn-fonts",
|
||||||
|
"adobe-source-han-serif-cn-fonts",
|
||||||
"atuin",
|
"atuin",
|
||||||
"base-devel",
|
"base-devel",
|
||||||
"base",
|
"base",
|
||||||
"bat",
|
"bat",
|
||||||
"btop",
|
"btop",
|
||||||
|
"chromium",
|
||||||
"curl",
|
"curl",
|
||||||
"direnv",
|
"direnv",
|
||||||
"duf",
|
"duf",
|
||||||
@@ -56,9 +59,7 @@ class BaseModule(Module):
|
|||||||
"sd",
|
"sd",
|
||||||
"starship",
|
"starship",
|
||||||
"sudo",
|
"sudo",
|
||||||
"tealdeer",
|
|
||||||
"wget",
|
"wget",
|
||||||
"xh",
|
|
||||||
"yazi",
|
"yazi",
|
||||||
"yq",
|
"yq",
|
||||||
"zoxide",
|
"zoxide",
|
||||||
|
|||||||
+5
-4
@@ -2,13 +2,14 @@ import decman
|
|||||||
from decman import File, Module
|
from decman import File, Module
|
||||||
from decman.plugins.pacman import packages as pacman_packages
|
from decman.plugins.pacman import packages as pacman_packages
|
||||||
|
|
||||||
BUN_GLOBAL_PACKAGES = [
|
BUN_GLOBAL_PACKAGES: list[str] = [
|
||||||
"@vue/language-server",
|
"@vue/language-server",
|
||||||
"dockerfile-language-server-nodejs",
|
"dockerfile-language-server-nodejs",
|
||||||
|
"oxlint",
|
||||||
"opencode-ai",
|
"opencode-ai",
|
||||||
]
|
]
|
||||||
|
|
||||||
GO_INSTALL_PACKAGES = [
|
GO_INSTALL_PACKAGES: list[str] = [
|
||||||
"github.com/code-yeongyu/go-claude-code-comment-checker/cmd/comment-checker@latest",
|
"github.com/code-yeongyu/go-claude-code-comment-checker/cmd/comment-checker@latest",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ class DevModule(Module):
|
|||||||
super().__init__("dev")
|
super().__init__("dev")
|
||||||
self.user = user
|
self.user = user
|
||||||
|
|
||||||
def files(self):
|
def files(self) -> dict[str, File]:
|
||||||
return {
|
return {
|
||||||
f"/home/{self.user}/.config/mise/config.toml": File(
|
f"/home/{self.user}/.config/mise/config.toml": File(
|
||||||
source_file="./home/.config/mise/config.toml",
|
source_file="./home/.config/mise/config.toml",
|
||||||
@@ -50,7 +51,7 @@ class DevModule(Module):
|
|||||||
"zellij",
|
"zellij",
|
||||||
}
|
}
|
||||||
|
|
||||||
def after_update(self, store):
|
def after_update(self, store: object) -> None:
|
||||||
failures: list[str] = []
|
failures: list[str] = []
|
||||||
for pkg in BUN_GLOBAL_PACKAGES:
|
for pkg in BUN_GLOBAL_PACKAGES:
|
||||||
try:
|
try:
|
||||||
|
|||||||
+22
-8
@@ -1,4 +1,5 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import decman
|
import decman
|
||||||
from decman import Module
|
from decman import Module
|
||||||
@@ -6,10 +7,19 @@ from decman.plugins.pacman import packages as pacman_packages
|
|||||||
from decman.plugins.systemd import units
|
from decman.plugins.systemd import units
|
||||||
|
|
||||||
|
|
||||||
|
def _is_wsl() -> bool:
|
||||||
|
"""检测是否在 WSL 环境"""
|
||||||
|
try:
|
||||||
|
return "microsoft" in Path("/proc/version").read_text().lower()
|
||||||
|
except OSError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class DockerModule(Module):
|
class DockerModule(Module):
|
||||||
def __init__(self, user: str):
|
def __init__(self, user: str):
|
||||||
super().__init__("docker")
|
super().__init__("docker")
|
||||||
self.user = user
|
self.user = user
|
||||||
|
self._is_wsl = _is_wsl()
|
||||||
|
|
||||||
@pacman_packages
|
@pacman_packages
|
||||||
def pacman_packages(self) -> set[str]:
|
def pacman_packages(self) -> set[str]:
|
||||||
@@ -19,26 +29,30 @@ class DockerModule(Module):
|
|||||||
def units(self) -> set[str]:
|
def units(self) -> set[str]:
|
||||||
return {"docker.socket"}
|
return {"docker.socket"}
|
||||||
|
|
||||||
def after_update(self, store):
|
def after_update(self, store: object) -> None:
|
||||||
self._ensure_user_in_docker_group()
|
self._ensure_user_in_docker_group()
|
||||||
|
if self._is_wsl:
|
||||||
self._disable_networkd_wait_online()
|
self._disable_networkd_wait_online()
|
||||||
|
|
||||||
def _ensure_user_in_docker_group(self):
|
def _ensure_user_in_docker_group(self) -> None:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["id", "-nG", self.user], capture_output=True, text=True
|
["id", "-nG", self.user],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
)
|
)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
return
|
raise decman.SourceError(f"无法读取用户 {self.user} 的组信息")
|
||||||
if "docker" not in result.stdout.split():
|
if "docker" not in result.stdout.split():
|
||||||
decman.prg(["gpasswd", "-a", self.user, "docker"])
|
decman.prg(["gpasswd", "-a", self.user, "docker"])
|
||||||
|
|
||||||
def _disable_networkd_wait_online(self):
|
def _disable_networkd_wait_online(self) -> None:
|
||||||
# systemd-networkd-wait-online.service 会阻塞 network-online.target
|
"""WSL 环境:禁用 systemd-networkd-wait-online 避免启动阻塞"""
|
||||||
# 直到所有 link ready 或 120s 超时,导致 docker.service 启动卡约两分钟
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["systemctl", "is-enabled", "systemd-networkd-wait-online.service"],
|
["systemctl", "is-enabled", "systemd-networkd-wait-online.service"],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
|
check=False,
|
||||||
)
|
)
|
||||||
if result.stdout.strip() == "enabled":
|
if result.returncode == 0 and result.stdout.strip() == "enabled":
|
||||||
decman.prg(["systemctl", "disable", "systemd-networkd-wait-online.service"])
|
decman.prg(["systemctl", "disable", "systemd-networkd-wait-online.service"])
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import subprocess
|
||||||
|
|
||||||
|
import decman
|
||||||
|
from decman import File, Module
|
||||||
|
from decman.plugins.pacman import packages as pacman_packages
|
||||||
|
|
||||||
|
|
||||||
|
class FishModule(Module):
|
||||||
|
def __init__(self, user: str):
|
||||||
|
super().__init__("fish")
|
||||||
|
self.user = user
|
||||||
|
|
||||||
|
def files(self) -> dict[str, File]:
|
||||||
|
return {
|
||||||
|
f"/home/{self.user}/.config/fish/config.fish": File(
|
||||||
|
source_file="./home/.config/fish/config.fish",
|
||||||
|
owner=self.user,
|
||||||
|
),
|
||||||
|
f"/home/{self.user}/.config/fish/functions/yy.fish": File(
|
||||||
|
source_file="./home/.config/fish/functions/yy.fish",
|
||||||
|
owner=self.user,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
@pacman_packages
|
||||||
|
def pacman_packages(self) -> set[str]:
|
||||||
|
return {
|
||||||
|
"fish",
|
||||||
|
"fzf",
|
||||||
|
}
|
||||||
|
|
||||||
|
def after_update(self, store: object) -> None:
|
||||||
|
result = subprocess.run(
|
||||||
|
["getent", "passwd", self.user],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise decman.SourceError(f"无法读取用户 {self.user} 的 passwd 信息")
|
||||||
|
# passwd 格式: name:x:uid:gid:gecos:home:shell
|
||||||
|
shell = result.stdout.strip().split(":")[-1]
|
||||||
|
if shell != "/usr/bin/fish":
|
||||||
|
decman.prg(["chsh", "-s", "/usr/bin/fish", self.user])
|
||||||
+2
-2
@@ -6,11 +6,11 @@ class LocaleModule(Module):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("locale")
|
super().__init__("locale")
|
||||||
|
|
||||||
def files(self):
|
def files(self) -> dict[str, File]:
|
||||||
return {
|
return {
|
||||||
"/etc/locale.conf": File(content="LANG=en_US.UTF-8\n"),
|
"/etc/locale.conf": File(content="LANG=en_US.UTF-8\n"),
|
||||||
"/etc/locale.gen": File(content="en_US.UTF-8 UTF-8\n"),
|
"/etc/locale.gen": File(content="en_US.UTF-8 UTF-8\n"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def on_change(self, store):
|
def on_change(self, store: object) -> None:
|
||||||
decman.prg(["locale-gen"])
|
decman.prg(["locale-gen"])
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
import subprocess
|
|
||||||
|
|
||||||
import decman
|
|
||||||
from decman import File, Module
|
|
||||||
from decman.plugins.aur import packages as aur_packages
|
|
||||||
from decman.plugins.pacman import packages as pacman_packages
|
|
||||||
|
|
||||||
|
|
||||||
class ZshModule(Module):
|
|
||||||
def __init__(self, user: str):
|
|
||||||
super().__init__("zsh")
|
|
||||||
self.user = user
|
|
||||||
|
|
||||||
def files(self):
|
|
||||||
return {
|
|
||||||
f"/home/{self.user}/.zshrc": File(
|
|
||||||
source_file="./home/.zshrc",
|
|
||||||
owner=self.user,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
@pacman_packages
|
|
||||||
def pacman_packages(self) -> set[str]:
|
|
||||||
return {
|
|
||||||
"fzf",
|
|
||||||
"zsh",
|
|
||||||
"zsh-autosuggestions",
|
|
||||||
"zsh-completions",
|
|
||||||
"zsh-syntax-highlighting",
|
|
||||||
}
|
|
||||||
|
|
||||||
@aur_packages
|
|
||||||
def aur_packages(self) -> set[str]:
|
|
||||||
return {
|
|
||||||
"fzf-tab-git",
|
|
||||||
}
|
|
||||||
|
|
||||||
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])
|
|
||||||
+7
-4
@@ -5,7 +5,10 @@ REPO_URL="https://git.furtherverse.com/imbytecat/archlinux-config.git"
|
|||||||
CONFIG_DIR="$HOME/.config/archlinux-config"
|
CONFIG_DIR="$HOME/.config/archlinux-config"
|
||||||
|
|
||||||
echo "🔑 验证 sudo 权限..."
|
echo "🔑 验证 sudo 权限..."
|
||||||
sudo -v < /dev/tty || { echo "❌ 需要 sudo 权限,请确认当前用户已配置 sudo"; exit 1; }
|
sudo -v </dev/tty || {
|
||||||
|
echo "❌ 需要 sudo 权限,请确认当前用户已配置 sudo"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
echo "🔄 更新系统..."
|
echo "🔄 更新系统..."
|
||||||
sudo pacman -Syu --noconfirm
|
sudo pacman -Syu --noconfirm
|
||||||
@@ -25,7 +28,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "📦 安装 decman..."
|
echo "📦 安装 decman..."
|
||||||
if ! command -v decman &> /dev/null; then
|
if ! command -v decman &>/dev/null; then
|
||||||
_tmpdir=$(mktemp -d)
|
_tmpdir=$(mktemp -d)
|
||||||
trap 'rm -rf "$_tmpdir"' EXIT
|
trap 'rm -rf "$_tmpdir"' EXIT
|
||||||
git clone https://aur.archlinux.org/decman.git "$_tmpdir"
|
git clone https://aur.archlinux.org/decman.git "$_tmpdir"
|
||||||
@@ -33,10 +36,10 @@ if ! command -v decman &> /dev/null; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "⚙️ 应用系统配置..."
|
echo "⚙️ 应用系统配置..."
|
||||||
sudo decman --source "$CONFIG_DIR/source.py" < /dev/tty
|
sudo decman --source "$CONFIG_DIR/source.py" </dev/tty
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "🎉 安装完成!重新登录以使用 zsh。"
|
echo "🎉 安装完成!重新登录以使用 fish。"
|
||||||
echo ""
|
echo ""
|
||||||
echo "后续更新配置:"
|
echo "后续更新配置:"
|
||||||
echo " cd $CONFIG_DIR && git pull && sudo decman"
|
echo " cd $CONFIG_DIR && git pull && sudo decman"
|
||||||
|
|||||||
+6
-6
@@ -1,13 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
if [[ "$(id -u)" -ne 0 ]]; then
|
||||||
echo "❌ 请以 root 身份运行此脚本"
|
echo "❌ 请以 root 身份运行此脚本"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
USERNAME="${1:-}"
|
USERNAME="${1:-}"
|
||||||
if [ -z "$USERNAME" ]; then
|
if [[ -z "$USERNAME" ]]; then
|
||||||
echo "用法: wsl-init.sh <用户名>"
|
echo "用法: wsl-init.sh <用户名>"
|
||||||
echo "示例: wsl-init.sh imbytecat"
|
echo "示例: wsl-init.sh imbytecat"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -16,25 +16,25 @@ fi
|
|||||||
echo "🔄 更新系统..."
|
echo "🔄 更新系统..."
|
||||||
pacman -Syu --noconfirm
|
pacman -Syu --noconfirm
|
||||||
|
|
||||||
if ! command -v sudo &> /dev/null; then
|
if ! command -v sudo &>/dev/null; then
|
||||||
echo "📦 安装 sudo..."
|
echo "📦 安装 sudo..."
|
||||||
pacman -S --needed --noconfirm sudo
|
pacman -S --needed --noconfirm sudo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🔐 配置 sudo 权限..."
|
echo "🔐 配置 sudo 权限..."
|
||||||
cat > /etc/sudoers.d/10-wheel << 'EOF'
|
cat >/etc/sudoers.d/10-wheel <<'EOF'
|
||||||
%wheel ALL=(ALL) NOPASSWD: ALL
|
%wheel ALL=(ALL) NOPASSWD: ALL
|
||||||
EOF
|
EOF
|
||||||
chmod 440 /etc/sudoers.d/10-wheel
|
chmod 440 /etc/sudoers.d/10-wheel
|
||||||
|
|
||||||
echo "👤 创建用户 $USERNAME..."
|
echo "👤 创建用户 $USERNAME..."
|
||||||
if id "$USERNAME" &> /dev/null; then
|
if id "$USERNAME" &>/dev/null; then
|
||||||
echo "⏩ 用户 $USERNAME 已存在,确保 wheel 组成员"
|
echo "⏩ 用户 $USERNAME 已存在,确保 wheel 组成员"
|
||||||
usermod -aG wheel "$USERNAME"
|
usermod -aG wheel "$USERNAME"
|
||||||
else
|
else
|
||||||
useradd -m -G wheel -s /bin/bash "$USERNAME"
|
useradd -m -G wheel -s /bin/bash "$USERNAME"
|
||||||
echo "请设置 $USERNAME 的密码:"
|
echo "请设置 $USERNAME 的密码:"
|
||||||
passwd "$USERNAME" < /dev/tty
|
passwd "$USERNAME" </dev/tty
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import modules.base
|
|||||||
import modules.dev
|
import modules.dev
|
||||||
import modules.docker
|
import modules.docker
|
||||||
import modules.locale
|
import modules.locale
|
||||||
import modules.zsh
|
import modules.fish
|
||||||
|
|
||||||
USERNAME = os.environ.get("SUDO_USER")
|
USERNAME = os.environ.get("SUDO_USER")
|
||||||
if not USERNAME:
|
if not USERNAME:
|
||||||
@@ -17,5 +17,5 @@ decman.modules += [
|
|||||||
modules.dev.DevModule(USERNAME),
|
modules.dev.DevModule(USERNAME),
|
||||||
modules.docker.DockerModule(USERNAME),
|
modules.docker.DockerModule(USERNAME),
|
||||||
modules.locale.LocaleModule(),
|
modules.locale.LocaleModule(),
|
||||||
modules.zsh.ZshModule(USERNAME),
|
modules.fish.FishModule(USERNAME),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user