重构脚本:重命名 root-setup 为 wsl-init 并修复关键问题

- 重命名 root-setup.sh 为 wsl-init.sh,明确 WSL 专属
- 添加 WSL 环境检查,防止在非 WSL 环境误执行
- 添加 sudoers 配置,修复 install.sh 无法使用 sudo 的问题
- 去掉 wsl-init 中的 -Syu,避免重复升级
- 备份已有 /etc/wsl.conf 再覆盖
- install.sh 克隆逻辑改为安全检测,避免误删已有仓库
- README 区分 WSL 首次启动和普通 Arch 两条路径
This commit is contained in:
2026-03-25 14:42:59 +08:00
parent bfb4d5b3d0
commit 6641a75fc9
3 changed files with 47 additions and 18 deletions
+21 -12
View File
@@ -1,36 +1,45 @@
# Arch Linux 配置仓库 # Arch Linux 配置仓库
使用 dcli 声明式管理 Arch Linux 配置(当前默认主机为 wsl,可扩展到其他主机) 使用 dcli 声明式管理 Arch Linux 配置。
当前默认主机为 `wsl`;非 WSL 环境请先新增/切换 host,再执行同步。
## 快速开始 ## 使用方式
### 1. 初始化用户(以 root 身份,仅 WSL 首次 ### A. Arch on WSL 首次启动(默认 root 登录
1. 初始化普通用户:
```bash ```bash
curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/scripts/root-setup.sh | bash -s -- <用户名> curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/scripts/wsl-init.sh | bash -s -- <用户名>
``` ```
然后在 PowerShell 中重启 WSL 2. 在 PowerShell 中重启 WSL
```powershell ```powershell
wsl --terminate archlinux wsl --terminate archlinux
``` ```
### 2. 安装配置(以普通用户身份) 3. 重新进入 Arch WSL 后,以普通用户执行:
```bash ```bash
curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/scripts/install.sh | bash curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/scripts/install.sh | bash
```
### 3. 应用配置
```bash
dcli sync dcli sync
``` ```
### B. 普通 Arch 安装(已存在普通用户)
跳过 WSL 初始化,直接执行:
```bash
curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/scripts/install.sh | bash
dcli sync
```
> 注意:当前 `config.yaml` 的 `active_host` 是 `wsl`。非 WSL 环境请先新增对应 `hosts/*.yaml` 并切换 `active_host`。
## 配置说明 ## 配置说明
- `hosts/wsl.yaml` - WSL 配置 - `hosts/` - 主机配置
- `modules/` - 模块化包管理 - `modules/` - 模块化包管理
- `files/` - 配置文件(自动同步) - `files/` - 配置文件(自动同步)
+8 -2
View File
@@ -22,8 +22,14 @@ echo "==> 安装 dcli..."
yay -S --needed --noconfirm dcli-arch-git yay -S --needed --noconfirm dcli-arch-git
echo "==> 克隆配置仓库..." echo "==> 克隆配置仓库..."
rm -rf "$CONFIG_DIR" if [ -d "$CONFIG_DIR/.git" ]; then
git clone "$REPO_URL" "$CONFIG_DIR" echo "配置仓库已存在:$CONFIG_DIR,跳过克隆"
elif [ -e "$CONFIG_DIR" ]; then
echo "目标路径已存在且不是 git 仓库:$CONFIG_DIR"
exit 1
else
git clone "$REPO_URL" "$CONFIG_DIR"
fi
echo "" echo ""
echo "✓ 安装完成!" echo "✓ 安装完成!"
+18 -4
View File
@@ -6,15 +6,26 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
if ! grep -qiE '(microsoft|wsl)' /proc/sys/kernel/osrelease 2>/dev/null; then
echo "此脚本仅用于 Arch Linux on WSL 的首次初始化"
exit 1
fi
USERNAME="${1:-}" USERNAME="${1:-}"
if [ -z "$USERNAME" ]; then if [ -z "$USERNAME" ]; then
echo "用法: ./root-setup.sh <用户名>" echo "用法: wsl-init.sh <用户名>"
echo "示例: ./root-setup.sh imbytecat" echo "示例: wsl-init.sh imbytecat"
exit 1 exit 1
fi fi
echo "==> 安装 sudo..." echo "==> 安装 sudo..."
pacman -Syu --noconfirm sudo pacman -S --needed --noconfirm sudo
echo "==> 配置 sudo 权限..."
cat > /etc/sudoers.d/10-wheel << 'EOF'
%wheel ALL=(ALL:ALL) ALL
EOF
chmod 440 /etc/sudoers.d/10-wheel
echo "==> 创建用户 $USERNAME..." echo "==> 创建用户 $USERNAME..."
if id "$USERNAME" &> /dev/null; then if id "$USERNAME" &> /dev/null; then
@@ -26,13 +37,16 @@ else
fi fi
echo "==> 配置 WSL 默认用户..." echo "==> 配置 WSL 默认用户..."
if [ -f /etc/wsl.conf ]; then
cp /etc/wsl.conf "/etc/wsl.conf.bak.$(date +%s)"
fi
cat > /etc/wsl.conf << EOF cat > /etc/wsl.conf << EOF
[user] [user]
default = $USERNAME default = $USERNAME
EOF EOF
echo "" echo ""
echo "✓ 初始化完成!" echo "✓ WSL 初始化完成!"
echo "" echo ""
echo "下一步:" echo "下一步:"
echo " 1. 在 PowerShell 中执行: wsl --terminate archlinux" echo " 1. 在 PowerShell 中执行: wsl --terminate archlinux"