I tested using debian/maintscript, and it did not work because
jwchat.conf was missing in the package.  But I came up with another
version using code in preinst and postinst to move the old file to
jwchat.dpkg-backup in the preinst if it exist, and move it from
jwchat.dpkg-backup to jwchat.conf in the postinst if the file exist,
before calling ucf.  This seem to solve it.

I've attached the adjusted patch.
-- 
Happy hacking
Petter Reinholdtsen
diff -Nru jwchat-1.0+dfsg/debian/postinst jwchat-1.0+dfsg/debian/postinst
--- jwchat-1.0+dfsg/debian/postinst     2010-09-17 20:11:48.000000000 +0200
+++ jwchat-1.0+dfsg/debian/postinst     2013-09-16 20:25:04.000000000 +0200
@@ -7,7 +7,8 @@
 
 configfile='/etc/jwchat/config.js'
 configsource='/usr/share/jwchat/config.js'
-apachefile='/etc/apache2/sites-available/jwchat'
+oldapachefile='/etc/apache2/sites-available/jwchat'
+apachefile='/etc/apache2/sites-available/jwchat.conf'
 apachesource='/usr/share/jwchat/apache.conf'
 wwwdir='/usr/share/jwchat/www'
 tempfile=$(mktemp)
@@ -24,6 +25,15 @@
 
 setup_apache()
 {
+        case "$1" in
+            configure)
+                if dpkg --compare-versions "$2" le "1.0+dfsg-1.1"; then
+                    if [ -e $oldapachefile.dpkg-backup ] && [ ! -e $apachefile 
] ; then
+                        mv  $oldapachefile.dpkg-backup $apachefile
+                    fi
+                fi
+        esac
+
        db_get jwchat/ApacheServerName
        apache_server_name="$RET"
        sed -e "s|__ApacheServerName__|$apache_server_name|g" $configsource > \
@@ -38,20 +48,21 @@
                    $apachesource > $tempfile
                ucf --three-way --debconf-ok $tempfile $apachefile
                db_stop
-               a2enmod proxy
-               a2enmod proxy_http
-               a2ensite jwchat
-               invoke-rc.d apache2 force-reload
+               if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+                       . /usr/share/apache2/apache2-maintscript-helper
+                       apache2_invoke enmod proxy
+                       apache2_invoke enmod proxy_http
+                       apache2_invoke ensite jwchat
+               fi
        fi
 }
 
+
 case $1 in
        configure|reconfigure)
-
        fixperms
-       setup_apache
+       setup_apache $@
        rm -f $tempfile
-       exit 0
        ;;
 
        *)
@@ -61,4 +72,3 @@
 esac
 
 #DEBHELPER#
-
diff -Nru jwchat-1.0+dfsg/debian/postrm jwchat-1.0+dfsg/debian/postrm
--- jwchat-1.0+dfsg/debian/postrm       2010-09-17 20:11:48.000000000 +0200
+++ jwchat-1.0+dfsg/debian/postrm       2013-09-16 18:38:18.000000000 +0200
@@ -6,14 +6,14 @@
 set -e
 
 configfile='/etc/jwchat/config.js'
-apachefile='/etc/apache2/sites-available/jwchat'
+apachefile='/etc/apache2/sites-available/jwchat.conf'
 
 case "$1" in
        remove)
 
-       if [ -x /usr/sbin/a2dissite -a -x /etc/init.d/apache2 -a -L 
/etc/apache2/sites-enabled/jwchat ]; then
-               a2dissite jwchat
-               invoke-rc.d apache2 force-reload
+       if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+               . /usr/share/apache2/apache2-maintscript-helper
+               apache2_invoke dissite jwchat
        fi
        ;;
 
diff -Nru jwchat-1.0+dfsg/debian/preinst jwchat-1.0+dfsg/debian/preinst
--- jwchat-1.0+dfsg/debian/preinst      1970-01-01 01:00:00.000000000 +0100
+++ jwchat-1.0+dfsg/debian/preinst      2013-09-16 20:18:49.000000000 +0200
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+set -e
+
+oldapachefile='/etc/apache2/sites-available/jwchat'
+
+case "$1" in
+    install|upgrade)
+       if dpkg --compare-versions "$2" le "1.0+dfsg-1.1"; then
+           if [ -e $oldapachefile ] ; then
+               mv $oldapachefile $oldapachefile.dpkg-backup
+           fi
+       fi
+esac
+
+#DEBHELPER#

Reply via email to