diff --git a/install.sh b/install.sh index b95afa1..67b69df 100644 --- a/install.sh +++ b/install.sh @@ -110,11 +110,12 @@ systemctl daemon-reload systemctl enable clawd-rfkill info "WiFi rfkill 解锁服务已创建 ✓" -# ── 移除系统自带 ttyd(避免与 clawd 托管的 ttyd 端口冲突)──────────────────── -if command -v dpkg &>/dev/null && dpkg -l ttyd 2>/dev/null | grep -q '^ii'; then - info "移除系统 ttyd 包(避免端口冲突)..." - apt-get remove -y ttyd >/dev/null 2>&1 || true - info "系统 ttyd 已移除 ✓" +# ── 安装 ttyd(Web 终端)──────────────────────────────────────────────────── +info "安装 ttyd..." +if apt-get install -y ttyd >/dev/null 2>&1; then + info "ttyd 已安装 ✓" +else + warn "ttyd 安装失败,Web 终端功能将不可用" fi # ── 安装 clawd ─────────────────────────────────────────────────────────────── @@ -150,31 +151,6 @@ chmod +x "$INSTALL_DIR/bin/clawd.js" info "clawd 已安装到 /usr/local/bin/clawd ✓" -# ── 下载 ttyd(Web 终端)──────────────────────────────────────────────────── -TTYD_BIN="$CONFIG_DIR/ttyd" -TTYD_VERSION="1.7.7" -if [ ! -f "$TTYD_BIN" ]; then - ARCH=$(uname -m) - case "$ARCH" in - aarch64|arm64) TTYD_ARCH="aarch64" ;; - x86_64) TTYD_ARCH="x86_64" ;; - armv7l|armv6l) TTYD_ARCH="armv7l" ;; - i686) TTYD_ARCH="i686" ;; - *) TTYD_ARCH="x86_64" ;; - esac - TTYD_URL="https://github.com/tsl0922/ttyd/releases/download/${TTYD_VERSION}/ttyd.${TTYD_ARCH}" - info "下载 ttyd ${TTYD_VERSION} (${TTYD_ARCH})..." - if curl -fsSL -o "$TTYD_BIN" "$TTYD_URL" && [ -s "$TTYD_BIN" ]; then - chmod 755 "$TTYD_BIN" - info "ttyd 已安装到 $TTYD_BIN ✓" - else - rm -f "$TTYD_BIN" - warn "ttyd 下载失败(网络问题?),请手动下载并放置到 $TTYD_BIN" - warn " 下载地址: $TTYD_URL" - fi -else - info "ttyd 已存在,跳过下载 ✓" -fi # ── 创建配置目录 + 环境变量文件 ────────────────────────────────────────────── mkdir -p "$CONFIG_DIR" diff --git a/lib/frpc.js b/lib/frpc.js index 29310df..2ceaf3d 100644 --- a/lib/frpc.js +++ b/lib/frpc.js @@ -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);