#!/bin/bash # ============================================================ # OpenDance Studio Web API —— 外部依赖 Assimp 的定位与安装 # # 本文件被 install.sh 引用(不要单独执行)。 # # Assimp 是**外部**命令行工具(BSD-3-Clause),不在 Node 依赖里。 # 它只影响两件事: # * 上传 .pmx / .fbx(或含它们的压缩包)时的服务端转换; # * FBX / glTF 动作的预处理。 # 直接上传 .glb / .vrm 模型,或 .bvh / .vmd / 关键点 JSON 动作,都不需要它。 # 因此这里「装不上」不叫失败,但必须给出结论与可复制的安装命令。 # ============================================================ # 当前发行版对应的安装命令(用于提示) # 注意:只装 assimp-utils(它会按发行版自动带上对应版本的 libassimp5/6), # 不写死库名 —— Debian 11 / Ubuntu 22.04 是 libassimp5,Debian 12+ 才是 libassimp6。 opendance_assimp_install_cmd() { if command -v apt-get >/dev/null 2>&1; then printf 'apt-get update && apt-get install -y assimp-utils' 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 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 }