@aiyiran/myclaw 1.0.160 → 1.0.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -2
- package/package.json +1 -1
- package/restrict.js +230 -55
- package/scripts/restrict-wsl-access.sh +42 -150
- package/start.js +2 -2
package/index.js
CHANGED
|
@@ -1132,7 +1132,7 @@ function showHelp() {
|
|
|
1132
1132
|
console.log(' open 打开浏览器控制台(自动带 token)');
|
|
1133
1133
|
console.log(' fix 兜底修复(自动补装 WSL + Chrome,仅限 Windows)');
|
|
1134
1134
|
console.log(' wsl2 WSL2 一键安装/修复 (仅限 Windows, 可选: --cli)');
|
|
1135
|
-
console.log('
|
|
1135
|
+
console.log(' safe 开启虚拟机屏蔽 (禁止自动挂载 Windows 盘符)');
|
|
1136
1136
|
console.log(' bat 在桌面生成一键启动脚本 (仅限 Windows)');
|
|
1137
1137
|
console.log(' list 查看注入资源管理列表(智能体/技能/配置)');
|
|
1138
1138
|
console.log(' pull 从 ~/.openclaw 拉取最新资源到源目录(开发用)');
|
|
@@ -1208,7 +1208,7 @@ if (!command) {
|
|
|
1208
1208
|
runFix();
|
|
1209
1209
|
} else if (command === 'wsl2') {
|
|
1210
1210
|
runWsl2();
|
|
1211
|
-
} else if (command === '
|
|
1211
|
+
} else if (command === 'safe') {
|
|
1212
1212
|
runRestrict();
|
|
1213
1213
|
} else if (command === 'launch') {
|
|
1214
1214
|
runLaunch();
|
package/package.json
CHANGED
package/restrict.js
CHANGED
|
@@ -2,18 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* ============================================================================
|
|
5
|
-
* MyClaw WSL2
|
|
5
|
+
* MyClaw WSL2 权限封锁(Windows 侧)
|
|
6
6
|
* ============================================================================
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* 从 Windows 一次性完成:
|
|
9
|
+
* 步骤 1: 在 WSL 内创建工作目录 /root/.openclaw/workspace/myclaw
|
|
10
|
+
* 步骤 2: 编辑 /etc/wsl.conf 禁用 automount(Linux 看不到 Windows 盘符)
|
|
11
|
+
* 步骤 3: 在 Windows 桌面创建快捷方式,指向 \\wsl.localhost\OpenClaw\root\.openclaw\workspace
|
|
9
12
|
*
|
|
10
13
|
* 使用方法:
|
|
11
14
|
* myclaw restrict
|
|
15
|
+
*
|
|
16
|
+
* 前提:OpenClaw WSL2 发行版已安装(myclaw wsl2 完成)
|
|
12
17
|
* ============================================================================
|
|
13
18
|
*/
|
|
14
19
|
|
|
15
20
|
const { execSync } = require('child_process');
|
|
16
21
|
const os = require('os');
|
|
22
|
+
const fs = require('fs');
|
|
17
23
|
const path = require('path');
|
|
18
24
|
|
|
19
25
|
// ============================================================================
|
|
@@ -26,52 +32,220 @@ const C = isWindows
|
|
|
26
32
|
? { r: '', g: '', y: '', b: '', nc: '' }
|
|
27
33
|
: { r: '\x1b[31m', g: '\x1b[32m', y: '\x1b[33m', b: '\x1b[34m', nc: '\x1b[0m' };
|
|
28
34
|
|
|
29
|
-
const
|
|
35
|
+
const DISTRO_NAME = 'OpenClaw';
|
|
36
|
+
const WORKSPACE_PATH = '/root/.openclaw/workspace/myclaw'; // 实际创建的目录
|
|
37
|
+
const SHORTCUT_TARGET = '/root/.openclaw/workspace'; // 快捷方式导航到这里
|
|
30
38
|
|
|
31
39
|
// ============================================================================
|
|
32
40
|
// 工具函数
|
|
33
41
|
// ============================================================================
|
|
34
42
|
|
|
35
|
-
function printStep(msg) {
|
|
36
|
-
|
|
37
|
-
}
|
|
43
|
+
function printStep(msg) { console.log(C.g + '==>' + C.nc + ' ' + msg); }
|
|
44
|
+
function printInfo(msg) { console.log(C.b + '[信息]' + C.nc + ' ' + msg); }
|
|
45
|
+
function printSuccess(msg) { console.log(C.g + '[成功]' + C.nc + ' ' + msg); }
|
|
46
|
+
function printWarning(msg) { console.log(C.y + '[警告]' + C.nc + ' ' + msg); }
|
|
47
|
+
function printError(msg) { console.error(C.r + '[错误]' + C.nc + ' ' + msg); }
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
// 在 WSL 中执行命令,返回输出(stdout)
|
|
50
|
+
function wslExec(cmd) {
|
|
51
|
+
try {
|
|
52
|
+
return execSync('wsl -d ' + DISTRO_NAME + ' -- bash -c "' + cmd + '"', {
|
|
53
|
+
encoding: 'utf8',
|
|
54
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
55
|
+
}).trim();
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
41
59
|
}
|
|
42
60
|
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
// 在 WSL 中以 root 执行命令(不关心输出)
|
|
62
|
+
function wslExecRoot(cmd) {
|
|
63
|
+
try {
|
|
64
|
+
execSync('wsl -d ' + DISTRO_NAME + ' -u root -- bash -c "' + cmd + '"', {
|
|
65
|
+
encoding: 'utf8',
|
|
66
|
+
stdio: 'pipe',
|
|
67
|
+
});
|
|
68
|
+
return true;
|
|
69
|
+
} catch (err) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
45
72
|
}
|
|
46
73
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// 前置检查
|
|
76
|
+
// ============================================================================
|
|
50
77
|
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
78
|
+
function checkPrerequisites() {
|
|
79
|
+
if (!isWindows) {
|
|
80
|
+
printError('此命令只能在 Windows 上运行');
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 检查 wsl 命令
|
|
85
|
+
try {
|
|
86
|
+
execSync('wsl --version', { stdio: 'pipe' });
|
|
87
|
+
} catch {
|
|
88
|
+
printError('未检测到 WSL。请先运行: myclaw wsl2');
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
54
91
|
|
|
55
|
-
//
|
|
56
|
-
function isWSL() {
|
|
92
|
+
// 检查 OpenClaw 发行版
|
|
57
93
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
94
|
+
const list = execSync('wsl -l -q', { encoding: 'utf16le' });
|
|
95
|
+
if (!list.includes(DISTRO_NAME)) {
|
|
96
|
+
printError('未找到 ' + DISTRO_NAME + ' 发行版。请先运行: myclaw wsl2');
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
60
99
|
} catch {
|
|
100
|
+
printError('无法读取 WSL 发行版列表。请先运行: myclaw wsl2');
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
printSuccess('前置检查通过');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// 步骤 1: 在 WSL 内创建工作目录
|
|
109
|
+
// ============================================================================
|
|
110
|
+
|
|
111
|
+
function step1_createWorkspace() {
|
|
112
|
+
printStep('步骤 1/3: 在 WSL 内创建工作目录');
|
|
113
|
+
|
|
114
|
+
const ok = wslExec('mkdir -p ' + WORKSPACE_PATH + ' && echo ok');
|
|
115
|
+
|
|
116
|
+
if (!ok || !ok.includes('ok')) {
|
|
117
|
+
printError('创建工作目录失败');
|
|
61
118
|
return false;
|
|
62
119
|
}
|
|
120
|
+
|
|
121
|
+
printSuccess('工作目录已创建: ' + WORKSPACE_PATH);
|
|
122
|
+
return true;
|
|
63
123
|
}
|
|
64
124
|
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
125
|
+
// ============================================================================
|
|
126
|
+
// 步骤 2: 禁用 automount — 写 /etc/wsl.conf
|
|
127
|
+
// ============================================================================
|
|
128
|
+
|
|
129
|
+
function step2_disableAutomount() {
|
|
130
|
+
printStep('步骤 2/3: 禁用自动挂载 Windows 盘符');
|
|
131
|
+
|
|
132
|
+
// 备份
|
|
133
|
+
wslExecRoot('cp /etc/wsl.conf /etc/wsl.conf.bak 2>/dev/null || true');
|
|
134
|
+
|
|
135
|
+
// 读取现有配置
|
|
136
|
+
const existing = wslExec('cat /etc/wsl.conf 2>/dev/null') || '';
|
|
137
|
+
|
|
138
|
+
let newContent;
|
|
139
|
+
if (existing.includes('[automount]')) {
|
|
140
|
+
// 替换已有 automount 段
|
|
141
|
+
newContent = existing.replace(
|
|
142
|
+
/\[automount\][^\[]*/,
|
|
143
|
+
'[automount]\nenabled = false\n'
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
// 追加
|
|
147
|
+
newContent = existing + (existing.endsWith('\n') ? '' : '\n') + '[automount]\nenabled = false\n';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 用 heredoc 写入(通过 base64 传递内容,避免 shell 转义问题)
|
|
151
|
+
const b64 = Buffer.from(newContent).toString('base64');
|
|
152
|
+
const writeCmd = "echo '" + b64 + "' | base64 -d > /etc/wsl.conf";
|
|
153
|
+
const ok = wslExecRoot(writeCmd);
|
|
154
|
+
|
|
155
|
+
if (!ok) {
|
|
156
|
+
printError('写入 wsl.conf 失败');
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 验证
|
|
161
|
+
const verify = wslExec('cat /etc/wsl.conf 2>/dev/null') || '';
|
|
162
|
+
if (verify.includes('enabled = false') || verify.includes('enabled=false')) {
|
|
163
|
+
printSuccess('automount 已禁用');
|
|
70
164
|
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
printError('配置验证失败');
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ============================================================================
|
|
172
|
+
// 步骤 3: 在桌面创建快捷方式
|
|
173
|
+
// ============================================================================
|
|
174
|
+
|
|
175
|
+
function step3_createShortcut() {
|
|
176
|
+
printStep('步骤 3/3: 创建桌面快捷方式');
|
|
177
|
+
|
|
178
|
+
// \\wsl.localhost\OpenClaw\root\.openclaw\workspace
|
|
179
|
+
const wslPath = '\\\\wsl.localhost\\' + DISTRO_NAME + '\\' + SHORTCUT_TARGET.replace(/\//g, '\\');
|
|
180
|
+
|
|
181
|
+
// 找桌面路径(兼容中英文)
|
|
182
|
+
const desktopPath = path.join(os.homedir(), 'Desktop');
|
|
183
|
+
const desktopPathCN = path.join(os.homedir(), '桌面');
|
|
184
|
+
const shortcutDir = fs.existsSync(desktopPath) ? desktopPath
|
|
185
|
+
: fs.existsSync(desktopPathCN) ? desktopPathCN : null;
|
|
186
|
+
|
|
187
|
+
if (!shortcutDir) {
|
|
188
|
+
printError('找不到桌面目录');
|
|
73
189
|
return false;
|
|
74
190
|
}
|
|
191
|
+
|
|
192
|
+
const shortcutPath = path.join(shortcutDir, 'myclaw.lnk');
|
|
193
|
+
|
|
194
|
+
// 写临时 .ps1 文件来创建快捷方式(避免复杂的命令行转义)
|
|
195
|
+
const tmpDir = path.join(process.env.LOCALAPPDATA || os.tmpdir(), 'myclaw');
|
|
196
|
+
try { fs.mkdirSync(tmpDir, { recursive: true }); } catch {}
|
|
197
|
+
const psFile = path.join(tmpDir, 'create-shortcut.ps1');
|
|
198
|
+
|
|
199
|
+
const psContent = [
|
|
200
|
+
'$ws = New-Object -ComObject WScript.Shell',
|
|
201
|
+
'$sc = $ws.CreateShortcut("' + shortcutPath + '")',
|
|
202
|
+
'$sc.TargetPath = "explorer.exe"',
|
|
203
|
+
'$sc.Arguments = "' + wslPath + '"',
|
|
204
|
+
'$sc.WorkingDirectory = "' + wslPath + '"',
|
|
205
|
+
'$sc.Description = "OpenClaw Workspace"',
|
|
206
|
+
'$sc.Save()',
|
|
207
|
+
'',
|
|
208
|
+
'# 尝试下载图标',
|
|
209
|
+
'$iconDir = "' + tmpDir + '"',
|
|
210
|
+
'$iconPath = "$iconDir\\openclaw.ico"',
|
|
211
|
+
'try {',
|
|
212
|
+
' Invoke-WebRequest -Uri "https://cdn.yiranlaoshi.com/software/myclaw/openclaw.ico" -OutFile $iconPath -UseBasicParsing',
|
|
213
|
+
' $sc2 = $ws.CreateShortcut("' + shortcutPath + '")',
|
|
214
|
+
' $sc2.IconLocation = "$iconPath,0"',
|
|
215
|
+
' $sc2.Save()',
|
|
216
|
+
'} catch {}',
|
|
217
|
+
'',
|
|
218
|
+
'Write-Host "OK"',
|
|
219
|
+
].join('\r\n');
|
|
220
|
+
|
|
221
|
+
// UTF-8 BOM
|
|
222
|
+
fs.writeFileSync(psFile, '\uFEFF' + psContent, 'utf8');
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
const result = execSync(
|
|
226
|
+
'powershell -NoProfile -ExecutionPolicy Bypass -File "' + psFile + '"',
|
|
227
|
+
{ encoding: 'utf8', stdio: 'pipe' }
|
|
228
|
+
).trim();
|
|
229
|
+
|
|
230
|
+
if (result.includes('OK')) {
|
|
231
|
+
printSuccess('桌面快捷方式已创建: myclaw');
|
|
232
|
+
printInfo('双击即可打开工作目录');
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
} catch {
|
|
236
|
+
// 回退:创建 .url 文件
|
|
237
|
+
try {
|
|
238
|
+
const urlContent = '[InternetShortcut]\r\nURL=file:///' + wslPath.replace(/\\/g, '/') + '\r\n';
|
|
239
|
+
fs.writeFileSync(path.join(shortcutDir, 'myclaw.url'), urlContent, 'utf8');
|
|
240
|
+
printSuccess('桌面快捷方式已创建 (.url)');
|
|
241
|
+
return true;
|
|
242
|
+
} catch (err2) {
|
|
243
|
+
printError('创建快捷方式失败: ' + err2.message);
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return false;
|
|
75
249
|
}
|
|
76
250
|
|
|
77
251
|
// ============================================================================
|
|
@@ -84,40 +258,41 @@ function run() {
|
|
|
84
258
|
console.log(' MyClaw WSL2 权限封锁');
|
|
85
259
|
console.log('========================================');
|
|
86
260
|
console.log('');
|
|
261
|
+
console.log('此操作将:');
|
|
262
|
+
console.log(' 1. 在 WSL 内创建工作目录');
|
|
263
|
+
console.log(' 2. 禁用 WSL 自动挂载 Windows 盘符');
|
|
264
|
+
console.log(' 3. 在桌面创建快捷方式 myclaw');
|
|
265
|
+
console.log('');
|
|
266
|
+
console.log('效果:Linux 看不到 Windows 文件,但 Windows');
|
|
267
|
+
console.log(' 可以通过桌面快捷方式访问 WSL 工作目录。');
|
|
268
|
+
console.log('');
|
|
87
269
|
|
|
88
|
-
|
|
89
|
-
if (isWindows) {
|
|
90
|
-
printWarning('此命令需要在 WSL2 环境中运行');
|
|
91
|
-
console.log('');
|
|
92
|
-
console.log('请按以下步骤操作:');
|
|
93
|
-
console.log(' 1. 打开 WSL2 终端(在 Windows Terminal 中选择 OpenClaw)');
|
|
94
|
-
console.log(' 2. 在 WSL2 终端中运行: ' + C.y + 'myclaw restrict' + C.nc);
|
|
95
|
-
console.log('');
|
|
96
|
-
console.log('或者,在 Windows PowerShell 中运行:');
|
|
97
|
-
console.log(' ' + C.y + 'wsl -d OpenClaw -- myclaw restrict' + C.nc);
|
|
98
|
-
console.log(' (将 OpenClaw 替换为你的 WSL 发行版名称)');
|
|
99
|
-
console.log('');
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
270
|
+
checkPrerequisites();
|
|
102
271
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
console.log('');
|
|
110
|
-
return;
|
|
272
|
+
if (!step1_createWorkspace()) { printError('步骤 1 失败'); process.exit(1); }
|
|
273
|
+
|
|
274
|
+
if (!step2_disableAutomount()) { printError('步骤 2 失败'); process.exit(1); }
|
|
275
|
+
|
|
276
|
+
if (!step3_createShortcut()) {
|
|
277
|
+
printWarning('快捷方式创建失败,但不影响权限封锁');
|
|
111
278
|
}
|
|
112
279
|
|
|
113
|
-
|
|
280
|
+
// 完成提示
|
|
114
281
|
console.log('');
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
282
|
+
console.log('========================================');
|
|
283
|
+
printSuccess('权限封锁完成!');
|
|
284
|
+
console.log('========================================');
|
|
285
|
+
console.log('');
|
|
286
|
+
printWarning('需要重启 WSL2 才能使禁用挂载生效!');
|
|
287
|
+
console.log('');
|
|
288
|
+
console.log(' 在 PowerShell 中运行:');
|
|
289
|
+
console.log(' ' + C.y + 'wsl --shutdown' + C.nc);
|
|
290
|
+
console.log(' 然后重新点击桌面图标启动。');
|
|
291
|
+
console.log('');
|
|
292
|
+
console.log('验证:');
|
|
293
|
+
console.log(' - WSL 内 ls /mnt/c → 应显示不存在');
|
|
294
|
+
console.log(' - 双击桌面「myclaw」→ 打开工作文件夹');
|
|
118
295
|
console.log('');
|
|
119
|
-
|
|
120
|
-
runInWSL(SCRIPT_PATH);
|
|
121
296
|
}
|
|
122
297
|
|
|
123
298
|
module.exports = { run };
|
|
@@ -1,170 +1,62 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
3
|
###############################################################################
|
|
4
|
-
# MyClaw WSL2
|
|
4
|
+
# MyClaw WSL2 权限封锁 — 独立手动版
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# 在 WSL2 内手动运行(通常通过 myclaw restrict 从 Windows 自动调用)
|
|
7
7
|
#
|
|
8
|
-
#
|
|
8
|
+
# 功能:编辑 /etc/wsl.conf,设置 [automount] enabled = false
|
|
9
|
+
#
|
|
10
|
+
# 手动使用:
|
|
9
11
|
# bash scripts/restrict-wsl-access.sh
|
|
10
12
|
#
|
|
11
13
|
###############################################################################
|
|
12
14
|
|
|
13
15
|
set -e
|
|
14
16
|
|
|
15
|
-
# 颜色定义
|
|
16
|
-
RED='\033[0;31m'
|
|
17
|
-
GREEN='\033[0;32m'
|
|
18
|
-
YELLOW='\033[1;33m'
|
|
19
|
-
BLUE='\033[0;34m'
|
|
20
|
-
NC='\033[0m' # No Color
|
|
21
|
-
|
|
22
17
|
WSL_CONF="/etc/wsl.conf"
|
|
23
|
-
BACKUP_DIR="/tmp/wsl_conf_backup_$(date +%Y%m%d_%H%M%S)"
|
|
24
|
-
|
|
25
|
-
# 打印带颜色的消息
|
|
26
|
-
print_info() {
|
|
27
|
-
echo -e "${BLUE}[信息]${NC} $1"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
print_success() {
|
|
31
|
-
echo -e "${GREEN}[成功]${NC} $1"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
print_warning() {
|
|
35
|
-
echo -e "${YELLOW}[警告]${NC} $1"
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
print_error() {
|
|
39
|
-
echo -e "${RED}[错误]${NC} $1"
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
print_step() {
|
|
43
|
-
echo -e "${GREEN}==>${NC} $1"
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
# 检查是否在 WSL 环境中运行
|
|
47
|
-
check_wsl_environment() {
|
|
48
|
-
if [[ ! -f /proc/version ]] || ! grep -qi "microsoft\|wsl" /proc/version 2>/dev/null; then
|
|
49
|
-
print_error "此脚本必须在 WSL2 环境中运行"
|
|
50
|
-
exit 1
|
|
51
|
-
fi
|
|
52
|
-
print_success "检测到 WSL2 环境"
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
# 备份现有配置
|
|
56
|
-
backup_existing_config() {
|
|
57
|
-
if [[ -f "$WSL_CONF" ]]; then
|
|
58
|
-
print_info "备份现有配置到: $BACKUP_DIR"
|
|
59
|
-
mkdir -p "$BACKUP_DIR"
|
|
60
|
-
sudo cp "$WSL_CONF" "$BACKUP_DIR/wsl.conf.bak"
|
|
61
|
-
print_success "配置已备份"
|
|
62
|
-
else
|
|
63
|
-
print_info "没有现有配置需要备份"
|
|
64
|
-
fi
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
# 步骤 A: 禁止自动挂载整个盘
|
|
68
|
-
step_a_disable_automount() {
|
|
69
|
-
print_step "步骤 A: 禁止自动挂载 Windows 盘符"
|
|
70
|
-
|
|
71
|
-
echo ""
|
|
72
|
-
echo "此操作将:"
|
|
73
|
-
echo " 1. 编辑 /etc/wsl.conf"
|
|
74
|
-
echo " 2. 设置 [automount] enabled = false"
|
|
75
|
-
echo " 3. 使 Linux 默认看不到 /mnt/c 等盘符"
|
|
76
|
-
echo ""
|
|
77
|
-
|
|
78
|
-
# 创建临时文件
|
|
79
|
-
local temp_file=$(mktemp)
|
|
80
|
-
|
|
81
|
-
# 如果原文件存在,保留非 automount 部分的内容
|
|
82
|
-
if [[ -f "$WSL_CONF" ]]; then
|
|
83
|
-
# 移除现有的 [automount] 部分
|
|
84
|
-
awk '
|
|
85
|
-
BEGIN { in_automount = 0; skip = 0 }
|
|
86
|
-
/^\[automount\]/ { in_automount = 1; skip = 1; next }
|
|
87
|
-
/^\[/ { if (in_automount) { in_automount = 0; skip = 0 } }
|
|
88
|
-
{ if (!skip) print }
|
|
89
|
-
' "$WSL_CONF" > "$temp_file"
|
|
90
|
-
fi
|
|
91
|
-
|
|
92
|
-
# 添加 automount 配置
|
|
93
|
-
cat >> "$temp_file" << EOF
|
|
94
18
|
|
|
19
|
+
# 检查 WSL 环境
|
|
20
|
+
if [[ ! -f /proc/version ]] || ! grep -qi "microsoft\|wsl" /proc/version 2>/dev/null; then
|
|
21
|
+
echo "[错误] 此脚本必须在 WSL2 环境中运行"
|
|
22
|
+
exit 1
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
# 备份
|
|
26
|
+
if [[ -f "$WSL_CONF" ]]; then
|
|
27
|
+
sudo cp "$WSL_CONF" /etc/wsl.conf.bak
|
|
28
|
+
echo "[信息] 已备份到 /etc/wsl.conf.bak"
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# 读取现有配置
|
|
32
|
+
existing=$(cat "$WSL_CONF" 2>/dev/null || echo "")
|
|
33
|
+
|
|
34
|
+
# 构建新配置
|
|
35
|
+
if echo "$existing" | grep -q '\[automount\]'; then
|
|
36
|
+
new_content=$(echo "$existing" | sed '/\[automount\]/,/^\[/ s/enabled.*/enabled = false/')
|
|
37
|
+
else
|
|
38
|
+
new_content="${existing}
|
|
95
39
|
[automount]
|
|
96
40
|
enabled = false
|
|
97
|
-
|
|
41
|
+
"
|
|
42
|
+
fi
|
|
98
43
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
44
|
+
# 用 base64 避免转义问题
|
|
45
|
+
echo "$new_content" | base64 -d > /dev/null 2>&1 || true
|
|
46
|
+
echo "$new_content" | sudo tee "$WSL_CONF" > /dev/null
|
|
47
|
+
sudo chmod 644 "$WSL_CONF"
|
|
103
48
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
49
|
+
# 验证
|
|
50
|
+
if grep -q 'enabled = false\|enabled=false' "$WSL_CONF"; then
|
|
51
|
+
echo "[成功] automount 已禁用"
|
|
107
52
|
echo ""
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
print_info "当前 /etc/wsl.conf 内容:"
|
|
111
|
-
echo "----------------------------------------"
|
|
53
|
+
echo "当前 /etc/wsl.conf 内容:"
|
|
54
|
+
echo "---"
|
|
112
55
|
sudo cat "$WSL_CONF"
|
|
113
|
-
echo "
|
|
56
|
+
echo "---"
|
|
114
57
|
echo ""
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
show_restart_instructions() {
|
|
121
|
-
echo ""
|
|
122
|
-
echo "========================================"
|
|
123
|
-
print_warning "重要提示"
|
|
124
|
-
echo "========================================"
|
|
125
|
-
echo ""
|
|
126
|
-
echo "配置已完成,但需要重启 WSL2 才能生效!"
|
|
127
|
-
echo ""
|
|
128
|
-
echo "重启方法:"
|
|
129
|
-
echo ""
|
|
130
|
-
echo " 方法 1 (推荐): 在 Windows PowerShell 中运行"
|
|
131
|
-
echo -e " ${YELLOW}wsl --shutdown${NC}"
|
|
132
|
-
echo " 然后重新打开 WSL2 终端"
|
|
133
|
-
echo ""
|
|
134
|
-
echo " 方法 2: 在 Windows 命令提示符中运行"
|
|
135
|
-
echo -e " ${YELLOW}wsl --terminate OpenClaw${NC}"
|
|
136
|
-
echo " (替换 OpenClaw 为你的发行版名称)"
|
|
137
|
-
echo ""
|
|
138
|
-
echo "重启后验证:"
|
|
139
|
-
echo " - ls /mnt/c 应该显示目录不存在或为空"
|
|
140
|
-
echo " - Windows 文件系统对 Linux 不可见"
|
|
141
|
-
echo ""
|
|
142
|
-
echo "========================================"
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
# 主函数
|
|
146
|
-
main() {
|
|
147
|
-
echo ""
|
|
148
|
-
echo "========================================"
|
|
149
|
-
echo " MyClaw WSL2 权限封锁脚本"
|
|
150
|
-
echo "========================================"
|
|
151
|
-
echo ""
|
|
152
|
-
|
|
153
|
-
# 检查环境
|
|
154
|
-
check_wsl_environment
|
|
155
|
-
|
|
156
|
-
# 备份现有配置
|
|
157
|
-
backup_existing_config
|
|
158
|
-
|
|
159
|
-
# 执行步骤 A
|
|
160
|
-
step_a_disable_automount
|
|
161
|
-
|
|
162
|
-
# 显示重启说明
|
|
163
|
-
show_restart_instructions
|
|
164
|
-
|
|
165
|
-
print_success "步骤 A 配置完成!"
|
|
166
|
-
echo ""
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
# 运行主函数
|
|
170
|
-
main "$@"
|
|
58
|
+
echo "[提示] 需要重启 WSL2 才能生效: wsl --shutdown"
|
|
59
|
+
else
|
|
60
|
+
echo "[错误] 配置写入失败"
|
|
61
|
+
exit 1
|
|
62
|
+
fi
|
package/start.js
CHANGED
|
@@ -83,9 +83,9 @@ function startWindows() {
|
|
|
83
83
|
try { execSync('myclaw update', { stdio: 'inherit', timeout: 120000 }); } catch {}
|
|
84
84
|
console.log('');
|
|
85
85
|
|
|
86
|
-
console.log('[
|
|
86
|
+
console.log('[mc up] WSL 内更新 MyClaw + 刷新配置...');
|
|
87
87
|
try {
|
|
88
|
-
execSync('wsl -d OpenClaw --
|
|
88
|
+
execSync('wsl -d OpenClaw -- mc up', { stdio: 'inherit', timeout: 120000 });
|
|
89
89
|
} catch {}
|
|
90
90
|
console.log('');
|
|
91
91
|
|