#Added by buildpkg 1.7.0
dotnew() {
        NEW="${1}.new"
        OLD="$1"
        if [ ! -e $OLD ]; then
                mv $NEW $OLD
        elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
                rm $NEW
        fi
}
dotnew etc/clamav/clamd.conf
dotnew etc/clamav/freshclam.conf
dotnew etc/clamav/clamav-milter.conf
doinst() {
	# Post-install procedures
	
	# Define minimum values for UID and GID
	MUID=43
	MGID=43
	USERNAME=clamav
	GROUPNAME=clamav
	COMMENT=ClamAV
	HOMEDIR=/var/lib/clamav

	(
	if ! grep -qe "^$GROUPNAME:" etc/group; then
		NEXTGID="$(MGID=$MGID awk -F: '{uid[$3]=1} END { for (i=ENVIRON["MGID"];i in uid;i++);print i}' etc/group)"
		chroot . /usr/sbin/groupadd -g $NEXTGID $GROUPNAME
	fi
	)
	(
	if ! grep -qe "^$USERNAME:" etc/passwd; then
		NEXTUID="$(MUID=$MUID awk -F: '{uid[$3]=1} END { for (i=ENVIRON["MUID"];i in uid;i++);print i}' etc/passwd)"
		chroot . /usr/sbin/useradd -g $GROUPNAME -u $NEXTUID -d $HOMEDIR -c $COMMENT -s /bin/false $USERNAME
	fi
	)
	chown -R ${USERNAME}:${GROUPNAME} var/lib/clamav

	# Create logs with right accesses out of convenience
	if [ ! -e /var/log/freshclam.log ]; then
		echo -n >> /var/log/freshclam.log
		chown ${USERNAME}:${GROUPNAME} /var/log/freshclam.log
	fi
	if [ ! -e /var/log/clamd.log ]; then
		echo -n >> /var/log/clamd.log
		chown ${USERNAME}:${GROUPNAME} /var/log/clamd.log
	fi

	# And we are done END
}
doinst
( cd usr/lib ; rm -rf libclamav.so )
( cd usr/lib ; ln -sf libclamav.so.6.1.9 libclamav.so )
( cd usr/lib ; rm -rf libclamunrar_iface.so )
( cd usr/lib ; ln -sf libclamunrar_iface.so.6.1.9 libclamunrar_iface.so )
( cd usr/lib ; rm -rf libclamunrar_iface.so.6 )
( cd usr/lib ; ln -sf libclamunrar_iface.so.6.1.9 libclamunrar_iface.so.6 )
( cd usr/lib ; rm -rf libclamunrar.so )
( cd usr/lib ; ln -sf libclamunrar.so.6.1.9 libclamunrar.so )
( cd usr/lib ; rm -rf libclamunrar.so.6 )
( cd usr/lib ; ln -sf libclamunrar.so.6.1.9 libclamunrar.so.6 )
( cd usr/lib ; rm -rf libclamav.so.6 )
( cd usr/lib ; ln -sf libclamav.so.6.1.9 libclamav.so.6 )
