summaryrefslogtreecommitdiff
path: root/debian/postinst
blob: 745ffdfa5d286f27f5e1fe4988b1a1f1f0673528 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh

##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
    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 [ ${NEED_UPDATE} -eq 0 ]; then
  write_config
else
  update_config
fi

make_rrd_dir

#DEBHELPER#
exit 0