Files
opendance-web/deploy/assimp-lib.sh
T
opendance da03777995 fix(models): Assimp 缺失时给出可操作报错,部署脚本自动安装
现象:服务器未安装 Assimp,上传 PMX 压缩包只得到
  GLB 直出:导出失败(ENOENT):spawn assimp ENOENT
  glTF 直出:导出失败(ENOENT):spawn assimp ENOENT
用户看不出缺什么、怎么装,也不知道只传 glb/vrm 其实不需要它。

修复:
1. 新增 src/common/assimp.ts:按 ASSIMP_BIN -> PATH -> /usr/bin、/usr/local/bin
   等常见目录定位可执行文件(只认文件,不认同名目录),转换前先预检;
   找不到就一次性给出各发行版安装命令、查过的路径与替代办法,
   不再打两条 ENOENT。动作预处理(FBX/glTF -> BVH)复用同一文案。
2. 新增 deploy/assimp-lib.sh:install.sh 按发行版自动安装
   (apt-get / dnf / yum / zypper / apk / pacman),装在非常规目录时把绝对
   路径写入 deploy/.env 的 ASSIMP_BIN;装不上只告警不中止,可用
   SKIP_ASSIMP_INSTALL=1 跳过。check-access.sh 自检增加 Assimp 一行。
3. /health 增加 assimp.path;管理端「概览 -> 服务健康」显示 Assimp 状态,
   不可用时给出安装提示。
4. 新增 test/assimp-locate.spec.ts 13 项;强化「assimp 不存在」用例断言安装命令。
   测试规模 12 文件 / 193 项。
5. 版本 0.2.2,README(.md/.txt)/DSH.md 同步(前置要求、FAQ、环境变量说明)。
2026-09-16 02:55:32 +08:00

69 lines
3.1 KiB
Bash
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
# ============================================================
# OpenDance Studio Web API —— 外部依赖 Assimp 的定位与安装
#
# 本文件被 install.sh 引用(不要单独执行)。
#
# Assimp 是**外部**命令行工具(BSD-3-Clause),不在 Node 依赖里。
# 它只影响两件事:
# * 上传 .pmx / .fbx(或含它们的压缩包)时的服务端转换;
# * FBX / glTF 动作的预处理。
# 直接上传 .glb / .vrm 模型,或 .bvh / .vmd / 关键点 JSON 动作,都不需要它。
# 因此这里「装不上」不叫失败,但必须给出结论与可复制的安装命令。
# ============================================================
# 当前发行版对应的安装命令(用于提示)
opendance_assimp_install_cmd() {
if command -v apt-get >/dev/null 2>&1; then
printf 'apt-get update && apt-get install -y assimp-utils libassimp6'
elif command -v dnf >/dev/null 2>&1; then
printf 'dnf install -y assimp'
elif command -v yum >/dev/null 2>&1; then
printf 'yum install -y assimp'
elif command -v zypper >/dev/null 2>&1; then
printf 'zypper --non-interactive install assimp'
elif command -v apk >/dev/null 2>&1; then
printf 'apk add --no-cache assimp'
elif command -v pacman >/dev/null 2>&1; then
printf 'pacman -S --noconfirm assimp'
else
printf '用发行版包管理器安装 assimp 命令行工具'
fi
}
# 真正执行安装(静默细节,成功返回 0)
opendance_assimp_install() {
if command -v apt-get >/dev/null 2>&1; then
DEBIAN_FRONTEND=noninteractive apt-get update -qq &&
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq assimp-utils libassimp6
elif command -v dnf >/dev/null 2>&1; then dnf install -y -q assimp
elif command -v yum >/dev/null 2>&1; then yum install -y -q assimp
elif command -v zypper >/dev/null 2>&1; then zypper --non-interactive install assimp
elif command -v apk >/dev/null 2>&1; then apk add --no-cache assimp
elif command -v pacman >/dev/null 2>&1; then pacman -S --noconfirm assimp
else return 1
fi
}
# 解析 Assimp 的实际路径:ASSIMP_BIN -> PATH -> 常见系统目录
# 找到时把绝对路径打印到 stdout 并返回 0;否则返回 1(stdout 为空)
opendance_assimp_resolve() {
local bin="${ASSIMP_BIN:-assimp}" dir candidate
# 必须同时是**文件**且可执行:只判 -x 会把目录(例如 ASSIMP_BIN=/usr/bin/)当成可执行文件
if [ -f "$bin" ] && [ -x "$bin" ]; then printf '%s' "$bin"; return 0; fi
if command -v "$bin" >/dev/null 2>&1; then command -v "$bin"; return 0; fi
for dir in /usr/bin /usr/local/bin /usr/sbin /usr/local/sbin /snap/bin; do
candidate="$dir/${bin##*/}" # 用参数展开代替 basename: PATH 极窄时 basename 可能不可用
if [ -f "$candidate" ] && [ -x "$candidate" ]; then printf '%s' "$candidate"; return 0; fi
done
return 1
}
# 该目录是否已在服务的默认 PATH 中(否 -> 需要把绝对路径写进 .env)
opendance_assimp_needs_env_path() {
case "$(dirname "${1:-}")" in
/bin|/usr/bin|/usr/local/bin|/sbin|/usr/sbin) return 1 ;;
*) return 0 ;;
esac
}