Files
xianyan/linux/packaging/build_deb.sh
Developer 27672343b8 520
2026-05-20 01:40:09 +08:00

152 lines
4.9 KiB
Bash

#!/bin/bash
# ============================================================
# 闲言APP — Linux打包脚本 (Debian/Ubuntu .deb)
# 创建时间: 2026-05-18
# 更新时间: 2026-05-18
# 作用: 将Flutter Linux构建产物打包为.deb安装包
# 上次更新: 初始创建
# ============================================================
set -e
APP_NAME="xianyan"
APP_DISPLAY_NAME="闲言"
APP_ID="apps.xy.xianyan"
APP_VERSION="5.2.0"
APP_ARCH="amd64"
BUILD_DIR="build/linux/x64/release/bundle"
OUTPUT_DIR="dist"
DEB_ROOT="${OUTPUT_DIR}/deb_staging"
echo "=========================================="
echo " ${APP_DISPLAY_NAME} — .deb 打包"
echo "=========================================="
if [ ! -d "${BUILD_DIR}" ]; then
echo "❌ 构建产物不存在,请先运行: flutter build linux --release"
exit 1
fi
rm -rf "${DEB_ROOT}"
mkdir -p "${DEB_ROOT}/DEBIAN"
mkdir -p "${DEB_ROOT}/opt/${APP_NAME}"
mkdir -p "${DEB_ROOT}/usr/bin"
mkdir -p "${DEB_ROOT}/usr/share/applications"
mkdir -p "${DEB_ROOT}/usr/share/metainfo"
mkdir -p "${DEB_ROOT}/usr/share/icons/hicolor/scalable/apps"
mkdir -p "${DEB_ROOT}/usr/share/icons/hicolor/256x256/apps"
mkdir -p "${DEB_ROOT}/usr/share/icons/hicolor/128x128/apps"
mkdir -p "${DEB_ROOT}/usr/share/icons/hicolor/64x64/apps"
mkdir -p "${DEB_ROOT}/usr/share/icons/hicolor/48x48/apps"
mkdir -p "${DEB_ROOT}/usr/share/doc/${APP_NAME}"
echo "📦 复制构建产物..."
cp -r "${BUILD_DIR}"/* "${DEB_ROOT}/opt/${APP_NAME}/"
chmod +x "${DEB_ROOT}/opt/${APP_NAME}/${APP_NAME}"
echo "📝 创建符号链接..."
ln -sf "/opt/${APP_NAME}/${APP_NAME}" "${DEB_ROOT}/usr/bin/${APP_NAME}"
echo "📋 创建控制文件..."
cat > "${DEB_ROOT}/DEBIAN/control" << EOF
Package: ${APP_NAME}
Version: ${APP_VERSION}
Section: utils
Priority: optional
Architecture: ${APP_ARCH}
Depends: libgtk-3-0 (>= 3.24), libglib2.0-0 (>= 2.58), libpango-1.0-0 (>= 1.42), libharfbuzz0b (>= 2.0), libcairo2 (>= 1.16), libgdk-pixbuf-2.0-0 (>= 2.38), libgstreamer1.0-0 (>= 1.14), libgstreamer-plugins-base1.0-0 (>= 1.14), libasound2 (>= 1.1), libsecret-1-0 (>= 0.18), libbluetooth3 (>= 5.48), libnotify4 (>= 0.7), libmpv2 (>= 0.29) | libmpv1
Recommends: gstreamer1.0-plugins-good, gstreamer1.0-plugins-bad, gstreamer1.0-libav
Suggests: fonts-noto-cjk, fonts-noto-color-emoji
Maintainer: 闲言 <xianyan@example.com>
Description: ${APP_DISPLAY_NAME} — 文字阅读更纯粹
句子阅读与壁纸制作应用,提供精选句子每日推荐、
壁纸制作与分享、卡片式阅读体验等功能。
Installed-Size: $(du -sk "${DEB_ROOT}/opt/${APP_NAME}" | cut -f1)
EOF
echo "📋 创建postinst脚本..."
cat > "${DEB_ROOT}/DEBIAN/postinst" << 'EOF'
#!/bin/bash
set -e
update-desktop-database /usr/share/applications 2>/dev/null || true
gtk-update-icon-cache /usr/share/icons/hicolor 2>/dev/null || true
update-mime-database /usr/share/mime 2>/dev/null || true
EOF
chmod 755 "${DEB_ROOT}/DEBIAN/postinst"
echo "📋 创建postrm脚本..."
cat > "${DEB_ROOT}/DEBIAN/postrm" << 'EOF'
#!/bin/bash
set -e
update-desktop-database /usr/share/applications 2>/dev/null || true
gtk-update-icon-cache /usr/share/icons/hicolor 2>/dev/null || true
EOF
chmod 755 "${DEB_ROOT}/DEBIAN/postrm"
echo "🖥️ 创建桌面快捷方式..."
if [ -f "linux/${APP_ID}.desktop" ]; then
cp "linux/${APP_ID}.desktop" "${DEB_ROOT}/usr/share/applications/"
else
cat > "${DEB_ROOT}/usr/share/applications/${APP_ID}.desktop" << EOF
[Desktop Entry]
Type=Application
Version=1.5
Name=${APP_DISPLAY_NAME}
Name[zh_CN]=${APP_DISPLAY_NAME}
Name[en]=Xianyan
Comment=文字阅读更纯粹
Comment[zh_CN]=文字阅读更纯粹
Comment[en]=Pure reading
Icon=${APP_ID}
Exec=/opt/${APP_NAME}/${APP_NAME}
Terminal=false
StartupNotify=true
Categories=Utility;Literature;Graphics;
Keywords=reading;sentence;wallpaper;
StartupWMClass=${APP_NAME}
MimeType=text/plain;x-scheme-handler/xianyan;
X-GNOME-UsesNotifications=true
EOF
fi
echo "📋 创建AppStream元数据..."
if [ -f "linux/${APP_ID}.appdata.xml" ]; then
cp "linux/${APP_ID}.appdata.xml" "${DEB_ROOT}/usr/share/metainfo/"
fi
echo "📄 创建版权文件..."
cat > "${DEB_ROOT}/usr/share/doc/${APP_NAME}/copyright" << EOF
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ${APP_NAME}
Upstream-Contact: xianyan@example.com
Files: *
Copyright: 2026 闲言
License: proprietary
EOF
echo "📋 注册URL Scheme..."
cat > "${DEB_ROOT}/usr/share/applications/${APP_ID}-url.desktop" << EOF
[Desktop Entry]
Type=Application
Name=${APP_DISPLAY_NAME} URL Handler
NoDisplay=true
Exec=/opt/${APP_NAME}/${APP_NAME} %u
MimeType=x-scheme-handler/xianyan;
EOF
mkdir -p "${OUTPUT_DIR}"
DEB_FILE="${OUTPUT_DIR}/${APP_NAME}_${APP_VERSION}_${APP_ARCH}.deb"
dpkg-deb --build "${DEB_ROOT}" "${DEB_FILE}"
DEB_SIZE=$(du -sh "${DEB_FILE}" | cut -f1)
echo ""
echo "✅ .deb 打包完成!"
echo " 文件: ${DEB_FILE}"
echo " 大小: ${DEB_SIZE}"
echo ""
echo "安装命令: sudo dpkg -i ${DEB_FILE}"
echo "卸载命令: sudo dpkg -r ${APP_NAME}"
rm -rf "${DEB_ROOT}"