contrib/split-tarball.sh
00c3dfe5
 #!/bin/bash
8470c0d4
 # Split an upstream tarball into +dfsg, and libclamunrar.
00c3dfe5
 if test $# -ne 2; then
     echo -e "Usage: $0 <PATH> <VERSION>\n\t<PATH> - directory that contains clamav-<VERSION>.tar.gz";
     exit 1;
 fi
 
 test -d $1 || { echo "Directory $1 doesn't exist"; exit 2; }
8470c0d4
 TARBALL="$PWD/$1/clamav-$2.tar.gz"
00c3dfe5
 test -f $TARBALL || { echo "Tarball $TARBALL doesn't exist"; exit 3; }
 
 TEMP=`mktemp -d __splitXXXXXX` || { echo "Cannot create temporary directory"; exit 2; }
 echo "Temporary directory is $TEMP"
 cd $TEMP || exit 3;
 echo "Extracting $TARBALL";
 tar -xzf $TARBALL || { echo "Failed to extract $TARBALL"; exit 4; }
 
8470c0d4
 UNRARPKG=libclamunrar_$2.orig.tar.gz
 DFSGPKG=clamav_$2+dfsg.orig.tar.gz
 UNRARDIR="libclamunrar-$2"
00c3dfe5
 MAKEFLAGS=-j4
 
8470c0d4
 set -e
 
 mv clamav-$2 clamav-$2+dfsg
 mkdir $UNRARDIR
 UNRARDIR="$PWD/$UNRARDIR"
 echo "Preparing dfsg package"
 cd clamav-$2+dfsg
 cp -R libclamunrar_iface $UNRARDIR
 mv libclamunrar $UNRARDIR
 cp -R m4/ $UNRARDIR
 cp -R config/ $UNRARDIR
 cp configure.in $UNRARDIR
7930508b
 cp platform.h.in $UNRARDIR
8470c0d4
 cp COPYING{,.unrar,.LGPL} $UNRARDIR
 cd ../
 tar -czf $DFSGPKG clamav-$2+dfsg/
 cd $UNRARDIR
 echo "Preparing unrar package"
7930508b
 # The sed sorcery below makes sure that the AC_OUTPUT in the unrar package looks
 # like:
 # AC_OUTPUT([
 # libclamunrar_iface/Makefile
 # Makefile
 # platform.h
 # ])
 # It also removes ltdl, and renames the AC_CONFIG_SRCDIR parameter to an
 # existing file.
8470c0d4
 sed -i '/AC_OUTPUT/,/])/ {
7930508b
 /^AC_OUTPUT(\[$/p
 s/^clamscan\/Makefile/libclamunrar_iface\/Makefile/p
00c3dfe5
 /^Makefile/p
7930508b
 /^platform.h/p
00c3dfe5
 /^])/p
 d
 }
 /LTDL/d
 /ltdl/d
 s/clamscan\/clamscan.c/libclamunrar_iface\/unrar_iface.c/
8470c0d4
 ' configure.in
00c3dfe5
 cat <<EOF >Makefile.am &&
 ACLOCAL_AMFLAGS=-I m4
 DISTCLEANFILES = target.h
 SUBDIRS = libclamunrar_iface
 EOF
8470c0d4
 autoreconf
 cd ..
 tar -czf $UNRARPKG libclamunrar-$2/
 
 printf "Test archives?"
 read yes
 if [ x$yes != xy ] ; then
     echo "Copying tarballs to current directory"
     mv $UNRARPKG ../ &&
     mv $DFSGPKG ../ &&
     echo "Ready (untested): $UNRARPKG $DFSGPKG" &&
     rm -rf $TEMP &&
     echo "Removed temporary directory $TEMP" &&
     exit 0
     exit 30
 fi
 
 mkdir testpfx || { echo "Failed to create testpfx"; exit 5; }
 TESTPFX="$PWD/testpfx"
 mkdir buildtest && cd buildtest
 echo "Running build-test for $DFSGPKG"
 tar -xzf ../$DFSGPKG && cd clamav-$2+dfsg
 echo "Configuring"
 ./configure --disable-clamav --disable-unrar --enable-milter --prefix=$TESTPFX >makelog
 echo "Building"
 make $MAKEFLAGS >>makelog
 echo "Checking"
 make $MAKEFLAGS check >>makelog 2>&1
 make $MAKEFLAGS install >>makelog
 make $MAKFELAGS installcheck >>makelog
 echo "OK"
 cd ..
 echo "Running build-test for $UNRARPKG"
 tar -xzf ../$UNRARPKG && cd libclamunrar-$2
 echo "Configuring"
 ./configure --disable-clamav --prefix=$TESTPFX >makelog
 echo "Building"
 make $MAKEFLAGS >>makelog
 make $MAKEFLAGS install >>makelog
 make $MAKEFLAGS installcheck >>makelog
 echo "OK"
 cd ../..
 echo "Testing whether unrar functionality works"
00c3dfe5
 cat <<EOF >test.hdb
 aa15bcf478d165efd2065190eb473bcb:544:ClamAV-Test-File
 EOF
 
 if test $? -ne 0; then
     tail makelog
     echo
     echo "Failed"
     exit 50;
 fi
8470c0d4
 # clamscan will exit with exitcode 1 on success (virus found)
 set +e
 $TESTPFX/bin/clamscan buildtest/clamav-$2+dfsg/test/clam-v*.rar -dtest.hdb >clamscanlog
00c3dfe5
 if test $? -ne 1; then
     echo "Test failed";
     cat clamscanlog
     exit 10;
 fi
 NDET=`grep FOUND clamscanlog | wc -l`
 if test "0$NDET" -eq "2"; then
     echo "All testfiles detected"
     echo "Copying tarballs to current directory"
     mv $UNRARPKG ../ &&
     mv $DFSGPKG ../ &&
     echo "Ready: $UNRARPKG $DFSGPKG" &&
     rm -rf $TEMP &&
     echo "Removed temporary directory $TEMP" &&
     exit 0
     exit 30
 fi
 echo "Test failed"
 cat clamscanlog
 exit 100