重构脚本:重命名 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
+8 -2
View File
@@ -22,8 +22,14 @@ echo "==> 安装 dcli..."
yay -S --needed --noconfirm dcli-arch-git
echo "==> 克隆配置仓库..."
rm -rf "$CONFIG_DIR"
git clone "$REPO_URL" "$CONFIG_DIR"
if [ -d "$CONFIG_DIR/.git" ]; then
echo "配置仓库已存在:$CONFIG_DIR,跳过克隆"
elif [ -e "$CONFIG_DIR" ]; then
echo "目标路径已存在且不是 git 仓库:$CONFIG_DIR"
exit 1
else
git clone "$REPO_URL" "$CONFIG_DIR"
fi
echo ""
echo "✓ 安装完成!"
+18 -4
View File
@@ -6,15 +6,26 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1
fi
if ! grep -qiE '(microsoft|wsl)' /proc/sys/kernel/osrelease 2>/dev/null; then
echo "此脚本仅用于 Arch Linux on WSL 的首次初始化"
exit 1
fi
USERNAME="${1:-}"
if [ -z "$USERNAME" ]; then
echo "用法: ./root-setup.sh <用户名>"
echo "示例: ./root-setup.sh imbytecat"
echo "用法: wsl-init.sh <用户名>"
echo "示例: wsl-init.sh imbytecat"
exit 1
fi
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..."
if id "$USERNAME" &> /dev/null; then
@@ -26,13 +37,16 @@ else
fi
echo "==> 配置 WSL 默认用户..."
if [ -f /etc/wsl.conf ]; then
cp /etc/wsl.conf "/etc/wsl.conf.bak.$(date +%s)"
fi
cat > /etc/wsl.conf << EOF
[user]
default = $USERNAME
EOF
echo ""
echo "✓ 初始化完成!"
echo "✓ WSL 初始化完成!"
echo ""
echo "下一步:"
echo " 1. 在 PowerShell 中执行: wsl --terminate archlinux"