Files
airborne_CO2/package.sh
xin c0f974fd4c 添加打包脚本 package.sh
用于构建项目并打包成 deb 文件
2026-03-04 15:08:52 +08:00

127 lines
2.7 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
# Airborne CO2 项目打包脚本
# 打包成 Debian 包
VERSION=1.0.0
PROJECT_NAME="AirborneCO2"
PACKAGE_NAME="${PROJECT_NAME}_V${VERSION}.deb"
BUILD_DIR="build"
DEB_DIR="DebpackAirborneCO2"
# 检查是否在正确目录
if [ ! -f "CMakeLists.txt" ]; then
echo "错误:请在项目根目录运行此脚本"
exit 1
fi
echo "========================================="
echo "Airborne CO2 打包脚本 v${VERSION}"
echo "========================================="
# 1. 构建项目
echo ""
echo "[1/5] 开始构建项目..."
# 清理旧的 build 目录并重新创建
#rm -rf $BUILD_DIR
mkdir -p $BUILD_DIR
cd $BUILD_DIR
cmake ..
#if [ $? -ne 0 ]; then
# echo "错误cmake 配置失败"
# exit 1
#fi
# 执行 make
make -j$(nproc)
if [ $? -ne 0 ]; then
echo "错误:构建失败"
exit 1
fi
cd ..
# 检查构建产物
if [ ! -f "${BUILD_DIR}/Project_Grixis" ]; then
echo "错误:构建产物不存在"
exit 1
fi
echo "构建完成"
# 2. 创建打包目录
echo ""
echo "[2/5] 创建打包目录..."
rm -rf $DEB_DIR
mkdir -p $DEB_DIR
# 3. 复制可执行文件和脚本文件
echo ""
echo "[3/5] 复制文件..."
mkdir -p ${DEB_DIR}/home/pi/bin
cp ${BUILD_DIR}/Project_Grixis ${DEB_DIR}/home/pi/bin/
chmod +x ${DEB_DIR}/home/pi/bin/Project_Grixis
# 复制脚本文件到 /home/pi/bin/
for script in rasp.sh raspusb.sh mountdjirndis.sh mountdjirndism400.sh mountrndis.sh usbbulk.sh choosescript.sh; do
if [ -f "$script" ]; then
cp "$script" ${DEB_DIR}/home/pi/bin/
chmod +x ${DEB_DIR}/home/pi/bin/"$script"
fi
done
# 5. 创建 DEBIAN 目录和配置文件
echo ""
echo "[4/5] 创建 DEBIAN 配置..."
mkdir -p ${DEB_DIR}/DEBIAN
# 创建 control 文件
cat > ${DEB_DIR}/DEBIAN/control <<EOF
Package: AirborneCO2
Version: ${VERSION}
Architecture: armhf
Maintainer: AirborneCO2 Team
Description: Airborne CO2 monitoring application
EOF
# 创建 postinst 脚本(安装后执行)
cat > ${DEB_DIR}/DEBIAN/postinst <<EOF
#!/bin/bash
echo "AirborneCO2 v${VERSION} installed"
echo "V${VERSION}" > /home/data/version
chmod +x /home/pi/bin/Project_Grixis
exit 0
EOF
# 创建 prerm 脚本(删除前执行)
cat > ${DEB_DIR}/DEBIAN/prerm <<EOF
#!/bin/bash
exit 0
EOF
chmod +x ${DEB_DIR}/DEBIAN/postinst
chmod +x ${DEB_DIR}/DEBIAN/prerm
# 6. 打包
echo ""
echo "[5/5] 打包成 deb 文件..."
sudo dpkg -b $DEB_DIR $PACKAGE_NAME
if [ $? -eq 0 ]; then
echo ""
echo "========================================="
echo "打包成功: ${PACKAGE_NAME}"
echo "========================================="
# 移动到 DEB 目录
mkdir -p DEB
mv $PACKAGE_NAME DEB/
echo "已移动到: DEB/${PACKAGE_NAME}"
# 清理临时目录
rm -rf $DEB_DIR
else
echo "错误:打包失败"
exit 1
fi