From a8230d47f6e0fd60cfc75e0b16f8f1f5a9b73765 Mon Sep 17 00:00:00 2001 From: Christoffer Sandberg Date: Mon, 7 Dec 2020 16:58:05 +0100 Subject: [PATCH] packaging: Add module restart/install logic - For clevo interfaces - For tuxedo_io from tuxedo_cc_wmi --- deb/module-name/DEBIAN/control | 4 +- deb/module-name/DEBIAN/postinst | 82 ++++++++++++++++++++++----------- src_pkg/rpm_pkg.spec | 36 ++++++++++++++- 3 files changed, 91 insertions(+), 31 deletions(-) diff --git a/deb/module-name/DEBIAN/control b/deb/module-name/DEBIAN/control index 8b66a0c..a819e20 100644 --- a/deb/module-name/DEBIAN/control +++ b/deb/module-name/DEBIAN/control @@ -3,8 +3,8 @@ Version: x.x.x Section: admin Priority: optional Depends: dkms (>= 1.95) -Conflicts: tuxedo-keyboard-dkms (<= 2.0.0), tuxedo-wmi-dkms (<= 1.5.1), tuxedo-xp-xc-touchpad-key-fix, tuxedo-touchpad-fix (<= 1.0.8), tuxedo-xp-xc-airplane-mode-fix (<= 0.6) -Replaces: tuxedo-keyboard-dkms (<= 2.0.0), tuxedo-wmi-dkms (<= 1.5.1), tuxedo-xp-xc-touchpad-key-fix, tuxedo-touchpad-fix (<= 1.0.8), tuxedo-xp-xc-airplane-mode-fix (<= 0.6) +Conflicts: tuxedo-keyboard-dkms (<= 2.0.0), tuxedo-wmi-dkms (<= 1.5.1), tuxedo-xp-xc-touchpad-key-fix, tuxedo-touchpad-fix (<= 1.0.8), tuxedo-xp-xc-airplane-mode-fix (<= 0.6), tuxedo-cc-wmi +Replaces: tuxedo-keyboard-dkms (<= 2.0.0), tuxedo-wmi-dkms (<= 1.5.1), tuxedo-xp-xc-touchpad-key-fix, tuxedo-touchpad-fix (<= 1.0.8), tuxedo-xp-xc-airplane-mode-fix (<= 0.6), tuxedo-cc-wmi Maintainer: TUXEDO Computers GmbH Homepage: https://www.tuxedocomputers.com Architecture: all diff --git a/deb/module-name/DEBIAN/postinst b/deb/module-name/DEBIAN/postinst index d943585..8f1fe6b 100755 --- a/deb/module-name/DEBIAN/postinst +++ b/deb/module-name/DEBIAN/postinst @@ -20,45 +20,73 @@ CVERSION=`dpkg-query -W -f='${Version}' $DEB_NAME | awk -F "-" '{print $1}' | cu ARCH=`dpkg --print-architecture` dkms_configure () { - for POSTINST in /usr/lib/dkms/common.postinst "/usr/share/$PACKAGE_NAME/postinst"; do - if [ -f "$POSTINST" ]; then - "$POSTINST" "$NAME" "$CVERSION" "/usr/share/$PACKAGE_NAME" "$ARCH" "$2" - return $? - fi - echo "WARNING: $POSTINST does not exist." >&2 - done - echo "ERROR: DKMS version is too old and $PACKAGE_NAME was not" >&2 - echo "built with legacy DKMS support." >&2 - echo "You must either rebuild $PACKAGE_NAME with legacy postinst" >&2 - echo "support or upgrade DKMS to a more current version." >&2 - return 1 + for POSTINST in /usr/lib/dkms/common.postinst "/usr/share/$PACKAGE_NAME/postinst"; do + if [ -f "$POSTINST" ]; then + "$POSTINST" "$NAME" "$CVERSION" "/usr/share/$PACKAGE_NAME" "$ARCH" "$2" + return $? + fi + echo "WARNING: $POSTINST does not exist." >&2 + done + echo "ERROR: DKMS version is too old and $PACKAGE_NAME was not" >&2 + echo "built with legacy DKMS support." >&2 + echo "You must either rebuild $PACKAGE_NAME with legacy postinst" >&2 + echo "support or upgrade DKMS to a more current version." >&2 + return 1 } # End dkms standard postinst case "$1" in configure) - # Run standard dkms build/install for all kernels with headers installed + # Run standard dkms build/install for all kernels with headers installed dkms_configure - # Attempt to (re-)load module immediately, fail silently if not possible at this stage - rmmod ${module} > /dev/null 2>&1 || true - modprobe ${module} > /dev/null 2>&1 || true + # Attempt to (re-)load module immediately, fail silently if not possible at this stage - # Install default config if none exist already - if [ ! -f "/etc/modprobe.d/tuxedo_keyboard.conf" ]; then - cp -f /usr/share/tuxedo-keyboard/tuxedo_keyboard.conf /etc/modprobe.d/tuxedo_keyboard.conf - fi + # Also stop tccd service if running before + echo "Check tccd running status" + if systemctl is-active --quiet tccd.service; then + TCCD_RUNNING=true + else + TCCD_RUNNING=false + fi - ;; + if $TCCD_RUNNING; then + echo "Stop tccd temporarily" + systemctl stop tccd 2>&1 || true + fi - abort-upgrade|abort-remove|abort-deconfigure) - ;; + echo "(Re)load modules if possible" + rmmod tuxedo_io > /dev/null 2>&1 || true + rmmod clevo_wmi > /dev/null 2>&1 || true + rmmod clevo_acpi > /dev/null 2>&1 || true + rmmod tuxedo_keyboard > /dev/null 2>&1 || true + + modprobe tuxedo_keyboard > /dev/null 2>&1 || true + modprobe clevo_wmi > /dev/null 2>&1 || true + modprobe clevo_acpi > /dev/null 2>&1 || true + modprobe tuxedo_io > /dev/null 2>&1 || true - *) - echo "postinst called with unknown argument \`$1'" >&2 - exit 1 - ;; + # Restart tccd after reload if it was running + if $TCCD_RUNNING; then + echo "Start tccd again" + systemctl start tccd 2>&1 || true + fi + + # Install default config if none exist already + if [ ! -f "/etc/modprobe.d/tuxedo_keyboard.conf" ]; then + cp -f /usr/share/tuxedo-keyboard/tuxedo_keyboard.conf /etc/modprobe.d/tuxedo_keyboard.conf + fi + + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; esac exit 0 diff --git a/src_pkg/rpm_pkg.spec b/src_pkg/rpm_pkg.spec index c365dac..8559855 100644 --- a/src_pkg/rpm_pkg.spec +++ b/src_pkg/rpm_pkg.spec @@ -31,6 +31,7 @@ Provides: tuxedo_keyboard = %{version}-%{release} Obsoletes: tuxedo_keyboard < %{version}-%{release} Obsoletes: tuxedo-xp-xc-touchpad-key-fix Obsoletes: tuxedo-touchpad-fix <= 1.0.1 +Obsoletes: tuxedo-cc-wmi Requires: dkms >= 1.95 BuildRoot: %{_tmppath} Packager: Tomte @@ -71,14 +72,45 @@ for POSTINST in /usr/lib/dkms/common.postinst /usr/share/%{module}/postinst; do if [ -f $POSTINST ]; then $POSTINST %{module} %{version} /usr/share/%{module} RET=$? - rmmod %{module} > /dev/null 2>&1 || true - modprobe %{module} > /dev/null 2>&1 || true + + # Attempt to (re-)load module immediately, fail silently if not possible at this stage + + # Also stop tccd service if running before + echo "Check tccd running status" + if systemctl is-active --quiet tccd.service; then + TCCD_RUNNING=true + else + TCCD_RUNNING=false + fi + + if $TCCD_RUNNING; then + echo "Stop tccd temporarily" + systemctl stop tccd 2>&1 || true + fi + + echo "(Re)load modules if possible" + + rmmod tuxedo_io > /dev/null 2>&1 || true + rmmod clevo_wmi > /dev/null 2>&1 || true + rmmod clevo_acpi > /dev/null 2>&1 || true + rmmod tuxedo_keyboard > /dev/null 2>&1 || true + + modprobe tuxedo_keyboard > /dev/null 2>&1 || true + modprobe clevo_wmi > /dev/null 2>&1 || true + modprobe clevo_acpi > /dev/null 2>&1 || true + modprobe tuxedo_io > /dev/null 2>&1 || true # Install default config if none exist already if [ ! -f "/etc/modprobe.d/tuxedo_keyboard.conf" ]; then cp -f /usr/share/tuxedo-keyboard/tuxedo_keyboard.conf /etc/modprobe.d/tuxedo_keyboard.conf fi + # Restart tccd after reload if it was running + if $TCCD_RUNNING; then + echo "Start tccd again" + systemctl start tccd 2>&1 || true + fi + exit $RET fi echo "WARNING: $POSTINST does not exist."