#!/bin/bash # 打包部署文件,用于快速部署到其它 RK3568 # 打包产物与 pack.sh 同目录 (deploy/) # 用法: ./deploy/pack.sh [-c] [-j N] # -c 打包前先编译 # -j N 编译并行数 (默认 nproc) set -e DIR="$(cd "$(dirname "$0")/.." && pwd)" BUILD_DIR="$DIR/build" DEPLOY_DIR="$(cd "$(dirname "$0")" && pwd)" OUT_DIR="/tmp/rtsp_multi_view_deploy" TARBALL="$DEPLOY_DIR/rtsp_multi_view_aarch64_$(date +%Y%m%d_%H%M%S).tar.gz" DO_BUILD=0 JOBS=${JOBS:-$(nproc)} while [ $# -gt 0 ]; do case "$1" in -c) DO_BUILD=1 ;; -j) JOBS="$2"; shift ;; *) echo "Unknown option: $1"; exit 1 ;; esac shift done if [ "$DO_BUILD" -eq 1 ]; then echo "== 编译 ==" "$DIR/build.sh" -j "$JOBS" fi # 检查必要文件 for f in "$BUILD_DIR/rtsp_multi_view" "$BUILD_DIR/plc_sim" "$DIR/plc_server.py" "$DIR/channels.conf" "$DEPLOY_DIR/install.sh"; do if [ ! -f "$f" ]; then echo "ERROR: $f 不存在,请先编译或检查文件" >&2 exit 1 fi done echo "== 准备打包目录 ==" rm -rf "$OUT_DIR" mkdir -p "$OUT_DIR"/{bin,conf,models,scripts,fonts} echo "== 复制文件 ==" # 二进制 cp "$BUILD_DIR/rtsp_multi_view" "$OUT_DIR/bin/" cp "$BUILD_DIR/plc_sim" "$OUT_DIR/bin/" chmod +x "$OUT_DIR/bin/"* # 配置 cp "$DIR/channels.conf" "$OUT_DIR/conf/" # 模型 if [ -d "$DIR/models" ] && ls "$DIR/models/"* >/dev/null 2>&1; then cp "$DIR/models/"* "$OUT_DIR/models/" fi # 脚本 cp "$DIR/plc_server.py" "$OUT_DIR/scripts/" cp "$DIR/plc_server.sh" "$OUT_DIR/scripts/" cp "$DIR/auto_reboot.sh" "$OUT_DIR/scripts/" chmod +x "$OUT_DIR/scripts/"*.sh # Logo if [ -f "$DIR/fltk.png" ]; then cp "$DIR/fltk.png" "$OUT_DIR/" fi # 中文字体(标题栏渲染用,避免目标机缺 wqy-microhei 时标题文字不显示) if [ -f "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc" ]; then cp "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc" "$OUT_DIR/fonts/" fi # 目标机安装脚本:复用统一的 deploy/install.sh(唯一维护源) cp "$DEPLOY_DIR/install.sh" "$OUT_DIR/install.sh" chmod +x "$OUT_DIR/install.sh" # 可选:离线依赖 deb(若 deploy/deps/ 存在则随包携带,install.sh 会自动使用) if [ -d "$DEPLOY_DIR/deps" ] && ls "$DEPLOY_DIR/deps/"*.deb >/dev/null 2>&1; then mkdir -p "$OUT_DIR/deps" cp "$DEPLOY_DIR/deps/"*.deb "$OUT_DIR/deps/" echo " 已包含离线依赖: $(ls "$DEPLOY_DIR/deps/"*.deb | wc -l) 个 deb" fi echo "== 生成打包 ==" cd /tmp tar czf "$TARBALL" -C /tmp rtsp_multi_view_deploy rm -rf "$OUT_DIR" SIZE=$(du -h "$TARBALL" | cut -f1) echo "" echo "==========================================" echo " 打包完成!" echo "==========================================" echo " 文件: $TARBALL" echo " 大小: $SIZE" echo "" echo " 部署到目标机:" echo " scp $TARBALL root@<目标IP>:/tmp/" echo " ssh root@<目标IP>" echo " cd /tmp && tar xzf $(basename "$TARBALL") && cd rtsp_multi_view_deploy && ./install.sh" echo ""