diff --git a/README.md b/README.md index 1d88754..eabb7b3 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,25 @@ ## 快速开始 +### 1. 初始化用户(以 root 身份,仅 WSL 首次) + +```bash +curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/root-setup.sh | bash -s -- <用户名> +``` + +然后在 PowerShell 中重启 WSL: + +```powershell +wsl --terminate archlinux +``` + +### 2. 安装配置(以普通用户身份) + ```bash curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/install.sh | bash ``` -安装完成后: +### 3. 应用配置 ```bash dcli sync diff --git a/root-setup.sh b/root-setup.sh new file mode 100755 index 0000000..37a4c09 --- /dev/null +++ b/root-setup.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -euo pipefail + +if [ "$(id -u)" -ne 0 ]; then + echo "请以 root 身份运行此脚本" + exit 1 +fi + +USERNAME="${1:-}" +if [ -z "$USERNAME" ]; then + echo "用法: ./root-setup.sh <用户名>" + echo "示例: ./root-setup.sh imbytecat" + exit 1 +fi + +echo "==> 安装 sudo..." +pacman -Syu --noconfirm sudo + +echo "==> 创建用户 $USERNAME..." +if id "$USERNAME" &> /dev/null; then + echo "用户 $USERNAME 已存在,跳过创建" +else + useradd -m -G wheel -s /bin/bash "$USERNAME" + echo "请设置 $USERNAME 的密码:" + passwd "$USERNAME" +fi + +echo "==> 配置 wheel 组免密 sudo..." +echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheel +chmod 440 /etc/sudoers.d/wheel + +echo "==> 配置 WSL 默认用户..." +cat > /etc/wsl.conf << EOF +[user] +default = $USERNAME +EOF + +echo "" +echo "✓ 初始化完成!" +echo "" +echo "下一步:" +echo " 1. 在 PowerShell 中执行: wsl --terminate archlinux" +echo " 2. 重新打开 Arch WSL(将以 $USERNAME 身份登录)" +echo " 3. 运行: curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/install.sh | bash"