]> git.etc.gen.nz Git - sapphire-remote.git/commitdiff
Convert to a non-native Debian package
authorAndrew Ruthven <andrew@etc.gen.nz>
Tue, 19 Feb 2019 09:26:12 +0000 (09:26 +0000)
committerAndrew Ruthven <andrew@etc.gen.nz>
Wed, 20 Feb 2019 00:45:28 +0000 (13:45 +1300)
20 files changed:
Makefile
README.txt [moved from sapphire-remote-7.1/README.txt with 100% similarity]
common.postinst [deleted file]
debian/patches/dkms.diff [new file with mode: 0644]
debian/patches/paths.diff
debian/patches/remove_rmmod.diff [moved from debian/patches/remove_rmmod with 89% similarity]
debian/patches/series
debian/rules
debian/sapphire-remote-dkms.install [new file with mode: 0644]
debian/sapphire-remote.docs
debian/sapphire-remote.install
extract_keydefs.sh [moved from sapphire-remote-7.1/extract_keydefs.sh with 100% similarity]
keymap.default [moved from sapphire-remote-7.1/keymap.default with 100% similarity]
sapphire-remote-7.1/Makefile [deleted file]
sapphire-remote-7.1/dkms.conf [deleted file]
sapphire.c [moved from sapphire-remote-7.1/sapphire.c with 100% similarity]
sapphire.h [moved from sapphire-remote-7.1/sapphire.h with 100% similarity]
sapphire_keymap.sh.part1 [moved from sapphire-remote-7.1/sapphire_keymap.sh.part1 with 100% similarity]
sapphire_keymap.sh.part3 [moved from sapphire-remote-7.1/sapphire_keymap.sh.part3 with 100% similarity]
sapphire_startup.sh [moved from sapphire-remote-7.1/sapphire_startup.sh with 100% similarity]

index 57e13d835f3d1512620ba2131aac2203d88a3df7..16d0e143b28d54b1fc809b538c55650e8cc373bb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,28 +1,86 @@
-#/usr/bin/make
-SRC = $(DESTDIR)/usr/src
-SHARE = $(DESTDIR)/usr/share/$(NAME)-dkms
+#
+# Makefile and (un-)Installer for Sapphire remote control driver,
+#    by Mark Lord 2012-2018.
+#
+MODNAME=sapphire
+MODSOURCE=$(MODNAME).c
+CONFLICTS=hid_topseed
+BLACKLIST=/etc/modprobe.d/blacklist-$(CONFLICTS).conf
+KEYMAP_SCRIPT=sapphire_keymap.sh
+EXTRACT_KEYDEFS=extract_keydefs.sh
+INPUT_H=$(shell [ -e /usr/include/linux/input-event-codes.h ] && echo /usr/include/linux/input-event-codes.h || echo /usr/include/linux/input.h)
 
-all:
+## MODPARMS is not used any more, but we have to nuke old copies to prevent issues:
+MODPARMS=/etc/modprobe.d/$(MODNAME).conf
+
+CWD    = $(shell pwd -P)
+KVER  ?= $(shell uname -r)
+KDIR  = /lib/modules/$(KVER)
+obj-m += $(MODNAME).o
+
+#EXTRA_CFLAGS += -Werror
+
+default: $(INPUT_H) kmod $(KEYMAP_SCRIPT)
+
+$(INPUT_H):
+       @echo "ERROR: $@: not found."
+       @echo
+       @echo "Please install the system development libraries first."
+       @echo "Eg. on Ubuntu/Mint systems:  sudo apt-get install build-essential"
+       @echo
+       @exit 1
+
+kmod:
+       $(MAKE) -C $(KDIR)/build M=$(CWD) modules
+
+$(MODNAME).ko: $(MODSOURCE) $(MODNAME).h
+       $(MAKE) kmod
+
+$(KEYMAP_SCRIPT): $(INPUT_H) $(EXTRACT_KEYDEFS) $(KEYMAP_SCRIPT).part1 $(KEYMAP_SCRIPT).part3 $(MODNAME).h $(INPUT_H)
+       @bash -c "type -all gawk" >/dev/null 2>&1 || (\
+               echo ;\
+               echo "gawk not found, needed by installer; Aborted." ;\
+               echo "For Ubuntu/Debian based systems, try this:  sudo apt-get install gawk" ;\
+               echo ;\
+               exit 2 ;\
+       )
+       chmod 0755 $(EXTRACT_KEYDEFS)
+       ./$(EXTRACT_KEYDEFS) $(INPUT_H) $(MODNAME).h | cat $(KEYMAP_SCRIPT).part1 - $(KEYMAP_SCRIPT).part3 > $(KEYMAP_SCRIPT)
+       chmod 0755 $(KEYMAP_SCRIPT)
+
+$(BLACKLIST):
+       @echo "Creating $(BLACKLIST)"
+       @echo "## $(CONFLICTS) Conflicts with $(MODNAME) driver" >  $(BLACKLIST)
+       @echo "blacklist $(CONFLICTS)"                           >> $(BLACKLIST)
+
+modinstall: $(MODNAME).ko $(KEYMAP_SCRIPT)
+       $(MAKE) -C $(KDIR)/build M=$(CWD) modules_install || exit 0
+       @[ -e $(KDIR)/extra/sapphire.ko -o -e $(KDIR)/extra/sapphire.ko.gz -o -e $(KDIR)/extra/sapphire.ko.xz ] || exit 1
+       depmod $(KVER)
+       @if [ "$(KVER)" = "$$(uname -r)" ]; then \
+               rmmod $(MODNAME)   2>/dev/null ;\
+               rmmod $(CONFLICTS) 2>/dev/null ;\
+               ./sapphire_startup.sh ;\
+       else \
+               exit 0 ;\
+       fi
 
 clean:
+       $(MAKE) -C $(KDIR)/build M=$(CWD) clean
+       -rm -f $(KEYMAP_SCRIPT)
+
+clean_modparms:
+       @if [ -e $(MODPARAMS) ]; then rm -f $(MODPARMS) ; fi ; exit 0
+
+uninstall: clean clean_modparms
+       -rmmod $(MODNAME)
+       -rm -f $(BLACKLIST)
+       -rm -f /usr/local/bin/$(KEYMAP_SCRIPT)
+       -rm -f $(KDIR)/extra/$(MODNAME).ko
+       depmod
+
+install: $(MODNAME).ko clean_modparms modinstall $(BLACKLIST) $(KEYMAP_SCRIPT)
+       install -m 0755 $(KEYMAP_SCRIPT) /usr/local/bin/
+       install -m 0755 sapphire_startup.sh /usr/local/bin/
 
-install:
-
-#source tree
-ifeq ("$(wildcard $(NAME)-$(VERSION))", "$(NAME)-$(VERSION)")
-       install -d "$(SRC)"
-       cp -a $(NAME)-$(VERSION) $(SRC)
-       chmod 644 -R "$(SRC)/$(NAME)-$(VERSION)"
-endif
-
-#tarball, possibly with binaries
-ifeq ("$(wildcard $(NAME)-$(VERSION).dkms.tar.gz)", "$(NAME)-$(VERSION).dkms.tar.gz")
-       install -d "$(SHARE)"
-       install -m 644 $(NAME)-$(VERSION).dkms.tar.gz "$(SHARE)"
-endif
-
-#postinst, only if we are supporting legacy mode
-ifeq ("$(wildcard common.postinst)", "common.postinst")
-       install -d "$(SHARE)"
-       install -m 755 $(PREFIX)/usr/lib/dkms/common.postinst $(SHARE)/postinst
-endif
+all: install
similarity index 100%
rename from sapphire-remote-7.1/README.txt
rename to README.txt
diff --git a/common.postinst b/common.postinst
deleted file mode 100755 (executable)
index 0c8cfc1..0000000
+++ /dev/null
@@ -1,295 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2002-2005 Flavio Stanchina
-# Copyright (C) 2005-2006 Aric Cyr
-# Copyright (C) 2007 Mario Limonciello
-# Copyright (C) 2009 Alberto Milone
-
-set -e
-
-uname_s=$(uname -s)
-
-_get_kernel_dir() {
-    KVER=$1
-    case ${uname_s} in
-       Linux)          DIR="/lib/modules/$KVER/build" ;;
-       GNU/kFreeBSD)   DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
-    esac
-    echo $DIR
-}
-
-_check_kernel_dir() {
-    DIR=$(_get_kernel_dir $1)
-    case ${uname_s} in
-       Linux)          test -e $DIR/include ;;
-       GNU/kFreeBSD)   test -e $DIR/kern && test -e $DIR/conf/kmod.mk ;;
-       *)              return 1 ;;
-    esac
-    return $?
-}
-
-# Check the existence of a kernel named as $1
-_is_kernel_name_correct() {
-    CORRECT="no"
-    KERNEL_NAME=$1
-
-    for kernel in /boot/config-*; do
-        KERNEL=${kernel#*-}
-        if [ "${KERNEL}" = "${KERNEL_NAME}" ]; then
-            CORRECT="yes"
-            break
-        fi
-    done
-
-    echo $CORRECT
-}
-
-
-# Get the most recent kernel on Debian based systems. This keeps
-# into account both the version and the ABI. If the current kernel
-# is the most recent kernel then the function will print a null string.
-_get_newest_kernel_debian() {
-    NEWEST_KERNEL=
-    NEWEST_VERSION=
-    NEWEST_ABI=
-
-    for kernel in /boot/config-*; do
-        KERNEL=${kernel#*-}
-        KERNEL_VERSION=${KERNEL%%-*}
-        ABI=${KERNEL#*-}
-        ABI=${ABI%%-*}
-
-        if [ -z "$NEWEST_KERNEL" ]; then
-            # The 1st time get a version which is bigger than $1
-            COMPARE_TO=$1
-        else
-            # Get the biggest version
-            COMPARE_TO="$NEWEST_VERSION-$NEWEST_ABI"
-        fi
-
-        # if $kernel is greater than $COMPARE_TO
-        if [ `dpkg --compare-versions "$KERNEL_VERSION-$ABI" gt "$COMPARE_TO" && echo "yes" || \
-              echo "no"` = "yes" ]; then
-            NEWEST_KERNEL=$KERNEL
-            NEWEST_VERSION=$KERNEL_VERSION
-            NEWEST_ABI=$ABI
-        fi
-    done
-
-    echo "$NEWEST_KERNEL"
-}
-
-# Get the most recent kernel in Rhel based systems. If the current kernel
-# is the most recent kernel then the function will print a null string.
-_get_newest_kernel_rhel() {
-    NEWEST_KERNEL=
-
-    LAST_INSTALLED_KERNEL=$(rpm -q --whatprovides kernel  --last | grep kernel -m1 | cut -f1 -d' ')
-
-    LIK_FORMATTED_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{VERSION}-%{RELEASE}.%{ARCH}\n")
-
-    if [ `echo $LIK_FORMATTED_NAME | grep 2.6 >/dev/null` ]; then
-        # Fedora and Suse
-        NEWEST_KERNEL=$LIK_FORMATTED_NAME
-    else
-        # Hack for Mandriva where $LIK_FORMATTED_NAME is broken
-        LIK_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{NAME}\n")
-        LIK_TYPE=${LIK_NAME#kernel-}
-        LIK_TYPE=${LIK_TYPE%%-*}
-        LIK_STRIPPED=${LIK_NAME#kernel-}
-        LIK_STRIPPED=${LIK_STRIPPED#$LIK_TYPE-}
-        LIK_STRIPPED_BASE=${LIK_STRIPPED%%-*}
-        LIK_STRIPPED_END=${LIK_STRIPPED#$LIK_STRIPPED_BASE-}
-        LIK_FINAL=$LIK_STRIPPED_BASE-$LIK_TYPE-$LIK_STRIPPED_END
-
-        NEWEST_KERNEL=$LIK_FINAL
-    fi
-
-    echo $NEWEST_KERNEL
-}
-
-# Get the newest kernel on Debian and Rhel based systems.
-get_newest_kernel() {
-    NEWEST_KERNEL=
-    # Try Debian first as rpm can be installed in Debian based distros
-    if [ -e /usr/bin/dpkg ]; then
-        # If DEB based
-        CURRENT_KERNEL=$1
-        CURRENT_VERSION=${CURRENT_KERNEL%%-*}
-        CURRENT_ABI=${CURRENT_KERNEL#*-}
-        CURRENT_FLAVOUR=${CURRENT_ABI#*-}
-        CURRENT_ABI=${CURRENT_ABI%%-*}
-        NEWEST_KERNEL=$(_get_newest_kernel_debian "$CURRENT_VERSION-$CURRENT_ABI")
-
-    elif [ `which rpm >/dev/null` ]; then
-        # If RPM based
-        NEWEST_KERNEL=$(_get_newest_kernel_rhel)
-    fi
-
-    # Make sure that kernel name that we extracted corresponds to an installed
-    # kernel
-    if [ -n "$NEWEST_KERNEL" ] && [ `_is_kernel_name_correct $NEWEST_KERNEL` = "no" ]; then
-        NEWEST_KERNEL=
-    fi
-
-    echo $NEWEST_KERNEL
-}
-
-NAME=$1
-VERSION=$2
-TARBALL_ROOT=$3
-ARCH=$4
-UPGRADE=$5
-
-if [ -z "$NAME" ] || [ -z "$VERSION" ]; then
-    echo "Need NAME, and VERSION defined"
-    echo "ARCH is optional"
-    exit 1
-fi
-
-KERNELS=$(ls /lib/modules/ 2>/dev/null || true)
-CURRENT_KERNEL=$(uname -r)
-
-#We never want to keep an older version side by side to prevent conflicts
-if [ -e "/var/lib/dkms/$NAME/$VERSION" ]; then
-    echo "Removing old $NAME-$VERSION DKMS files..."
-    dkms remove -m $NAME -v $VERSION --all
-fi
-
-#Load new files, by source package and by tarball
-if [ -f "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz" ]; then
-    if ! dkms ldtarball --archive "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz"; then
-        echo ""
-        echo ""
-        echo "Unable to load DKMS tarball $TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz."
-        echo "Common causes include: "
-        echo " - You must be using DKMS 2.1.0.0 or later to support binaries only"
-        echo "   distribution specific archives."
-        echo " - Corrupt distribution specific archive"
-        echo ""
-        echo ""
-        exit 2
-    fi
-elif [ -d "/usr/src/$NAME-$VERSION" ]; then
-    echo "Loading new $NAME-$VERSION DKMS files..."
-    dkms add -m $NAME -v $VERSION > /dev/null
-fi
-
-# On 1st installation, let us look for a directory
-# in /lib/modules which matches `uname -r`. If none
-# is found it is possible that buildd is being used
-# and that uname -r is giving us the name of the
-# kernel used by the buildd machine.
-#
-# If this is the case we try to build the kernel
-# module for each kernel which has a directory in
-# /lib/modules. Furthermore we will have to tell
-# DKMS which architecture it should build the module
-# for (e.g. if the buildd machine is using a
-# 2.6.24-23-xen 64bit kernel).
-#
-# NOTE: if the headers are not installed then the
-#       module won't be built, as usual
-if [ -z "$UPGRADE" ]; then
-    echo "First Installation: checking all kernels..."
-    for KERNEL in $KERNELS; do
-        if [ ${KERNEL} = ${CURRENT_KERNEL} ]; then
-            # Kernel found
-            KERNELS=$CURRENT_KERNEL
-            break
-        fi
-    done
-else
-    KERNELS=$CURRENT_KERNEL
-fi
-
-# Here we look for the most recent kernel so that we can
-# build the module for it (in addition to doing it for the
-# current kernel.
-NEWEST_KERNEL=$(get_newest_kernel "$KERNELS")
-
-# If the current kernel doesn't come from the host of a chroot
-if [ `_is_kernel_name_correct $CURRENT_KERNEL` = "yes" ]; then
-    # See if it's worth building the module for both the newest kernel
-    # and for the current kernel
-    if [ -n "$NEWEST_KERNEL" ] && [ ${CURRENT_KERNEL} != ${NEWEST_KERNEL} ]; then
-        echo "Building for $CURRENT_KERNEL and $NEWEST_KERNEL"
-        KERNELS="$CURRENT_KERNEL $NEWEST_KERNEL"
-    else
-        echo "Building only for $CURRENT_KERNEL"
-    fi
-# The current kernel is not useful as it's the host's
-else
-    echo "It is likely that $CURRENT_KERNEL belongs to a chroot's host"
-
-    # Let's use only the newest kernel
-    if [ -n "$NEWEST_KERNEL" ]; then
-        KERNELS="$NEWEST_KERNEL"
-        echo "Building only for $NEWEST_KERNEL"
-    fi
-fi
-
-if [ -n "$ARCH" ]; then
-    if which lsb_release >/dev/null && [ $(lsb_release -s -i) = "Ubuntu" ]; then
-        case $ARCH in
-            amd64)
-                ARCH="x86_64"
-                ;;
-            lpia|i?86)
-                ARCH="i686"
-                ;;
-        esac
-    fi
-    echo "Building for architecture $ARCH"
-    ARCH="-a $ARCH"
-fi
-
-for KERNEL in $KERNELS; do
-    dkms_status=`dkms status -m $NAME -v $VERSION -k $KERNEL $ARCH`
-    if [ `echo $KERNEL | grep -c "BOOT"` -gt 0 ]; then
-        echo ""
-        echo "Module build and install for $KERNEL was skipped as "
-        echo "it is a BOOT variant"
-        continue
-    fi
-
-
-    #if the module isn't yet built, try to build it
-    if [ `echo $dkms_status | grep -c ": built"` -eq 0 ]; then
-        if [ ! -L /var/lib/dkms/$NAME/$VERSION/source ]; then
-            echo "This package appears to be a binaries-only package"
-            echo " you will not be able to build against kernel $KERNEL"
-            echo " since the package source was not provided"
-            continue
-        fi
-        if _check_kernel_dir $KERNEL; then
-            echo "Building initial module for $KERNEL"
-            set +e
-            dkms build -m $NAME -v $VERSION -k $KERNEL $ARCH > /dev/null
-            case $? in
-            9)
-                set -e
-                echo "Skipped."
-                continue
-                ;;
-            0)
-                set -e
-                echo "Done."
-                ;;
-            *)
-                exit $?
-                ;;
-            esac
-            dkms_status=`dkms status -m $NAME -v $VERSION -k $KERNEL $ARCH`
-        else
-            echo "Module build for the currently running kernel was skipped since the"
-            echo "kernel source for this kernel does not seem to be installed."
-        fi
-    fi
-
-    #if the module is built (either pre-built or just now), install it
-    if [ `echo $dkms_status | grep -c ": built"` -eq 1 ] && 
-       [ `echo $dkms_status | grep -c ": installed"` -eq 0 ]; then
-        dkms install -m $NAME -v $VERSION -k $KERNEL $ARCH
-    fi
-done
-
diff --git a/debian/patches/dkms.diff b/debian/patches/dkms.diff
new file mode 100644 (file)
index 0000000..68e64bd
--- /dev/null
@@ -0,0 +1,314 @@
+Files required for setting up DKMS.
+--- /dev/null
++++ b/dkms.conf
+@@ -0,0 +1,12 @@
++PACKAGE_VERSION="7.1"
++
++# Items below here should not have to change with each driver version
++PACKAGE_NAME="sapphire-remote"
++MAKE[0]="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build modules"
++CLEAN="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"
++
++BUILT_MODULE_NAME[0]="sapphire"
++DEST_MODULE_LOCATION[0]="/extra/"
++
++AUTOINSTALL=yes
++REMAKE_INITRD=no
+--- /dev/null
++++ b/postinst
+@@ -0,0 +1,295 @@
++#!/bin/sh
++# Copyright (C) 2002-2005 Flavio Stanchina
++# Copyright (C) 2005-2006 Aric Cyr
++# Copyright (C) 2007 Mario Limonciello
++# Copyright (C) 2009 Alberto Milone
++
++set -e
++
++uname_s=$(uname -s)
++
++_get_kernel_dir() {
++    KVER=$1
++    case ${uname_s} in
++      Linux)          DIR="/lib/modules/$KVER/build" ;;
++      GNU/kFreeBSD)   DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
++    esac
++    echo $DIR
++}
++
++_check_kernel_dir() {
++    DIR=$(_get_kernel_dir $1)
++    case ${uname_s} in
++      Linux)          test -e $DIR/include ;;
++      GNU/kFreeBSD)   test -e $DIR/kern && test -e $DIR/conf/kmod.mk ;;
++      *)              return 1 ;;
++    esac
++    return $?
++}
++
++# Check the existence of a kernel named as $1
++_is_kernel_name_correct() {
++    CORRECT="no"
++    KERNEL_NAME=$1
++
++    for kernel in /boot/config-*; do
++        KERNEL=${kernel#*-}
++        if [ "${KERNEL}" = "${KERNEL_NAME}" ]; then
++            CORRECT="yes"
++            break
++        fi
++    done
++
++    echo $CORRECT
++}
++
++
++# Get the most recent kernel on Debian based systems. This keeps
++# into account both the version and the ABI. If the current kernel
++# is the most recent kernel then the function will print a null string.
++_get_newest_kernel_debian() {
++    NEWEST_KERNEL=
++    NEWEST_VERSION=
++    NEWEST_ABI=
++
++    for kernel in /boot/config-*; do
++        KERNEL=${kernel#*-}
++        KERNEL_VERSION=${KERNEL%%-*}
++        ABI=${KERNEL#*-}
++        ABI=${ABI%%-*}
++
++        if [ -z "$NEWEST_KERNEL" ]; then
++            # The 1st time get a version which is bigger than $1
++            COMPARE_TO=$1
++        else
++            # Get the biggest version
++            COMPARE_TO="$NEWEST_VERSION-$NEWEST_ABI"
++        fi
++
++        # if $kernel is greater than $COMPARE_TO
++        if [ `dpkg --compare-versions "$KERNEL_VERSION-$ABI" gt "$COMPARE_TO" && echo "yes" || \
++              echo "no"` = "yes" ]; then
++            NEWEST_KERNEL=$KERNEL
++            NEWEST_VERSION=$KERNEL_VERSION
++            NEWEST_ABI=$ABI
++        fi
++    done
++
++    echo "$NEWEST_KERNEL"
++}
++
++# Get the most recent kernel in Rhel based systems. If the current kernel
++# is the most recent kernel then the function will print a null string.
++_get_newest_kernel_rhel() {
++    NEWEST_KERNEL=
++
++    LAST_INSTALLED_KERNEL=$(rpm -q --whatprovides kernel  --last | grep kernel -m1 | cut -f1 -d' ')
++
++    LIK_FORMATTED_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{VERSION}-%{RELEASE}.%{ARCH}\n")
++
++    if [ `echo $LIK_FORMATTED_NAME | grep 2.6 >/dev/null` ]; then
++        # Fedora and Suse
++        NEWEST_KERNEL=$LIK_FORMATTED_NAME
++    else
++        # Hack for Mandriva where $LIK_FORMATTED_NAME is broken
++        LIK_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{NAME}\n")
++        LIK_TYPE=${LIK_NAME#kernel-}
++        LIK_TYPE=${LIK_TYPE%%-*}
++        LIK_STRIPPED=${LIK_NAME#kernel-}
++        LIK_STRIPPED=${LIK_STRIPPED#$LIK_TYPE-}
++        LIK_STRIPPED_BASE=${LIK_STRIPPED%%-*}
++        LIK_STRIPPED_END=${LIK_STRIPPED#$LIK_STRIPPED_BASE-}
++        LIK_FINAL=$LIK_STRIPPED_BASE-$LIK_TYPE-$LIK_STRIPPED_END
++
++        NEWEST_KERNEL=$LIK_FINAL
++    fi
++
++    echo $NEWEST_KERNEL
++}
++
++# Get the newest kernel on Debian and Rhel based systems.
++get_newest_kernel() {
++    NEWEST_KERNEL=
++    # Try Debian first as rpm can be installed in Debian based distros
++    if [ -e /usr/bin/dpkg ]; then
++        # If DEB based
++        CURRENT_KERNEL=$1
++        CURRENT_VERSION=${CURRENT_KERNEL%%-*}
++        CURRENT_ABI=${CURRENT_KERNEL#*-}
++        CURRENT_FLAVOUR=${CURRENT_ABI#*-}
++        CURRENT_ABI=${CURRENT_ABI%%-*}
++        NEWEST_KERNEL=$(_get_newest_kernel_debian "$CURRENT_VERSION-$CURRENT_ABI")
++
++    elif [ `which rpm >/dev/null` ]; then
++        # If RPM based
++        NEWEST_KERNEL=$(_get_newest_kernel_rhel)
++    fi
++
++    # Make sure that kernel name that we extracted corresponds to an installed
++    # kernel
++    if [ -n "$NEWEST_KERNEL" ] && [ `_is_kernel_name_correct $NEWEST_KERNEL` = "no" ]; then
++        NEWEST_KERNEL=
++    fi
++
++    echo $NEWEST_KERNEL
++}
++
++NAME=$1
++VERSION=$2
++TARBALL_ROOT=$3
++ARCH=$4
++UPGRADE=$5
++
++if [ -z "$NAME" ] || [ -z "$VERSION" ]; then
++    echo "Need NAME, and VERSION defined"
++    echo "ARCH is optional"
++    exit 1
++fi
++
++KERNELS=$(ls /lib/modules/ 2>/dev/null || true)
++CURRENT_KERNEL=$(uname -r)
++
++#We never want to keep an older version side by side to prevent conflicts
++if [ -e "/var/lib/dkms/$NAME/$VERSION" ]; then
++    echo "Removing old $NAME-$VERSION DKMS files..."
++    dkms remove -m $NAME -v $VERSION --all
++fi
++
++#Load new files, by source package and by tarball
++if [ -f "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz" ]; then
++    if ! dkms ldtarball --archive "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz"; then
++        echo ""
++        echo ""
++        echo "Unable to load DKMS tarball $TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz."
++        echo "Common causes include: "
++        echo " - You must be using DKMS 2.1.0.0 or later to support binaries only"
++        echo "   distribution specific archives."
++        echo " - Corrupt distribution specific archive"
++        echo ""
++        echo ""
++        exit 2
++    fi
++elif [ -d "/usr/src/$NAME-$VERSION" ]; then
++    echo "Loading new $NAME-$VERSION DKMS files..."
++    dkms add -m $NAME -v $VERSION > /dev/null
++fi
++
++# On 1st installation, let us look for a directory
++# in /lib/modules which matches `uname -r`. If none
++# is found it is possible that buildd is being used
++# and that uname -r is giving us the name of the
++# kernel used by the buildd machine.
++#
++# If this is the case we try to build the kernel
++# module for each kernel which has a directory in
++# /lib/modules. Furthermore we will have to tell
++# DKMS which architecture it should build the module
++# for (e.g. if the buildd machine is using a
++# 2.6.24-23-xen 64bit kernel).
++#
++# NOTE: if the headers are not installed then the
++#       module won't be built, as usual
++if [ -z "$UPGRADE" ]; then
++    echo "First Installation: checking all kernels..."
++    for KERNEL in $KERNELS; do
++        if [ ${KERNEL} = ${CURRENT_KERNEL} ]; then
++            # Kernel found
++            KERNELS=$CURRENT_KERNEL
++            break
++        fi
++    done
++else
++    KERNELS=$CURRENT_KERNEL
++fi
++
++# Here we look for the most recent kernel so that we can
++# build the module for it (in addition to doing it for the
++# current kernel.
++NEWEST_KERNEL=$(get_newest_kernel "$KERNELS")
++
++# If the current kernel doesn't come from the host of a chroot
++if [ `_is_kernel_name_correct $CURRENT_KERNEL` = "yes" ]; then
++    # See if it's worth building the module for both the newest kernel
++    # and for the current kernel
++    if [ -n "$NEWEST_KERNEL" ] && [ ${CURRENT_KERNEL} != ${NEWEST_KERNEL} ]; then
++        echo "Building for $CURRENT_KERNEL and $NEWEST_KERNEL"
++        KERNELS="$CURRENT_KERNEL $NEWEST_KERNEL"
++    else
++        echo "Building only for $CURRENT_KERNEL"
++    fi
++# The current kernel is not useful as it's the host's
++else
++    echo "It is likely that $CURRENT_KERNEL belongs to a chroot's host"
++
++    # Let's use only the newest kernel
++    if [ -n "$NEWEST_KERNEL" ]; then
++        KERNELS="$NEWEST_KERNEL"
++        echo "Building only for $NEWEST_KERNEL"
++    fi
++fi
++
++if [ -n "$ARCH" ]; then
++    if which lsb_release >/dev/null && [ $(lsb_release -s -i) = "Ubuntu" ]; then
++        case $ARCH in
++            amd64)
++                ARCH="x86_64"
++                ;;
++            lpia|i?86)
++                ARCH="i686"
++                ;;
++        esac
++    fi
++    echo "Building for architecture $ARCH"
++    ARCH="-a $ARCH"
++fi
++
++for KERNEL in $KERNELS; do
++    dkms_status=`dkms status -m $NAME -v $VERSION -k $KERNEL $ARCH`
++    if [ `echo $KERNEL | grep -c "BOOT"` -gt 0 ]; then
++        echo ""
++        echo "Module build and install for $KERNEL was skipped as "
++        echo "it is a BOOT variant"
++        continue
++    fi
++
++
++    #if the module isn't yet built, try to build it
++    if [ `echo $dkms_status | grep -c ": built"` -eq 0 ]; then
++        if [ ! -L /var/lib/dkms/$NAME/$VERSION/source ]; then
++            echo "This package appears to be a binaries-only package"
++            echo " you will not be able to build against kernel $KERNEL"
++            echo " since the package source was not provided"
++            continue
++        fi
++        if _check_kernel_dir $KERNEL; then
++            echo "Building initial module for $KERNEL"
++            set +e
++            dkms build -m $NAME -v $VERSION -k $KERNEL $ARCH > /dev/null
++            case $? in
++            9)
++                set -e
++                echo "Skipped."
++                continue
++                ;;
++            0)
++                set -e
++                echo "Done."
++                ;;
++            *)
++                exit $?
++                ;;
++            esac
++            dkms_status=`dkms status -m $NAME -v $VERSION -k $KERNEL $ARCH`
++        else
++            echo "Module build for the currently running kernel was skipped since the"
++            echo "kernel source for this kernel does not seem to be installed."
++        fi
++    fi
++
++    #if the module is built (either pre-built or just now), install it
++    if [ `echo $dkms_status | grep -c ": built"` -eq 1 ] &&
++       [ `echo $dkms_status | grep -c ": installed"` -eq 0 ]; then
++        dkms install -m $NAME -v $VERSION -k $KERNEL $ARCH
++    fi
++done
++
index 35e075acd10aa5c08562b0e133b09d562648fbc7..50d17015626ec3e1bb1bb8064e9320484270e211 100644 (file)
@@ -1,6 +1,6 @@
 Set the path that we're installing to.
---- a/sapphire-remote-7.1/sapphire_startup.sh
-+++ b/sapphire-remote-7.1/sapphire_startup.sh
+--- a/sapphire_startup.sh
++++ b/sapphire_startup.sh
 @@ -37,5 +37,5 @@
                fi
        fi
similarity index 89%
rename from debian/patches/remove_rmmod
rename to debian/patches/remove_rmmod.diff
index ea57f75902e27f242e3e6e891821b3fb7f35e00e..e61c572b53ded08c73e421f084641687d17422aa 100644 (file)
@@ -4,8 +4,8 @@ bound, then move them over to sapphire.
 I was running into a problem where after unloading hid_topseed,
 when I loaded sapphire the remote wasn't being registered
 with sapphire until I unplugged it and plugged it back it.
---- a/sapphire-remote-7.1/sapphire_startup.sh
-+++ b/sapphire-remote-7.1/sapphire_startup.sh
+--- a/sapphire_startup.sh
++++ b/sapphire_startup.sh
 @@ -8,8 +8,9 @@
  #
  TOPSEED=/sys/bus/hid/drivers/topseed
index 1963f0a2fbd6679ca26b5a7453b7fba330262e07..64c6d4cf3cff9bfd92a87045eac85579d742e443 100644 (file)
@@ -1,2 +1,3 @@
 paths.diff
-remove_rmmod
+remove_rmmod.diff
+dkms.diff
index 6502f244f342902bd8ad17325f6acc7b101fd477..3aed04daf1c6ab162f44f1389726850605fb4275 100755 (executable)
@@ -18,14 +18,12 @@ build: build-stamp
 
 build-stamp: configure-stamp 
        dh_testdir
-       $(MAKE)
        touch $@
 
 clean:
        dh_testdir
        dh_testroot
        rm -f build-stamp configure-stamp
-       -$(MAKE) clean
        dh_clean
 
 install: build
@@ -38,7 +36,6 @@ install: build
        dh_systemd_enable
        dh_installdocs
        dh_installchangelogs
-       $(MAKE) DESTDIR=$(CURDIR)/debian/$(DEB_NAME)-dkms NAME=$(NAME) VERSION=$(VERSION) install
 
 binary-arch: build install
 
diff --git a/debian/sapphire-remote-dkms.install b/debian/sapphire-remote-dkms.install
new file mode 100644 (file)
index 0000000..62562ab
--- /dev/null
@@ -0,0 +1,5 @@
+dkms.conf /usr/src/sapphire-remote-7.1
+Makefile /usr/src/sapphire-remote-7.1
+sapphire.c /usr/src/sapphire-remote-7.1
+sapphire.h /usr/src/sapphire-remote-7.1
+postinst /usr/share/sapphire-remote-dkms
index 5586e4fa17bd9b0cc6cec237b61b75ed09accae2..682db757c6780ec74869aeead5e0f13a7b000f1e 100644 (file)
@@ -1 +1 @@
-sapphire-remote-7.1/README.txt 
+README.txt 
index 2b88d2f887a9543c98b07cc6bf60f3fd4fef2162..47b168077925c3fe770abf4e13ac8782829142c1 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/dh-exec
-sapphire-remote-7.1/extract_keydefs.sh => /usr/lib/sapphire-remote/extract_keydefs.sh
-sapphire-remote-7.1/sapphire_keymap.sh.part1 => /usr/lib/sapphire-remote/sapphire_keymap.sh.part1
-sapphire-remote-7.1/sapphire_keymap.sh.part3 => /usr/lib/sapphire-remote/sapphire_keymap.sh.part3
-sapphire-remote-7.1/sapphire_startup.sh => /usr/lib/sapphire-remote/sapphire_startup.sh
-sapphire-remote-7.1/keymap.default => /etc/sapphire.keymap
+extract_keydefs.sh => /usr/lib/sapphire-remote/extract_keydefs.sh
+sapphire_keymap.sh.part1 => /usr/lib/sapphire-remote/sapphire_keymap.sh.part1
+sapphire_keymap.sh.part3 => /usr/lib/sapphire-remote/sapphire_keymap.sh.part3
+sapphire_startup.sh => /usr/lib/sapphire-remote/sapphire_startup.sh
+keymap.default => /etc/sapphire.keymap
 
diff --git a/sapphire-remote-7.1/Makefile b/sapphire-remote-7.1/Makefile
deleted file mode 100644 (file)
index 16d0e14..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-#
-# Makefile and (un-)Installer for Sapphire remote control driver,
-#    by Mark Lord 2012-2018.
-#
-MODNAME=sapphire
-MODSOURCE=$(MODNAME).c
-CONFLICTS=hid_topseed
-BLACKLIST=/etc/modprobe.d/blacklist-$(CONFLICTS).conf
-KEYMAP_SCRIPT=sapphire_keymap.sh
-EXTRACT_KEYDEFS=extract_keydefs.sh
-INPUT_H=$(shell [ -e /usr/include/linux/input-event-codes.h ] && echo /usr/include/linux/input-event-codes.h || echo /usr/include/linux/input.h)
-
-## MODPARMS is not used any more, but we have to nuke old copies to prevent issues:
-MODPARMS=/etc/modprobe.d/$(MODNAME).conf
-
-CWD    = $(shell pwd -P)
-KVER  ?= $(shell uname -r)
-KDIR  = /lib/modules/$(KVER)
-obj-m += $(MODNAME).o
-
-#EXTRA_CFLAGS += -Werror
-
-default: $(INPUT_H) kmod $(KEYMAP_SCRIPT)
-
-$(INPUT_H):
-       @echo "ERROR: $@: not found."
-       @echo
-       @echo "Please install the system development libraries first."
-       @echo "Eg. on Ubuntu/Mint systems:  sudo apt-get install build-essential"
-       @echo
-       @exit 1
-
-kmod:
-       $(MAKE) -C $(KDIR)/build M=$(CWD) modules
-
-$(MODNAME).ko: $(MODSOURCE) $(MODNAME).h
-       $(MAKE) kmod
-
-$(KEYMAP_SCRIPT): $(INPUT_H) $(EXTRACT_KEYDEFS) $(KEYMAP_SCRIPT).part1 $(KEYMAP_SCRIPT).part3 $(MODNAME).h $(INPUT_H)
-       @bash -c "type -all gawk" >/dev/null 2>&1 || (\
-               echo ;\
-               echo "gawk not found, needed by installer; Aborted." ;\
-               echo "For Ubuntu/Debian based systems, try this:  sudo apt-get install gawk" ;\
-               echo ;\
-               exit 2 ;\
-       )
-       chmod 0755 $(EXTRACT_KEYDEFS)
-       ./$(EXTRACT_KEYDEFS) $(INPUT_H) $(MODNAME).h | cat $(KEYMAP_SCRIPT).part1 - $(KEYMAP_SCRIPT).part3 > $(KEYMAP_SCRIPT)
-       chmod 0755 $(KEYMAP_SCRIPT)
-
-$(BLACKLIST):
-       @echo "Creating $(BLACKLIST)"
-       @echo "## $(CONFLICTS) Conflicts with $(MODNAME) driver" >  $(BLACKLIST)
-       @echo "blacklist $(CONFLICTS)"                           >> $(BLACKLIST)
-
-modinstall: $(MODNAME).ko $(KEYMAP_SCRIPT)
-       $(MAKE) -C $(KDIR)/build M=$(CWD) modules_install || exit 0
-       @[ -e $(KDIR)/extra/sapphire.ko -o -e $(KDIR)/extra/sapphire.ko.gz -o -e $(KDIR)/extra/sapphire.ko.xz ] || exit 1
-       depmod $(KVER)
-       @if [ "$(KVER)" = "$$(uname -r)" ]; then \
-               rmmod $(MODNAME)   2>/dev/null ;\
-               rmmod $(CONFLICTS) 2>/dev/null ;\
-               ./sapphire_startup.sh ;\
-       else \
-               exit 0 ;\
-       fi
-
-clean:
-       $(MAKE) -C $(KDIR)/build M=$(CWD) clean
-       -rm -f $(KEYMAP_SCRIPT)
-
-clean_modparms:
-       @if [ -e $(MODPARAMS) ]; then rm -f $(MODPARMS) ; fi ; exit 0
-
-uninstall: clean clean_modparms
-       -rmmod $(MODNAME)
-       -rm -f $(BLACKLIST)
-       -rm -f /usr/local/bin/$(KEYMAP_SCRIPT)
-       -rm -f $(KDIR)/extra/$(MODNAME).ko
-       depmod
-
-install: $(MODNAME).ko clean_modparms modinstall $(BLACKLIST) $(KEYMAP_SCRIPT)
-       install -m 0755 $(KEYMAP_SCRIPT) /usr/local/bin/
-       install -m 0755 sapphire_startup.sh /usr/local/bin/
-
-all: install
diff --git a/sapphire-remote-7.1/dkms.conf b/sapphire-remote-7.1/dkms.conf
deleted file mode 100644 (file)
index 1217b3e..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-PACKAGE_VERSION="7.1"
-
-# Items below here should not have to change with each driver version
-PACKAGE_NAME="sapphire-remote"
-MAKE[0]="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build modules"
-CLEAN="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"
-
-BUILT_MODULE_NAME[0]="sapphire"
-DEST_MODULE_LOCATION[0]="/extra/"
-
-AUTOINSTALL=yes
-REMAKE_INITRD=no
similarity index 100%
rename from sapphire-remote-7.1/sapphire.c
rename to sapphire.c
similarity index 100%
rename from sapphire-remote-7.1/sapphire.h
rename to sapphire.h