-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
424 lines (370 loc) · 15.3 KB
/
Copy pathinstall.sh
File metadata and controls
424 lines (370 loc) · 15.3 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#!/bin/bash
set -euo pipefail
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
printf '%s\n' "Missing required command: $1" >&2
exit 1
fi
}
# Run a command as root - tries sudo, doas, su in order.
run_root() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
elif command -v sudo >/dev/null 2>&1; then
sudo "$@"
elif command -v doas >/dev/null 2>&1; then
doas "$@"
else
su -c "$(printf '%q ' "$@")"
fi
}
AUTO_DEPS=1
INSTALL_STANDALONE_QML_MODULE=0
INSTALL_WATCHER=1
REBUILD_ONLY=0
for arg in "$@"; do
case "$arg" in
--no-deps) AUTO_DEPS=0 ;;
--no-watcher) INSTALL_WATCHER=0 ;;
--rebuild) REBUILD_ONLY=1 ; AUTO_DEPS=0 ; INSTALL_WATCHER=0 ;;
--install-standalone-qml-module) INSTALL_STANDALONE_QML_MODULE=1 ;;
-h|--help)
cat <<'EOF'
Usage: ./install.sh [--no-deps] [--no-watcher] [--install-standalone-qml-module]
Options:
--no-deps Skip automatic dependency installation.
--no-watcher Skip auto-update watcher install.
--install-standalone-qml-module
Also copy the native plugin/qmldir to the user-local Qt6 QML
module path for stricter distro/policy setups.
EOF
exit 0
;;
esac
done
install_deps_best_effort() {
if [ "$AUTO_DEPS" -ne 1 ]; then
return 0
fi
printf '%s\n' "[ deps ] Installing build dependencies..."
printf '%s\n' " Package names vary by distro — missing optional packages are non-fatal."
local pm="" pm_update="" pm_install="" pm_provider_prefix=""
if command -v apt-get >/dev/null 2>&1; then
pm="apt-get"
pm_update="apt-get update"
pm_install="apt-get install -y"
# libvncserver-dev ships both libvncserver and libvncclient headers on Debian/Ubuntu.
# libqtermwidget6 dev pkg is version-suffixed on some releases - both names listed.
pkgs_build="cmake make g++ pkg-config qt6-base-dev qt6-declarative-dev qt6-websockets-dev libsecret-1-dev libvncserver-dev libutf8proc-dev qtermwidget6-data"
pkgs_qtermwidget="libqtermwidget6-2-dev libqtermwidget6-dev"
pkgs_ecm="extra-cmake-modules"
pkgs_kpackage="libkf6package-bin"
elif command -v zypper >/dev/null 2>&1; then
pm="zypper"
pm_update="zypper refresh"
pm_install="zypper install -y"
pkgs_build="cmake make gcc-c++ pkg-config qt6-base-devel qt6-declarative-devel qt6-websockets-devel LibVNCServer-devel utf8proc-devel"
pkgs_qtermwidget="qtermwidget-devel qtermwidget-qt6-devel"
pkgs_ecm="extra-cmake-modules"
elif command -v dnf >/dev/null 2>&1; then
pm="dnf"
pm_install="dnf install -y"
pm_provider_prefix="*/"
pkgs_build="cmake make gcc-c++ pkgconf-pkg-config qt6-qtbase-devel qt6-qtdeclarative-devel qt6-qtwebsockets-devel libvncserver-devel utf8proc-devel"
pkgs_qtermwidget="qtermwidget-devel"
pkgs_ecm="extra-cmake-modules"
elif command -v pacman >/dev/null 2>&1; then
pm="pacman"
pm_install="pacman -Sy --noconfirm --needed"
pkgs_build="cmake make gcc pkgconf qt6-base qt6-declarative qt6-websockets libvncserver libutf8proc"
pkgs_qtermwidget="qtermwidget"
pkgs_ecm="extra-cmake-modules"
else
printf '%s\n' "No supported package manager detected (apt-get/zypper/dnf/pacman). Skipping auto deps." >&2
return 0
fi
install_pkgs_best_effort() {
# shellcheck disable=SC2086
run_root $pm_install "$@" || true
}
install_provider_best_effort() {
local provider_query="$1"
local pkg=""
if [ "$pm" = "zypper" ]; then
pkg="$(zypper --non-interactive se -x -f "$provider_query" 2>/dev/null | awk -F'|' 'NR>2 && $2 ~ /\S/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2; exit}')" || true
elif [ "$pm" = "dnf" ]; then
pkg="$(dnf -q --cacheonly provides "$provider_query" 2>/dev/null | awk '/:/{print $1; exit}')" || true
fi
if [ -n "${pkg:-}" ]; then
sudo -v 2>/dev/null || true
install_pkgs_best_effort "$pkg"
fi
}
[ -n "$pm_update" ] && run_root $pm_update
# shellcheck disable=SC2086
install_pkgs_best_effort $pkgs_build
install_pkgs_best_effort "$pkgs_ecm"
# Try each qtermwidget6 dev candidate; stop at the first available one.
if [ -n "${pkgs_qtermwidget:-}" ]; then
for candidate in $pkgs_qtermwidget; do
if [ "$pm" = "apt-get" ]; then
if apt-cache show "$candidate" >/dev/null 2>&1; then
install_pkgs_best_effort "$candidate"
break
fi
else
install_pkgs_best_effort "$candidate" && break
fi
done
fi
if [ -n "${pkgs_kpackage:-}" ]; then
install_pkgs_best_effort "$pkgs_kpackage"
else
command -v kpackagetool6 >/dev/null 2>&1 || install_provider_best_effort "${pm_provider_prefix}kpackagetool6"
fi
if [ "$pm" = "zypper" ] || [ "$pm" = "dnf" ]; then
rpm -q extra-cmake-modules >/dev/null 2>&1 || install_provider_best_effort "${pm_provider_prefix}ECMConfig.cmake"
rpm -q kf6-plasma-devel >/dev/null 2>&1 || install_provider_best_effort "${pm_provider_prefix}KF6PlasmaConfig.cmake"
fi
if [ "$pm" = "dnf" ]; then
printf '%s\n' " (Fedora) sudo prompts may appear mid-output — this is normal."
fi
}
# Prime sudo upfront so the password prompt doesn't interrupt build output.
if [ "$AUTO_DEPS" -eq 1 ] && [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1; then
sudo -v
fi
install_deps_best_effort
KPACKAGETOOL=""
if command -v kpackagetool6 >/dev/null 2>&1; then
KPACKAGETOOL="kpackagetool6"
elif command -v kpackagetool5 >/dev/null 2>&1; then
KPACKAGETOOL="kpackagetool5"
else
printf '%s\n' "Could not find kpackagetool6 or kpackagetool5. Install KDE Plasma packaging tools." >&2
exit 1
fi
if command -v git >/dev/null 2>&1 && [ -f .gitmodules ] && [ -d .git ]; then
printf '%s\n' "[ git ] Initializing submodules..."
# Refresh cached submodule URLs from .gitmodules first, so checkouts made
# before the qtkeychain fork repoint don't try to fetch the pinned commit
# from the old upstream URL (where it doesn't exist).
git submodule sync --recursive
git submodule update --init --recursive
fi
require_cmd cmake
require_cmd mktemp
require_cmd getconf
require_cmd cp
require_cmd mkdir
printf '%s\n' "[ build] Compiling native plugin..."
BUILD_DIR="$(mktemp -d -t proxmon-build-XXXXXX)"
trap 'rm -rf "$BUILD_DIR"' EXIT
cmake -S contents/lib -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release || exit 1
JOBS="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)"
BUILD_START="$(date +%s)"
cmake --build "$BUILD_DIR" -- -j"$JOBS" || exit 1
BUILD_END="$(date +%s)"
printf '%s\n' "[ build] Done in $(( BUILD_END - BUILD_START ))s"
# Replace dst atomically via rename(2). A plain cp truncates and rewrites the
# existing inode in place - if a running plasmashell has that .so mmap'd, its
# code pages are corrupted under it and it segfaults (reliably so with VNC
# console worker threads executing plugin code during the copy).
atomic_cp() {
local src="$1" dst="$2"
[ -d "$dst" ] && dst="$dst/$(basename "$src")"
cp "$src" "$dst.tmp.$$" && mv -f "$dst.tmp.$$" "$dst"
}
# Stage .so into the plasmoid package - main.qml uses a relative import
# resolved to contents/lib/proxmox/, which kpackagetool installs verbatim.
atomic_cp "$BUILD_DIR/libproxmoxclientplugin.so" contents/lib/proxmox/
printf '%s\n' "[ build] Plugin staged → contents/lib/proxmox/libproxmoxclientplugin.so"
detect_qt6_qml_user_dir() {
local arch_triplet=""
if command -v dpkg-architecture >/dev/null 2>&1; then
arch_triplet="$(dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null || true)"
fi
if [ -n "${arch_triplet:-}" ] && echo "$arch_triplet" | grep -q '-'; then
printf '%s/.local/lib/%s/qt6/qml' "$HOME" "$arch_triplet"
else
printf '%s/.local/lib/qt6/qml' "$HOME"
fi
}
QT6_QML_USER_DIR="$(detect_qt6_qml_user_dir)"
QML_MODULE_USER_DIR="$QT6_QML_USER_DIR/org/kde/plasma/proxmox"
if [ "$INSTALL_STANDALONE_QML_MODULE" -eq 1 ]; then
mkdir -p "$QML_MODULE_USER_DIR"
atomic_cp "$BUILD_DIR/libproxmoxclientplugin.so" "$QML_MODULE_USER_DIR/"
atomic_cp contents/lib/proxmox/qmldir "$QML_MODULE_USER_DIR/"
printf '%s\n' "[ qml ] Standalone module copied → $QML_MODULE_USER_DIR"
fi
# Remove stale env file from older installs.
PLASMA_ENV_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/plasma-workspace/env/proxmon-qml.sh"
if [ -f "$PLASMA_ENV_FILE" ]; then
rm -f "$PLASMA_ENV_FILE"
fi
PLASMOID_CONTENTS="${XDG_DATA_HOME:-$HOME/.local/share}/plasma/plasmoids/org.kde.plasma.proxmox/contents"
ICON_BASE="${XDG_DATA_HOME:-$HOME/.local/share}/icons"
ICON_DIR="$ICON_BASE/hicolor/scalable/apps"
# Checksum-based sync: copy only files whose md5 differs from the installed copy.
# Copies everything unconditionally if md5sum is unavailable.
sync_contents() {
local src="$1" dst="$2"
local have_md5=1
command -v md5sum >/dev/null 2>&1 || have_md5=0
local copied=0
while IFS= read -r -d '' srcfile; do
local rel="${srcfile#$src/}"
local dstfile="$dst/$rel"
local copy=1
if [ "$have_md5" -eq 1 ] && [ -f "$dstfile" ]; then
local src_sum dst_sum
src_sum="$(md5sum "$srcfile" | cut -d' ' -f1)"
dst_sum="$(md5sum "$dstfile" | cut -d' ' -f1)"
[ "$src_sum" = "$dst_sum" ] && copy=0
fi
if [ "$copy" -eq 1 ]; then
mkdir -p "$(dirname "$dstfile")"
atomic_cp "$srcfile" "$dstfile"
copied=$(( copied + 1 ))
fi
done < <(find "$src" -type f -print0)
printf '%s\n' "[ install] Synced $copied file(s) → $dst"
}
# First install: register with kpackagetool so Plasma knows the plasmoid exists.
PKG_PATH="."
if [ ! -d "$PLASMOID_CONTENTS" ]; then
if "$KPACKAGETOOL" --help 2>/dev/null | grep -q -- '--type'; then
"$KPACKAGETOOL" --type Plasma/Applet --install "$PKG_PATH" 2>/dev/null || \
"$KPACKAGETOOL" --type Plasma/Applet --upgrade "$PKG_PATH" || true
else
"$KPACKAGETOOL" -t Plasma/Applet -i "$PKG_PATH" 2>/dev/null || \
"$KPACKAGETOOL" -t Plasma/Applet -u "$PKG_PATH" || true
fi
fi
# Checksum sync contents - skips unchanged files.
# --rebuild: running from the installed dir so src == dst; install .so directly instead.
if [ "$REBUILD_ONLY" -eq 1 ]; then
mkdir -p "$PLASMOID_CONTENTS/lib/proxmox"
atomic_cp "$BUILD_DIR/libproxmoxclientplugin.so" "$PLASMOID_CONTENTS/lib/proxmox/"
printf '%s\n' "[ install] Plugin installed → $PLASMOID_CONTENTS/lib/proxmox/libproxmoxclientplugin.so"
elif [ -d "$PLASMOID_CONTENTS" ]; then
sync_contents "contents" "$PLASMOID_CONTENTS"
# metadata.json sits at the package root, outside contents/, so the sync
# above never reaches it. kpackagetool only runs on a first install, so
# without this the About tab keeps reporting whichever version was
# current when the plasmoid was first installed.
atomic_cp "metadata.json" "$(dirname "$PLASMOID_CONTENTS")/"
printf '%s\n' "[ install] metadata.json synced → $(dirname "$PLASMOID_CONTENTS")/metadata.json"
fi
mkdir -p "$ICON_DIR"
if [ -d "contents/icons" ]; then
while IFS= read -r -d '' icon; do
dst_icon="$ICON_DIR/$(basename "$icon")"
icon_copy=1
if [ -f "$dst_icon" ] && command -v md5sum >/dev/null 2>&1; then
[ "$(md5sum "$icon" | cut -d' ' -f1)" = "$(md5sum "$dst_icon" | cut -d' ' -f1)" ] && icon_copy=0
fi
[ "$icon_copy" -eq 1 ] && cp "$icon" "$dst_icon"
done < <(find "contents/icons" -name "*.svg" -print0)
fi
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
gtk-update-icon-cache "$ICON_BASE/hicolor/" 2>/dev/null || true
fi
if command -v kbuildsycoca6 >/dev/null 2>&1; then
kbuildsycoca6 >/dev/null 2>&1 || true
elif command -v kbuildsycoca5 >/dev/null 2>&1; then
kbuildsycoca5 >/dev/null 2>&1 || true
fi
# Installs a systemd path unit that watches runtime libs and triggers a rebuild
# via check-and-rebuild.sh when any of them change (e.g. after a Qt update).
install_autoupdate() {
if ! command -v systemctl >/dev/null 2>&1; then
printf '%s\n' "systemctl not found — skipping auto-update watcher install."
return 0
fi
local plasmoid_dir="${XDG_DATA_HOME:-$HOME/.local/share}/plasma/plasmoids/org.kde.plasma.proxmox"
local systemd_dir="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
mkdir -p "$plasmoid_dir" "$systemd_dir"
if [ -f "check-and-rebuild.sh" ]; then
cp check-and-rebuild.sh "$plasmoid_dir/check-and-rebuild.sh"
chmod +x "$plasmoid_dir/check-and-rebuild.sh"
cp "$0" "$plasmoid_dir/install.sh"
chmod +x "$plasmoid_dir/install.sh"
else
printf '%s\n' "WARNING: check-and-rebuild.sh not found — skipping auto-update install." >&2
return 0
fi
if [ -f "proxmox-plasmoid-rebuild.service" ]; then
cp proxmox-plasmoid-rebuild.service "$systemd_dir/"
else
printf '%s\n' "WARNING: proxmox-plasmoid-rebuild.service not found — skipping auto-update install." >&2
return 0
fi
# Resolve a lib path via ldconfig with a find fallback.
resolve_lib() {
local pattern="$1"
local result
result="$(ldconfig -p 2>/dev/null | grep -i "$pattern" | awk '{print $NF}' | head -1)" || true
if [ -z "${result:-}" ]; then
result="$(find /usr/lib64 /usr/lib /lib64 /lib -name "${pattern}*" 2>/dev/null | grep '\.so\.[0-9]*$' | head -1)" || true
fi
printf '%s' "${result:-}"
}
local libplasma_path libqt6core_path libvncclient_path libqtermwidget_path
libplasma_path="$(resolve_lib 'libPlasma\.so\.')"
if [ -z "${libplasma_path:-}" ]; then
printf '%s\n' "WARNING: Could not resolve libplasma.so — skipping auto-update install." >&2
return 0
fi
libqt6core_path="$(resolve_lib 'libQt6Core\.so\.')"
libvncclient_path="$(resolve_lib 'libvncclient\.so\.')"
libqtermwidget_path="$(resolve_lib 'libqtermwidget')"
printf '%s\n' "[ watch] libplasma.so → $libplasma_path"
[ -n "${libqt6core_path:-}" ] && printf '%s\n' "[ watch] libQt6Core.so → $libqt6core_path"
[ -n "${libvncclient_path:-}" ] && printf '%s\n' "[ watch] libvncclient.so → $libvncclient_path"
[ -n "${libqtermwidget_path:-}" ] && printf '%s\n' "[ watch] libqtermwidget6 → $libqtermwidget_path"
{
cat <<'EOF'
[Unit]
Description=Proxmox Plasmoid - watch runtime libraries for changes
[Path]
EOF
printf 'PathChanged=%s\n' "$libplasma_path"
[ -n "${libqt6core_path:-}" ] && printf 'PathChanged=%s\n' "$libqt6core_path"
[ -n "${libvncclient_path:-}" ] && printf 'PathChanged=%s\n' "$libvncclient_path"
[ -n "${libqtermwidget_path:-}" ] && printf 'PathChanged=%s\n' "$libqtermwidget_path"
cat <<'EOF'
[Install]
WantedBy=default.target
EOF
} > "$systemd_dir/proxmox-plasmoid-rebuild.path"
systemctl --user daemon-reload
systemctl --user enable --now proxmox-plasmoid-rebuild.path
printf '%s\n' "[ watch] Auto-update watcher enabled."
}
if [ "$INSTALL_WATCHER" -eq 1 ]; then
install_autoupdate
fi
PLASMOID_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/plasma/plasmoids/org.kde.plasma.proxmox"
FINGERPRINT_FILE="$PLASMOID_DIR/.build_fingerprint"
{ ldconfig -p 2>/dev/null | grep -iE 'libplasma|libQt6|libvncclient|libqtermwidget' || true; } \
| awk '{print $NF}' \
| sort \
| xargs -r md5sum 2>/dev/null \
| md5sum \
| cut -d' ' -f1 > "$FINGERPRINT_FILE"
printf '\n'
printf '%s\n' "Install complete."
printf '\n'
printf '%s\n' " Restart Plasma to activate:"
printf '%s\n' " kquitapp6 plasmashell && kstart plasmashell"
printf '%s\n' " or simply log out and back in."
printf '\n'
printf '%s\n' " Add the widget:"
printf '%s\n' " Right-click panel → Add Widgets → search 'Proxmox'"
printf '\n'
printf '%s\n' " Auto-update watcher:"
printf '%s\n' " systemctl --user status proxmox-plasmoid-rebuild.path"
printf '%s\n' " tail -f $PLASMOID_DIR/rebuild.log"
printf '\n'