[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Need advice wrt #295306 (Was: debian/uw-imapd-ssl.postinst clobbers existing imaps line params)



* Pierre Habouzit [Fri, 25 Feb 2005 14:50:54 +0100]:
>   - : this is really not trivial : inetd.conf is sorted by categories,
>       and it will be really difficult to put the entries at the right
>       place in the postinst

  In fact, is not very difficult, since you just feed update-inetd the
  appropriate --group option, and the original line as it was in the
  inetd.conf file.

  See the attached patch. It's untested, and probably not the best one,
  but perhaps gives you some ideas for the final version.

>   - : this fix will use quite a big amount of code, touch to many
>       scripts, and thereof may lead to new bugs, really more easily than
>       the previous "solution"

  Indeed. :/

-- 
Adeodato Simó
    EM: asp16 [ykwim] alu.ua.es | PK: DA6AE621
    Listening to: Cristina Lliso - Tú cambias de canal
 
Don't worry about what anybody else is going to do. The best way to
predict the future is to invent it.
                -- Alan Kay
diff -u -rN uw.orig/preinst uw/preinst
--- uw.orig/preinst	1970-01-01 01:00:00.000000000 +0100
+++ uw/preinst	2005-02-25 16:04:36.457498298 +0100
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+
+PROGRAM=uw-imapd
+# PROGRAM=ipopd
+
+MY_FILE=/var/cache/${PROGRAM}_inetd.conf_copy
+
+if [ "$1" = "upgrade" ] && dpkg --compare-versions "$2" le 7:2002edebian1-6
+then
+    # See Bug#295306: the postrm that will be called after unpacking
+    # will remove entries from /etc/inetd.conf, so we save them for
+    # restoring them in the postinst.
+    
+    . /usr/share/debconf/confmodule
+    db_version 2.0
+
+    db_get uw-imapd/protocol
+    for i in `echo "$RET" | sed 's/,/ /g'`; do
+	case "$i" in
+	    imap2|imap3|imaps)
+		grep -E "^([# ]+|#<off># +)?${i}" /etc/inetd.conf >>"$MY_FILE"
+		;;
+	esac
+    done
+fi
diff -u -rN uw.orig/postrm uw/postrm
--- uw.orig/postrm	2005-02-04 01:30:37.000000000 +0100
+++ uw/postrm	2005-02-25 16:08:31.455391951 +0100
@@ -10,15 +10,20 @@
 ## Remove imapd from inetd.conf
 ##
 
+if [ "$1" = "purge" ]; then
+    UPDATE_INETD_ARG='--remove'
+else
+    # Note that we disable in upgrades too
+    UPDATE_INETD_ARG='--disable'
+fi
+
 db_get uw-imapd/protocol
 for i in `echo "$RET" | sed 's/,/ /g'`; do
-	if [ "$i" = "imap2" ]; then
-		update-inetd --remove imap2;
-	elif [ "$i" = "imap3" ]; then
-		update-inetd --remove imap3;
-	elif [ "$i" = "imaps" ]; then
-		update-inetd --remove imaps;
-	fi
+    case "$i" in
+	imap2|imap3|imaps)
+	    update-inetd $UPDATE_INETD_ARG $i
+	    ;;
+    esac
 done
 
 if [ "$1" = "purge" -a -f /etc/ssl/certs/imapd.pem ]; then
diff -u -rN uw.orig/postinst uw/postinst
--- uw.orig/postinst	2005-02-04 01:30:37.000000000 +0100
+++ uw/postinst	2005-02-25 16:06:59.793425663 +0100
@@ -2,20 +2,46 @@
 
 set -e
 
+PROGRAM=uw-imapd
+# PROGRAM=ipopd
+
 # Source debconf library.
 . /usr/share/debconf/confmodule
 db_version 2.0
 
-db_get uw-imapd/protocol
-for i in `echo "$RET" | sed 's/,/ /g'`; do
-	if [ "$i" = "imap2" ]; then
-		update-inetd --group mail --add "imap2	stream	tcp	nowait	root	/usr/sbin/tcpd /usr/sbin/imapd";
-	elif [ "$i" = "imap3" ]; then
-		update-inetd --group mail --add "imap3	stream	tcp	nowait	root	/usr/sbin/tcpd /usr/sbin/imapd";
-	elif [ "$i" = "imaps" ]; then
-		update-inetd --group mail --add "imaps	stream	tcp	nowait	root	/usr/sbin/tcpd /usr/sbin/imapd";
+if [ "$1" = "configure" ]; then
+    if [ -z "$2" ]; then
+	UPDATE_INETD_ARG='--group mail --add'
+	UPDATE_INETD_ARG_EXTRA="	stream	tcp	nowait	root	/usr/sbin/tcpd /usr/sbin/imapd"
+    else
+	UPDATE_INETD_ARG='--enable'
+
+	# Bug#295306
+	if dpkg --compare-versions "$2" le 7:2002edebian1-6
+	then
+	    MY_FILE=/var/cache/${PROGRAM}_inetd.conf_copy
+	    if [ -r "$MY_FILE" ]; then
+		while read line; do
+		    update-inetd --group mail --add "$line"
+		done <"$MY_FILE"
+	    else
+		# The file has disappeared, or we're installing from
+		# 'config files' state. Install default entries.
+		UPDATE_INETD_ARG='--group mail --add'
+		UPDATE_INETD_ARG_EXTRA="	stream	tcp	nowait	root	/usr/sbin/tcpd /usr/sbin/imapd"
+	    fi
 	fi
-done
+    fi
+
+    db_get uw-imapd/protocol
+    for i in `echo "$RET" | sed 's/,/ /g'`; do
+	case "$i" in
+	    imap2|imap3|imaps)
+		update-inetd $UPDATE_INETD_ARG "${i}${UPDATE_INETD_ARG_EXTRA}"
+		;;
+	esac
+    done
+fi
 
 cd /etc/ssl/certs
 PATH=$PATH:/usr/bin/ssl

Reply to: