diff -Nru gnumeric-1.12.18/debian/changelog gnumeric-1.12.18/debian/changelog
--- gnumeric-1.12.18/debian/changelog	2015-03-19 06:03:42.000000000 +0100
+++ gnumeric-1.12.18/debian/changelog	2015-04-14 12:06:28.000000000 +0200
@@ -1,3 +1,11 @@
+gnumeric (1.12.18-2.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * Add some sanity checks to the preinst to prevent it from bailing out
+    too easily (Closes: #782137)
+
+ -- Raphael Geissert <raphael-externe.geissert@edf.fr>  Tue, 14 Apr 2015 10:39:49 +0200
+
 gnumeric (1.12.18-2) unstable; urgency=low
 
   * New "772075.patch" to fix undo crash (Closes: #772075).
diff -Nru gnumeric-1.12.18/debian/clean gnumeric-1.12.18/debian/clean
--- gnumeric-1.12.18/debian/clean	2013-06-03 16:31:47.000000000 +0200
+++ gnumeric-1.12.18/debian/clean	2015-04-14 12:11:34.000000000 +0200
@@ -1,4 +1,5 @@
 debian/gnome-gnumeric.xpm
+debian/gnumeric.preinst
 src/parser.c
 config.log
 po*/POTFILES
diff -Nru gnumeric-1.12.18/debian/gnumeric.preinst gnumeric-1.12.18/debian/gnumeric.preinst
--- gnumeric-1.12.18/debian/gnumeric.preinst	2010-07-31 11:22:13.000000000 +0200
+++ gnumeric-1.12.18/debian/gnumeric.preinst	1970-01-01 01:00:00.000000000 +0100
@@ -1,37 +0,0 @@
-#! /bin/sh
-set -e
-
-if ! test -e /usr/share/debconf/confmodule ; then
-	# Nothing we can do
-	exit 0
-fi
-
-if ! pgrep gnumeric 2>&1 >/dev/null ; then
-	# Nothing more to do
-	exit 0
-fi
-
-. /usr/share/debconf/confmodule
-
-db_version 2.0
-db_settitle gnumeric/existing-process-title
-
-# Ignore the fact that this question may have been answered on another
-# occasion already
-db_fset gnumeric/existing-process seen false
-
-# Try hard to get it answered
-db_input high gnumeric/existing-process || true
-db_go
-db_get gnumeric/existing-process
-if [ "$RET" = "false" ] ; then
-	# Abort installation of the package
-	db_stop
-	exit 1
-fi
-
-db_stop
-
-#DEBHELPER#
-
-exit 0
diff -Nru gnumeric-1.12.18/debian/gnumeric.preinst.in gnumeric-1.12.18/debian/gnumeric.preinst.in
--- gnumeric-1.12.18/debian/gnumeric.preinst.in	1970-01-01 01:00:00.000000000 +0100
+++ gnumeric-1.12.18/debian/gnumeric.preinst.in	2015-04-14 12:04:58.000000000 +0200
@@ -0,0 +1,82 @@
+#! /bin/sh
+set -e
+
+confirm_upgrade=true
+case "$1" in
+	install|upgrade)
+		if [ -z "$2" ]; then
+			# if not upgrading then it is all good
+			confirm_upgrade=false
+		else
+			old_upstream=${2:%-*}
+			if [ "$old_upstream" = "@UVER@" ]; then
+				confirm_upgrade=false
+			fi
+		fi
+	;;
+	*)
+		:
+	;;
+esac
+
+confirm_upgrade_if_running() {
+	local pid gnumeric_running=false
+
+	if ! test -e /usr/share/debconf/confmodule ; then
+		# Nothing we can do
+		return 0
+	fi
+
+	# Check: if there's a gnumeric process running
+	for pid in $(pidof gnumeric); do
+		local running_exe target_exe
+
+		# Check: if it is not some other random process (e.g.
+		# debug gnumeric builtby the user)
+		# N.b. when run from a chroot, this can't tell an
+		# instance running in the chroot and outside apart
+		if ! [ -L "/proc/$pid/exe" ]; then
+		    continue
+		fi
+
+		# This won't play very well with dpkg diversions
+		running_exe="$(readlink -f "/proc/$pid/exe" 2>&1)"
+		target_exe="$(readlink -f /usr/bin/gnumeric 2>&1)"
+		if [ "$running_exe" = "$target_exe" ]; then
+			gnumeric_running=true
+		fi
+	done
+
+	if ! $gnumeric_running; then
+		return 0
+	fi
+
+	. /usr/share/debconf/confmodule
+
+	db_version 2.0
+	db_settitle gnumeric/existing-process-title
+
+	# Ignore the fact that this question may have been answered on another
+	# occasion already
+	db_fset gnumeric/existing-process seen false
+
+	# Try hard to get it answered
+	db_input high gnumeric/existing-process || true
+	db_go
+	db_get gnumeric/existing-process
+	if [ "$RET" = "false" ] ; then
+		# Abort installation of the package
+		db_stop
+		exit 1
+	fi
+
+	db_stop
+}
+
+if $confirm_upgrade; then
+	confirm_upgrade_if_running
+fi
+
+#DEBHELPER#
+
+exit 0
diff -Nru gnumeric-1.12.18/debian/rules gnumeric-1.12.18/debian/rules
--- gnumeric-1.12.18/debian/rules	2015-03-19 06:00:57.000000000 +0100
+++ gnumeric-1.12.18/debian/rules	2015-04-14 12:11:39.000000000 +0200
@@ -117,6 +117,12 @@
             usr/share/xml/docbook/stylesheet/nwalsh/images  usr/share/gnumeric/$(UVER)/doc/C/images \
             usr/share/gnome/help/gnumeric  usr/share/gnumeric/$(UVER)/doc
 
+debian/gnumeric.preinst: debian/gnumeric.preinst.in
+	sed -r 's/@UVER@/$(UVER)/g' $< > $@
+
+override_dh_installdeb: debian/gnumeric.preinst
+	dh_installdeb
+
 override_dh_gencontrol:
 	dh_gencontrol -v -- -VUpstream-Version=$(UVER)
 
