From cc0712f26b594e7f9815de236da5c94f36daf8c0 Mon Sep 17 00:00:00 2001 From: Julien Valroff Date: Wed, 6 Jan 2010 20:45:11 +0100 Subject: Complete rewrite of the postinst script --- debian/postinst | 122 +++++++++++++++++++++++++------------------------------- 1 file changed, 54 insertions(+), 68 deletions(-) (limited to 'debian/postinst') 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: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-deconfigure' `in-favour' +# `removing' +# +# 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 < "${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 + -- cgit v1.2.3