File: clamav-milter.postinst.in

package info (click to toggle)
clamav 0.101.4+dfsg-0+deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 29,564 kB
  • sloc: ansic: 158,978; sh: 8,178; cpp: 5,173; makefile: 2,088; yacc: 1,351; lex: 714; python: 120; perl: 17
file content (286 lines) | stat: -rw-r--r-- 9,037 bytes parent folder | download | duplicates (3)
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
#! /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

#COMMON-FUNCTIONS#

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 "$OnClean" ] || [ "$OnClean" = 'true' ] && OnClean="Accept"
    [ -z "$MaxFileSize" ] && MaxFileSize="25M"

    cat >> $DEBCONFFILE << EOF
MilterSocket $MilterSocket
FixStaleSocket $Fixstalesocket
User $User
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 -p "$CLAMAVMILTERCONF"
  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.

#DEBHELPER#

exit 0