From 67bc9dc2a5ca517a623735996b92f49c0d3a1cd6 Mon Sep 17 00:00:00 2001
From: Mario Fetka <mario@localhost.localdomain>
Date: Sat, 11 Nov 2017 03:29:22 +0100
Subject: [PATCH] add wrapper to trick 2.6 kernel

---
 debian/3dm2.wrapper32 |  4 ++++
 debian/3dm2.wrapper64 |  4 ++++
 debian/init           |  5 +++--
 debian/rules          | 10 +++++++---
 4 files changed, 18 insertions(+), 5 deletions(-)
 create mode 100644 debian/3dm2.wrapper32
 create mode 100644 debian/3dm2.wrapper64

diff --git a/debian/3dm2.wrapper32 b/debian/3dm2.wrapper32
new file mode 100644
index 0000000..31391f7
--- /dev/null
+++ b/debian/3dm2.wrapper32
@@ -0,0 +1,4 @@
+#!/bin/sh
+LD_LIBRARY_PATH=/usr/lib/3dm2:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH
+exec linux32 --uname-2.6 /usr/lib/3dm2/3dm2.real $@
\ No newline at end of file
diff --git a/debian/3dm2.wrapper64 b/debian/3dm2.wrapper64
new file mode 100644
index 0000000..ed60fa3
--- /dev/null
+++ b/debian/3dm2.wrapper64
@@ -0,0 +1,4 @@
+#!/bin/sh
+LD_LIBRARY_PATH=/usr/lib/3dm2:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH
+exec linux64 --uname-2.6 /usr/lib/3dm2/3dm2.real $@
\ No newline at end of file
diff --git a/debian/init b/debian/init
index 6ff15c8..8275b96 100644
--- a/debian/init
+++ b/debian/init
@@ -16,6 +16,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC="3ware 3DM2 RAID HBAs Management Utility"
 NAME=3dm2
 DAEMON=/usr/sbin/$NAME
+DAEMON_REAL=/usr/lib/$NAME/$NAME.real
 SCRIPTNAME=/etc/init.d/$NAME
 LOCKFILE=/var/lock/subsys/3dm2
 
@@ -54,7 +55,7 @@ do_stop()
 	#   1 if daemon was already stopped
 	#   2 if daemon could not be stopped
 	#   other if a failure occurred
-	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --exec $DAEMON
+	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --exec $DAEMON_REAL
 	RETVAL="$?"
 	[ "$RETVAL" = 2 ] && return 2
 	# Wait for children to finish too if this is a daemon that forks
@@ -63,7 +64,7 @@ do_stop()
 	# that waits for the process to drop all resources that could be
 	# needed by services started subsequently.  A last resort is to
 	# sleep for some time.
-	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON_REAL
 	[ "$?" = 2 ] && return 2
 	rm -f $LOCKFILE
 	return "$RETVAL"
diff --git a/debian/rules b/debian/rules
index edd6ae1..e921c6f 100755
--- a/debian/rules
+++ b/debian/rules
@@ -22,14 +22,18 @@ install: build
 	dh_installdirs
 	# Install data
 ifeq ($(DEB_BUILD_ARCH),amd64)
-	install -m 755 $(CURDIR)/amd64/3dm2.x86_64 \
-	               $(DESTDIR)/usr/sbin/3dm2
+	install -D -m 0755 $(CURDIR)/debian/3dm2.wrapper64 \
+		       $(DESTDIR)/usr/sbin/3dm2
+	install -D -m 0755 $(CURDIR)/amd64/3dm2.x86_64 \
+	               $(DESTDIR)/usr/lib/3dm2/3dm2.real
 	install -m 600 $(CURDIR)/amd64/3dm2.conf \
 		       $(DESTDIR)/etc/3dm2/3dm2.conf
 endif
 ifeq ($(DEB_BUILD_ARCH),i386)
-	install -m 755 $(CURDIR)/i386/3dm2.x86 \
+	install -D -m 0755 $(CURDIR)/debian/3dm2.wrapper32 \
 	               $(DESTDIR)/usr/sbin/3dm2
+	install -D -m 0755 $(CURDIR)/i386/3dm2.x86 \
+		       $(DESTDIR)/usr/lib/3dm2/3dm2.real
 	install -m 600 $(CURDIR)/i386/3dm2.conf \
 		       $(DESTDIR)/etc/3dm2/3dm2.conf
 endif