Frank Küster <[EMAIL PROTECTED]> wrote:

> tags 397383 patch
> thanks
>
> Julien Danjou <[EMAIL PROTECTED]> wrote:
>
>> Package: webalizer
>> Version: 2.01.10-30.1
>> Severity: serious
>>
>> Hi,
>>
>> It seems that you're doing things in .config file that should be in
>> postinst:
>
> Here's a patch:

Sorry, that was too simple.  I assumed the old code already did the
debconf handling somehow sane, but instead it just did nothing when it
was reconfigured.  

Consequently the complete handling of the debconf-managed conffile
according to debconf-devel(7) had to be written from scratch, in order
to avoid unconditionally overwriting local changes.  Here's an updated
patch.

Regards, Frank

diff -Nur webalizer-2.01.10.old/debian/changelog webalizer-2.01.10/debian/changelog
--- webalizer-2.01.10.old/debian/changelog	2006-11-07 11:10:41.000000000 +0100
+++ webalizer-2.01.10/debian/changelog	2006-11-07 13:23:54.000000000 +0100
@@ -1,3 +1,15 @@
+webalizer (2.01.10-30.2~2) unstable; urgency=low
+
+  * Move actual configuration of the package to the postinst script.  The
+    config script now only contains the questions (closes: #397383).
+    Thanks to Julien Danjou <[EMAIL PROTECTED]>.
+  * Parse the configuration file in the config script, if it exists, and
+    register the information in the debconf database.  This way, the
+    postinst will respect local changes, and dpkg-reconfigure can actually
+    be used (which wasn't possible in the old setup).
+
+ -- Frank Küster <[EMAIL PROTECTED]>  Tue,  7 Nov 2006 13:10:45 +0100
+
 webalizer (2.01.10-30.1) unstable; urgency=medium
 
   * Non-maintainer upload for RC bug.
diff -Nur webalizer-2.01.10.old/debian/config webalizer-2.01.10/debian/config
--- webalizer-2.01.10.old/debian/config	2006-11-07 11:10:41.000000000 +0100
+++ webalizer-2.01.10/debian/config	2006-11-07 13:21:45.000000000 +0100
@@ -10,7 +10,7 @@
 db_version 2.0
 
 case "$1" in
-    configure)
+    configure|reconfigure)
       if [ "$2" ] && dpkg --compare-versions $2 lt 2.01.6-1; then
         db_input high webalizer/upgrading || true
         db_go
@@ -23,65 +23,51 @@
 
       if [ -f "/etc/webalizer.conf" ] && [ ! -f "/etc/webalizer/webalizer.conf" ]; then
         mv /etc/webalizer.conf /etc/webalizer/webalizer.conf;
-        exit 0;  # already configured
       fi
-      [ ! -f "/etc/webalizer/webalizer.conf" ] || exit 0;
-      
-      # Now determine the system's hostname and domainname
-      HOSTNAME=$(/bin/hostname);
+      conffile="/etc/webalizer/webalizer.conf"
+      OUTPUTDIR=""
+      REPORTTITLE=""
+      LOGFILE=""
+      if [ -f $conffile ]; then
+	# parse existing configuration.  This code happily
+	# concatenates multiple occurences of a configuration item,
+	# but that should never occur <[EMAIL PROTECTED]>.
+	OUTPUTDIR=`sed -ne '/^OutputDir/ [EMAIL PROTECTED]:space:]]\([^[:space:]]*\)@\1@;p}' $conffile`
+	REPORTTITLE=`sed -ne '/^ReportTitle/ [EMAIL PROTECTED]:space:]]\([^[:space:]]*\)@\1@;p}' $conffile`
+	LOGFILE=`sed -ne '/^LogFile/ [EMAIL PROTECTED]:space:]]\([^[:space:]]*\)@\1@;p}' $conffile`
+	
+      fi
+      # assign default values
+      [ -n "$OUTPUTDIR" ] || OUTPUTDIR="/var/www/webalizer"
+      [ -n "$REPORTTITLE" ] || REPORTTITLE="Usage statistics for"
+      if [ -z "$LOGFILE" ]; then
+        # apache2 found?
+	if [ -f /var/log/apache2/access.log.1 ] || [ -f /var/log/apache2/access.log ]; then
+          LOGFILE="/var/log/apache2/access.log.1";
+	else
+          LOGFILE="/var/log/apache/access.log.1";
+	fi
+      fi
       
+      # now preseed the debconf questions with what we found
+      db_set webalizer/directory "$OUTPUTDIR" || true
+      db_set webalizer/doc_title "$REPORTTITLE" || true
+      db_set webalizer/logfile "$LOGFILE" || true
+  
+    
       # Ask for the directory the output should be put in
       db_input medium webalizer/directory || true
       db_go
-      db_get webalizer/directory
-      OUTPUTDIR="$RET";
-      [ ! -z $OUTPUTDIR ] || OUTPUTDIR="/var/www/webalizer";
-      
-      if [ ! -d $OUTPUTDIR ]; then
-        mkdir -p $OUTPUTDIR;
-        if [ $? -eq 0 ]; then
-          echo "$OUTPUTDIR created";
-        else
-          echo "Something went wrong...";
-          exit 1;
-        fi;
-      fi
       
       # At this point, ask the user what the title of webalizer's reports should be
       db_input medium webalizer/doc_title || true
       db_go
-      db_get webalizer/doc_title
-      REPORTTITLE="$RET";
-      [ ! -z "$REPORTTITLE" ] || REPORTTITLE="Usage statistics for";
 
       # Ask for the rotated logfile
       # by default  is access log file of apache, but if I found apache2 log file,
       # I changed default to this one.
-      
-      # apache2 found
-      if [ -f /var/log/apache2/access.log.1 ] || [ -f /var/log/apache2/access.log ]; then
-        LOGFILE="/var/log/apache2/access.log.1";
-      else
-        LOGFILE="/var/log/apache/access.log.1";
-      fi
-      
-      db_set "webalizer/logfile" $LOGFILE || true
       db_input medium webalizer/logfile || true
       db_go
-      db_get webalizer/logfile
-      [ ! -z "$RET" ] || LOGFILE="$RET";
-      
-      # Finally put these variables in /etc/webalizer/webalizer.conf using sed
-      cat /usr/share/doc/webalizer/examples/sample.conf.gz | gunzip | /bin/sed \
-	-e "s/^#HostName .*/HostName ${HOSTNAME}/" \
-	-e "s|^#OutputDir .*|OutputDir ${OUTPUTDIR}|" \
-	-e "s/^#ReportTitle .*/ReportTitle ${REPORTTITLE}/" \
-	-e "s|^#LogFile .*|LogFile ${LOGFILE}|" \
-	> /etc/webalizer/webalizer.conf;
-    ;;
-
-    reconfigure)
-        exit 1;
     ;;
 
     *)
diff -Nur webalizer-2.01.10.old/debian/postinst webalizer-2.01.10/debian/postinst
--- webalizer-2.01.10.old/debian/postinst	2006-11-07 11:10:41.000000000 +0100
+++ webalizer-2.01.10/debian/postinst	2006-11-07 13:23:00.000000000 +0100
@@ -23,6 +23,49 @@
 
 case "$1" in
     configure)
+      db_get webalizer/directory || true
+      OUTPUTDIR="$RET"
+      if [ -z "$OUTPUTDIR" ]; then
+	echo "Fatal: No ouptut dir given, not creating webalizer configuration" >&2
+        exit 1;
+      else
+	if [ ! -d $OUTPUTDIR ]; then
+          if mkdir -p $OUTPUTDIR; then
+            echo "$OUTPUTDIR created" >&2
+          else
+            echo "Something went wrong..." >&2
+            exit 1;
+          fi;
+	fi
+      fi
+
+      db_get webalizer/doc_title || true
+      REPORTTITLE="$RET";
+
+      db_get webalizer/logfile || true
+      LOGFILE="$RET";
+
+      # creae conffile if it doesn't exist yet
+      conffile="/etc/webalizer/webalizer.conf"
+      template_gz=/usr/share/doc/webalizer/examples/sample.conf.gz
+      if [ ! -f $conffile ]; then
+	zcat $template_gz > $conffile
+	HOSTNAME=$(hostname)
+	# uncomment the debconf-handled items
+	sed -i \
+	  -e "s/^#HostName .*/HostName ${HOSTNAME}/" \
+	  -e "s/^#OutputDir /OutputDir /" \
+	  -e "s/^#ReportTitle /ReportTitle/" \
+	  -e "s/^#LogFile /LogFile /" \
+	  $conffile
+      fi
+      
+      # Finally put these variables in /etc/webalizer/webalizer.conf using sed
+      sed -i \
+	-e "s|^OutputDir .*|OutputDir ${OUTPUTDIR}|" \
+	-e "s/^ReportTitle .*/ReportTitle ${REPORTTITLE}/" \
+	-e "s|^LogFile .*|LogFile ${LOGFILE}|" \
+	$conffile
 
     ;;
 


-- 
Dr. Frank Küster
Single Molecule Spectroscopy, Protein Folding @ Inst. f. Biochemie, Univ. Zürich
Debian Developer (teTeX/TeXLive)

Reply via email to