summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/init2
-rw-r--r--debian/postinst83
2 files changed, 71 insertions, 14 deletions
diff --git a/debian/init b/debian/init
index cd5bdff..7cc4f7c 100644
--- a/debian/init
+++ b/debian/init
@@ -35,7 +35,7 @@ fi
case "$1" in
start)
echo -n "Starting Postfix Mail Statistics: $NAME"
- start-stop-daemon -S -q -b -p $PID_FILE -x $DAEMON -- -l $MAIL_LOG -d --daemon_rrd=$RRD_DIR $IGNORE_OPTION
+ start-stop-daemon -S -q -b -p $PID_FILE -x $DAEMON -- -l $MAIL_LOG -d --daemon_rrd=$RRD_DIR $IGNORE_OPTION $EXTRA_OPTIONS
echo "."
;;
stop)
diff --git a/debian/postinst b/debian/postinst
index d17f371..745ffdf 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -1,20 +1,77 @@
#!/bin/sh
-if [ ! -f /etc/default/mailgraph ]; then
- . /usr/share/debconf/confmodule
- db_get mailgraph/start_on_boot
- echo "BOOT_START=$RET" > /etc/default/mailgraph
- db_get mailgraph/mail_log
- echo "MAIL_LOG=$RET" >> /etc/default/mailgraph
- db_get mailgraph/ignore_localhost
- if [ "$RET" = "true" ] ; then
- echo "IGNORE_LOCALHOST=false" >> /etc/default/mailgraph
+
+##set -x
+
+CONFIG=/etc/default/mailgraph
+CONFIG_BAK=/etc/default/mailgraph.bak
+RRD_DIR=/var/lib/mailgraph
+NEED_UPDATE=0
+
+# load debconf library
+. /usr/share/debconf/confmodule
+
+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}
+# 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
- echo "IGNORE_LOCALHOST=true" >> /etc/default/mailgraph
+ mv ${CONFIG_BAK} ${CONFIG}
fi
+}
+
+make_rrd_dir()
+{
+ if [ ! -d ${RRD_DIR} ]; then
+ mkdir ${RRD_DIR}
+ chown www-data:www-data ${RRD_DIR}
+ fi
+}
+
+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 [ ! -d /var/lib/mailgraph ]; then
- mkdir /var/lib/mailgraph
- chown www-data:www-data /var/lib/mailgraph
+
+if [ ${NEED_UPDATE} -eq 0 ]; then
+ write_config
+else
+ update_config
fi
+
+make_rrd_dir
+
#DEBHELPER#
exit 0