#!/bin/sh # $Id: clamav.SlackBuild,v 1.35 2008/07/08 21:52:23 root Exp root $ # Copyright (c) 2006 Eric Hameleers # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ----------------------------------------------------------------------------- # Slackware SlackBuild script # =========================== # By: Eric Hameleers # For: clamav # URL: http://clamav.net/ # Needs: # Changelog: # 0.80-1: 30/nov/2004 by Eric Hameleers # * Initial build. # 0.80-2: 02/dec/2004 by Eric Hameleers # * Fix permissions on "/var/run/clamav" directory # 0.81-1: 02/feb/2005 by Eric Hameleers # * Rebuilt for new version # 0.83-1: 15/feb/2005 by Eric Hameleers # * Rebuilt for new version # 0.83-2: 15/feb/2005 by Eric Hameleers # * Patch freshclam.conf and clamav.conf for better package # defaults. Make rc.clamav executable. Add option to rc.clamav # to disable milter support. # 0.84-1: 30/apr/2005 by Eric Hameleers # * Rebuilt for new version # 0.85-1: 14/may/2005 by Eric Hameleers # * Add '--enable-id-check' to configure command. # 0.85.1-1: 21/may/2005 by Eric Hameleers # * Rebuilt for the new release. # 0.86.1-1: 27/jun/2005 by Eric Hameleers # * Rebuilt for the new release. # 0.86.2-1: 27/jul/2005 by Eric Hameleers # * Rebuilt for the new release. # 0.87-1: 16/sep/2005 by Eric Hameleers # * Rebuilt for the new release. Removed 'contrib' from the doc # directory as none of it makes any sense. # 0.87.1-1: 08/nov/2005 by Eric Hameleers # * Rebuilt for the new release. # 0.88-1: 10/jan/2006 by Eric Hameleers # * Rebuilt for the new release. # 0.88.1-1: 04/apr/2006 by Eric Hameleers # * Rebuilt for the new release. # 0.88.2-1: 29/may/2006 by Eric Hameleers # * Rebuilt for the new release. # 0.88.2-2: 15/jun/2006 by Eric Hameleers # * Fixed permission for directory '/var/run/clamav' again # (it is now 771 so that the AllowSupplementaryGroups works) # 0.88.3-1: 22/jul/2006 by Eric Hameleers # * Rebuilt for the new release. Since 'configure' now uses the new # DATAROOTDIR, explicitly configure the mandir. # 0.88.4-1: 10/aug/2006 by Eric Hameleers # * Rebuilt for the new release. # 0.88.5-1: 18/oct/2006 by Eric Hameleers # * Rebuilt for the new release. # 0.88.6-1: 07/nov/2006 by Eric Hameleers # * New release. Patched the default value of 'DatabaseDirectory' in # the /etc/*.conf files to be '/usr/share/clamav', to reflect what # this package uses instead of '/var/lib/clamav'. Also correctly # creates clamav user/group and assigns ownership if the target # root is not that of the running machine (using chroot). # 0.88.7-1: 13/dec/2006 by Eric Hameleers # * New release. # 0.90-1: 14/feb/2007 by Eric Hameleers # * New release. Since clamav's .conf files changed quite a bit, # I had to re-do the .patch files. # 0.90.1-1: 05/mar/2007 by Eric Hameleers # * New release. # 0.90.2-1: 16/apr/2007 by Eric Hameleers # * New release. # 0.90.3-1: 02/jun/2007 by Eric Hameleers # * New release. # 0.91.1-1: 23/jul/2007 by Eric Hameleers # * New release. # 0.91.2-1: 22/aug/2007 by Eric Hameleers # * New release. # 0.92-1: 22/dec/2007 by Eric Hameleers # * New release. # 0.92.1-1: 13/feb/2008 by Eric Hameleers # * New release. And the day I buried my dad. # 0.93-1: 15/apr/2008 by Eric Hameleers # * New release. Note that if you build this release while you # still have a previous clamav package installed, the binaries # will link dynamically to the present libclamunrar_iface.so.3 # which will be gone after you run upgradepkg. This results in # runtime errors. Remedy: build this release after removing an # existing clamav from your disk. # 0.93.1-1: 10/jun/2008 by Eric Hameleers # * New release. # 0.93.3-1: 09/jul/2008 by Eric Hameleers # * New release. # # Run 'sh clamav.SlackBuild --cleanup' to build a Slackware package. # The package (.tgz) plus descriptive .txt file are created in /tmp . # Install using 'installpkg'. # # ----------------------------------------------------------------------------- # Set initial variables: PRGNAM=clamav VERSION=${VERSION:-"0.93.3"} ARCH=${ARCH:-"i486"} BUILD=${BUILD:-1} TAG=${TAG:-alien} # Read "README.slackware" for compatibility with amavisd-new CLAMUSR=clamav CLAMGRP=clamav # Where do we look for sources? SRCDIR=$(cd $(dirname $0); pwd) # Place to build (TMP) package (PKG) and output (OUTPUT) the program: TMP=${TMP:-"/tmp/build"} PKG=$TMP/package-$PRGNAM OUTPUT=${OUTPUT:-"/tmp"} # Exit the script on errors: set -e trap 'echo "$0 FAILED at line $LINENO!" | tee $OUTPUT/error-${PRGNAM}.log' ERR # Catch unitialized variables: set -u P1=${1:-1} SOURCE="$SRCDIR/${PRGNAM}-${VERSION}.tar.gz" SRCURL="http://downloads.sourceforge.net/${PRGNAM}/${PRGNAM}-${VERSION}.tar.gz" ## ## --- with a little luck, you won't have to edit below this point --- ## ## # Slackware 11 and up need other option (gcc > 3.3.x) if [ $(gcc -dumpversion | tr -d '.' |cut -c 1-2) -gt 33 ]; then MOPT=tune else MOPT=cpu fi case "$ARCH" in i486) SLKCFLAGS="-O2 -march=i486 -m${MOPT}=i686" SLKLDFLAGS=""; LIBDIRSUFFIX="" ;; s390) SLKCFLAGS="-O2" SLKLDFLAGS=""; LIBDIRSUFFIX="" ;; powerpc) SLKCFLAGS="-O2" SLKLDFLAGS=""; LIBDIRSUFFIX="" ;; x86_64) SLKCFLAGS="-O2 -fPIC" SLKLDFLAGS="-L/usr/lib64"; LIBDIRSUFFIX="64" ;; athlon-xp) SLKCFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" SLKLDFLAGS=""; LIBDIRSUFFIX="" ;; esac # Prepare a sane build environment: mkdir -p $TMP/tmp-$PRGNAM # location to build the source rm -rf $TMP/tmp-$PRGNAM/* # remove the remnants of previous build mkdir -p $PKG # place for the package to be built rm -rf $PKG/* # erase old package's contents mkdir -p $OUTPUT # place for the package to be saved # Source file availability: if ! [ -f ${SOURCE} ]; then if ! [ "x${SRCURL}" == "x" ]; then # Check if the $SRCDIR is writable at all - if not, download to $OUTPUT [ -w "$SRCDIR" ] || SOURCE="$OUTPUT/$(basename $SOURCE)" echo "Source '${SOURCE}' not available yet... will download now:" wget -nv -T 30 -O "${SOURCE}" "${SRCURL}" || true if [ $? -ne 0 -o ! -s "${SOURCE}" ]; then echo "Downloading '${SOURCE}' failed... aborting the build." mv -f "${SOURCE}" "${SOURCE}".FAIL exit 1 fi else echo "File '${SOURCE}' not available... aborting the build." exit 1 fi fi if [ "$P1" == "--download" ]; then echo "Download complete." exit 0 fi # --- PACKAGE BUILDING --- echo "++" echo "|| $PRGNAM-$VERSION" echo "++" cd $TMP/tmp-$PRGNAM echo "Extracting the source archive(s) for $PRGNAM..." tar -xzvf $SOURCE cd ${PRGNAM}-${VERSION} chown -R root:root . chmod -R u+w,go+r-w,a-s . # Compiling the package source: echo Building ... # We need the "clamav" user and group to exist at the time of # configuring the software... # Add the 'clamav' group if it doesn't already exist: /usr/sbin/groupadd ${CLAMGRP} 2> /dev/null || true # Add the 'clamav' user if it doesn't exist already: /usr/sbin/useradd -c "ClamAV user" -g ${CLAMGRP} \ -s "/bin/false" ${CLAMUSR} 2> /dev/null || true LDFLAGS="$SLKLDFLAGS" \ CFLAGS="$SLKCFLAGS" \ CXXFLAGS="$SLKCFLAGS" \ ./configure --prefix=/usr \ --libdir=/usr/lib${LIBDIRSUFFIX} \ --localstatedir=/var \ --sysconfdir=/etc \ --mandir=/usr/man \ --with-user=${CLAMUSR} --with-group=${CLAMGRP} \ --with-dbdir=/usr/share/clamav \ --with-libcurl \ --with-tcpwrappers \ --enable-milter \ --enable-id-check \ --disable-static \ 2>&1 | tee $OUTPUT/configure-${PRGNAM}.log make 2>&1 | tee $OUTPUT/make-${PRGNAM}.log cd etc patch < $SRCDIR/clamd.conf.patch 2>&1 | tee $OUTPUT/patch-${PRGNAM}.log patch < $SRCDIR/freshclam.conf.patch 2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log cd - # Install all the needed stuff to the package dir; # Use installwatch if available: if $(which installwatch > /dev/null 2>&1); then installwatch -o $OUTPUT/install-${PRGNAM}.log make DESTDIR=$PKG install else make DESTDIR=$PKG install 2>&1 |tee $OUTPUT/install-${PRGNAM}.log fi # Prepare the config files: cd $PKG/etc mv clamd.conf clamd.conf.new mv freshclam.conf freshclam.conf.new cd - # Where to store the pid file: mkdir -p $PKG/var/run/clamav # Our rc script: mkdir -p $PKG/etc/rc.d/ cp $SRCDIR/rc.clamav $PKG/etc/rc.d/rc.clamav.new chown root:root $PKG/etc/rc.d/rc.clamav.new chmod 754 $PKG/etc/rc.d/rc.clamav.new # Add a post-install script: mkdir -p $PKG/install cat < $PKG/install/doinst.sh # Handle the incoming configuration files: config() { for infile in \$1; do NEW="\$infile" OLD="\`dirname \$NEW\`/\`basename \$NEW .new\`" # If there's no config file by that name, mv it over: if [ ! -r \$OLD ]; then mv \$NEW \$OLD elif [ "\`cat \$OLD | md5sum\`" = "\`cat \$NEW | md5sum\`" ]; then # toss the redundant copy rm \$NEW fi # Otherwise, we leave the .new copy for the admin to consider... done } config etc/freshclam.conf.new config etc/clamd.conf.new config etc/rc.d/rc.clamav.new # Create log files touch var/log/clamd.log touch var/log/freshclam.log # Only way to create and use the correct uid and gid on the target system, # is to use chroot: chroot . </dev/null # Add the '${CLAMGRP}' group if it doesn't already exist: # Actually, the use of "amavis" group is for compatibility with amavisd-new. /usr/sbin/groupadd ${CLAMGRP} 2> /dev/null # Add the '${CLAMUSR}' user if it doesn't already exist: /usr/sbin/useradd -c "ClamAV user" \\ -g ${CLAMGRP} -s "/bin/false" ${CLAMUSR} 2> /dev/null # Restore the correct permissions chown ${CLAMUSR} usr/sbin/clamav-milter chmod 4700 usr/sbin/clamav-milter chown -R ${CLAMUSR}:${CLAMGRP} var/run/clamav chmod 771 var/run/clamav chown ${CLAMUSR}:${CLAMGRP} var/log/clamd.log chmod 660 var/log/clamd.log chown ${CLAMUSR}:${CLAMGRP} var/log/freshclam.log chmod 660 var/log/freshclam.log chown -R ${CLAMUSR}:${CLAMGRP} usr/share/clamav chmod -R 770 usr/share/clamav EOR EOINS # --- End of 'doinst.sh' script ----------- # Add documentation: cp $SRCDIR/00README.slackware README.slackware cp -a clamav-milter/INSTALL INSTALL.milter DOCS="AUTHORS BUGS COPYING ChangeLog FAQ INSTALL NEWS README TODO UPGRADE \ docs/*.pdf docs/html examples \ INSTALL.milter \ README.slackware" mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION cp -a $DOCS $PKG/usr/doc/$PRGNAM-$VERSION || true cp -a $SRCDIR/$(basename $0) $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild chown -R root:root $PKG/usr/doc/$PRGNAM-$VERSION find $PKG/usr/doc -type f -exec chmod 644 {} \; # Compress the man page(s): find $PKG/usr/man -type f -name "*.?" -exec gzip -9f {} \; # Strip binaries: cd $PKG find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true cd - # Add a package description: mkdir -p $PKG/install cat $SRCDIR/slack-desc > $PKG/install/slack-desc if [ -f $SRCDIR/doinst.sh ]; then cat $SRCDIR/doinst.sh >> $PKG/install/doinst.sh fi # Set ownership to root - the doinst.sh will set things straight again: chown -R root:root $PKG # Build the package: cd $PKG makepkg --linkadd y --chown n $OUTPUT/$PRGNAM-$VERSION-$ARCH-${BUILD}${TAG}.tgz 2>&1 | tee $OUTPUT/makepkg-${PRGNAM}.log cd $OUTPUT md5sum $PRGNAM-$VERSION-$ARCH-${BUILD}${TAG}.tgz > $PRGNAM-$VERSION-$ARCH-${BUILD}${TAG}.tgz.md5 cd - cat $PKG/install/slack-desc | grep "^${PRGNAM}" > $OUTPUT/$PRGNAM-$VERSION-$ARCH-${BUILD}${TAG}.txt # Cleanup: if [ "$P1" = "--cleanup" ]; then rm -rf $TMP/tmp-$PRGNAM rm -rf $PKG fi