Files
agent/skills/office/install.sh
T
kicer a52b227d8b refactor(skills): 本地安装改成「README 式说明」,install.sh/requirements.txt 归服务器
按三条原则收紧:
1) 线上零影响:office/install.sh 回退成原来的 linux-only 版本(本地本来就不该跑它);
   image-process 的字体候选表撤回(那是在代码里写环境兼容,方向错了)。
2) install.sh / requirements.txt 只做服务器工件:镜像构建与 agent-executor-init 读它们,
   行为一字未变。
3) 本机缺东西时由 .md 指路,模型自己去装:四个技能各加 INSTALL.md(具体命令 + 平台
   资产/字体表 + 验证方式),并在 SKILL.md 里各加一行指向它(skill get 就能看到)。
   报错文案带上 INSTALL.md 的绝对路径,所以「撞到缺依赖」的那一刻就能拿到说明书。

保留的两处代码钩子都不是环境探测,而是「说明书里写的安装方式得真能生效」:
- office: start.sh 把 skills/office/scripts 塞进 PATH(本地没 root 写 /usr/local/bin);
  封装层 ENOENT 指向 INSTALL.md。
- x2pdf: find_soffice() 探 macOS app bundle(brew cask 装的 soffice 不在 PATH);
  WeasyPrint 不可用时回落 LibreOffice,让本地只需一个后端而不是 pango+WeasyPrint 两条链。

INSTALL.md 里 officecli 指向 releases/latest(它会自更新,实测 1.0.157 跑一次变 1.0.160),
不要求与服务器 pin 对齐。

实测:office --version / office create / office view outline 正常;x2pdf 缺 markdown 与
image-process 缺字体两条报错都给出 INSTALL.md 绝对路径,按 font 参数即通过。
2026-11-11 17:34:30 +08:00

68 lines
3.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# office 技能资产与入口(skills/README 5.2 约定:本脚本在「镜像构建(skills 阶段)」与「启动 init」两处都跑,必须幂等):
#
# 1) 资产 bin/officecli —— officecli 官方 .NET 单文件二进制(v1.0.157 linux-x64)。
# 不进 git(.gitignore 已排除 skills/office/bin/)、不进镜像:init 阶段写进宿主 ./skills 卷,
# executor 容器以 :ro 挂到 /workspace/skills —— 运行期只读执行,改动版本=改本文件 pin 重启。
# 构建阶段($HERE 在 /tmp 下,产物即弃)跳过下载,只烘 PATH 入口。
# 主源 GitHub,备源 gh-proxy(国内网络);sha256 必须等于 pin,宁缺毋错。
# 2) PATH 入口 /usr/local/bin/office -> <运行期技能根>/scripts/office —— 构建阶段写进镜像层持久;
# init 阶段根只读,|| true 静默(镜像里已就位)。officecli 二进制刻意不进 PATH:模型只见封装层。
#
# 两个源都拉不到:exit 1(init 不写 marker,下次启动自动重试);救急可手动放置同名二进制到
# skills/office/bin/officecli(sha 对上即认),再 docker compose up -d 重跑 init。
set -u
HERE="$(cd "$(dirname "$0")" && pwd)"
VER=v1.0.157
SHA=f8eefe88dbfa7464bee421e5421efe57fc26bc3180b30e56eef58594c8245c94
ASSET="$HERE/bin/officecli"
ln -sfn "${EXECUTOR_SKILLS_DIR:-/workspace/skills}/office/scripts/office" /usr/local/bin/office 2>/dev/null || true
# 构建阶段:PATH 入口已烘,资产交给 init(避免每次 skills 层重建白拉 35MB)
case "$HERE" in
/tmp/*) echo "[office] build stage: PATH 入口就位;bin/officecli 资产由 init 阶段落到技能卷"; exit 0 ;;
esac
verify() { [ -f "$ASSET" ] && echo "$SHA $ASSET" | sha256sum -c - >/dev/null 2>&1; }
if verify; then
echo "[office] 资产已就位(sha 匹配):$ASSET"
exit 0
fi
mkdir -p "$HERE/bin"
for u in "https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/officecli-linux-x64" \
"https://gh-proxy.com/https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/officecli-linux-x64"; do
echo "[office] 拉取 $u (connect<=10s, speed>=100KB/s, max 300s)"
t0=$(date +%s)
if curl -fL \
--connect-timeout 10 \
--max-time 300 \
--speed-limit 102400 \
--speed-time 20 \
--retry 1 \
--progress-bar \
-o "$ASSET.tmp" "$u"; then
got="$(sha256sum "$ASSET.tmp" | cut -d' ' -f1)"
if [ "$got" = "$SHA" ]; then
mv -f "$ASSET.tmp" "$ASSET"
chmod 755 "$ASSET"
echo "[office] officecli $VER installed -> $ASSET ($(( $(date +%s) - t0 ))s)"
break
fi
echo "[office] sha256 mismatch (got $got), trying next source"
else
echo "[office] $(( $(date +%s) - t0 ))s 后失败: $u"
fi
rm -f "$ASSET.tmp"
done
if verify; then
echo "[office] 就绪:$ASSET"
exit 0
else
echo "[office] 两个源都拉不到 bin/officecli —— 手动放置 $ASSET(sha 对上即认)后 docker compose up -d 重试" >&2
exit 1
fi