#!/bin/sh # $Id$ # 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 # * Rew 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 # * Rew release. # 0.90-1: 14/feb/2007 by Eric Hameleers # * Rew 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 # * Rew release. # 0.90.2-1: 16/apr/2007 by Eric Hameleers # * Rew 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'. # # ----------------------------------------------------------------------------- # --- INIT --- # Set initial variables: PRGNAM=clamav VERSION=${VERSION:-0.90.2} ARCH=${ARCH:-i486} BUILD=${BUILD:-1} # Read "README.slackware" for compatibility with amavisd-new CLAMUSR=clamav CLAMGRP=clamav # Where do we look for sources? CWD=`pwd` SRCDIR=`dirname $0` [ "${SRCDIR:0:1}" == "." ] && SRCDIR=${CWD}/${SRCDIR} # 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://dl.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 i386) SLKCFLAGS="-O2 -march=i386 -m${MOPT}=i686" SLKLDFLAGS=""; LIBDIRSUFFIX="" ;; 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 if [ ! -d $TMP/tmp-$PRGNAM ]; then mkdir -p $TMP/tmp-$PRGNAM # location to build the source elif [ "$P1" != "--oldbuild" ]; then # If the "--oldbuild" parameter is present, we keep # the old build files and continue; # By default we remove the remnants of previous build and continue: rm -rf $TMP/tmp-$PRGNAM/* fi if [ "$PKG" = "" -o "$PKG" = "/" ] ; then echo "Please provide a sane value for the variable 'PKG'." exit 1 elif [ ! -d $PKG ]; then mkdir -p $PKG # place for the package to be built else rm -rf $PKG/* # We always erase old package's contents: fi if [ ! -d $OUTPUT ]; then mkdir -p $OUTPUT # place for the package to be saved fi # --- 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 -O "${SOURCE}" "${SRCURL}" || true if [ $? -ne 0 ]; 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 * # --- BUILDING --- 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" \ ./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 # --- POST-INSTALL SCRIPT --- # # # --- Fabricate the 'doinst.sh' 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 ----------- # --- 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 chmod -R a-w $PKG/usr/doc/$PRGNAM-$VERSION/* # 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 - # --- OWNERSHIP, RIGHTS --- chmod -R o-w $PKG # --- 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 # --- BUILDING --- # Build the package: cd $PKG makepkg --linkadd y --chown n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD.tgz 2>&1 | tee $OUTPUT/makepkg-${PRGNAM}.log cd $OUTPUT md5sum $PRGNAM-$VERSION-$ARCH-$BUILD.tgz > $PRGNAM-$VERSION-$ARCH-$BUILD.tgz.md5 cd - cat $PKG/install/slack-desc | grep "^${PRGNAM}" > $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD.txt # --- CLEANUP --- # Clean up the extra stuff: if [ "$P1" = "--cleanup" ]; then rm -rf $TMP/tmp-$PRGNAM rm -rf $PKG fi