添加 root-setup.sh 脚本用于 WSL 首次初始化
- 自动安装 sudo、创建用户、配置免密 sudo - 写入 /etc/wsl.conf 设置默认用户 - 整合 WSL.md 内容到脚本中,删除原文档 - 更新 README 为两阶段安装流程
This commit is contained in:
@@ -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
|
```bash
|
||||||
curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/install.sh | bash
|
curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
安装完成后:
|
### 3. 应用配置
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dcli sync
|
dcli sync
|
||||||
|
|||||||
Executable
+44
@@ -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"
|
||||||
Reference in New Issue
Block a user