This file is indexed.

postinst is in clamav-milter 0.99+dfsg-1ubuntu1.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
#! /bin/sh
# postinst script for #PACKAGE#
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

#loading debconf module
. /usr/share/debconf/confmodule

to_lower()
{
  word="$1"
  lcword=$(echo "$word" | tr A-Z a-z)
  echo "$lcword"
}

is_true()
{
  var="$1"
  lcvar=$(to_lower "$var")
  [ 'true' = "$lcvar" ] || [ 'yes' = "$lcvar" ] || [ 1 = "$lcvar" ]
  return $?
}

is_false()
{
  var="$1"
  lcvar=$(to_lower "$var")
  [ 'false' = "$lcvar" ] || [ 'no' = "$lcvar" ] || [ 0 = "$lcvar" ]
  return $?
}

ucf_cleanup()
{
  # This only does something if I've fucked up before
  # Not entirely impossible :(

  configfile=$1

  if [ `grep "$configfile" /var/lib/ucf/hashfile | wc -l` -gt 1 ]; then
    grep -v "$configfile" /var/lib/ucf/hashfile > /var/lib/ucf/hashfile.tmp
    grep "$configfile" /var/lib/ucf/hashfile | tail -n 1  >> /var/lib/ucf/hashfile.tmp
    mv /var/lib/ucf/hashfile.tmp /var/lib/ucf/hashfile
  fi
}

add_to_ucf()
{
  configfile=$1
  ucffile=$2

  if ! grep -q "$configfile" /var/lib/ucf/hashfile; then
    md5sum $configfile >> /var/lib/ucf/hashfile
    cp $configfile $ucffile
  fi
}

ucf_upgrade_check()
{
  configfile=$1
  sourcefile=$2
  ucffile=$3

  if [ -f "$configfile" ]; then
    add_to_ucf $configfile $ucffile
    ucf --three-way --debconf-ok "$sourcefile" "$configfile"
  else
    [ -d /var/lib/ucf/cache ] || mkdir -p /var/lib/ucf/cache
    pathfind restorecon && restorecon /var/lib/ucf/cache
    cp $sourcefile $configfile
    add_to_ucf $configfile $ucffile
  fi
}

slurp_config()
{
  CLAMAVCONF="$1"
  
  if [ -e "$CLAMAVCONF" ]; then
    for variable in `egrep -a -v '^[[:space:]]*(#|$)' "$CLAMAVCONF" | awk '{print $1}'`; do
      case "$variable" in
        DatabaseMirror)
        if [ -z "$DatabaseMirror" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$value $i"
          done
        else
          continue
        fi
        ;;
        DatabaseCustomURL)
        if [ -z "$DatabaseCustomURL" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$value $i"
          done
        else
          continue
        fi
        ;;
        IncludePUA)
        if [ -z "$IncludePUA" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$i $value"
          done
        else
          continue
        fi
        ;;
        ExcludePUA)
        if [ -z "$ExcludePUA" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$i $value"
          done
        else
          continue
        fi
        ;;
        ExtraDatabase)
        if [ -z "$ExtraDatabase" ]; then
          for i in `grep -a ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$value $i"
          done
        else
          continue
        fi
        ;;
        VirusEvent|OnUpdateExecute|OnErrorExecute|RejectMsg)
        value=`grep -a ^$variable $CLAMAVCONF | head -n1 | sed -e s/$variable\ //`
        ;;
        *)
        value=`grep -a "^$variable[[:space:]]" $CLAMAVCONF | head -n1 | awk '{print $2}'`
        ;;
      esac
      if [ -z "$value" ]; then 
        export "$variable"="true"
      elif [ "$value" != "$variable" ]; then
        export "$variable"="$value"
      else
        export "$variable"="true"
      fi
      unset value
    done
  fi
}

pathfind() {
  OLDIFS="$IFS"
  IFS=:
  for p in $PATH; do
    if [ -x "$p/$*" ]; then
      IFS="$OLDIFS"
      return 0
    fi
  done
  IFS="$OLDIFS"
  return 1
}

set_debconf_value()
{
prog=$1
name=$2
eval variable="\$${name}"
if [ -n "$variable" ]; then
  db_set clamav-$prog/$name "$variable" || true
fi
}

make_dir()
{
  DIR=$1
  if [ -d "$DIR" ]; then
    return 0;
  fi
  [ -n "$User" ] || User=clamav
  mkdir -p -m 0755 "$DIR"
  chown "$User" "$DIR"
  pathfind restorecon && restorecon "$DIR"
}

# Debconf Functions

isdigit ()
{
  case $1 in
    [[:digit:]]*)
    ISDIGIT=1
    ;;
    *)
    ISDIGIT=0
    ;;
  esac
}

inputdigit ()
{
  ISDIGIT=0
  while [ "$ISDIGIT" = '0' ]; do
    db_input "$1" "$2" || true
    if ! db_go; then
      return 30
    fi
    db_get $2 || true
    isdigit $RET
    if [ "$ISDIGIT" = '0' ]; then
      db_input critical clamav-base/numinfo || true
      db_go
    fi
  done
  return 0
}

StateGeneric()
{
  PRIO=$1
  QUESTION=$2
  NEXT=$3
  LAST=$4

  db_input $PRIO $QUESTION || true
  if db_go; then
    STATE=$NEXT
  else
    STATE=$LAST
  fi
}

StateGenericDigit()
{
  PRIO=$1
  QUESTION=$2
  NEXT=$3
  LAST=$4

  inputdigit $PRIO $QUESTION || true
  if db_go; then
    STATE=$NEXT
  else
    STATE=$LAST
  fi
}


case "$1" in
  configure)

  CLAMAVMILTERCONF=/etc/clamav/clamav-milter.conf
  DEBROTATEFILE=/var/lib/clamav/clamav-milter.rotate.debconf
  CLAMAVROTATEFILE=/etc/logrotate.d/clamav-milter
  DEBCONFFILE=/var/lib/clamav/clamav-milter.conf
  
  db_get clamav-milter/debconf || true
  if [ "$RET" = "true" ]; then

    # Read the configuration file
    slurp_config "$CLAMAVMILTERCONF"

    db_get clamav-milter/MilterSocket || true
    MilterSocket="$RET"
    db_get clamav-milter/FixStaleSocket || true
    Fixstalesocket="$RET"
    db_get clamav-milter/MilterSocketGroup || true
    MilterSocketGroup="$RET"
    db_get clamav-milter/MilterSocketMode || true
    MilterSocketMode="$RET"
    db_get clamav-milter/User || true
    User="$RET"
    db_get clamav-milter/AddGroups || true
    Addgroups="$RET"
    db_get clamav-milter/ReadTimeout || true
    ReadTimeout="$RET"
    db_get clamav-milter/Foreground || true
    Foreground="$RET"
    db_get clamav-milter/Chroot || true
    Chroot="$RET"
    db_get clamav-milter/PidFile || true
    PidFile="$RET"
    db_get clamav-milter/TemporaryDirectory || true
    TemporaryDirectory="$RET"
    db_get clamav-milter/ClamdSocket || true
    ClamdSocket="$RET"
    db_get clamav-milter/LocalNet || true
    LocalNet="$RET"
    db_get clamav-milter/Whitelist || true
    Whitelist="$RET"
    db_get clamav-milter/OnInfected || true
    OnInfected="$RET"
    db_get clamav-milter/OnFail || true
    OnFail="$RET"
    db_get clamav-milter/RejectMsg || true
    RejectMsg="$RET"
    db_get clamav-milter/AddHeader || true
    AddHeader="$RET"
    db_get clamav-milter/LogFile || true
    LogFile="$RET"
    db_get clamav-milter/LogFileUnlock || true
    LogFileUnlock="$RET"
    db_get clamav-milter/LogFileMaxSize || true
    LogFileMaxSize="$RET"
    db_get clamav-milter/LogTime || true
    LogTime="$RET"
    db_get clamav-milter/LogSyslog || true
    LogSyslog="$RET"
    db_get clamav-milter/LogFacility || true
    LogFacility="$RET"
    db_get clamav-milter/LogVerbose || true
    LogVerbose="$RET"
    db_get clamav-milter/LogInfected || true
    LogInfected="$RET"
    db_get clamav-milter/LogClean || true
    LogClean="$RET"
    db_get clamav-milter/MaxFileSize || true
    maxfilesize="`echo $RET | sed -e s/M//g`"
    MaxFileSize="${maxfilesize}M"
    db_get clamav-milter/LogRotate || true
    LogRotate="$RET"
    db_get clamav-milter/SupportMultipleRecipients || true
    SupportMultipleRecipients="$RET"

    if [ -z "$LogFile" ] || [ "$LogFile" = 'none' ]; then
      LogSyslog=true
    fi

    if is_false $AddHeader; then
      AddHeader=no
    elif is_true $AddHeader; then
      AddHeader=Replace
    fi

    # Test for the broken versions, see #741675.
    if [ "$2" = "0.98.1+dfsg-3" ] || [ "$2" = "0.98.1+dfsg-1+deb7u2" ] || [ "$2" = "0.98.1+dfsg-1+deb6u2" ]; then
      # Use the defaults instead of the bogus values created by that versions.
      db_metaget clamav-milter/LogRotate default || true
      LogRotate="$RET"
      db_metaget clamav-milter/SupportMultipleRecipients default || true
      SupportMultipleRecipients="$RET"
    fi

    echo "#Automatically Generated by clamav-milter postinst" > $DEBCONFFILE
    echo "#To reconfigure clamav-milter run #dpkg-reconfigure clamav-milter" >> $DEBCONFFILE
    echo "#Please read /usr/share/doc/clamav-base/README.Debian.gz for details" >> $DEBCONFFILE
    [ -z "$MilterSocket" ] || [ "$MilterSocket" = 'true' ] && MilterSocket="/var/run/clamav/clamav-milter.ctl"
    [ -z "$User" ] && User=clamav
    [ -z "$AllowSupplementaryGroups" -o -n "$AddGroups" ] && AllowSupplementaryGroups=true
    [ -z "$OnClean" ] || [ "$OnClean" = 'true' ] && OnClean="Accept"
    [ -z "$MaxFileSize" ] && MaxFileSize="25M"

    cat >> $DEBCONFFILE << EOF
MilterSocket $MilterSocket
FixStaleSocket $Fixstalesocket
User $User
AllowSupplementaryGroups $AllowSupplementaryGroups
ReadTimeout $ReadTimeout
Foreground $Foreground
PidFile $PidFile
ClamdSocket $ClamdSocket
OnClean $OnClean
OnInfected $OnInfected
OnFail $OnFail
AddHeader $AddHeader
LogSyslog $LogSyslog
LogFacility $LogFacility
LogVerbose $LogVerbose
LogInfected $LogInfected
LogClean $LogClean
LogRotate $LogRotate
MaxFileSize $MaxFileSize
SupportMultipleRecipients $SupportMultipleRecipients
EOF
    if [ -n "$SkipAuthenticated" ]; then
      cat >> $DEBCONFFILE << EOF
SkipAuthenticated $SkipAuthenticated
EOF
    fi

    if [ -n "$Chroot" ]; then
      cat >> $DEBCONFFILE << EOF
Chroot $Chroot
EOF
    fi

    if [ -n "$LocalNet" ]; then
      cat >> $DEBCONFFILE << EOF
LocalNet $LocalNet
EOF
    fi

    if [ -n "$Whitelist" ]; then
      cat >> $DEBCONFFILE << EOF
Whitelist $Whitelist
EOF
    fi

    if [ -n "$RejectMsg" ]; then
      cat >> $DEBCONFFILE << EOF
RejectMsg $RejectMsg
EOF
    fi

    if [ -n "$TemporaryDirectory" ]; then
	cat >> $DEBCONFFILE << EOF
TemporaryDirectory $TemporaryDirectory
EOF
    else
	cat >> $DEBCONFFILE << EOF
# TemporaryDirectory is not set to its default /tmp here to make overriding
# the default with environment variables TMPDIR/TMP/TEMP possible
EOF
    fi

    if [ -n "$LogFile" ] && [ "$LogFile" != 'none' ]; then
      echo "LogFile $LogFile" >> $DEBCONFFILE
      echo "LogTime $LogTime" >> $DEBCONFFILE
      echo "LogFileUnlock $LogFileUnlock" >> $DEBCONFFILE
      echo "LogFileMaxSize $LogFileMaxSize" >> $DEBCONFFILE
    fi

    [ -n "$MilterSocketGroup" ] && echo "MilterSocketGroup $MilterSocketGroup" >> $DEBCONFFILE
    [ -n "$MilterSocketMode" ] && echo "MilterSocketMode $MilterSocketMode" >> $DEBCONFFILE
    [ -n "$ReportHostname" ] && echo "ReportHostname $ReportHostname" >> $DEBCONFFILE
    [ -n "$VirusAction" ] && echo "VirusAction $VirusAction" >> $DEBCONFFILE

    ucf_cleanup "$CLAMAVMILTERCONF"
    ucf_upgrade_check "$CLAMAVMILTERCONF" "$DEBCONFFILE" /var/lib/ucf/cache/:etc:clamav:clamav-milter.conf
    rm -f "$DEBCONFFILE"

    if [ -n "$AddGroups" ]; then
      for group in $AddGroups; do
        id "$User" | grep -q "$group" || adduser "$User" "$group"
      done
    fi
    
  else
    ucf_cleanup "$CLAMAVMILTERCONF"
    ucf_upgrade_check "$CLAMAVMILTERCONF" /usr/share/doc/clamav-milter/examples/clamav-milter.conf.sample /var/lib/ucf/cache/:etc:clamav:clamav-milter.conf
  fi

  if [ -f "$CLAMAVMILTERCONF" ] && [ ! -L "$CLAMAVMILTERCONF" ]; then
    chmod 644 $CLAMAVMILTERCONF || true
    chown root:root $CLAMAVMILTERCONF || true
  fi
  
  if [ -n "$LogFile" ] && [ "$LogFile" != 'none' ]; then
    if echo "$LogFile" | grep -q '^/dev/'; then
      make_logrotate=false
    else
      if [ "$LogRotate" = "true" ]; then
        make_logrotate=true
      else
        make_logrotate=false
      fi
    fi
    if [ "$make_logrotate" = 'true' ]; then
      echo "$LogFile {" > $DEBROTATEFILE
      echo "     rotate 12" >> $DEBROTATEFILE
      echo "     weekly" >> $DEBROTATEFILE
      echo "     compress" >> $DEBROTATEFILE
      echo "     delaycompress" >> $DEBROTATEFILE
      echo "     create 640  $User adm" >> $DEBROTATEFILE
      echo "     postrotate" >> $DEBROTATEFILE
      echo "     /etc/init.d/clamav-milter restart > /dev/null || true" >> $DEBROTATEFILE
      echo "     endscript" >> $DEBROTATEFILE
      echo "     }" >> $DEBROTATEFILE
      touch "$LogFile"
      if [ -f "$LogFile" ] && [ ! -L "$LogFile" ]; then
        chown "$User":adm "$LogFile"
        chmod 0640 "$LogFile"
      fi
      ucf_cleanup "$CLAMAVROTATEFILE"
      ucf_upgrade_check "$CLAMAVROTATEFILE" "$DEBROTATEFILE" /var/lib/ucf/cache/:etc:logrotate.d:clamav-milter
      rm -f $DEBROTATEFILE
    else
      if [ -e "$CLAMAVROTATEFILE" ]; then
        echo "Disabling old logrotate script for clamav-milter"
        mv "$CLAMAVROTATEFILE" "$CLAMAVROTATEFILE".dpkg-old
        ucf -p "$CLAMAVROTATEFILE"
      fi
    fi
  else
    if [ -e "$CLAMAVROTATEFILE" ]; then
      echo "Disabling old logrotate script for clamav-milter"
      mv "$CLAMAVROTATEFILE" "$CLAMAVROTATEFILE".dpkg-old
      ucf -p "$CLAMAVROTATEFILE"
    fi
  fi
  db_stop || true
  ;;
  abort-upgrade|abort-remove|abort-deconfigure)
  ;;
  *)
  echo "postinst called with unknown argument \`$1'" >&2
  exit 1
  ;;
esac

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

# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/clamav-milter" ]; then
		update-rc.d clamav-milter defaults >/dev/null
	fi
	if [ -x "/etc/init.d/clamav-milter" ] || [ -e "/etc/init/clamav-milter.conf" ]; then
		invoke-rc.d clamav-milter start || exit $?
	fi
fi
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper rm_conffile /etc/default/clamav-milter 0.98.5~beta1+dfsg-3~ clamav-milter -- "$@"
# End automatically added section


exit 0