@xaidenlabs/uso 1.1.42 → 1.1.43
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/bin/index.js +1 -0
- package/package.json +1 -1
- package/src/commands/init.js +13 -1
- package/src/platforms/wsl.js +122 -0
- package/src/utils/wsl-bridge.js +84 -0
package/bin/index.js
CHANGED
|
@@ -16,6 +16,7 @@ program
|
|
|
16
16
|
.command('init [component]')
|
|
17
17
|
.alias('install')
|
|
18
18
|
.description('Install Rust, Solana CLI, Anchor Framework, or specific component (rust, solana, anchor)')
|
|
19
|
+
.option('--wsl', 'Install in Stealth WSL Mode (Windows Only)')
|
|
19
20
|
.action(init);
|
|
20
21
|
|
|
21
22
|
program
|
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -10,9 +10,21 @@ const { ensureWalletInteractive } = require('../utils/wallet');
|
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const fs = require('fs');
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const { installWsl } = require('../platforms/wsl');
|
|
14
|
+
|
|
15
|
+
const init = async (component, options) => {
|
|
14
16
|
const platform = os.platform();
|
|
15
17
|
|
|
18
|
+
// Check for Stealth WSL Mode
|
|
19
|
+
if (options && options.wsl) {
|
|
20
|
+
if (platform !== 'win32') {
|
|
21
|
+
log.error("❌ WSL Stealth Mode is only available on Windows.");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
await installWsl();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
16
28
|
if (component) {
|
|
17
29
|
component = component.toLowerCase();
|
|
18
30
|
log.info(`🎯 Targeted installation: ${component}`);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const shell = require('shelljs');
|
|
2
|
+
const { log, spinner } = require('../utils/logger');
|
|
3
|
+
const { isWslInstalled, runWsl, toWslPath } = require('../utils/wsl-bridge');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
|
|
8
|
+
const installWsl = async () => {
|
|
9
|
+
log.header("🐧 Configuring Stealth WSL Environment...");
|
|
10
|
+
|
|
11
|
+
// 1. Check if WSL is enabled
|
|
12
|
+
if (!shell.which('wsl')) {
|
|
13
|
+
log.error("❌ WSL is not enabled on this Windows machine.");
|
|
14
|
+
log.warn("👉 Please enable 'Windows Subsystem for Linux' in 'Turn Windows features on or off'.");
|
|
15
|
+
log.warn("👉 Or run this in PowerShell as Admin: wsl --install");
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 2. Install Ubuntu silently if missing
|
|
20
|
+
// We target 'Ubuntu' as the standard distro.
|
|
21
|
+
const checkDistro = shell.exec('wsl -l -v', { silent: true });
|
|
22
|
+
if (!checkDistro.stdout.includes('Ubuntu')) {
|
|
23
|
+
log.info("📦 Installing Ubuntu (This may prompt for Admin access)...");
|
|
24
|
+
|
|
25
|
+
// This command usually triggers a UAC prompt and a console window.
|
|
26
|
+
// We can't fully hide the install process itself, but we can automate it.
|
|
27
|
+
const install = shell.exec('wsl --install -d Ubuntu');
|
|
28
|
+
|
|
29
|
+
if (install.code !== 0) {
|
|
30
|
+
log.error("❌ Failed to install Ubuntu.");
|
|
31
|
+
log.warn("👉 Try running manually: wsl --install -d Ubuntu");
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
log.success("✅ Ubuntu installed.");
|
|
35
|
+
} else {
|
|
36
|
+
log.success("✅ Ubuntu is already installed.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 3. Configure Internal Environment (Rust + Solana + Anchor)
|
|
40
|
+
// We create a shell script and run it inside WSL.
|
|
41
|
+
|
|
42
|
+
log.info("⚙️ Configuring internal Linux environment...");
|
|
43
|
+
|
|
44
|
+
const setupScript = `
|
|
45
|
+
#!/bin/bash
|
|
46
|
+
set -e
|
|
47
|
+
|
|
48
|
+
# 1. Hush Login
|
|
49
|
+
touch ~/.hushlogin
|
|
50
|
+
|
|
51
|
+
# 2. Update & Install Dependencies
|
|
52
|
+
if ! command -v curl &> /dev/null; then
|
|
53
|
+
sudo apt-get update && sudo apt-get install -y curl build-essential pkg-config libssl-dev
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
# 3. Install Rust
|
|
57
|
+
if ! command -v cargo &> /dev/null; then
|
|
58
|
+
echo "Installing Rust..."
|
|
59
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
|
60
|
+
source $HOME/.cargo/env
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
# 4. Install Solana
|
|
64
|
+
if ! command -v solana &> /dev/null; then
|
|
65
|
+
echo "Installing Solana..."
|
|
66
|
+
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
|
|
67
|
+
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
# 5. Install Anchor (AVM)
|
|
71
|
+
if ! command -v avm &> /dev/null; then
|
|
72
|
+
echo "Installing AVM..."
|
|
73
|
+
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
|
|
74
|
+
avm install latest
|
|
75
|
+
avm use latest
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
echo "✅ WSL Setup Complete."
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
// Write script to a temporary file in Windows (which is mounted in WSL)
|
|
82
|
+
const scriptPath = path.join(process.cwd(), 'setup_wsl.sh');
|
|
83
|
+
fs.writeFileSync(scriptPath, setupScript);
|
|
84
|
+
|
|
85
|
+
// Convert path to WSL format
|
|
86
|
+
const wslScriptPath = toWslPath(scriptPath);
|
|
87
|
+
|
|
88
|
+
// Run the script inside WSL
|
|
89
|
+
// We pipe the script content to bash to avoid permission issues with the file itself
|
|
90
|
+
// Or just run it. Let's run it.
|
|
91
|
+
|
|
92
|
+
const spin = spinner('Running Linux setup script (this takes a while)...').start();
|
|
93
|
+
|
|
94
|
+
// Ensure line endings are LF
|
|
95
|
+
const linuxScript = setupScript.replace(/\r\n/g, '\n');
|
|
96
|
+
fs.writeFileSync(scriptPath, linuxScript);
|
|
97
|
+
|
|
98
|
+
const res = shell.exec(`wsl -d Ubuntu -e bash "${wslScriptPath}"`);
|
|
99
|
+
|
|
100
|
+
// Clean up
|
|
101
|
+
fs.unlinkSync(scriptPath);
|
|
102
|
+
|
|
103
|
+
if (res.code === 0) {
|
|
104
|
+
spin.succeed('Linux environment configured successfully.');
|
|
105
|
+
|
|
106
|
+
// 4. Set "Stealth Mode" config (could be a local file or env var)
|
|
107
|
+
// For now, we assume if the user ran --wsl, they want to use it.
|
|
108
|
+
// We could create a .uso-config.json
|
|
109
|
+
const configPath = path.join(os.homedir(), '.uso-config.json');
|
|
110
|
+
const config = { mode: 'wsl', distro: 'Ubuntu' };
|
|
111
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
112
|
+
|
|
113
|
+
log.success("✅ Stealth Mode Enabled. 'uso' commands will now run via WSL.");
|
|
114
|
+
return true;
|
|
115
|
+
} else {
|
|
116
|
+
spin.fail('Setup script failed.');
|
|
117
|
+
log.error(res.stderr);
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
module.exports = { installWsl };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const shell = require('shelljs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const { log } = require('./logger');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Checks if WSL is installed and enabled.
|
|
8
|
+
*/
|
|
9
|
+
const isWslInstalled = () => {
|
|
10
|
+
if (os.platform() !== 'win32') return false;
|
|
11
|
+
const res = shell.exec('wsl --status', { silent: true });
|
|
12
|
+
return res.code === 0;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Checks if a specific distro is installed.
|
|
17
|
+
* @param {string} distro Name of the distro (e.g., "Ubuntu")
|
|
18
|
+
*/
|
|
19
|
+
const isDistroInstalled = (distro = 'Ubuntu') => {
|
|
20
|
+
if (os.platform() !== 'win32') return false;
|
|
21
|
+
// wsl --list --quiet returns names only, utf-16le encoded often in PowerShell.
|
|
22
|
+
// simpler to use wsl -l -v and check output
|
|
23
|
+
const res = shell.exec('wsl -l -v', { silent: true });
|
|
24
|
+
return res.stdout.includes(distro) || res.stderr.includes(distro); // sometimes stderr depending on version
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Converts a Windows path (C:\Users\...) to a WSL path (/mnt/c/Users/...).
|
|
29
|
+
* @param {string} windowsPath
|
|
30
|
+
*/
|
|
31
|
+
const toWslPath = (windowsPath) => {
|
|
32
|
+
if (!windowsPath) return '';
|
|
33
|
+
// Handle drive letter
|
|
34
|
+
let wslPath = windowsPath.replace(/^([a-zA-Z]):/, (match, drive) => `/mnt/${drive.toLowerCase()}`);
|
|
35
|
+
// Replace backslashes with forward slashes
|
|
36
|
+
wslPath = wslPath.replace(/\\/g, '/');
|
|
37
|
+
return wslPath;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Runs a command inside the default WSL distro (or specified one).
|
|
42
|
+
* @param {string} command The shell command to run in Linux
|
|
43
|
+
* @param {object} options { distro: 'Ubuntu', cwd: 'C:\\...', interactive: false }
|
|
44
|
+
*/
|
|
45
|
+
const runWsl = (command, options = {}) => {
|
|
46
|
+
const distro = options.distro || 'Ubuntu';
|
|
47
|
+
const cwd = options.cwd ? toWslPath(options.cwd) : '';
|
|
48
|
+
|
|
49
|
+
// Construct the WSL command
|
|
50
|
+
// wsl -d Ubuntu -e bash -c "cd /mnt/c/... && <command>"
|
|
51
|
+
|
|
52
|
+
let wslCmd = `wsl -d ${distro}`;
|
|
53
|
+
|
|
54
|
+
if (options.user) {
|
|
55
|
+
wslCmd += ` -u ${options.user}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Prepare the bash script
|
|
59
|
+
let bashScript = '';
|
|
60
|
+
if (cwd) {
|
|
61
|
+
bashScript += `cd "${cwd}" && `;
|
|
62
|
+
}
|
|
63
|
+
bashScript += command;
|
|
64
|
+
|
|
65
|
+
// Execute
|
|
66
|
+
// Note: We use shell.exec. If interactive, maybe spawn?
|
|
67
|
+
// For "Stealth Mode", we usually want to capture output or just run it.
|
|
68
|
+
|
|
69
|
+
// Escape double quotes for the -c argument
|
|
70
|
+
const escapedScript = bashScript.replace(/"/g, '\\"');
|
|
71
|
+
|
|
72
|
+
const fullCmd = `${wslCmd} -e bash -c "${escapedScript}"`;
|
|
73
|
+
|
|
74
|
+
// log.info(`[WSL Bridge] Executing: ${fullCmd}`); // Debug
|
|
75
|
+
|
|
76
|
+
return shell.exec(fullCmd, options.execOpts || {});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
module.exports = {
|
|
80
|
+
isWslInstalled,
|
|
81
|
+
isDistroInstalled,
|
|
82
|
+
toWslPath,
|
|
83
|
+
runWsl
|
|
84
|
+
};
|