Files
insta360-link-tools/plasmoid/install.sh
T
brad f95853dc25 Add GPL-3.0 licensing and prepare for a public repository
metadata.json claimed MIT while no LICENSE file existed, so the repository
had no effective licence at all. It is now GPL-3.0-or-later: the full FSF
text in LICENSE, the identifier in metadata.json, and REUSE-style
SPDX-FileCopyrightText and SPDX-License-Identifier headers on all 33 source
files, which is the convention KDE itself uses.

Worth recording that GPL-3.0 is a preference here rather than an obligation.
Nothing in the dependency graph forces it: linkctl is MIT and is invoked as a
subprocess rather than linked, and the KDE QML modules the applet imports are
LGPL.

Removed two things that should not ship in a public repository. tests's QML
linter had an absolute sandbox path, /tmp/pyside/PySide6/qmllint, baked into
its search list; it now looks for Qt's qmllint and PySide6's pyside6-qmllint
on PATH and honours a QMLLINT override, and says how to install one when it
finds nothing. The systemd unit carried a Documentation= URL pointing at a
host that does not exist, and its ExecStart silently assumed a particular
checkout directory; the URL is gone and the path is now an obvious
PATH/TO/CHECKOUT placeholder next to the comment telling you to edit it.

Added a Credits section naming the work this is built on, since the project
is mostly glue: linkctl does the camera control, schlarpc's firmware teardown
documents the extension-unit protocol, and vrwallace's controller established
that the Link 2 needs both pan and tilt axes in a single VIDIOC_S_EXT_CTRLS
call, which is the detail the whole thing depends on.

Also made the two Python tests executable, matching the other scripts.

Audited for operator-specific detail: no credentials, tokens, private
hostnames, IP addresses or absolute home paths in any tracked file or
anywhere in the history's diffs. Three merge commits do carry Reviewed-on and
Reviewed-by trailers naming a private forge, added by the forge at merge
time; those are commit metadata rather than file content and are handled
separately.

Tested: 169 checks across seven suites plus the QML linter, all passing after
the header insertion, which confirms it did not disturb the order-sensitive
`.pragma library` line in logic.js or the qmldir module definitions.
shellcheck clean.
2026-10-13 20:54:23 -07:00

108 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2026 branderson
# SPDX-License-Identifier: GPL-3.0-or-later
#
# install.sh - install the Insta360 Link Joystick applet into Plasma.
#
# Usage:
# ./install.sh install, or upgrade if already present
# ./install.sh --uninstall remove it
# ./install.sh --restart also restart plasmashell (needed to pick up
# changes to an already-running applet)
#
# After installing: right-click the desktop or panel, Add Widgets, and search
# for "Insta360".
set -euo pipefail
readonly APPLET_ID="com.github.insta360linktools.joystick"
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
readonly SCRIPT_DIR
readonly PKG="$SCRIPT_DIR/package"
RESTART=0
MODE=install
die() { printf 'error: %s\n' "$*" >&2; exit 1; }
while [[ $# -gt 0 ]]; do
case $1 in
--uninstall) MODE=uninstall; shift ;;
--restart) RESTART=1; shift ;;
-h|--help)
awk 'NR>1 { if (!/^#/) exit; sub(/^# ?/, ""); print }' \
"${BASH_SOURCE[0]}"
exit 0 ;;
*) die "unknown option: $1" ;;
esac
done
if command -v kpackagetool6 >/dev/null 2>&1; then
KPT=kpackagetool6
elif command -v kpackagetool5 >/dev/null 2>&1; then
KPT=kpackagetool5
else
die "neither kpackagetool6 nor kpackagetool5 found; is this a KDE Plasma session?"
fi
# Qt caches compiled QML and JS on disk. Replacing the applet's files does not
# invalidate that cache reliably, and a stale compiled logic.js missing a
# newer helper function is enough to break bindings that reference it. Clearing
# it costs only a slower first load.
clear_qml_cache() {
local cleared=0 d
for d in "${XDG_CACHE_HOME:-$HOME/.cache}"/plasmashell/qmlcache \
"${XDG_CACHE_HOME:-$HOME/.cache}"/org.kde.plasmashell/qmlcache \
"${XDG_CACHE_HOME:-$HOME/.cache}"/qmlcache; do
if [[ -d $d ]]; then
rm -rf -- "$d" && echo " cleared $d" && cleared=1
fi
done
(( cleared )) || echo " no QML cache to clear"
}
restart_shell() {
(( RESTART )) || return 0
echo "Restarting plasmashell:"
if systemctl --user restart plasma-plasmashell.service 2>/dev/null; then
echo " restarted via systemd"
elif command -v kquitapp6 >/dev/null 2>&1; then
kquitapp6 plasmashell 2>/dev/null || true
sleep 2
(setsid plasmashell >/dev/null 2>&1 &)
echo " restarted"
else
echo " could not restart; log out and back in to pick up changes"
fi
}
case $MODE in
install)
[[ -f $PKG/metadata.json ]] || die "no package found at $PKG"
# Fail early on malformed metadata rather than leaving a half-installed
# applet that Plasma silently refuses to load.
python3 -c "import json,sys; json.load(open('$PKG/metadata.json'))" \
2>/dev/null || die "metadata.json is not valid JSON"
if "$KPT" --type Plasma/Applet --list 2>/dev/null | grep -qx "$APPLET_ID"; then
echo "Already installed; upgrading:"
"$KPT" --type Plasma/Applet --upgrade "$PKG"
else
echo "Installing:"
"$KPT" --type Plasma/Applet --install "$PKG"
fi
echo "Clearing the compiled QML cache:"
clear_qml_cache
restart_shell
echo
echo "Done. Right-click a panel or the desktop, Add Widgets, search 'Insta360'."
;;
uninstall)
echo "Removing:"
"$KPT" --type Plasma/Applet --remove "$APPLET_ID"
restart_shell
echo "Done."
;;
esac