~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to debian/clamav-freshclam.postinst.in

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mto: (0.35.3 sid)
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: james.westby@ubuntu.com-20080905172534-2lxrdzafr26tqfkx
Tags: 0.94.dfsg-1
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
# postinst script for #PACKAGE#
 
3
#
 
4
# see: dh_installdeb(1)
 
5
 
 
6
set -e
 
7
 
 
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>
 
12
#          <new-version>
 
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
 
18
#
 
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'.
 
25
 
 
26
#loading debconf module
 
27
. /usr/share/debconf/confmodule
 
28
 
 
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
 
34
 
 
35
#COMMON-FUNCTIONS#
 
36
 
 
37
UCFVER=`check_ucf`
 
38
 
 
39
case "$1" in
 
40
  configure)
 
41
 
 
42
  # Configure the hardcoded stuff
 
43
  dbowner=clamav
 
44
  udlogfile="$FRESHCLAMLOGFILE"
 
45
  maxatt=5
 
46
  
 
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}'`
 
52
  else
 
53
    mirrors="$rawmirrors"
 
54
  fi
 
55
  db_metaget clamav-freshclam/autoupdate_freshclam value || true
 
56
  runas="$RET"
 
57
  if [ "$runas" = "ifup.d" ]; then
 
58
    db_metaget clamav-freshclam/internet_interface value || true
 
59
    if [ "$RET" != "" ]; then
 
60
      iface="$RET"
 
61
    else
 
62
      # Like the template promised
 
63
      runas="daemon"
 
64
    fi
 
65
  fi
 
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
 
70
        checks="$RET"
 
71
      else
 
72
        if [ "$RET" -ge 24 ]; then
 
73
          echo "To check for updates more often than hourly, please run freshclam as a daemon."
 
74
          cronhour=1
 
75
        else
 
76
          cronhour="`expr 24 / $RET`"
 
77
        fi
 
78
      fi
 
79
    fi
 
80
  fi
 
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`"
 
86
    fullurl="$RET"
 
87
    db_metaget clamav-freshclam/proxy_user value || true
 
88
    if [ "$RET" != "" ]; then
 
89
      fulluser="$RET"
 
90
      puser="`echo "$RET" | cut -d':' -f 1`"
 
91
      ppass="`echo "$RET" | cut -d':' -f 2`"
 
92
    fi
 
93
  fi
 
94
  db_metaget clamav-freshclam/NotifyClamd value || true
 
95
  [ "$RET" = "true" ] && notify="/etc/clamav/clamd.conf"
 
96
 
 
97
  slurp_config "$FRESHCLAMCONFFILE"
 
98
 
 
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"
 
103
 
 
104
  # Set up cron method
 
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"
 
114
  else
 
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
 
119
      echo "done"
 
120
    fi
 
121
  fi
 
122
  
 
123
  # Set up ifup.d method
 
124
  if [ "$runas" = 'ifup.d' ]; then
 
125
    [ -n "$iface" ] && echo "$iface" > /var/lib/clamav/interface
 
126
  else
 
127
    [ -f /var/lib/clamav/interface ] && rm -f /var/lib/clamav/interface
 
128
  fi
 
129
  
 
130
  dpkg --compare-versions "$2" lt 0.79 && DNSDatabaseInfo=current.cvd.clamav.net # Only for this upgrade
 
131
  
 
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
 
147
 
 
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
 
152
 
 
153
DatabaseOwner $dbowner
 
154
UpdateLogFile $udlogfile
 
155
LogVerbose $LogVerbose
 
156
LogSyslog $LogSyslog
 
157
LogFacility $LogFacility
 
158
LogFileMaxSize $LogFileMaxSize
 
159
LogTime $LogTime
 
160
Foreground $Foreground
 
161
Debug $Debug
 
162
MaxAttempts $maxatt
 
163
DatabaseDirectory $DatabaseDirectory
 
164
DNSDatabaseInfo $DNSDatabaseInfo
 
165
AllowSupplementaryGroups $AllowSupplementaryGroups
 
166
PidFile $PidFile
 
167
ConnectTimeout $ConnectTimeout
 
168
ReceiveTimeout $ReceiveTimeout
 
169
ScriptedUpdates $ScriptedUpdates
 
170
CompressLocalDatabase $CompressLocalDatabase
 
171
EOF
 
172
 
 
173
  if [ -n "$notify" ] ;then
 
174
    if [ -n "$NotifyClamd" ] && is_true "$NotifyClamd"; then
 
175
      echo "NotifyClamd $NotifyClamd" >> $DEBCONFILE
 
176
    else
 
177
      echo "NotifyClamd /etc/clamav/clamd.conf" >> $DEBCONFILE
 
178
    fi
 
179
  fi
 
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
 
184
    fi
 
185
  fi
 
186
  if [ -n "$mirrors" ]; then
 
187
    for i in $mirrors; do
 
188
      echo "DatabaseMirror $i" >> $DEBCONFILE
 
189
    done
 
190
  fi
 
191
  if ! echo "$mirrors" | grep -q database.clamav.net; then
 
192
    echo "DatabaseMirror database.clamav.net" >> $DEBCONFILE
 
193
  fi
 
194
  if [ -n "$DatabaseMirror" ]; then
 
195
    for m in $DatabaseMirror; do
 
196
      grep -q "$m" "$DEBCONFILE" || echo "DatabaseMirror $m" >> $DEBCONFILE
 
197
    done
 
198
  fi
 
199
 
 
200
  if [ -n "$phost" ] && [ -n "$pport" ]; then
 
201
    echo "# Proxy: $fullurl" >> $DEBCONFILE
 
202
    echo "HTTPProxyServer $phost" >> $DEBCONFILE
 
203
    echo "HTTPProxyPort $pport" >> $DEBCONFILE
 
204
  fi
 
205
  if [ -n "$puser" ] && [ -n "$ppass" ]; then
 
206
    echo "# Proxy authentication: $fulluser" >> $DEBCONFILE
 
207
    echo "HTTPProxyUsername $puser" >> $DEBCONFILE
 
208
    echo "HTTPProxyPassword $ppass" >> $DEBCONFILE
 
209
  fi
 
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
 
215
  
 
216
  ucf_cleanup "$FRESHCLAMCONFFILE"
 
217
  ucf_upgrade_check "$FRESHCLAMCONFFILE" "$DEBCONFILE" /var/lib/ucf/cache/:etc:clamav:freshclam.conf
 
218
  rm -f "$DEBCONFILE"
 
219
 
 
220
  db_stop || true
 
221
  
 
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"
 
229
    fi
 
230
  done
 
231
  touch $FRESHCLAMLOGFILE
 
232
  chmod 640 $FRESHCLAMLOGFILE
 
233
  chown "$dbowner":adm $FRESHCLAMLOGFILE
 
234
  
 
235
  # Tighten the permissions up if it contains a password
 
236
  if [ -n "$ppass" ]; then
 
237
    chmod 600 $FRESHCLAMCONFFILE
 
238
  else
 
239
    chmod 644 $FRESHCLAMCONFFILE
 
240
  fi
 
241
 
 
242
  chown "$dbowner":adm $FRESHCLAMCONFFILE
 
243
  
 
244
  if [ "$runas" = 'daemon' ]; then
 
245
    if [ -x "/etc/init.d/clamav-freshclam" ]; then
 
246
      update-rc.d clamav-freshclam defaults >/dev/null
 
247
    fi
 
248
    if [ -x /usr/sbin/invoke-rc.d ]; then
 
249
      invoke-rc.d clamav-freshclam start
 
250
    else
 
251
      /etc/init.d/clamav-freshclam start
 
252
    fi
 
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
 
258
        else
 
259
          IFACE="$intrface" /etc/init.d/clamav-freshclam start || true
 
260
        fi
 
261
        break
 
262
      fi
 
263
    done
 
264
    update-rc.d -f clamav-freshclam remove > /dev/null 2>&1
 
265
  else
 
266
    echo "Starting database update: "
 
267
    if [ -x /usr/sbin/invoke-rc.d ]; then
 
268
      invoke-rc.d clamav-freshclam no-daemon || true
 
269
    else
 
270
      /etc/init.d/clamav-freshclam no-daemon || true
 
271
    fi
 
272
    update-rc.d -f clamav-freshclam remove > /dev/null 2>&1
 
273
  fi
 
274
  ;;
 
275
  abort-remove|abort-deconfigure|abort-upgrade)
 
276
  ;;
 
277
  *)
 
278
  echo "postinst called with unknown argument \`$1'" >&2
 
279
  exit 1
 
280
  ;;
 
281
esac
 
282
 
 
283
#DEBHELPER#
 
284
 
 
285
exit 0