post_install() {
    :
#!/bin/sh
# Desktop Linux post-install — PRD module M8 (Linux portion).
#
# The Electron app spawns the CLI by the bare name `ardexa-remote` (see
# src-electron/remote.js), so the CLI must be on PATH. The matching-version CLI
# binary is bundled inside the package's resources directory (electron-builder
# `linux.extraResources`); place it on PATH here. Run by FPM as root for the
# deb/rpm/pacman after-install scriptlet.
set -e

# electron-builder installs the app under /opt/<sanitizedProductName>/ and
# extraResources land in its resources/ dir. Try the deterministic path first,
# then fall back to a glob so a productName change doesn't silently break this.
for candidate in \
	"/opt/Ardexa Remote/resources/ardexa-remote" \
	/opt/*/resources/ardexa-remote; do
	if [ -f "$candidate" ]; then
		install -m 0755 "$candidate" /usr/bin/ardexa-remote
		echo "ardexa-remote CLI installed to /usr/bin/ardexa-remote"
		exit 0
	fi
done

echo "ERROR: bundled ardexa-remote CLI not found in package resources;" >&2
echo "       the desktop app's 'ardexa-remote' spawn will not resolve." >&2
exit 1

}
post_remove() {
    :
#!/bin/sh
# Desktop Linux post-remove — PRD module M8 (Linux portion).
#
# Remove the CLI binary that after-install.sh placed on PATH — but ONLY on a
# genuine package removal, never during an upgrade. This one script is the
# post-remove scriptlet for all three package managers, and they signal
# "upgrade vs removal" differently:
#   rpm    (%postun)     : $1 = remaining-instance count — "0" on final erase,
#                          ">=1" while upgrading.
#   deb    (postrm)      : $1 = action — "remove"/"purge" on removal,
#                          "upgrade"/"abort-upgrade"/"failed-upgrade" mid-upgrade.
#   pacman (post_remove) : no args, and it is invoked ONLY on a real removal
#                          (upgrades run post_upgrade instead).
#
# An unconditional `rm` is wrong for rpm: rpm runs the OLD package's %postun
# AFTER the NEW package's %post, so it would delete the CLI that the new
# package's after-install.sh just placed (a vanished CLI after `dnf upgrade`).
# `case` only ever runs `rm -f` or nothing, so this scriptlet never fails the
# package transaction.
set -e
case "${1:-remove}" in
	1|2|upgrade|failed-upgrade|abort-upgrade) ;;   # upgrade in progress — keep the CLI
	*) rm -f /usr/bin/ardexa-remote ;;             # 0 / remove / purge / pacman (no arg)
esac

}
