-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-deb.sh
More file actions
executable file
·116 lines (99 loc) · 3.77 KB
/
build-deb.sh
File metadata and controls
executable file
·116 lines (99 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
# Build a .deb package for md-reader
set -euo pipefail
APP_NAME="md-reader"
VERSION="0.5.2"
ARCH="all"
INSTALL_DIR="/opt/${APP_NAME}"
PKG_DIR="${APP_NAME}_${VERSION}_${ARCH}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
echo "==> Building ${APP_NAME} ${VERSION} .deb package"
# Clean previous build
rm -rf "${SCRIPT_DIR}/${PKG_DIR}" "${SCRIPT_DIR}/${PKG_DIR}.deb"
# Create directory structure
mkdir -p "${PKG_DIR}/DEBIAN"
mkdir -p "${PKG_DIR}${INSTALL_DIR}"
mkdir -p "${PKG_DIR}/usr/bin"
mkdir -p "${PKG_DIR}/usr/share/applications"
mkdir -p "${PKG_DIR}/usr/share/icons/hicolor/scalable/apps"
# --- Copy application files ---
echo "==> Copying application files"
cp "${SCRIPT_DIR}/main.py" "${PKG_DIR}${INSTALL_DIR}/"
cp -r "${SCRIPT_DIR}/core" "${PKG_DIR}${INSTALL_DIR}/"
cp -r "${SCRIPT_DIR}/config" "${PKG_DIR}${INSTALL_DIR}/"
cp -r "${SCRIPT_DIR}/ui" "${PKG_DIR}${INSTALL_DIR}/"
cp -r "${SCRIPT_DIR}/resources" "${PKG_DIR}${INSTALL_DIR}/"
# --- Bundle Python dependencies (newer than system packages) ---
echo "==> Bundling Python dependencies"
pip install --target "${PKG_DIR}${INSTALL_DIR}/vendor" --no-deps --quiet markdown2 pygments
# Remove __pycache__ directories
find "${PKG_DIR}${INSTALL_DIR}" -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
# --- Create launcher script ---
echo "==> Creating launcher script"
cat > "${PKG_DIR}/usr/bin/${APP_NAME}" << 'LAUNCHER'
#!/usr/bin/env bash
export PYTHONPATH="/opt/md-reader/vendor:${PYTHONPATH:-}"
exec python3 /opt/md-reader/main.py "$@"
LAUNCHER
chmod 755 "${PKG_DIR}/usr/bin/${APP_NAME}"
# --- Install desktop file and icon ---
cp "${SCRIPT_DIR}/resources/md-reader.desktop" "${PKG_DIR}/usr/share/applications/"
cp "${SCRIPT_DIR}/resources/md-reader.svg" "${PKG_DIR}/usr/share/icons/hicolor/scalable/apps/"
# --- Calculate installed size ---
INSTALLED_SIZE=$(du -sk "${PKG_DIR}" | cut -f1)
# --- Create DEBIAN/control ---
cat > "${PKG_DIR}/DEBIAN/control" << EOF
Package: ${APP_NAME}
Version: ${VERSION}
Section: text
Priority: optional
Architecture: ${ARCH}
Installed-Size: ${INSTALLED_SIZE}
Depends: python3 (>= 3.10), python3-pyqt6, python3-pyqt6.qtwebengine
Maintainer: tio <tio@local>
Description: A feature-rich GUI markdown viewer
Markdown Reader is a desktop application for viewing markdown files
with syntax highlighting, table of contents, search, bookmarks,
Mermaid diagrams, LaTeX math, export (HTML/PDF), print preview,
presentation mode, split view, and multiple themes. Built with PyQt6.
Homepage: https://github.com/TioGlo/md_reader
EOF
# --- Create postinst to update desktop database ---
cat > "${PKG_DIR}/DEBIAN/postinst" << 'EOF'
#!/bin/sh
set -e
if command -v update-desktop-database > /dev/null 2>&1; then
update-desktop-database -q /usr/share/applications || true
fi
if command -v gtk-update-icon-cache > /dev/null 2>&1; then
gtk-update-icon-cache -q /usr/share/icons/hicolor || true
fi
EOF
chmod 755 "${PKG_DIR}/DEBIAN/postinst"
# --- Create postrm to clean up ---
cat > "${PKG_DIR}/DEBIAN/postrm" << 'EOF'
#!/bin/sh
set -e
if [ "$1" = "purge" ]; then
rm -rf /opt/md-reader
fi
if command -v update-desktop-database > /dev/null 2>&1; then
update-desktop-database -q /usr/share/applications || true
fi
EOF
chmod 755 "${PKG_DIR}/DEBIAN/postrm"
# --- Set correct permissions ---
find "${PKG_DIR}" -type d -exec chmod 755 {} +
find "${PKG_DIR}" -type f -exec chmod 644 {} +
chmod 755 "${PKG_DIR}/usr/bin/${APP_NAME}"
chmod 755 "${PKG_DIR}/DEBIAN/postinst"
chmod 755 "${PKG_DIR}/DEBIAN/postrm"
# --- Build the package ---
echo "==> Building .deb package"
dpkg-deb --build --root-owner-group "${PKG_DIR}"
echo ""
echo "==> Package built: ${PKG_DIR}.deb"
echo " Install with: sudo apt install ./${PKG_DIR}.deb"
echo " Remove with: sudo apt remove ${APP_NAME}"
# Clean up build directory
rm -rf "${PKG_DIR}"