#!/bin/sh
# postinst script for mythtv-status
#
# see: dh_installdeb(1)

PACKAGE=mythtv-status

. /usr/share/debconf/confmodule

set -e

case "$1" in
  configure|reconfigure)
    DEBIANCONFIG=/etc/default/$PACKAGE

    # Default to --email-only-on-alert but allow it be unset in the config file.
    EMAIL_ARGS="--email-only-on-alert"

    # load current settings, most of which will be overwritten.
    [ -f $DEBIANCONFIG ] && . $DEBIANCONFIG

    db_get $PACKAGE/host
    HOST="${RET:-localhost}"

    db_get $PACKAGE/enable
    UPDATE_MOTD="${RET:-true}"

    [ $UPDATE_MOTD = 'true' ] && UPDATE_MOTD='yes'

    # Support the old variable name.
    [ "x$RUN" != "x" ] && UPDATE_MOTD=$RUN

    # Support the old variable name.
    [ "x$ARGS" != "x" ] && UPDATE_MOTD_ARGS=$ARGS

    db_get $PACKAGE/email
    EMAIL="${RET:-none}"

    cat <<_eof > $DEBIANCONFIG
# $PACKAGE Debian configuration
#
# You can run 'dpkg-reconfigure $PACKAGE' to modify the values in this
# file, if you want. You can also change the values here and changes will
# be preserved.  But other changes will not be preserved.
#
# Do note that only the values are preserved; the rest of the file is
# rewritten.
#

# HOST:
#  What host should we check the status on?
HOST=$HOST

########################################################################
# The following settings are used by the /etc/init.d/mythtv-status and #
# mythtv-update-motd scripts to update the MOTD.                       #
########################################################################

# UPDATE_MOTD:
#  Should we actually run and update the MOTD?
UPDATE_MOTD=$UPDATE_MOTD

# UPDATE_MOTD_ARGS:
#  Any extra arguments to pass to mythtv-status (i.e., -e -d).
UPDATE_MOTD_ARGS="$UPDATE_MOTD_ARGS"

########################################################################
# The following settings are used by the /etc/cron.daily/mythtv-status #
# script when generating the daily status email report.                #
########################################################################

# EMAIL:
#  A comma separated list of email address to send status emails to.
#
#  Set to none to disable daily emails, if empty then default to root.
EMAIL=$EMAIL

# EMAIL_ARGS:
#  Command line arguments that are used when sending the daily email.
EMAIL_ARGS="$EMAIL_ARGS"
_eof

    db_stop
  ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
