@aiyiran/myclaw 1.0.166 → 1.0.168
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/package.json +1 -1
- package/restrict.js +11 -13
package/package.json
CHANGED
package/restrict.js
CHANGED
|
@@ -58,26 +58,24 @@ function wslExec(cmd) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
// 写临时 shell 脚本到 WSL
|
|
62
|
-
//
|
|
61
|
+
// 写临时 shell 脚本到 Windows,然后让 WSL 执行
|
|
62
|
+
// 避免 cmd.exe 转义问题:脚本内容通过文件传递,不走命令行
|
|
63
63
|
function wslRunScriptAsRoot(scriptContent) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
64
|
+
const tmpDir = path.join(process.env.LOCALAPPDATA || os.tmpdir(), 'myclaw');
|
|
65
|
+
try { fs.mkdirSync(tmpDir, { recursive: true }); } catch {}
|
|
66
|
+
const scriptFile = path.join(tmpDir, 'safe-setup.sh');
|
|
67
|
+
fs.writeFileSync(scriptFile, scriptContent, 'utf8');
|
|
68
|
+
|
|
69
|
+
// Windows 路径转 WSL 路径: C:\Users\... → /mnt/c/Users/...
|
|
70
|
+
const wslPath = '/mnt/' + scriptFile.charAt(0).toLowerCase() + scriptFile.slice(2).replace(/\\/g, '/');
|
|
67
71
|
|
|
68
72
|
try {
|
|
69
|
-
|
|
70
|
-
execSync('wsl -d ' + DISTRO_NAME + ' -u root -- bash -c "echo ' + b64 + ' | base64 -d > ' + tmpScript + '"', {
|
|
71
|
-
encoding: 'utf8',
|
|
72
|
-
stdio: 'pipe',
|
|
73
|
-
});
|
|
74
|
-
// 执行脚本
|
|
75
|
-
execSync('wsl -d ' + DISTRO_NAME + ' -u root -- bash ' + tmpScript, {
|
|
73
|
+
execSync('wsl -d ' + DISTRO_NAME + ' -u root -- bash ' + wslPath, {
|
|
76
74
|
encoding: 'utf8',
|
|
77
75
|
stdio: 'pipe',
|
|
78
76
|
});
|
|
79
77
|
return true;
|
|
80
|
-
} catch
|
|
78
|
+
} catch {
|
|
81
79
|
return false;
|
|
82
80
|
}
|
|
83
81
|
}
|