ScreenLockDetector/check_packaging_env.sh

236 lines
6.8 KiB
Bash
Raw Normal View History

2025-11-07 14:57:13 +08:00
#!/bin/bash
# Qt Screen Lock Demo - 打包环境检查脚本
# 用于验证所有打包依赖是否就绪
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} 打包环境检查${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
ERRORS=0
WARNINGS=0
# 检查函数
check_success() {
echo -e "${GREEN}${NC} $1"
}
check_fail() {
echo -e "${RED}${NC} $1"
ERRORS=$((ERRORS + 1))
}
check_warn() {
echo -e "${YELLOW}${NC} $1"
WARNINGS=$((WARNINGS + 1))
}
# 1. 检查 linuxdeployqt
echo -e "${YELLOW}[1/7] 检查 linuxdeployqt...${NC}"
LINUXDEPLOYQT="$HOME/dev/sunvpack-py/bin/linuxdeployqt"
if [ -f "$LINUXDEPLOYQT" ]; then
check_success "linuxdeployqt 存在: $LINUXDEPLOYQT"
if [ -x "$LINUXDEPLOYQT" ]; then
check_success "linuxdeployqt 可执行"
else
check_warn "linuxdeployqt 不可执行,尝试添加执行权限"
chmod +x "$LINUXDEPLOYQT" 2>/dev/null && check_success "权限已修复" || check_fail "无法修改权限"
fi
else
check_fail "linuxdeployqt 未找到: $LINUXDEPLOYQT"
echo -e " ${YELLOW}提示: 请确保 linuxdeployqt 安装在该路径${NC}"
fi
echo ""
# 2. 检查 Qt 5.15.2
echo -e "${YELLOW}[2/7] 检查 Qt 5.15.2...${NC}"
QT_DIR="$HOME/sdk/qt-5.15.2"
if [ -d "$QT_DIR" ]; then
check_success "Qt 目录存在: $QT_DIR"
# 检查关键文件
if [ -f "$QT_DIR/bin/qmake" ]; then
check_success "qmake 存在"
QT_VERSION=$("$QT_DIR/bin/qmake" -query QT_VERSION 2>/dev/null || echo "unknown")
echo -e " ${BLUE}Qt 版本: $QT_VERSION${NC}"
else
check_fail "qmake 未找到"
fi
if [ -d "$QT_DIR/lib" ]; then
check_success "Qt 库目录存在"
else
check_fail "Qt 库目录未找到"
fi
if [ -d "$QT_DIR/plugins" ]; then
check_success "Qt 插件目录存在"
else
check_warn "Qt 插件目录未找到"
fi
else
check_fail "Qt 目录未找到: $QT_DIR"
echo -e " ${YELLOW}提示: 请确保 Qt 5.15.2 安装在该路径${NC}"
fi
echo ""
# 3. 检查 dpkg 工具
echo -e "${YELLOW}[3/7] 检查 dpkg 打包工具...${NC}"
if command -v dpkg-deb &> /dev/null; then
check_success "dpkg-deb 已安装"
DPKG_VERSION=$(dpkg-deb --version | head -n1)
echo -e " ${BLUE}$DPKG_VERSION${NC}"
else
check_fail "dpkg-deb 未安装"
echo -e " ${YELLOW}安装命令: sudo apt-get install dpkg-dev${NC}"
fi
if command -v debhelper &> /dev/null || dpkg -l debhelper &> /dev/null; then
check_success "debhelper 已安装"
else
check_warn "debhelper 未安装(可选)"
echo -e " ${YELLOW}安装命令: sudo apt-get install debhelper${NC}"
fi
echo ""
# 4. 检查项目文件
echo -e "${YELLOW}[4/7] 检查项目文件...${NC}"
if [ -f "CMakeLists.txt" ]; then
check_success "CMakeLists.txt 存在"
else
check_fail "CMakeLists.txt 未找到"
fi
if [ -f "screenlockdemo.desktop" ]; then
check_success "desktop 文件存在"
else
check_fail "screenlockdemo.desktop 未找到"
fi
if [ -d "debian" ]; then
check_success "debian/ 配置目录存在"
# 检查必需的 debian 文件
for file in control copyright changelog compat rules; do
if [ -f "debian/$file" ]; then
check_success "debian/$file 存在"
else
check_fail "debian/$file 未找到"
fi
done
else
check_fail "debian/ 配置目录未找到"
fi
echo ""
# 5. 检查打包脚本
echo -e "${YELLOW}[5/7] 检查打包脚本...${NC}"
if [ -f "make_deb.sh" ]; then
check_success "make_deb.sh 存在"
if [ -x "make_deb.sh" ]; then
check_success "make_deb.sh 可执行"
else
check_warn "make_deb.sh 不可执行"
chmod +x make_deb.sh 2>/dev/null && check_success "权限已修复" || check_fail "无法修改权限"
fi
else
check_fail "make_deb.sh 未找到"
fi
if [ -f "build_deb.sh" ]; then
check_success "build_deb.sh 存在"
if [ -x "build_deb.sh" ]; then
check_success "build_deb.sh 可执行"
else
check_warn "build_deb.sh 不可执行"
chmod +x build_deb.sh 2>/dev/null && check_success "权限已修复" || check_fail "无法修改权限"
fi
else
check_fail "build_deb.sh 未找到"
fi
echo ""
# 6. 检查编译环境
echo -e "${YELLOW}[6/7] 检查编译环境...${NC}"
if command -v cmake &> /dev/null; then
check_success "CMake 已安装"
CMAKE_VERSION=$(cmake --version | head -n1)
echo -e " ${BLUE}$CMAKE_VERSION${NC}"
else
check_fail "CMake 未安装"
echo -e " ${YELLOW}安装命令: sudo apt-get install cmake${NC}"
fi
if command -v g++ &> /dev/null; then
check_success "G++ 编译器已安装"
GCC_VERSION=$(g++ --version | head -n1)
echo -e " ${BLUE}$GCC_VERSION${NC}"
else
check_fail "G++ 未安装"
echo -e " ${YELLOW}安装命令: sudo apt-get install build-essential${NC}"
fi
if [ -f "build.sh" ]; then
check_success "build.sh 存在"
else
check_warn "build.sh 未找到"
fi
echo ""
# 7. 检查可执行文件
echo -e "${YELLOW}[7/7] 检查已编译的程序...${NC}"
if [ -f "build/bin/ScreenLockDemo" ]; then
check_success "ScreenLockDemo 可执行文件存在"
echo -e " ${BLUE}位置: build/bin/ScreenLockDemo${NC}"
else
check_warn "ScreenLockDemo 尚未编译"
echo -e " ${YELLOW}提示: 运行 ./build.sh 进行编译${NC}"
fi
echo ""
# 总结
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} 检查结果总结${NC}"
echo -e "${BLUE}========================================${NC}"
if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then
echo -e "${GREEN}✓ 完美!所有检查通过${NC}"
echo -e "${GREEN}✓ 打包环境已就绪${NC}"
echo ""
echo -e "${BLUE}下一步:${NC}"
echo -e " 1. 运行打包: ${YELLOW}./make_deb.sh${NC}"
echo -e " 2. 或详细打包: ${YELLOW}./build_deb.sh${NC}"
exit 0
elif [ $ERRORS -eq 0 ]; then
echo -e "${YELLOW}⚠ 有 $WARNINGS 个警告${NC}"
echo -e "${YELLOW}可以继续打包,但建议解决警告项${NC}"
echo ""
echo -e "${BLUE}下一步:${NC}"
echo -e " 运行打包: ${YELLOW}./make_deb.sh${NC}"
exit 0
else
echo -e "${RED}✗ 发现 $ERRORS 个错误${NC}"
if [ $WARNINGS -gt 0 ]; then
echo -e "${YELLOW}⚠ 另有 $WARNINGS 个警告${NC}"
fi
echo ""
echo -e "${RED}请先解决上述错误,然后重新运行此脚本${NC}"
echo ""
echo -e "${BLUE}常见解决方案:${NC}"
echo -e " • linuxdeployqt: 确保路径正确或安装到指定位置"
echo -e " • Qt 5.15.2: 确保安装在 \$HOME/sdk/qt-5.15.2"
echo -e " • dpkg-deb: sudo apt-get install dpkg-dev debhelper"
echo -e " • 编译工具: sudo apt-get install cmake build-essential"
exit 1
fi