[Pkg-bugzilla-commits] r64 - trunk/bugzilla-2.18/debian

Alexis Sukrieh sukria-guest@costa.debian.org
Fri, 22 Apr 2005 10:17:58 +0000


Author: sukria-guest
Date: 2005-04-22 10:17:58 +0000 (Fri, 22 Apr 2005)
New Revision: 64

Modified:
   trunk/bugzilla-2.18/debian/bugzilla.postinst
Log:
The postinst now comapres version, and do a better upgrade

Modified: trunk/bugzilla-2.18/debian/bugzilla.postinst
===================================================================
--- trunk/bugzilla-2.18/debian/bugzilla.postinst	2005-04-22 05:53:04 UTC (rev 63)
+++ trunk/bugzilla-2.18/debian/bugzilla.postinst	2005-04-22 10:17:58 UTC (rev 64)
@@ -18,18 +18,26 @@
 
 set -e
 
+debug()
+{
+	if [ $DEBIAN_BUGZILLA_DEBUG = 1 ]; then
+		echo "$1" >&2
+	fi
+}
+
 # Use the same order as for mv
 replace_file()
 {
 	file_source="$1"
 	file_dest="$2"
 
-	echo "replace_file $file_source $file_dest" >&2
 
 	if [ ! -f $file_dest ]; then
 		mv $file_source $file_dest || exit 10
+		debug "mv $file_source $file_dest"
 	else
 		cp $file_dest ${file_dest}.old
+		debug "ucf --debconf-ok $file_source $file_dest"
 		ucf --debconf-ok $file_source $file_dest || exit 11
 	fi
 	chown www-data:www-data $file_dest
@@ -37,32 +45,45 @@
 }
 
 if [ "$1" = "configure" ]; then
+	
+	params_218_dest="/usr/share/bugzilla/web/data/params"
+	params_218_src="/usr/share/bugzilla/debian/params"
+	params_218_new="/usr/share/bugzilla/web/data/params.new"
+	
+	# manage the upgrade before 2.18
+	# We aim here to upgrade the params file from oldest version.
+	if  [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.18; then
+		debug "Upgrading $2"	
+		params_216="/var/lib/bugzilla/data/params"
+		
+		# As we are upgrading from 2.16, we must not find
+		# a file in the 2.18 location
+		if [ ! -f $params_218_dest ]; then
+			mv $params_216 $params_218_dest
+		else
+			echo "Error in postinst: there is a file from a bugzilla 2.18 package ($params_218_dest)" >&2
+			echo "but you are upgrading from a lower version." >&2
+			exit 15
+		fi
+	fi
 
-	# First call the postinst-db helper
+	# Now we try to put our package's version of the params file
+	# We use ucf here if there is yet a file 
+	# Here, user should keep his 2.16 version if needed, the checksetup
+	# run will upgrade it to the new format.
+	replace_file $params_218_src $params_218_dest 
+
+	# Debconf is needed here for the postinst-db.pl script
+	. /usr/share/debconf/confmodule
+	
+	# We call the postinst-db.pl script to grab all the Debconf values
 	postinst_db="/usr/share/bugzilla/debian/postinst-db.pl"
 	if [ ! -f $postinst_db ]; then
 		exit 1
 	fi
 	chmod a+x $postinst_db
-
-	# Debconf is needed here
-	. /usr/share/debconf/confmodule
 	$postinst_db || exit 2
 
-	# Update of the "params" file
-	params_216="/var/lib/bugzilla/data/params"
-	params_218_src="/usr/share/bugzilla/debian/params"
-	params_218_dest="/usr/share/bugzilla/web/data/params"
-	params_218_new="/usr/share/bugzilla/web/data/params.new"
-	
-	# We move safely the params we ship with 2.18
-	replace_file $params_218_src $params_218_dest
-	
-	if [ -f $params_216 ]; then 
-		echo "2.16 params file found, asking for a merge..." >&2
-		replace_file $params_216 $params_218_dest || exit 3
-	fi
-
 	# The answer file has been generated by $postinst_db before
 	answerfile=/usr/share/bugzilla/debian/checksetup-answer.conf.pl
 	if [ ! -f $answerfile ]; then
@@ -71,7 +92,13 @@
 	fi
 	
 	# Call checksetup now that everything is ready
+	# The params file will then be updated if needed, the resulting file
+	# will be saved in $params_218_new
 	/usr/share/bugzilla/lib/checksetup.pl $answerfile > /tmp/bugzilla.checksetup.log || true
+	if [ ! -f $params_218_new ]; then
+		echo "Error in postinst: unable to find $params_218_new"
+		exit 13
+	fi
 	
 	# the answerfile should be removed now
 	rm -f $answerfile