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

Alexis Sukrieh sukria-guest@costa.debian.org
Wed, 20 Apr 2005 15:35:51 +0000


Author: sukria-guest
Date: 2005-04-20 15:35:51 +0000 (Wed, 20 Apr 2005)
New Revision: 55

Removed:
   trunk/bugzilla-2.18/debian/bugzilla.preinst
Modified:
   trunk/bugzilla-2.18/debian/bugzilla.postinst
Log:
first step towards a better handling of params file

Modified: trunk/bugzilla-2.18/debian/bugzilla.postinst
===================================================================
--- trunk/bugzilla-2.18/debian/bugzilla.postinst	2005-04-20 12:46:55 UTC (rev 54)
+++ trunk/bugzilla-2.18/debian/bugzilla.postinst	2005-04-20 15:35:51 UTC (rev 55)
@@ -25,6 +25,7 @@
 sub random_string($);
 sub update_debconf_keys();
 sub escape_dbname();
+sub replace_file($$);
 
 # Default MySQL vars
 my $BUGZILLA_DBNAME = 'bugzilla';
@@ -230,19 +231,35 @@
 debug "This is the time to update the localconfig file.";
 alter_localconfig();
 
+##############################################################
+# Update of the "params" file
+##############################################################
 
-# Maybe, there was yet a "params" file, it has been 
-# saved by preinst before, so restore it for the
-# user's happyness ;)
-if ( -f '/tmp/bugzilla.params') {
-	print STDERR "Restoring previous params\n";
-	`rm -f /usr/share/bugzilla/web/data/params`;
-	`cp /tmp/bugzilla.params /usr/share/bugzilla/web/data/params`;
-	unlink '/tmp/bugzilla.params';
-	`chown www-data:www-data /usr/share/bugzilla/web/data/params`;
+# We have to stop debconf
+stop();
+
+my $params_216 = "/var/lib/bugzilla/data/params";
+my $params_218 = "/etc/bugzilla/params";
+
+# If we find the 2.16 params file, we replace the one we 
+# ship with it.
+if (-f $params_216) {
+	debug "2.16 params file found: $params_216, trying to move it on $params_218";
+	unless (replace_file($params_216, $params_218)) {
+		debug "Unable to replace $params_218";
+		exit 1;
+	}
 }
 
-# Now running checksetup.pl for updating database and params.
+# Here, we are sure $params_218 is the params file of the user:
+#  - it may be an existing file from a previous 2.18 package 
+#    (but as a conffile, user is already aware of its changes)
+#  - it may be a 2.16 params file, coming from the step before.
+
+# Then, we have to run checksetup.pl, wich will upgrade 
+# the params file and store it in ${params_218}.new
+# (See debian/patches/101_Config.diff
+
 my $file = create_answer_file();
 debug "Calling checksetup with the answer file $file...";
 print STDERR "Please wait, running checksetup.pl...\n";
@@ -253,6 +270,15 @@
 debug "deleting $file";
 unlink $file;
 
+# At this time, checksetup.pl has run and should have make a new
+# params file, named $params_218.new
+if (-f "${params_218}.new") {
+	# We use our safe way to replace the new file:
+	replace_file($params_218, "${params_218}.new");
+}
+else {
+	error "No ${params_218}.new file found! checksetup.pl error...";
+}
 
 my $temp="set -e\nset -- @ARGV\n" . << 'EOF';
 
@@ -542,4 +568,26 @@
         return (join ("", @chars[map {rand scalar @chars} (1 .. $length)]));
 }
 
+# This sill safely move file_source to file_dest,
+# using ucf id neeeded.
+sub replace_file($$)
+{
+	my $file_source = shift;
+	my $file_dest = shift;
+	return 0 unless defined $file_source
+		and defined $file_dest;
+	
+	if (! -f $file_dest) {
+		debug "$file_dest does not exist, I can safely move $file_source here.";
+		system("mv $file_source $file_dest");
+	}
+	else {
+		debug "$file_dest exists, calling ucf for safe replace.";
+		system("ucf --debconf-ok $file_source $file_dest");
+	}
+	# Fixing permissions	
+	system("chown www-data:www-data $file_dest");
+	return -f $file_dest;
+}
+
 #DEBHELPER#

Deleted: trunk/bugzilla-2.18/debian/bugzilla.preinst
===================================================================
--- trunk/bugzilla-2.18/debian/bugzilla.preinst	2005-04-20 12:46:55 UTC (rev 54)
+++ trunk/bugzilla-2.18/debian/bugzilla.preinst	2005-04-20 15:35:51 UTC (rev 55)
@@ -1,26 +0,0 @@
-#!/bin/sh
-
-set -e 
-
-# Previous version of the package installed a symlink
-# that has to be removed.
-if [ -L /usr/share/bugzilla/web/index.html ]; then
-	rm -f /var/www/bugzilla/index.html
-fi
-
-# Save the previous "params" file. from a <= 2.16 version
-param_file="/var/lib/bugzilla/data/params"
-if [ -e $param_file ]; then
-	echo "$param_file" > /tmp/debug.log
-	cp $param_file /tmp/bugzilla.params
-	exit 0
-fi
-
-# from a >= 2.18 version
-param_file="/usr/share/bugzilla/web/data/params"
-if [ -e $param_file ]; then
-	echo "$param_file" > /tmp/debug.log
-	cp $param_file /tmp/bugzilla.params
-fi
-
-#DEBHELPER#