Repository navigation
Expand file tree
/
Copy pathbuild_deb.sh
More file actions
executable file
·142 lines (124 loc) · 6.27 KB
/
Copy pathbuild_deb.sh
File metadata and controls
executable file
·142 lines (124 loc) · 6.27 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
#!/usr/bin/env bash
# --- [ Module: Debian Package Builder ] ---
set -euo pipefail
DEV_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION="0.3.4-1"
PKG_NAME="canonic-update"
BUILD_ROOT=$(mktemp -d /tmp/${PKG_NAME}_build.XXXXXX)
trap 'rm -rf "${BUILD_ROOT}"' EXIT
OUTPUT_DEB="${DEV_DIR}/canonic-update.deb"
SRC_DIR="${DEV_DIR}"
ICONS_SRC="${DEV_DIR}/assets"
echo "==> Preparing build tree for v${VERSION} in ${BUILD_ROOT}..."
mkdir -p "${BUILD_ROOT}"/{DEBIAN,usr/bin,usr/lib/canonic-update,usr/share/canonic-update/lib,usr/share/canonic-update/locales,usr/share/canonic-update/assets,usr/share/applications,etc/xdg/autostart,usr/share/icons/hicolor/128x128/apps,usr/share/doc/canonic-update,usr/lib/systemd/system,etc/polkit-1/rules.d,etc/kernel/postinst.d}
# --- [ File Staging ] ---
echo "==> Staging binaries and libraries..."
cp "${SRC_DIR}/bin/canonic-update-cli" "${BUILD_ROOT}/usr/bin/"
cp "${SRC_DIR}/bin/canonic-update-check" "${BUILD_ROOT}/usr/bin/"
cp "${SRC_DIR}/lib/canonic-update-tray" "${BUILD_ROOT}/usr/lib/canonic-update/"
cp "${SRC_DIR}/lib/check_backend.sh" "${BUILD_ROOT}/usr/share/canonic-update/lib/"
cp "${SRC_DIR}/lib/canonic_update_i18n.py" "${BUILD_ROOT}/usr/share/canonic-update/lib/"
cp "${SRC_DIR}/lib/canonic_os_detect.py" "${BUILD_ROOT}/usr/share/canonic-update/lib/"
cp "${SRC_DIR}/lib/canonic_kernel_mgr.py" "${BUILD_ROOT}/usr/share/canonic-update/lib/"
cp "${SRC_DIR}/kernel/canonic-kernel-sign" "${BUILD_ROOT}/etc/kernel/postinst.d/"
cp "${SRC_DIR}"/locales/*.json "${BUILD_ROOT}/usr/share/canonic-update/locales/"
cp "${SRC_DIR}/assets/ko-fi.png" "${BUILD_ROOT}/usr/share/canonic-update/assets/" 2>/dev/null || true
cp "${SRC_DIR}/desktop/canonic-update-tray.desktop" "${BUILD_ROOT}/usr/share/applications/"
cp "${SRC_DIR}/desktop/canonic-update-tray.desktop" "${BUILD_ROOT}/etc/xdg/autostart/"
cp "${SRC_DIR}/systemd/canonic-update-check.service" "${BUILD_ROOT}/usr/lib/systemd/system/"
cp "${SRC_DIR}/systemd/canonic-update-check.timer" "${BUILD_ROOT}/usr/lib/systemd/system/"
cp "${SRC_DIR}/polkit/50-canonic-update.rules" "${BUILD_ROOT}/etc/polkit-1/rules.d/"
if [ -d "$ICONS_SRC" ]; then
echo "==> Staging system icons from assets..."
cp "$ICONS_SRC"/*.png "${BUILD_ROOT}/usr/share/icons/hicolor/128x128/apps/" 2>/dev/null || true
cp "$ICONS_SRC"/*.svg "${BUILD_ROOT}/usr/share/icons/hicolor/128x128/apps/" 2>/dev/null || true
fi
# --- [ DEBIAN Control Metadata ] ---
echo "==> Generating DEBIAN control metadata..."
cat << CONTROL_EOF > "${BUILD_ROOT}/DEBIAN/control"
Package: canonic-update
Version: ${VERSION}
Section: admin
Priority: optional
Architecture: all
Maintainer: tux <tux@localhost>
Depends: python3, python3-pyqt5, python3-pyqt5.qtsvg, systemd, needrestart
Recommends: flatpak, snapd, mokutil
Suggests: sbsigntool
Description: System update suite and system tray monitor for Ubuntu and flavors
A modular update management companion providing APT, Flatpak, Snap,
and Mainline Kernel tracking with MOK Secure Boot integration.
CONTROL_EOF
cat << 'POSTINST_EOF' > "${BUILD_ROOT}/DEBIAN/postinst"
#!/bin/sh
set -e
case "$1" in
configure)
mkdir -p /var/cache/canonic-update
chmod 0755 /var/cache/canonic-update
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload || true
systemctl enable --now canonic-update-check.timer || true
systemctl start --no-block canonic-update-check.service || true
fi
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true
fi
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database -q /usr/share/applications || true
fi
# Trigger tray execution for active desktop sessions
if command -v loginctl >/dev/null 2>&1; then
for session in $(loginctl list-sessions --no-legend 2>/dev/null | awk '{print $1}'); do
session_type=$(loginctl show-session "$session" -p Type --value 2>/dev/null || true)
session_user=$(loginctl show-session "$session" -p Name --value 2>/dev/null || true)
session_state=$(loginctl show-session "$session" -p State --value 2>/dev/null || true)
if [ "$session_state" = "active" ] && { [ "$session_type" = "x11" ] || [ "$session_type" = "wayland" ]; }; then
user_uid=$(id -u "$session_user" 2>/dev/null || true)
if [ -n "$user_uid" ] && [ "$user_uid" -ge 1000 ]; then
if ! pgrep -u "$user_uid" -f "canonic-update-tray" >/dev/null 2>&1; then
systemd-run --user --machine="${session_user}@.host" --unit="canonic-update-tray-session" --quiet /usr/lib/canonic-update/canonic-update-tray >/dev/null 2>&1 || true
fi
fi
fi
done
fi
;;
esac
exit 0
POSTINST_EOF
chmod 755 "${BUILD_ROOT}/DEBIAN/postinst"
cat << 'PRERM_EOF' > "${BUILD_ROOT}/DEBIAN/prerm"
#!/bin/sh
set -e
case "$1" in
remove|deconfigure)
if command -v systemctl >/dev/null 2>&1; then
if systemctl is-active --quiet canonic-update-check.timer 2>/dev/null; then
systemctl stop canonic-update-check.timer || true
fi
if systemctl is-enabled --quiet canonic-update-check.timer 2>/dev/null; then
systemctl disable canonic-update-check.timer || true
fi
fi
pkill -f canonic-update-tray || true
;;
esac
exit 0
PRERM_EOF
chmod 755 "${BUILD_ROOT}/DEBIAN/prerm"
# --- [ Permissions & Assembly ] ---
echo "==> Setting file permissions..."
find "${BUILD_ROOT}" -type d -exec chmod 755 {} \;
find "${BUILD_ROOT}" -type f -exec chmod 644 {} \;
chmod 755 "${BUILD_ROOT}/usr/bin/canonic-update-cli"
chmod 755 "${BUILD_ROOT}/usr/bin/canonic-update-check"
chmod 755 "${BUILD_ROOT}/usr/lib/canonic-update/canonic-update-tray"
chmod 755 "${BUILD_ROOT}/usr/share/canonic-update/lib/check_backend.sh"
chmod 755 "${BUILD_ROOT}/etc/kernel/postinst.d/canonic-kernel-sign"
chmod 755 "${BUILD_ROOT}/DEBIAN/postinst"
chmod 755 "${BUILD_ROOT}/DEBIAN/prerm"
echo "==> Compiling Debian package..."
dpkg-deb --root-owner-group --build "${BUILD_ROOT}" "${OUTPUT_DEB}"
rm -rf "${BUILD_ROOT}"
echo "==> Build complete: ${OUTPUT_DEB}"