Repository navigation
Expand file tree
/
Copy pathbuild_packages.sh
More file actions
executable file
·328 lines (285 loc) · 12.5 KB
/
Copy pathbuild_packages.sh
File metadata and controls
executable file
·328 lines (285 loc) · 12.5 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
set -euo pipefail
# build_packages.sh - Build amd64 and arm64 .deb packages for QtMonitor.
# Outputs the resulting .deb files to ./output/ and removes leftover build
# artifacts and previously built packages from the project root and dist/.
# Python test scripts are never deleted.
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
VERSION="0.0.3-1"
OUTPUT_DIR="${PROJECT_DIR}/output"
ARM64_BUILD_DIR="${PROJECT_DIR}/build-arm64"
cd "$PROJECT_DIR"
# ---------------------------------------------------------------------------
# 0. Verify build dependencies (auto-install missing ones via apt)
# ---------------------------------------------------------------------------
# Native (amd64) build needs: dpkg-buildpackage, make, file, qt6-base-dev,
# and the qmake6 / moc / rcc helpers that come with qt6-base-dev-tools.
# Cross (arm64) build additionally needs: g++-aarch64-linux-gnu,
# qt6-base-dev:arm64, libsensors-dev:arm64, plus the arm64 multiarch enabled.
NATIVE_PKGS=(
dpkg-dev
make
file
qt6-base-dev
qt6-base-dev-tools
)
CROSS_PKGS=(
g++-aarch64-linux-gnu
qt6-base-dev:arm64
libsensors-dev:arm64
)
# Only attempt the cross-build if invoked on an amd64 host (the script's arm64
# stage is a true cross-compile and assumes an x86_64 build machine). On any
# other host, skip cross-build deps and the cross-build itself.
HOST_ARCH="$(dpkg --print-architecture 2>/dev/null || echo unknown)"
if [ "$HOST_ARCH" != "amd64" ]; then
echo "Note: host architecture is '$HOST_ARCH'; skipping arm64 cross-build dependencies."
CROSS_PKGS=()
fi
check_pkgs() {
local missing=()
local pkg
for pkg in "$@"; do
# Strip the :arch suffix for dpkg-query; check the multiarch-suffixed
# name only when the architecture is enabled.
local query="${pkg%%:*}"
if ! dpkg-query -W -f='${Status}' "$query" 2>/dev/null \
| grep -q "install ok installed"; then
missing+=("$pkg")
fi
done
if [ "${#missing[@]}" -gt 0 ]; then
echo "Missing packages: ${missing[*]}"
return 1
fi
return 0
}
if ! check_pkgs "${NATIVE_PKGS[@]}" "${CROSS_PKGS[@]}"; then
# Re-scan to split into two groups so apt can be told about both arches.
NEED_NATIVE=()
for p in "${NATIVE_PKGS[@]}"; do
if ! dpkg-query -W -f='${Status}' "${p%%:*}" 2>/dev/null \
| grep -q "install ok installed"; then
NEED_NATIVE+=("$p")
fi
done
NEED_CROSS=()
for p in "${CROSS_PKGS[@]}"; do
if ! dpkg-query -W -f='${Status}' "${p%%:*}" 2>/dev/null \
| grep -q "install ok installed"; then
NEED_CROSS+=("$p")
fi
done
# arm64 packages need the foreign architecture enabled first.
if [ "${#NEED_CROSS[@]}" -gt 0 ] \
&& ! dpkg --print-foreign-architectures 2>/dev/null \
| grep -qx "arm64"; then
echo "Enabling arm64 foreign architecture..."
if [ -t 0 ] && [ -t 1 ]; then
sudo dpkg --add-architecture arm64
sudo apt-get update
elif sudo -n true 2>/dev/null; then
sudo -n dpkg --add-architecture arm64
sudo -n apt-get update
else
cat >&2 <<EOF
ERROR: Need to enable arm64 foreign architecture but cannot run sudo
non-interactively. Re-run with a TTY, or execute:
sudo dpkg --add-architecture arm64 && sudo apt-get update
EOF
exit 1
fi
fi
if [ "${#NEED_NATIVE[@]}" -gt 0 ] || [ "${#NEED_CROSS[@]}" -gt 0 ]; then
echo "Installing missing build dependencies..."
if [ -t 0 ] && [ -t 1 ]; then
sudo apt-get install -y "${NEED_NATIVE[@]}" "${NEED_CROSS[@]}"
elif sudo -n true 2>/dev/null; then
sudo -n apt-get install -y "${NEED_NATIVE[@]}" "${NEED_CROSS[@]}"
else
cat >&2 <<EOF
ERROR: Need to install missing packages but cannot run sudo
non-interactively. Re-run with a TTY, or execute:
sudo apt-get install -y ${NEED_NATIVE[*]} ${NEED_CROSS[*]}
EOF
exit 1
fi
fi
# Re-verify so a failed install doesn't silently let the build proceed.
if ! check_pkgs "${NATIVE_PKGS[@]}" "${CROSS_PKGS[@]}"; then
echo "ERROR: dependencies still missing after install attempt." >&2
exit 1
fi
fi
# Repair ownership of any stale root-owned files inside the project tree from
# a prior `sudo`-elevated build; otherwise the next dpkg-buildpackage clean
# step will fail to remove them under set -e.
if find "$PROJECT_DIR" -not -user "$(id -un)" -print -quit 2>/dev/null | grep -q .; then
if [ -t 0 ] && [ -t 1 ]; then
echo "Repairing root-owned files inside the project tree..."
sudo chown -R "$(id -un):$(id -gn)" "$PROJECT_DIR"
elif sudo -n true 2>/dev/null; then
echo "Repairing root-owned files inside the project tree..."
sudo -n chown -R "$(id -un):$(id -gn)" "$PROJECT_DIR"
else
cat >&2 <<EOF
ERROR: Found root-owned files inside the project tree but cannot run sudo
non-interactively. Re-run with a TTY, or execute:
sudo chown -R "$(id -un):$(id -gn)" "$PROJECT_DIR"
then re-run $0.
EOF
exit 1
fi
fi
# ---------------------------------------------------------------------------
# 1. Prepare output directory
# ---------------------------------------------------------------------------
mkdir -p "$OUTPUT_DIR"
# ---------------------------------------------------------------------------
# 2. Clean previously built packages and transient build artifacts
# ---------------------------------------------------------------------------
# Remove root-level .deb/.ddeb/.changes/.buildinfo packages (old layout).
rm -f "${PROJECT_DIR}/qtmonitor_${VERSION}"_*.deb
rm -f "${PROJECT_DIR}/qtmonitor_${VERSION}"_*.changes
rm -f "${PROJECT_DIR}/qtmonitor_${VERSION}"_*.buildinfo
rm -f "${PROJECT_DIR}/qtmonitor-dbgsym_${VERSION}"_*.ddeb
rm -f "${PROJECT_DIR}/mon-cli_${VERSION}"_*.deb
rm -f "${PROJECT_DIR}/mon-cli-dbgsym_${VERSION}"_*.ddeb
rm -f "${PROJECT_DIR}/"*.ddeb
# Remove packages left in dist/ by earlier builds.
rm -f "${PROJECT_DIR}/dist/"*.deb
rm -f "${PROJECT_DIR}/dist/"*.ddeb
rm -f "${PROJECT_DIR}/dist/"*.changes
rm -f "${PROJECT_DIR}/dist/"*.buildinfo
# Clean leftover qmake/build files from older layouts (keep .py test scripts
# and any in-progress compiled binaries).
rm -f "${PROJECT_DIR}/.qmake.stash"
rm -f "${PROJECT_DIR}/moc_"*.cpp
rm -f "${PROJECT_DIR}/moc_"*.h
rm -f "${PROJECT_DIR}/qrc_resources.cpp"
# ---------------------------------------------------------------------------
# 3. amd64 native build via dpkg-buildpackage
# ---------------------------------------------------------------------------
dpkg-buildpackage -us -uc -b
# dpkg-buildpackage writes results one directory above the project root.
for arch in amd64; do
for pkg in qtmonitor mon-cli; do
if [ -f "${PROJECT_DIR}/../${pkg}_${VERSION}_${arch}.deb" ]; then
mv "${PROJECT_DIR}/../${pkg}_${VERSION}_${arch}.deb" "${OUTPUT_DIR}/"
fi
if [ -f "${PROJECT_DIR}/../${pkg}-dbgsym_${VERSION}_${arch}.ddeb" ]; then
mv "${PROJECT_DIR}/../${pkg}-dbgsym_${VERSION}_${arch}.ddeb" "${OUTPUT_DIR}/"
fi
done
if [ -f "${PROJECT_DIR}/../qtmonitor_${VERSION}_${arch}.changes" ]; then
mv "${PROJECT_DIR}/../qtmonitor_${VERSION}_${arch}.changes" "${OUTPUT_DIR}/"
fi
if [ -f "${PROJECT_DIR}/../qtmonitor_${VERSION}_${arch}.buildinfo" ]; then
mv "${PROJECT_DIR}/../qtmonitor_${VERSION}_${arch}.buildinfo" "${OUTPUT_DIR}/"
fi
done
# ---------------------------------------------------------------------------
# 4. arm64 cross build
# ---------------------------------------------------------------------------
mkdir -p "$ARM64_BUILD_DIR"
aarch64-linux-gnu-qmake6 \
-spec /usr/lib/aarch64-linux-gnu/qt6/mkspecs/linux-aarch64-gnu-g++ \
CONFIG+=release \
"${PROJECT_DIR}/qtmonitor.pro" \
-o "$ARM64_BUILD_DIR/Makefile"
make -C "$ARM64_BUILD_DIR" -j"$(nproc)"
# Stage the arm64 .deb manually.
STAGE_DIR="$(mktemp -d)"
mkdir -p "${STAGE_DIR}/DEBIAN" \
"${STAGE_DIR}/usr/bin" \
"${STAGE_DIR}/usr/share/applications" \
"${STAGE_DIR}/usr/share/doc/qtmonitor/examples" \
"${STAGE_DIR}/usr/share/icons/hicolor/16x16/apps" \
"${STAGE_DIR}/usr/share/icons/hicolor/24x24/apps" \
"${STAGE_DIR}/usr/share/icons/hicolor/32x32/apps" \
"${STAGE_DIR}/usr/share/icons/hicolor/48x48/apps" \
"${STAGE_DIR}/usr/share/icons/hicolor/64x64/apps" \
"${STAGE_DIR}/usr/share/icons/hicolor/128x128/apps" \
"${STAGE_DIR}/usr/share/icons/hicolor/256x256/apps"
cp "${ARM64_BUILD_DIR}/qtmonitor" "${STAGE_DIR}/usr/bin/qtmonitor"
chmod 755 "${STAGE_DIR}/usr/bin/qtmonitor"
# Copy example Python scripts (matches amd64 packaging).
if [ -f "${PROJECT_DIR}/scripts/cli_demo_remote_sync.py" ]; then
cp "${PROJECT_DIR}/scripts/cli_demo_remote_sync.py" \
"${STAGE_DIR}/usr/share/doc/qtmonitor/examples/"
fi
cp "${PROJECT_DIR}/packaging/debian/qtmonitor.desktop" "${STAGE_DIR}/usr/share/applications/"
for s in 16 24 32 48 64 128 256; do
cp "${PROJECT_DIR}/icons/qtmonitor_${s}.png" \
"${STAGE_DIR}/usr/share/icons/hicolor/${s}x${s}/apps/qtmonitor.png"
done
cat > "${STAGE_DIR}/DEBIAN/control" <<EOF
Package: qtmonitor
Version: ${VERSION}
Architecture: arm64
Maintainer: QtMonitor Team <dev@qtmonitor.local>
Priority: optional
Section: utils
Depends: libqt6core6t64, libqt6gui6, libqt6widgets6, libqt6network6, libqt6printsupport6, libqt6openglwidgets6, libsensors5
Description: Hardware temperature monitoring with Qt6 and lm-sensors
QtMonitor is a desktop application that reads hardware temperature sensors
via lm-sensors and displays real-time charts, statistics, alarms, and
logging. It supports dark/light themes, sensor selection, curve coloring,
remote sync, and offline operation.
EOF
find "${STAGE_DIR}" -type f ! -path "*/DEBIAN/*" -print0 | \
xargs -0 md5sum | sed "s| ${STAGE_DIR}/| /|" > "${STAGE_DIR}/DEBIAN/md5sums"
chmod 644 "${STAGE_DIR}/DEBIAN/md5sums"
chmod 644 "${STAGE_DIR}/DEBIAN/control"
dpkg-deb --root-owner-group --build "${STAGE_DIR}" "${OUTPUT_DIR}/qtmonitor_${VERSION}_arm64.deb"
rm -rf "${STAGE_DIR}"
# ---------------------------------------------------------------------------
# 4b. arm64 mon-cli cross build
# ---------------------------------------------------------------------------
CLI_ARM64_BUILD_DIR="${PROJECT_DIR}/build-cli-arm64"
mkdir -p "$CLI_ARM64_BUILD_DIR"
aarch64-linux-gnu-qmake6 \
-spec /usr/lib/aarch64-linux-gnu/qt6/mkspecs/linux-aarch64-gnu-g++ \
CONFIG+=release \
"${PROJECT_DIR}/mon-cli.pro" \
-o "$CLI_ARM64_BUILD_DIR/Makefile"
make -C "$CLI_ARM64_BUILD_DIR" -j"$(nproc)"
CLI_STAGE_DIR="$(mktemp -d)"
mkdir -p "${CLI_STAGE_DIR}/DEBIAN" \
"${CLI_STAGE_DIR}/usr/bin"
cp "${CLI_ARM64_BUILD_DIR}/mon-cli" "${CLI_STAGE_DIR}/usr/bin/mon-cli"
chmod 755 "${CLI_STAGE_DIR}/usr/bin/mon-cli"
cat > "${CLI_STAGE_DIR}/DEBIAN/control" <<EOF
Package: mon-cli
Version: ${VERSION}
Architecture: arm64
Maintainer: QtMonitor Team <dev@qtmonitor.local>
Priority: optional
Section: utils
Depends: libqt6core6t64, libqt6network6, libsensors5
Description: Headless CLI temperature monitor (companion to qtmonitor)
mon-cli is a Qt Core + Network-only command-line companion to qtmonitor.
It reads hardware temperature sensors via lm-sensors and offers one-shot
dumps, a live ANSI-redraw TUI, a remote-collection HTTP server, and a
remote-sync client. Suitable for headless servers.
EOF
find "${CLI_STAGE_DIR}" -type f ! -path "*/DEBIAN/*" -print0 | \
xargs -0 md5sum | sed "s| ${CLI_STAGE_DIR}/| /|" > "${CLI_STAGE_DIR}/DEBIAN/md5sums"
chmod 644 "${CLI_STAGE_DIR}/DEBIAN/md5sums"
chmod 644 "${CLI_STAGE_DIR}/DEBIAN/control"
dpkg-deb --root-owner-group --build "${CLI_STAGE_DIR}" "${OUTPUT_DIR}/mon-cli_${VERSION}_arm64.deb"
rm -rf "${CLI_STAGE_DIR}"
# ---------------------------------------------------------------------------
# 5. Final cleanup of transient files that builds may have dropped in the tree
# (compiled binaries and build trees are intentionally kept).
# ---------------------------------------------------------------------------
rm -f "${PROJECT_DIR}/Makefile"
rm -f "${PROJECT_DIR}/.qmake.stash"
rm -f "${PROJECT_DIR}/moc_"*.cpp
rm -f "${PROJECT_DIR}/moc_"*.h
rm -f "${PROJECT_DIR}/qrc_resources.cpp"
# ---------------------------------------------------------------------------
# 6. Report
# ---------------------------------------------------------------------------
echo "Build complete. Packages in ${OUTPUT_DIR}:"
ls -la "${OUTPUT_DIR}/"