summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Valroff <julien@kirya.net>2010-01-06 20:45:11 +0100
committerJulien Valroff <julien@kirya.net>2010-01-06 20:45:11 +0100
commitcc0712f26b594e7f9815de236da5c94f36daf8c0 (patch)
treedb03686f8baaf0d08ffa7f448a9588d77dc0e31c
parent359a73f4842b49120014c0b2bf69d740d43a8a89 (diff)
Complete rewrite of the postinst script
-rw-r--r--debian/changelog4
-rw-r--r--debian/default18
-rw-r--r--debian/init3
-rw-r--r--debian/postinst122
-rw-r--r--debian/postrm9
-rw-r--r--debian/preinst16
6 files changed, 82 insertions, 90 deletions
diff --git a/debian/changelog b/debian/changelog
index e8e5bea..424b93c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -16,10 +16,8 @@ mailgraph (1.14-2) UNRELEASED; urgency=low
(Closes: #370091)
* Allow extra options to be passed to mailgraph through default file
(Closes: #311437, #258980)
- * Fix postinst script to correctly update default file
- (Closes: #513634, #337923)
+ * Complete rewrite of the postinst script (Closes: #513634, #337923, #283664)
* Add ${misc:Depends} to the dependencies
- * Set the -e flag to postinst script
* Make sure the rrd directory has the correct ownership
* Add mailgraph.css to the package (Closes: #513527)
* Call mailgraph with --daemon_pid option (Closes: #508786)
diff --git a/debian/default b/debian/default
new file mode 100644
index 0000000..eb76247
--- /dev/null
+++ b/debian/default
@@ -0,0 +1,18 @@
+# This file is sourced by /etc/init.d/mailgraph
+#
+# This is a POSIX shell fragment
+#
+
+# Should Mailgraph start on boot (true|false) (default: true)
+BOOT_START=true
+
+# Logfile used by mailgraph (default: /var/log/mail.log)
+MAIL_LOG=/var/log/mail.log
+
+# Ignore mails from localhost (true|false) (default: false)
+# When true, this will pass --ignore-localhost to mailgraph daemon
+IGNORE_LOCALHOST=true
+
+# Extra options to be passed to mailgraph daemon
+# See mailgraph -h output (no default)
+EXTRA_OPTIONS=
diff --git a/debian/init b/debian/init
index 958b8f9..8a4a7be 100644
--- a/debian/init
+++ b/debian/init
@@ -15,12 +15,13 @@ DAEMON="/usr/sbin/mailgraph"
PID_FILE="/var/run/mailgraph.pid"
RRD_DIR="/var/lib/mailgraph"
IGNORE_OPTION=""
+MAIL_LOG="/var/log/mail.log"
if [ -f $MAILGRAPH_CONFIG ]; then
. $MAILGRAPH_CONFIG
else
exit 0
-fi
+fi
test -x $DAEMON || exit 0
diff --git a/debian/postinst b/debian/postinst
index 329a95c..aa74e9c 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -1,77 +1,63 @@
-#!/bin/sh
+#! /bin/sh
+# postinst script for mailgraph
+#
+# see: dh_installdeb(1)
set -e
-CONFIG=/etc/default/mailgraph
-CONFIG_BAK=/etc/default/mailgraph.bak
-RRD_DIR=/var/lib/mailgraph
-NEED_UPDATE=0
+# summary of how this script can be called:
+# * <postinst> `configure' <most-recently-configured-version>
+# * <old-postinst> `abort-upgrade' <new version>
+# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+# <new-version>
+# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+# <failed-install-package> <version> `removing'
+# <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+#
-# load debconf library
. /usr/share/debconf/confmodule
+DF=/etc/default/mailgraph
-write_config()
-{
- cat <<EOF > "${CONFIG}"
-# variables for /etc/init.d/mailgraph
-#
-# Should Mailgraph start on boot (true|false) [debconf]
-BOOT_START=${BOOT_START}
-# Logfile used by mailgraph (default: /var/log/mail.log) [debconf]
-MAIL_LOG=${MAIL_LOG}
-# Ignore mails from localhost (true|false) [debconf]
-IGNORE_LOCALHOST=${IGNORE_LOCALHOST}
-# Extra options to be passed to mailgraph (see mailgraph -h output)
-EXTRA_OPTIONS="${EXTRA_OPTIONS}"
-EOF
- return $?
-}
-
-update_config()
-{
- # create backup
- cp ${CONFIG} ${CONFIG_BAK}
- # write new configuration
- write_config
- # remove backup, if configuration was created successfully
- if [ $? -eq 0 ]; then
- rm ${CONFIG_BAK}
- else
- mv ${CONFIG_BAK} ${CONFIG}
- fi
-}
-
-make_rrd_dir()
-{
- if [ ! -d ${RRD_DIR} ]; then
- mkdir ${RRD_DIR}
- fi
- chown www-data:www-data ${RRD_DIR}
-}
-
-if [ -f ${CONFIG} ]; then
- . ${CONFIG}
- NEED_UPDATE=1
-fi
-
-db_get mailgraph/start_on_boot
-BOOT_START=${RET}
-db_get mailgraph/mail_log
-MAIL_LOG=${RET}
-db_get mailgraph/ignore_localhost
-IGNORE_LOCALHOST=${RET}
-
-if [ ! -n "${EXTRA_OPTIONS}" ]; then
- EXTRA_OPTIONS=""
-fi
-
-if [ ${NEED_UPDATE} -eq 0 ]; then
- write_config
-else
- update_config
-fi
-
-make_rrd_dir
+case "$1" in
+ configure)
+
+ db_get mailgraph/start_on_boot || true
+ BOOT_START=$RET
+
+ db_get mailgraph/mail_log || true
+ MAIL_LOG=$RET
+
+ db_get mailgraph/ignore_localhost
+ IGNORE_LOCALHOST=$RET
+
+ if [ -w $DF ]; then
+ TEMPFILE=`mktemp` || exit 1
+ sed $DF -e "s,^ *BOOT_START=.*,BOOT_START=$BOOTSTART," \
+ -e "s,^ *MAIL_LOG=.*,MAIL_LOG=$MAIL_LOG," \
+ -e "s,^ *IGNORE_LOCALHOST=.*,IGNORE_LOCALHOST=$IGNORE_LOCALHOST," \
+ > $TEMPFILE
+ mv -f $TEMPFILE $DF
+ chmod 644 $DF
+ fi
+
+ ;;
+
+ abort-upgrade|abort-remove|abort-deconfigure)
+
+ ;;
+
+ *)
+ echo "postinst called with unknown argument \`$1'" >&2
+ exit 1
+ ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
#DEBHELPER#
+
exit 0
+
diff --git a/debian/postrm b/debian/postrm
deleted file mode 100644
index fab1b24..0000000
--- a/debian/postrm
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-set -e
-
-if [ "$1" = "purge" ] ; then
- rm -f /etc/default/mailgraph
-fi
-#DEBHELPER#
-exit 0
diff --git a/debian/preinst b/debian/preinst
index 0070083..729ecc5 100644
--- a/debian/preinst
+++ b/debian/preinst
@@ -12,13 +12,13 @@ set -e
case "$1" in
upgrade)
if [ "$2" \< "1.13-1.1" ]; then
- if [ -f /etc/default/mailgraph ]; then
- . /usr/share/debconf/confmodule
- . /etc/default/mailgraph
- db_set mailgraph/start_on_boot "$BOOT_START"
- db_set mailgraph/mail_log "$MAIL_LOG"
- db_set mailgraph/ignore_localhost "$IGNORE_LOCALHOST"
- fi
+ if [ -r /etc/default/mailgraph ]; then
+ . /usr/share/debconf/confmodule
+ . /etc/default/mailgraph
+ db_set mailgraph/start_on_boot "$BOOT_START"
+ db_set mailgraph/mail_log "$MAIL_LOG"
+ db_set mailgraph/ignore_localhost "$IGNORE_LOCALHOST"
+ fi
fi
;;
@@ -37,5 +37,3 @@ esac
#DEBHELPER#
exit 0
-
-