Gentoo ebuild for simscan 1.2

From Qmailwiki
Jump to: navigation, search

Explains how to cleanly install simscan on gentoo systems using a custom ebuild that nicely integrates with the rest of the system so you do not have to fear about vital files being overwritten by portage after you hacked up your system.

Create a portage overlay

If you do not already have one, create a portage overlay directory. Normally, portage searches for its ebuilds in /usr/portage, where the official gentoo ebuilds are stored. An overlay is an ebuild directory where portage will look before checking the official ebuild repository.

You create a portage overlay by adding the following line to your /etc/make.conf:

# /etc/make.conf

# Add this line to set up a portage overlay

Of course, if you don't have a /usr/local/portage directory yet, you'll have to create it.

Create the simscan ebuild

A good place to put our simscan ebuild is /usr/local/portage/mail-filter/simscan, so we'll create this directory now:

mkdir -p /usr/local/portage/mail-filter/simscan

Then use your favority text editor to create a new file at /usr/local/portage/mail-filter/simscan/simscan-1.2.ebuild with the following contents:

# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit toolchain-funcs eutils fixheadtails flag-o-matic

DESCRIPTION="simscan is a powerful qmail content scanner."

DEPEND="|| ( mail-mta/qmail-ldap mail-mta/qmail mail-mta/qmail-mysql)
        pcre? ( >=dev-libs/libpcre-5.0 )


# Where will simscan unpack mail messages for scanning?

# User simscan will run as.  "simscan" is the default.

# For us with --enable-spamc-args, below:

append-flags "-Wl,-z,now"

pkg_setup() {
        einfo "Creating user and working directory..."
        enewuser ${simscan_user} -1 -1 ${simscan_workdir} clamav
        pwconv || die

src_unpack() {
        unpack ${P}.tar.gz
        cd ${S}

src_compile() {

        local myconf


        # "simscan" is the default user.  If you want to change this, please us$
        #       variable above.
        myconf="${myconf} --enable-user=${simscan_user}"

        # Directory where simscan will scan messages.  Please edit variable abo$
        #       to change this value.
        myconf="${myconf} --enable-workdir=${simscan_workdir}"

        # If you want to keep SPAM/virus messages in a quarantine, uncomment th$
        # myconf="${myconf} --enable-quarantinedir=${simscan_workdir}/quarantin$

        # Scanning attachments is a good idea, eh?
        myconf="${myconf} --enable-attach=y"

        # If scanning for attachments, we need ripmime:
        myconf="${myconf} --enable-ripmime=`which ripmime`"

        # Allow different configuration rules for different domains.  This ebui$
        #       provides a reasonable default "catchall" rule, so leaving this $
        #       won't really hurt anything.
        myconf="${myconf} --enable-per-domain=y"

        # clamav is enabled by default.  Change to "n" and uncomment to disable
        # myconf="${myconf} --enable-clamav=y"

        # Tell simscan where the clamdscan binary is.  This option does nothing$
        #       clamav is not enabled.
        myconf="${myconf} --enable-clamdscan=`which clamdscan`"

        # spamassassin scanning is enabled.  Uncomment the 'spamc-args' line
        #       to pass custom arguments to spamc.
        myconf="${myconf} --enable-spam=y"
        myconf="${myconf} --enable-spamc=`which spamc`"
        # myconf="${myconf} --enable-spamc-args='${spamc_args}'"

        # By default, this installation will reject any message with
        #       a spamassassin score > 4
        myconf="${myconf} --enable-spam-hits=4"
        #myconf="${myconf} --enable-dropmsg=y"

        # If you want SPAM/virus messages to go on to their intended user,
        #       uncomment the following line and comment out "spam-hits" and "d$
        #       above
        # myconf="${myconf} --enable-spam-passthru

        # If you want to set up super-funky per-user spam scanning options, rea$
        #       docs and change this to "y"
        myconf="${myconf} --enable-spam-user=n"

        # Enable regular expression scanning if 'pcre' is in USE
        myconf="${myconf} `use_enable pcre regex`"
        # This adds a "Received:" header to scanned e-mail, showing how many sc$
        #       simscan invoked.  If you comment this out, you can comment out $
        #       below.
        #myconf="${myconf} --enable-received=y"

        # Path information for 'enable-received'
        #myconf="${myconf} --enable-clamavdb-path=/var/lib/clamav"
        #myconf="${myconf} --enable-sigtool-path=`which sigtool`"
        #myconf="${myconf} --enable-spamassassin-path=`which spamassassin`"

        econf ${myconf} || die

        emake || die

src_install() {

        insopts -o simscan -g clamav -m 0755
        insinto /var/qmail/bin
        doins simscanmk

        insopts -o simscan -g clamav -m 4755
        insinto /var/qmail/bin
        doins simscan

        einfo "Creating documentation..."
        dodoc README
        dodoc TODO
        dodoc AUTHORS

        einfo "Setting default configuration..."
        touch simcontrol
        echo :clam=yes,spam=yes,$
        insopts -o root -g root -m 644
        insinto /var/qmail/control
        doins simcontrol

        touch ssattach
        insopts -o root -g root -m 644
        insinto /var/qmail/control
        doins ssattach

        keepdir ${simscan_workdir}

pkg_preinst() {
        einfo "Creating user and directory..."
        enewuser simscan -1 /bin/false /var/spool/simscan clamav
        diropts -m 2775 -o simscan -g clamav
        dodir ${simscan_workdir}

pkg_postinst() {
        einfo "To activate simscan, please edit your"
        einfo "/var/qmail/control/conf-common file and set:"
        einfo "export QMAILQUEUE=/var/qmail/bin/simscan"
        einfo "or place it in your tcprules file."
    echo ""
        echo ""
        einfo "Running '/var/qmail/bin/simscanmk' & '/var/qmail/bin/simscanmk -$
        einfo "your configuration."
        einfo " `/var/qmail/bin/simscanmk` "
        einfo " `/var/qmail/bin/simscanmk -g`"
        echo ""
        echo ""
        ewarn "Simscan has been configured to block the following attachments b$
        ewarn " .scr:    Windows screensavers"
        ewarn " .bat:    'DOS' batch file executables"
        ewarn " .com:    Windows command files"
        ewarn " .pif:    Windows Program Information File"
        ewarn " .exe:    Windows executables"
        ewarn " .vb*:    Visual Basic Attachments"
        ewarn " .reg:    Windows Registry data"
        ewarn " .msi:    Microsoft Installer files"
        ewarn " .dll:    Windows dynamic libraries"
        ewarn "Read the documentation and see /var/qmail/control/simcontrol"
        echo ""

pkg_postrm() {

        if  ! has_version =mail-filter/${P}  ; then

                ewarn " If you are removing this package for good, don't forget$
                echo ""
                ewarn "         rm -f /var/qmail/control/sim*"
                ewarn " and"
                ewarn "         userdel -r ${simscan_user}"
                echo  ""



As every time you do something to an ebuild, you have to update its md5 checksums by typing

ebuild simscan-1.2.ebuild digest

Test it

You should now be able to properly set up simscan on your system simply by typing

emerge simscan

What remains to do is adding /var/qmail/bin/simscan instead of /var/qmail/bin/qmail-queue into your /etc/tcprules.d/tcp.qmail-smtp or your domain specific qmail configuration file.

Personal tools