File: postinst

package info (click to toggle)
trafstats 0.4.20-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 296 kB
  • ctags: 110
  • sloc: cpp: 1,036; sh: 475; perl: 173; makefile: 98
file content (162 lines) | stat: -rw-r--r-- 3,052 bytes parent folder | download
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh -e

# Source debconf functions.
. /usr/share/debconf/confmodule

# source trafstats-specific functions
. /usr/share/trafstats/dbfuncs.sh

set -e 

createmailconffile() {
	if ! [ -a /etc/trafstats/mail.conf ]; then
		cat <<EOF > /etc/trafstats/mail.conf
# /etc/trafstats/mail.conf
# generated by debconf $NOW
RECIPIENTS="$RECIPIENTS"
EOF
	else
		LINE="RECIPIENTS=\"${RECIPIENTS}\""
		TMPFILE=`tempfile`
		cat /etc/trafstats/mail.conf | sed -e "s/RECIPIENTS.*/${LINE}/" > $TMPFILE
		mv $TMPFILE /etc/trafstats/mail.conf
	fi
}

# initialise file writer
createconffile() {
cat <<EOF >/etc/trafstats/trafstats.conf
# Config file for trafstats; this file is read and used by 
#    /etc/init.d/trafstats
# This file is automatically generated.
# Use dpkg-reconfigure to modify it.

# Wether or not to start trafstats at boot time. Default is no.
$STARTBOOTSTR

# What interface to run trafstats on
IFACE=$IFACE

# Database storage interval in seconds
SDELAY=$SDELAY

# Timestamp interval in seconds
TDELAY=$TDELAY

# Name of the database to connect to
DBNAME=$DBNAME

# Userid to connect as in order to store data
DBWRITER=$DBWRITER

# Userid to connect as in order to read data
DBREADER=$DBREADER

# Run in reduced functionality mode
CASTRATE=$CASTRATE

# Verbosity level in syslogs:
# 0 - No logging.
# Any other number: Log anything with a priority higher than or equal to it.
VERBOSITY=$VERBOSITY
EOF
}

db_get trafstats/startonboot || true
if [ "$RET" = "true" ]
then
	BOOT=1
	STARTBOOTSTR="STARTONBOOT=1"
else
	BOOT=0
	STARTONBOOTSTR="STARTONBOOT=0"
fi

db_get trafstats/interface || true
IFACE=$RET
db_get trafstats/storage-delay || true
SDELAY=$RET
db_get trafstats/timestamp-delay || true
TDELAY=$RET

if [ $SDELAY -lt $TDELAY ]
then
	SDELAY=$TDELAY
fi

db_get trafstats/dbname || true
DBNAME=$RET
db_get trafstats/writer || true
DBWRITER=$RET
db_get trafstats/reader || true
DBREADER=$RET

db_get trafstats/nodaemon || true
if [ "$RET" = "true" ]
then
	NODAEMONSTR="NODAEMON=1"
else
	NODAEMONSTR="# NODAEMON=0"
fi
db_get trafstats/castrate || true
if [ "$RET" = "true" ]
then
	CASTRATE=1
else
	CASTRATE=0
fi

db_get trafstats/verbosity || true
case "$RET" in
	none)
		VERBOSITY=0
		;;
	critical)
		VERBOSITY=2
		;;
	warnings)
		VERBOSITY=4
		;;
	notices)
		VERBOSITY=5
		;;
	info)
		VERBOSITY=6
		;;
	debugging)
		VERBOSITY=7
		;;
	insane)
		VERBOSITY=14
		;;
	*) # WTF? 
		VERBOSITY=4
		echo "WARNING: debconf returned an unexpected value: $RET."
		echo -n "File a bug against debconf about this, and notify "
		echo "this package's maintainer. If possible, include your"
		echo "debconf answers to trafstats questions in the report."
	esac
	
db_get trafstats/recipients || true 
RECIPIENTS="$RET"

NOW=`date`

if [ "$1" = "configure" ] ; then
	if [ -f /etc/trafstats/trafstats.conf ] ; then 
		db_get trafstats/overwrite || true
		if [ "$RET" = "false" ]
		then
			echo "Not overwriting /etc/trafstats/trafstats.conf..."
		else
			createconffile
		fi
	else
		createconffile
	fi
	createmailconffile
fi
#close debconf
db_stop

#DEBHELPER#