Files
imbytecat b96e144e82 refactor(modules): 添加类型注解并优化 WSL 检测
- 全模块补全类型注解 (files, after_update, on_change)
- docker: 仅在 WSL 环境禁用 networkd-wait-online
- docker: 添加 _is_wsl() 自动检测函数
- zsh/docker: 改进错误输出使用 decman.error
- wsl-init: 统一使用 [[ ]] 并格式化代码
2026-04-09 12:09:00 +08:00

50 lines
1.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -euo pipefail
if [[ "$(id -u)" -ne 0 ]]; then
echo "❌ 请以 root 身份运行此脚本"
exit 1
fi
USERNAME="${1:-}"
if [[ -z "$USERNAME" ]]; then
echo "用法: wsl-init.sh <用户名>"
echo "示例: wsl-init.sh imbytecat"
exit 1
fi
echo "🔄 更新系统..."
pacman -Syu --noconfirm
if ! command -v sudo &>/dev/null; then
echo "📦 安装 sudo..."
pacman -S --needed --noconfirm sudo
fi
echo "🔐 配置 sudo 权限..."
cat >/etc/sudoers.d/10-wheel <<'EOF'
%wheel ALL=(ALL) NOPASSWD: ALL
EOF
chmod 440 /etc/sudoers.d/10-wheel
echo "👤 创建用户 $USERNAME..."
if id "$USERNAME" &>/dev/null; then
echo "⏩ 用户 $USERNAME 已存在,确保 wheel 组成员"
usermod -aG wheel "$USERNAME"
else
useradd -m -G wheel -s /bin/bash "$USERNAME"
echo "请设置 $USERNAME 的密码:"
passwd "$USERNAME" </dev/tty
fi
echo ""
echo "🎉 WSL 初始化完成!"
echo ""
echo "下一步:"
echo " 1. 在 PowerShell 中设置默认用户:"
echo " wsl --manage archlinux --set-default-user $USERNAME"
echo " 2. 重启 WSL"
echo " wsl --terminate archlinux"
echo " 3. 重新打开 Arch WSL 后运行:"
echo " curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/scripts/install.sh | bash"