#! /bin/sh # postinst script for clamav-milter # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-deconfigure' `in-favour' # `removing' # # 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 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 [ -n "$AllowList" ] && echo "AllowList $AllowList" >> $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 " invoke-rc.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/13.15.3 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -z "${DPKG_ROOT:-}" ] && [ -x "/etc/init.d/clamav-milter" ]; then update-rc.d clamav-milter defaults >/dev/null if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi invoke-rc.d --skip-systemd-native clamav-milter $_dh_action || exit 1 fi fi # End automatically added section exit 0