File: split-tarball.sh

package info (click to toggle)
clamav 0.101.4+dfsg-0+deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 29,564 kB
  • sloc: ansic: 158,978; sh: 8,178; cpp: 5,173; makefile: 2,088; yacc: 1,351; lex: 714; python: 120; perl: 17
file content (177 lines) | stat: -rwxr-xr-x 5,237 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
# Split an upstream tarball into +dfsg, and libclamunrar.
if test $# -ne 2; then
    echo -e "Usage: $0 <PATH> <VERSION>\n\t<PATH> - directory that contains clamav-<VERSION>.tar.gz";
    exit 1;
fi

DIR=$1
VERS=$2

test -d $DIR || { echo "Directory $DIR doesn't exist"; exit 2; }
TARBALL="$PWD/$DIR/clamav-$VERS.tar.gz"
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; }

UNRARPKG=libclamunrar_$VERS.orig.tar.xz
DFSGPKG=clamav_$VERS+dfsg.orig.tar.xz
UNRARDIR="libclamunrar-$VERS"
MAKEFLAGS=-j4

set -e

mv clamav-* clamav-$VERS+dfsg

mkdir $UNRARDIR
UNRARDIR="$PWD/$UNRARDIR"
echo "Preparing dfsg package"
cd clamav-$VERS+dfsg
# remove win32 stuff, doesn't make sense to ship it
rm -rf win32
sed -i 's/ win32//' Makefile.am Makefile.in
sed -i 's@libclammspack/config.h:libclammspack/config.h.in@@' configure.ac
find shared -name '*.la' -o -name '*.lo' -o -name Makefile  -exec rm {} \;
# cleanup llvm
set -- libclamav/c++/llvm/utils/lit/lit/*.pyc
if [ -f "$1" ] ; then
  echo "Pre-compiled python files found!"
  exit 1
fi
rm -rf libclamav/c++/llvm/tools libclamav/c++/llvm/unittests \
 libclamav/c++/llvm/bindings libclamav/c++/llvm/bindings/ocaml \
 libclamav/c++/llvm/examples libclamav/c++/llvm/runtime \
 libclamav/c++/llvm/projects libclamav/c++/llvm/test
# remove llvm, we build with the system version
#rm -rf libclamav/c++/llvm
cp -R libclamunrar_iface $UNRARDIR
cp libclamav/Makefile.am $UNRARDIR/libclamunrar_iface
mv libclamunrar $UNRARDIR
cp -R m4/ $UNRARDIR
cp -R config/ $UNRARDIR
cp configure.ac $UNRARDIR
cp platform.h.in $UNRARDIR
cp COPYING{,.unrar,.LGPL} $UNRARDIR
cd ../
tar -cJf $DFSGPKG --numeric-owner clamav-$VERS+dfsg/
cd $UNRARDIR
echo "Preparing unrar package"
# The sed sorcery below makes sure that the AC_CONFIG_FILES in the unrar package looks
# like:
# AC_CONFIG_FILES([
# libclamunrar_iface/Makefile
# Makefile
# platform.h
# ])
# It also removes ltdl, and renames the AC_CONFIG_SRCDIR parameter to an
# existing file.
sed -i '/AC_CONFIG_FILES/,/])/ {
/^AC_CONFIG_FILES(\[$/p
s/^clamscan\/Makefile/libclamunrar_iface\/Makefile/p
/^Makefile/p
/^platform.h/p
/^])/p
d
}
/LTDL/d
/ltdl/d
/.*m4\/reorganization\/llvm.m4/d
/.*m4\/reorganization\/libmspack.m4/d
/AC_OUTPUT(\[.*Makefile/d
s/clamscan\/clamscan.c/libclamunrar_iface\/unrar_iface.cpp/
' configure.ac
cat <<EOF >Makefile.am &&
ACLOCAL_AMFLAGS=-I m4
DISTCLEANFILES = target.h
SUBDIRS = libclamunrar_iface
EOF

# The complete Makefile.am from libclamav/Makefile.am is huge and we
# only need the libclamunrar pieces. If we keep everything it will
# break for instance due to missing c++ folder or something else.
# The UNRAR block is the first one followed by LLVM so try to remove
# everything after the LLVM block so we should have enough to get the
# complete libclamunrar compiled.
sed -i '/if ENABLE_LLVM/,$d' libclamunrar_iface/Makefile.am

autoreconf
rm -r autom4te.cache
cd ..
tar -cJf $UNRARPKG --numeric-owner libclamunrar-$VERS/

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" &&
    cd .. && rm -r $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 -xJf ../$DFSGPKG && cd clamav-$VERS+dfsg
echo "Configuring"
./configure --disable-clamav --disable-unrar --enable-milter --prefix=$TESTPFX | tee -a makelog
echo "Building"
make $MAKEFLAGS | tee -a makelog
echo "Checking"
make $MAKEFLAGS check VERBOSE=1 2>&1 | tee -a makelog
make $MAKEFLAGS install 2>&1 | tee -a makelog
make $MAKFELAGS installcheck 2>&1 | tee -a makelog
echo "OK"
cd ..
echo "Running build-test for $UNRARPKG"
tar -xJf ../$UNRARPKG && cd libclamunrar-$VERS
echo "Configuring"
./configure --disable-clamav --prefix=$TESTPFX | tee -a makelog
echo "Building"
make $MAKEFLAGS 2>&1 | tee -a makelog
make $MAKEFLAGS install 2>&1 | tee -a makelog
make $MAKEFLAGS installcheck 2>&1 | tee -a makelog
echo "OK"
cd ../..
echo "Testing whether unrar functionality works"
cat <<EOF >test.hdb
aa15bcf478d165efd2065190eb473bcb:544:ClamAV-Test-File
EOF

if test $? -ne 0; then
    tail makelog
    echo
    echo "Failed"
    exit 50;
fi
# clamscan will exit with exitcode 1 on success (virus found)
set +e
$TESTPFX/bin/clamscan buildtest/clamav-$VERS+dfsg/test/clam-v*.rar -dtest.hdb >clamscanlog
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" &&
    cd .. && rm -r $TEMP &&
    echo "Removed temporary directory $TEMP" &&
    exit 0
    exit 30
fi
echo "Test failed"
cat clamscanlog
exit 100