feat: add simplified windows x86 support
This commit is contained in:
+40
-22
@@ -1,16 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const { execSync, spawn } = require('child_process');
|
||||
const { execSync, execFileSync, spawn } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const https = require('https');
|
||||
const log = require('./logger');
|
||||
const { Watchdog } = require('./watchdog');
|
||||
const { IS_WINDOWS, getConfigDir, getOpenClawConfigCandidates } = require('./platform-paths');
|
||||
|
||||
const CONFIG_DIR = process.env.CLAWD_CONFIG_DIR
|
||||
|| (process.getuid && process.getuid() === 0 ? '/etc/clawd' : path.join(os.homedir(), '.clawd'));
|
||||
const FRPC_BIN = path.join(CONFIG_DIR, 'frpc');
|
||||
const CONFIG_DIR = getConfigDir();
|
||||
const FRPC_BIN = path.join(CONFIG_DIR, IS_WINDOWS ? 'frpc.exe' : 'frpc');
|
||||
const FRPC_CONFIG = path.join(CONFIG_DIR, 'frpc.toml');
|
||||
|
||||
const FRP_VERSION = '0.62.0';
|
||||
@@ -26,9 +26,7 @@ function findTtydBin() {
|
||||
|
||||
/** openclaw 持久化配置(JSON),结构与原 YAML 解析结果一致。 */
|
||||
const OPENCLAW_JSON_CANDIDATES = [
|
||||
path.join(os.homedir(), '.openclaw', 'openclaw.json'),
|
||||
'/home/sts/.openclaw/openclaw.json',
|
||||
'/root/.openclaw/openclaw.json',
|
||||
...getOpenClawConfigCandidates(),
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -77,23 +75,37 @@ async function downloadFrpc() {
|
||||
};
|
||||
const frpArch = archMap[arch] || 'amd64';
|
||||
|
||||
const filename = `frp_${FRP_VERSION}_${platform}_${frpArch}.tar.gz`;
|
||||
const ext = IS_WINDOWS ? 'zip' : 'tar.gz';
|
||||
const filename = `frp_${FRP_VERSION}_${platform}_${frpArch}.${ext}`;
|
||||
const releaseBase = 'https://git.cutos.ai/claw-daemon/fatedier/releases/download';
|
||||
const attachmentMap = {
|
||||
'linux/arm64': 'https://git.cutos.ai/attachments/071748ed-955b-44c0-8dfb-38396b5dae6e',
|
||||
};
|
||||
const url = attachmentMap[`${platform}/${frpArch}`] || `${releaseBase}/v${FRP_VERSION}/${filename}`;
|
||||
const tmpFile = `/tmp/${filename}`;
|
||||
const tmpFile = path.join(os.tmpdir(), filename);
|
||||
|
||||
log.info('frpc', `下载 frpc ${FRP_VERSION} (${platform}/${frpArch})...`);
|
||||
|
||||
await downloadFile(url, tmpFile);
|
||||
|
||||
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
||||
execSync(`tar -xzf ${tmpFile} -C /tmp && cp /tmp/frp_${FRP_VERSION}_${platform}_${frpArch}/frpc ${FRPC_BIN}`, {
|
||||
stdio: 'inherit'
|
||||
});
|
||||
fs.chmodSync(FRPC_BIN, 0o755);
|
||||
const packageDir = `frp_${FRP_VERSION}_${platform}_${frpArch}`;
|
||||
if (IS_WINDOWS) {
|
||||
const extractDir = path.join(os.tmpdir(), `clawd-frp-${FRP_VERSION}-${Date.now()}`);
|
||||
fs.mkdirSync(extractDir, { recursive: true });
|
||||
execFileSync('powershell.exe', [
|
||||
'-NoProfile',
|
||||
'-ExecutionPolicy', 'Bypass',
|
||||
'-Command',
|
||||
`Expand-Archive -Force -LiteralPath '${tmpFile.replace(/'/g, "''")}' -DestinationPath '${extractDir.replace(/'/g, "''")}'`,
|
||||
], { stdio: 'inherit', windowsHide: true });
|
||||
fs.copyFileSync(path.join(extractDir, packageDir, 'frpc.exe'), FRPC_BIN);
|
||||
} else {
|
||||
execSync(`tar -xzf ${tmpFile} -C /tmp && cp /tmp/${packageDir}/frpc ${FRPC_BIN}`, {
|
||||
stdio: 'inherit'
|
||||
});
|
||||
fs.chmodSync(FRPC_BIN, 0o755);
|
||||
}
|
||||
log.info('frpc', `frpc 已安装到 ${FRPC_BIN}`);
|
||||
}
|
||||
|
||||
@@ -103,6 +115,11 @@ async function downloadFrpc() {
|
||||
* ttyd 绑定 127.0.0.1:7681,供 frpc 代理。
|
||||
*/
|
||||
async function startTtyd() {
|
||||
if (IS_WINDOWS) {
|
||||
log.info('ttyd', 'Windows/x86 mode: terminal proxy is disabled');
|
||||
return false;
|
||||
}
|
||||
|
||||
const ttydBin = findTtydBin();
|
||||
if (!ttydBin) {
|
||||
log.warn('ttyd', '未找到 ttyd,请重新运行 install.sh');
|
||||
@@ -150,13 +167,20 @@ function downloadFile(url, dest) {
|
||||
function writeFrpcConfig(clawId, frpConfig, sshSecretKey) {
|
||||
const { auth_token, dashboard_local_port = 18789 } = frpConfig;
|
||||
const ttyRemotePort = 10000 + Number(clawId);
|
||||
const stcpBlock = sshSecretKey ? `
|
||||
const stcpBlock = (!IS_WINDOWS && sshSecretKey) ? `
|
||||
[[proxies]]
|
||||
name = "ssh-${clawId}-secret"
|
||||
type = "stcp"
|
||||
secretKey = "${sshSecretKey}"
|
||||
localPort = 22
|
||||
` : '';
|
||||
const ttyBlock = IS_WINDOWS ? '' : `
|
||||
[[proxies]]
|
||||
name = "tty-${clawId}"
|
||||
type = "tcp"
|
||||
localPort = ${TTYD_PORT}
|
||||
remotePort = ${ttyRemotePort}
|
||||
`;
|
||||
const toml = `# 由 clawd 自动生成,请勿手动修改
|
||||
serverAddr = "frp.claw.cutos.ai"
|
||||
serverPort = 443
|
||||
@@ -173,16 +197,10 @@ name = "dashboard-${clawId}"
|
||||
type = "http"
|
||||
localPort = ${dashboard_local_port}
|
||||
subdomain = "${clawId}"
|
||||
|
||||
[[proxies]]
|
||||
name = "tty-${clawId}"
|
||||
type = "tcp"
|
||||
localPort = ${TTYD_PORT}
|
||||
remotePort = ${ttyRemotePort}
|
||||
${stcpBlock}`;
|
||||
${ttyBlock}${stcpBlock}`;
|
||||
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
||||
fs.writeFileSync(FRPC_CONFIG, toml, 'utf8');
|
||||
log.info('frpc', `frpc.toml 已写入: dashboard subdomain=${clawId}, tty tcp-port=${ttyRemotePort}${sshSecretKey ? ', ssh stcp=enabled' : ''}`);
|
||||
log.info('frpc', `frpc.toml 已写入: dashboard subdomain=${clawId}${IS_WINDOWS ? '' : `, tty tcp-port=${ttyRemotePort}`}${stcpBlock ? ', ssh stcp=enabled' : ''}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user