Files
ocr_data/scripts/build_bundle.sh
2026-09-28 16:09:31 +08:00

49 lines
1.9 KiB
Bash
Raw Permalink 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.

#!/usr/bin/env bash
# =============================================================================
# 一键构建离线部署包(在【能联网】的打包机上跑)
#
# setup_server.sh(装环境) → make_portable.sh(自包含) → pack.sh(打包) 三步合一
#
# 用法:
# bash build_bundle.sh cpu # CPU 版包:johnvansickle ffmpeg,老 glibc 也能跑
# bash build_bundle.sh gpu # GPU 版包:BtbN cuda ffmpeg,目标机需 glibc>=2.28
# bash build_bundle.sh gpu --whisper-gpu # GPU 版 + 把 CUDA 库打进包(目标机无系统 CUDA 也能 whisper GPU)
#
# 产物: /tmp/ocr_offline_bundle.tar.gz
# 拷到目标机后: bash deploy.sh /tmp/ocr_offline_bundle.tar.gz /opt
# =============================================================================
set -euo pipefail
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VARIANT="${1:-cpu}" # cpu | gpu
WHISPER_GPU_FLAG=0
[ "${2:-}" = "--whisper-gpu" ] && WHISPER_GPU_FLAG=1
log() { echo -e "\n\033[1;36m##### $* #####\033[0m"; }
case "$VARIANT" in
cpu) FFV=cpu ;;
gpu) FFV=gpu ;;
*) echo "用法: bash build_bundle.sh [cpu|gpu] [--whisper-gpu]"; exit 1 ;;
esac
SD="$(cd "$(dirname "$0")" && pwd)"
log "构建 $VARIANT 版离线包 (whisper_gpu=$WHISPER_GPU_FLAG)"
# 1) 装基础环境(已装过会跳过大部分)
log "1/3 setup_server.sh(装 gcc/uv/python/依赖)"
bash "$SD/setup_server.sh"
# 2) 转自包含(python+模型+ffmpeg 进项目)
log "2/3 make_portable.sh(FFMPEG_VARIANT=$FFV)"
FFMPEG_VARIANT="$FFV" WHISPER_GPU="$WHISPER_GPU_FLAG" bash "$SD/make_portable.sh"
# 3) 打包(按变体命名,cpu/gpu 两个包不会互相覆盖)
OUT="/tmp/ocr_bundle_${VARIANT}.tar.gz"
log "3/3 pack.sh(打成 tar → $OUT)"
bash "$SD/pack.sh" "$OUT"
echo
echo "✅ 完成。产物: $OUT"
echo " 拷到目标机后: bash $SD/deploy.sh $OUT /opt"