2
# postinst script for #PACKAGE#
4
# see: dh_installdeb(1)
8
# summary of how this script can be called:
9
# * <postinst> `configure' <most-recently-configured-version>
10
# * <old-postinst> `abort-upgrade' <new version>
11
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
13
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14
# <failed-install-package> <version> `removing'
15
# <conflicting-package> <version>
16
# for details, see http://www.debian.org/doc/debian-policy/ or
17
# the debian-policy package
19
# quoting from the policy:
20
# Any necessary prompting should almost always be confined to the
21
# post-installation script, and should be protected with a conditional
22
# so that unnecessary prompting doesn't happen if a package's
23
# installation fails and the `postinst' is called with `abort-upgrade',
24
# `abort-remove' or `abort-deconfigure'.
26
#loading debconf module
27
. /usr/share/debconf/confmodule
29
FRESHCLAMCONFFILE=/etc/clamav/freshclam.conf
30
FRESHCLAMLOGFILE=/var/log/clamav/freshclam.log
31
DEBCONFILE=/var/lib/clamav/freshclam.conf
32
LOGROTFILE=/etc/logrotate.d/clamav-freshclam
33
DEBROTFILE=/var/lib/clamav/clamav-freshclam
42
# Configure the hardcoded stuff
44
udlogfile="$FRESHCLAMLOGFILE"
47
# Get the debconf answers
48
db_metaget clamav-freshclam/local_mirror value || true
49
[ "$RET" = "" ] || rawmirrors="$RET"
50
if echo "$rawmirrors" | egrep -q '(\(|\))'; then
51
mirrors=`echo "$rawmirrors" | awk '{print $1}'`
55
db_metaget clamav-freshclam/autoupdate_freshclam value || true
57
if [ "$runas" = "ifup.d" ]; then
58
db_metaget clamav-freshclam/internet_interface value || true
59
if [ "$RET" != "" ]; then
62
# Like the template promised
66
if [ "$runas" = "ifup.d" ] || [ "$runas" = "daemon" ] || [ "$runas" = "cron" ]; then
67
db_metaget clamav-freshclam/update_interval value || true
68
if [ "$RET" != "" ]; then
69
if [ "$runas" != "cron" ]; then
72
if [ "$RET" -ge 24 ]; then
73
echo "To check for updates more often than hourly, please run freshclam as a daemon."
76
cronhour="`expr 24 / $RET`"
81
db_metaget clamav-freshclam/http_proxy value || true
82
if [ "$RET" != "" ]; then
83
url="`echo "$RET" | sed -e 's,^http://,,g' | sed -e 's,/$,,g'`"
84
phost="`echo "$url" | cut -d':' -f 1`"
85
pport="`echo "$url" | cut -d':' -f 2`"
87
db_metaget clamav-freshclam/proxy_user value || true
88
if [ "$RET" != "" ]; then
90
puser="`echo "$RET" | cut -d':' -f 1`"
91
ppass="`echo "$RET" | cut -d':' -f 2`"
94
db_metaget clamav-freshclam/NotifyClamd value || true
95
[ "$RET" = "true" ] && notify="/etc/clamav/clamd.conf"
97
slurp_config "$FRESHCLAMCONFFILE"
99
# Make sure user changes to unasked questions remain intact
100
[ -n "$DatabaseOwner" ] && [ "$DatabaseOwner" != "$dbowner" ] && dbowner="$DatabaseOwner"
101
[ -n "$UpdateLogFile" ] && [ "$UpdateLogFile" != "$udlogfile" ] && udlogfile="$UpdateLogFile"
102
[ -n "$MaxAttempts" ] && [ "$MaxAttempts" != "$maxatt" ] && maxatt="$MaxAttempts"
105
if [ "$runas" = cron ]; then
106
min=$(( `od -A n -N 2 -l < /dev/urandom` % 3600 / 60 ))
107
# min=`perl -e 'print int(rand(60))'`
108
FRESHCLAMCRON=/etc/cron.d/clamav-freshclam
109
FRESHCLAMTEMP=/var/lib/clamav/freshclam.cron
110
echo "$min */$cronhour * * * $dbowner [ -x /usr/bin/freshclam ] && /usr/bin/freshclam --quiet >/dev/null" > "$FRESHCLAMTEMP"
111
ucf_cleanup "$FRESHCLAMCRON"
112
ucf_upgrade_check "$FRESHCLAMCRON" "$FRESHCLAMTEMP" /var/lib/ucf/cache/:etc:cron.d:clamav-freshclam
113
rm -f "$FRESHCLAMTEMP"
115
if [ -e /etc/cron.d/clamav-freshclam ]; then
116
echo -n "Disabling old cron script . . . "
117
mv /etc/cron.d/clamav-freshclam /etc/cron.d/clamav-freshclam.dpkg-old
118
ucf -p /etc/cron.d/clamav-freshclam > /dev/null 2>&1 || true
123
# Set up ifup.d method
124
if [ "$runas" = 'ifup.d' ]; then
125
[ -n "$iface" ] && echo "$iface" > /var/lib/clamav/interface
127
[ -f /var/lib/clamav/interface ] && rm -f /var/lib/clamav/interface
130
dpkg --compare-versions "$2" lt 0.79 && DNSDatabaseInfo=current.cvd.clamav.net # Only for this upgrade
132
[ -z "$LogVerbose" ] && LogVerbose=false
133
[ -z "$LogSyslog" ] && LogSyslog=false
134
[ -z "$LogFacility" ] && LogFacility=LOG_LOCAL6
135
[ -z "$LogFileMaxSize" ] && LogFileMaxSize=0
136
[ -z "$Foreground" ] && Foreground=false
137
[ -z "$Debug" ] && Debug=false
138
[ -z "$DatabaseDirectory" ] && DatabaseDirectory='/var/lib/clamav/'
139
[ -z "$DNSDatabaseInfo" ] && DNSDatabaseInfo='current.cvd.clamav.net'
140
[ -z "$AllowSupplementaryGroups" ] && AllowSupplementaryGroups=false
141
[ -z "$PidFile" ] && PidFile='/var/run/clamav/freshclam.pid'
142
[ -z "$ConnectTimeout" ] && ConnectTimeout=30
143
[ -z "$ReceiveTimeout" ] && ReceiveTimeout=30
144
[ -z "$ScriptedUpdates" ] && ScriptedUpdates=yes
145
[ -z "$LogTime" ] && LogTime=no
146
[ -z "$CompressLocalDatabase" ] && CompressLocalDatabase=no
148
# Generate config file
149
cat >> $DEBCONFILE << EOF
150
# Automatically created by the clamav-freshclam postinst
151
# Comments will get lost when you reconfigure the clamav-freshclam package
153
DatabaseOwner $dbowner
154
UpdateLogFile $udlogfile
155
LogVerbose $LogVerbose
157
LogFacility $LogFacility
158
LogFileMaxSize $LogFileMaxSize
160
Foreground $Foreground
163
DatabaseDirectory $DatabaseDirectory
164
DNSDatabaseInfo $DNSDatabaseInfo
165
AllowSupplementaryGroups $AllowSupplementaryGroups
167
ConnectTimeout $ConnectTimeout
168
ReceiveTimeout $ReceiveTimeout
169
ScriptedUpdates $ScriptedUpdates
170
CompressLocalDatabase $CompressLocalDatabase
173
if [ -n "$notify" ] ;then
174
if [ -n "$NotifyClamd" ] && is_true "$NotifyClamd"; then
175
echo "NotifyClamd $NotifyClamd" >> $DEBCONFILE
177
echo "NotifyClamd /etc/clamav/clamd.conf" >> $DEBCONFILE
180
if [ "$runas" != "cron" ] || [ "$runas" != "manual" ]; then
181
if [ -n "$checks" ] && [ "$checks" != "true" ]; then
182
echo "# Check for new database $checks times a day" >> $DEBCONFILE
183
echo "Checks $checks" >> $DEBCONFILE
186
if [ -n "$mirrors" ]; then
187
for i in $mirrors; do
188
echo "DatabaseMirror $i" >> $DEBCONFILE
191
if ! echo "$mirrors" | grep -q database.clamav.net; then
192
echo "DatabaseMirror database.clamav.net" >> $DEBCONFILE
194
if [ -n "$DatabaseMirror" ]; then
195
for m in $DatabaseMirror; do
196
grep -q "$m" "$DEBCONFILE" || echo "DatabaseMirror $m" >> $DEBCONFILE
200
if [ -n "$phost" ] && [ -n "$pport" ]; then
201
echo "# Proxy: $fullurl" >> $DEBCONFILE
202
echo "HTTPProxyServer $phost" >> $DEBCONFILE
203
echo "HTTPProxyPort $pport" >> $DEBCONFILE
205
if [ -n "$puser" ] && [ -n "$ppass" ]; then
206
echo "# Proxy authentication: $fulluser" >> $DEBCONFILE
207
echo "HTTPProxyUsername $puser" >> $DEBCONFILE
208
echo "HTTPProxyPassword $ppass" >> $DEBCONFILE
210
[ -n "$HTTPUserAgent" ] && echo "HTTPUserAgent $HTTPUserAgent" >> $DEBCONFILE
211
[ -n "$OnOutdatedExecute" ] && echo "OnOutdatedExecute $OnOutdatedExecute" >> $DEBCONFILE
212
[ -n "$OnUpdateExecute" ] && echo "OnUpdateExecute $OnUpdateExecute" >> $DEBCONFILE
213
[ -n "$OnErrorExecute" ] && echo "OnErrorExecute $OnErrorExecute" >> $DEBCONFILE
214
[ -n "$LocalIPAddress" ] && echo "LocalIPAddress $LocalIPAddress" >> $DEBCONFILE
216
ucf_cleanup "$FRESHCLAMCONFFILE"
217
ucf_upgrade_check "$FRESHCLAMCONFFILE" "$DEBCONFILE" /var/lib/ucf/cache/:etc:clamav:freshclam.conf
222
# Permissions are still fsck'd - repair manually
223
for script in /etc/network/if-up.d/clamav-freshclam-ifupdown \
224
/etc/network/if-down.d/clamav-freshclam-ifupdown \
225
/etc/ppp/ip-down.d/clamav-freshclam-ifupdown \
226
/etc/ppp/ip-up.d/clamav-freshclam-ifupdown; do
227
if [ -e "$script" ]; then
228
[ -x "$script" ] || chmod +x "$script"
231
touch $FRESHCLAMLOGFILE
232
chmod 640 $FRESHCLAMLOGFILE
233
chown "$dbowner":adm $FRESHCLAMLOGFILE
235
# Tighten the permissions up if it contains a password
236
if [ -n "$ppass" ]; then
237
chmod 600 $FRESHCLAMCONFFILE
239
chmod 644 $FRESHCLAMCONFFILE
242
chown "$dbowner":adm $FRESHCLAMCONFFILE
244
if [ "$runas" = 'daemon' ]; then
245
if [ -x "/etc/init.d/clamav-freshclam" ]; then
246
update-rc.d clamav-freshclam defaults >/dev/null
248
if [ -x /usr/sbin/invoke-rc.d ]; then
249
invoke-rc.d clamav-freshclam start
251
/etc/init.d/clamav-freshclam start
253
elif [ "$runas" = 'ifup.d' ]; then
254
for intrface in $iface; do
255
if route | grep -q "$intrface"; then
256
if [ -x /usr/sbin/invoke-rc.d ]; then
257
IFACE="$intrface" invoke-rc.d clamav-freshclam start || true
259
IFACE="$intrface" /etc/init.d/clamav-freshclam start || true
264
update-rc.d -f clamav-freshclam remove > /dev/null 2>&1
266
echo "Starting database update: "
267
if [ -x /usr/sbin/invoke-rc.d ]; then
268
invoke-rc.d clamav-freshclam no-daemon || true
270
/etc/init.d/clamav-freshclam no-daemon || true
272
update-rc.d -f clamav-freshclam remove > /dev/null 2>&1
275
abort-remove|abort-deconfigure|abort-upgrade)
278
echo "postinst called with unknown argument \`$1'" >&2