aur/crossmacro.install
2026-03-11 05:12:29 +00:00

108 lines
3.6 KiB
Text

_crossmacro_load_uinput() {
# Best effort: make uinput available immediately for the daemon.
# Persistent boot-time loading is handled by /usr/lib/modules-load.d/crossmacro.conf.
if command -v modprobe >/dev/null 2>&1; then
modprobe uinput >/dev/null 2>&1 || true
fi
}
_crossmacro_has_cmd() {
command -v "$1" >/dev/null 2>&1
}
_crossmacro_has_systemd_runtime() {
[ -d /run/systemd/system ] && _crossmacro_has_cmd systemctl
}
_crossmacro_reload_udev() {
if _crossmacro_has_cmd udevadm; then
udevadm control --reload-rules >/dev/null 2>&1 || true
udevadm settle >/dev/null 2>&1 || true
fi
}
post_install() {
if _crossmacro_has_systemd_runtime; then
echo "Reloading systemd daemon..."
systemctl daemon-reload >/dev/null 2>&1 || true
fi
_crossmacro_reload_udev
_crossmacro_load_uinput
if _crossmacro_has_cmd udevadm; then
udevadm trigger >/dev/null 2>&1 || true
udevadm settle >/dev/null 2>&1 || true
fi
auto_service_status="systemd runtime not detected; skipped auto enable/start"
if _crossmacro_has_systemd_runtime; then
if systemctl enable --now crossmacro.service >/dev/null 2>&1; then
auto_service_status="crossmacro.service enabled and started automatically"
else
auto_service_status="auto enable/start failed; run: sudo systemctl enable --now crossmacro.service"
fi
fi
installer_user=""
if [ -n "${SUDO_USER:-}" ] && [ "${SUDO_USER}" != "root" ]; then
installer_user="${SUDO_USER}"
elif [ -n "${PKEXEC_UID:-}" ] && [ "${PKEXEC_UID}" != "0" ]; then
installer_user="$(getent passwd "${PKEXEC_UID}" | cut -d: -f1)"
fi
if [ -n "$installer_user" ] && getent passwd "$installer_user" >/dev/null 2>&1; then
usermod -aG crossmacro "$installer_user" >/dev/null 2>&1 || true
fi
echo "------------------------------------------------------------------------"
echo "CrossMacro Daemon installed."
echo "Service: $auto_service_status"
echo ""
if [ -n "$installer_user" ]; then
echo "1. '$installer_user' was added to 'crossmacro' group (best effort)."
echo " If needed, run: sudo usermod -aG crossmacro \$USER"
else
echo "1. Add yourself to the 'crossmacro' group to communicate with the daemon:"
echo " sudo usermod -aG crossmacro \$USER"
fi
echo ""
echo "2. Log out and log back in for group changes to take effect."
echo "------------------------------------------------------------------------"
}
post_upgrade() {
if _crossmacro_has_systemd_runtime; then
systemctl daemon-reload >/dev/null 2>&1 || true
fi
_crossmacro_reload_udev
_crossmacro_load_uinput
if _crossmacro_has_cmd udevadm; then
udevadm trigger >/dev/null 2>&1 || true
udevadm settle >/dev/null 2>&1 || true
fi
# Only restart if service is active
if _crossmacro_has_systemd_runtime && systemctl is-active --quiet crossmacro.service 2>/dev/null; then
systemctl try-restart crossmacro.service >/dev/null 2>&1 || true
fi
}
pre_remove() {
if ! _crossmacro_has_systemd_runtime; then
return 0
fi
# Only disable if service exists and is enabled/active
if systemctl is-enabled --quiet crossmacro.service 2>/dev/null || \
systemctl is-active --quiet crossmacro.service 2>/dev/null; then
systemctl disable --now crossmacro.service >/dev/null 2>&1 || true
fi
}
post_remove() {
if _crossmacro_has_systemd_runtime; then
systemctl daemon-reload >/dev/null 2>&1 || true
fi
_crossmacro_reload_udev
}