Browse Source

Add debconf to assist configuration migration

Christoph Biedl 12 years ago
parent
commit
13ab2a2aa4
7 changed files with 201 additions and 13 deletions
  1. 2 0
      debian/control
  2. 96 0
      debian/ngircd.config
  3. 6 7
      debian/ngircd.postinst
  4. 8 6
      debian/ngircd.postrm
  5. 23 0
      debian/ngircd.templates
  6. 1 0
      debian/po/POTFILES.in
  7. 65 0
      debian/po/templates.pot

+ 2 - 0
debian/control

@@ -8,6 +8,7 @@ Build-Depends: debhelper (>= 7.0.50~),
     autotools-dev,
     expect,
     libgnutls-dev,
+    po-debconf,
     procps,
     telnet,
 Vcs-Svn: svn://svn.debian.org/pkg-irc/
@@ -17,6 +18,7 @@ Standards-Version: 3.9.2
 Package: ngircd
 Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends},
+    debconf,
     lsb-base (>= 3.0-6),
 Replaces: ircd
 Conflicts: dancer-ircd, ircd-hybrid, ircd-irc2, ircd-ircu, rageircd

+ 96 - 0
debian/ngircd.config

@@ -0,0 +1,96 @@
+#!/bin/sh
+
+set -e
+
+# Source debconf library.
+. /usr/share/debconf/confmodule
+
+NGIRCD=/usr/sbin/ngircd
+CONFIG=/etc/ngircd/ngircd.conf
+CONVERT=/usr/share/ngircd/ngircd-conf-convert
+
+[ -x "$NGIRCD" ] || exit 0
+[ -f "$CONFIG" ] || exit 0
+[ -x "$CONVERT" ] || exit 0
+
+TEMPDIR=
+
+# conversion required?
+if grep -qiE '^[ \t]*\[(Limits|Options|SSL)\]' "$CONFIG" ; then
+    # Using new section names, we're done
+    exit 0
+fi
+
+while true ; do
+    # Shall we do conversion?
+    db_reset ngircd/conversion-do
+    db_input high ngircd/conversion-do || true
+    db_go
+    db_get ngircd/conversion-do
+    if [ "$RET" = "false" ]; then
+	break
+    fi
+
+    # Check old configuration
+    if </dev/null "$NGIRCD" --configtest --config "$CONFIG" >/dev/null ; then
+	:
+    else
+	# broken
+	db_input high ngircd/broken-oldconfig || true
+	db_go
+	break
+    fi
+
+    # have a temporary directory
+    TEMPDIR=$(mktemp -d /tmp/ngircd.XXXXX)
+    [ "$TEMPDIR" ] && [ -d "$TEMPDIR" ] || exit 0
+    chmod 700 "$TEMPDIR"
+
+    # create new configuration
+    CONFIG_NEW="$TEMPDIR/ngircd.conf"
+    touch "$CONFIG_NEW"
+    "$CONVERT" "$CONFIG" "$CONFIG_NEW"
+    if cmp -s "$CONFIG" "$CONFIG_NEW" ; then
+	echo "Nothing to do."
+	break
+    fi
+
+    # create dumps from --configtest and compare
+    DUMP_OLD="$TEMPDIR/dump.old"
+    </dev/null "$NGIRCD" --configtest --config "$CONFIG" |
+    sed -n '/GLOBAL/,$p' >"$DUMP_OLD"
+    DUMP_NEW="$TEMPDIR/dump.new"
+    </dev/null "$NGIRCD" --configtest --config "$CONFIG_NEW" |
+    sed -n '/GLOBAL/,$p' >"$DUMP_NEW"
+
+    if cmp -s "$DUMP_OLD" "$DUMP_NEW" ; then
+	# success
+	CONFIG_BAK="$CONFIG.pre18"
+	chown --reference="$CONFIG" "$CONFIG_NEW"
+	chmod --reference="$CONFIG" "$CONFIG_NEW"
+	mv "$CONFIG" "$CONFIG_BAK"
+	mv "$CONFIG_NEW" "$CONFIG"
+
+	echo "Conversion and verification sucessfull. Your configuration file is at"
+	echo "    $CONFIG"
+	echo "A backup of the old configuration has been saved to"
+	echo "    $CONFIG_BAK"
+	break
+    fi
+
+    DIFF="$(sdiff -BbW "$DUMP_OLD" "$DUMP_NEW")"
+    db_capb escape
+    db_subst ngircd/conversion-fail DIFF "$(printf %s "$DIFF" | debconf-escape -e)"
+    db_input critical ngircd/conversion-fail || true
+    db_go
+    db_reset ngircd/conversion-fail
+    db_capb
+
+    break
+done
+
+# cleanup
+db_purge
+[ "$TEMPDIR" ] && rm -rf "$TEMPDIR"
+
+exit 0

+ 6 - 7
debian/ngircd.postinst

@@ -1,17 +1,14 @@
 #!/bin/sh
-# postinst script for ngircd
-#
-# see: dh_installdeb(1)
 
 set -e
 
+. /usr/share/debconf/confmodule
+
 case "$1" in
 configure)
-;;
-
+    ;;
 abort-upgrade|abort-remove|abort-deconfigure)
-;;
-
+    ;;
 *)
     echo "postinst called with unknown argument \`$1'" >&2
     exit 1
@@ -20,4 +17,6 @@ esac
 
 #DEBHELPER#
 
+db_stop
+
 exit 0

+ 8 - 6
debian/ngircd.postrm

@@ -1,14 +1,16 @@
 #!/bin/sh
-# postrm script for ngircd
-#
-# see: dh_installdeb(1)
 
 set -e
 
 case "$1" in
-purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
-;;
-
+purge)
+    if [ -e /usr/share/debconf/confmodule ]; then
+	. /usr/share/debconf/confmodule
+	db_purge
+    fi
+    ;;
+remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+    ;;
 *)
     echo "postrm called with unknown argument \`$1'" >&2
     exit 1

+ 23 - 0
debian/ngircd.templates

@@ -0,0 +1,23 @@
+Template: ngircd/conversion-do
+Type: boolean
+_Description: Convert ngIRCd configuration?
+ In version 18, the ngIRCd configuration file format has changed.
+ You can choose to have your configuration re-written.
+ Don't worry, the old format is still supported.
+
+Template: ngircd/broken-oldconfig
+Type: text
+_Description: Cannot convert configuration
+ The present configuration file contains errors and cannot
+ be converted. Please check manually using
+    ngircd --configtest
+ and run 'dpkg-reconfigure ngircd' to try again.
+
+Template: ngircd/conversion-fail
+Type: text
+_Description: Error
+ Verification after conversion failed. This is a bug, please report it
+ in the Debian bug tracker. Please include your configuration but make
+ sure all passwords are removed.
+ The diff below might give you some help:
+    ${DIFF}

+ 1 - 0
debian/po/POTFILES.in

@@ -0,0 +1 @@
+[type: gettext/rfc822deb] ngircd.templates

+ 65 - 0
debian/po/templates.pot

@@ -0,0 +1,65 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: ngircd@packages.debian.org\n"
+"POT-Creation-Date: 2011-11-04 22:08+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Type: boolean
+#. Description
+#: ../ngircd.templates:1001
+msgid "Convert ngIRCd configuration?"
+msgstr ""
+
+#. Type: boolean
+#. Description
+#: ../ngircd.templates:1001
+msgid ""
+"In version 18, the ngIRCd configuration file format has changed. You can "
+"choose to have your configuration re-written. Don't worry, the old format is "
+"still supported."
+msgstr ""
+
+#. Type: text
+#. Description
+#: ../ngircd.templates:2001
+msgid "Cannot convert configuration"
+msgstr ""
+
+#. Type: text
+#. Description
+#: ../ngircd.templates:2001
+msgid ""
+"The present configuration file contains errors and cannot be converted. "
+"Please check manually using\n"
+"   ngircd --configtest\n"
+"and run 'dpkg-reconfigure ngircd' to try again."
+msgstr ""
+
+#. Type: text
+#. Description
+#: ../ngircd.templates:3001
+msgid "Error"
+msgstr ""
+
+#. Type: text
+#. Description
+#: ../ngircd.templates:3001
+msgid ""
+"Verification after conversion failed. This is a bug, please report it in the "
+"Debian bug tracker. Please include your configuration but make sure all "
+"passwords are removed. The diff below might give you some help:\n"
+"   ${DIFF}"
+msgstr ""