fix: ttyd 改用 apt install,不再从 GitHub 下载

- install.sh: 改为 apt install -y ttyd,删除 GitHub 下载逻辑
- frpc.js: TTYD_BIN 改为 findTtydBin() 动态查找系统路径,删除 downloadTtyd()

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-04-06 15:17:27 +08:00
parent f6afcd5cc2
commit 43deb9afa0
2 changed files with 24 additions and 55 deletions

View File

@@ -12,11 +12,17 @@ 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 FRPC_CONFIG = path.join(CONFIG_DIR, 'frpc.toml');
const TTYD_BIN = path.join(CONFIG_DIR, 'ttyd');
const FRP_VERSION = '0.62.0';
const TTYD_VERSION = '1.7.7';
const TTYD_PORT = 7681;
const FRP_VERSION = '0.62.0';
const TTYD_PORT = 7681;
function findTtydBin() {
const candidates = ['/usr/bin/ttyd', '/usr/local/bin/ttyd', path.join(CONFIG_DIR, 'ttyd')];
for (const p of candidates) {
if (fs.existsSync(p)) return p;
}
return null;
}
/** openclaw 持久化配置JSON结构与原 YAML 解析结果一致。 */
const OPENCLAW_JSON_CANDIDATES = [
@@ -87,48 +93,35 @@ async function downloadFrpc() {
log.info('frpc', `frpc 已安装到 ${FRPC_BIN}`);
}
async function downloadTtyd() {
const arch = os.arch();
const archMap = { arm64: 'aarch64', x64: 'x86_64', arm: 'armv7l', ia32: 'i686' };
const ttydArch = archMap[arch] || 'x86_64';
const url = `https://github.com/tsl0922/ttyd/releases/download/${TTYD_VERSION}/ttyd.${ttydArch}`;
log.info('ttyd', `下载 ttyd ${TTYD_VERSION} (${ttydArch})...`);
fs.mkdirSync(CONFIG_DIR, { recursive: true });
await downloadFile(url, TTYD_BIN);
fs.chmodSync(TTYD_BIN, 0o755);
log.info('ttyd', `ttyd 已安装到 ${TTYD_BIN}`);
}
/**
* 启动 ttyd由 install.sh 预装到 TTYD_BIN)。
* 启动 ttyd由 install.sh 通过 apt 安装)。
* ttyd 绑定 127.0.0.1:7681供 frpc 代理。
*/
async function startTtyd() {
if (!fs.existsSync(TTYD_BIN)) {
log.warn('ttyd', `未找到 ttyd${TTYD_BIN}),请重新运行 install.sh`);
const ttydBin = findTtydBin();
if (!ttydBin) {
log.warn('ttyd', '未找到 ttyd请重新运行 install.sh');
return false;
}
// 终止所有 ttyd 进程(包括系统自带的,避免端口冲突
// 终止所有 ttyd 进程,避免端口冲突
try {
execSync('pkill -x ttyd 2>/dev/null; pkill -x ttyd.aarch64 2>/dev/null; true', { timeout: 3000, shell: true });
execSync('pkill -x ttyd 2>/dev/null; true', { timeout: 3000, shell: true });
await new Promise(r => setTimeout(r, 500));
} catch (_) {}
try {
const shell = fs.existsSync('/bin/bash') ? '/bin/bash' : '/bin/sh';
// 以普通用户身份启动 shell与 SSH 登录一致)
const ttydUser = process.env.CLAWD_TTY_USER || 'sts';
const ttyEnv = { ...process.env };
delete ttyEnv.NOTIFY_SOCKET;
const proc = spawn(TTYD_BIN, ['-p', String(TTYD_PORT), '-i', '127.0.0.1', '-W', '-t', 'cursorBlink=true', '/bin/su', '-', ttydUser], {
const proc = spawn(ttydBin, ['-p', String(TTYD_PORT), '-i', '127.0.0.1', '-W', '-t', 'cursorBlink=true', '/bin/su', '-', ttydUser], {
stdio: 'ignore',
detached: true,
env: ttyEnv,
});
proc.unref();
log.info('ttyd', `已启动,端口 ${TTYD_PORT},用户=${ttydUser}`);
log.info('ttyd', `已启动,端口 ${TTYD_PORT},用户=${ttydUser}bin=${ttydBin}`);
return true;
} catch (e) {
log.warn('ttyd', '启动失败:', e.message);