summaryrefslogtreecommitdiffstats
path: root/clamav/build/clamav.SlackBuild
blob: abee7c0d128ec07c80d5f9deebea6b0858c02ca0 (plain)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
#!/bin/sh
# $Id$

# Copyright 2006-2018  Eric Hameleers, Eindhoven, NL
# 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.
# 0.94-1:    04/sep/2008 by Eric Hameleers
#            * New release. Add "--disable-check" to 'configure', to avoid
#              a (harmless) warning about missing 'check'.
# 0.94.1-1:  10/nov/2008 by Eric Hameleers
#            * New release.
# 0.94.2-1:  28/nov/2008 by Eric Hameleers
#            * New release.
# 0.95-1:    24/mar/2009 by Eric Hameleers
#            * New release.
# 0.95.1-1:  17/apr/2009 by Eric Hameleers
#            * New release.
# 0.95.2-1:  11/jun/2009 by Eric Hameleers
#            * New release.
# 0.95.3-1:  30/oct/2009 by Eric Hameleers
#            * New release.
# 0.96-1:    02/apr/2010 by Eric Hameleers
#            * New release.
# 0.96.1-1:  27/may/2010 by Eric Hameleers
#            * New release plugs a critical hole.
# 0.96.3-1:  21/sep/2010 by Eric Hameleers
#            * New release.
# 0.96.4-1:  26/oct/2010 by Eric Hameleers
#            * New release.
# 0.96.5-1:  02/dec/2010 by Eric Hameleers
#            * New release.
# 0.97-1:    11/feb/2011 by Eric Hameleers
#            * New release.
# 0.97.1-1:  11/jun/2011 by Eric Hameleers
#            * New release.
# 0.97.2-1:  19/aug/2011 by Eric Hameleers
#            * New release.
# 0.97.3-1:  24/nov/2011 by Eric Hameleers
#            * New release.
# 0.97.4-1:  21/mar/2012 by Eric Hameleers
#            * New release.
# 0.97.5-1:  17/jun/2012 by Eric Hameleers
#            * New release.
# 0.98-1:    20/Sep/2013 by Eric Hameleers
#            * Update.
# 0.98.7-1:  31/may/2015 by Eric Hameleers
#            * Update.
# 0.99.2-1:  05/aug/2017 by Eric Hameleers
#            * Update. Adopted the enhancements from the SBo copy.
#              Enable milter.
# 0.100.2-1: 28/oct/2018 by Eric Hameleers
#            * Update. The 'AllowSupplementaryGroups' keyword is deprecated
#              since 0.100 because it is now used by default.
# 
# Run 'sh clamav.SlackBuild' 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.100.2"}
BUILD=${BUILD:-1}
TAG=${TAG:-alien}

# The 2-letter ISO code of the country that hosts your clamav mirror:
ISOCC=${ISOCC:-"nl"}

# 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"}

SOURCE="$SRCDIR/${PRGNAM}-${VERSION}.tar.gz"
SRCURL="http://www.clamav.net/downloads/production/${PRGNAM}-${VERSION}.tar.gz"

##
## --- with a little luck, you won't have to edit below this point --- ##
##

# Automatically determine the architecture we're building on:
MARCH=$( uname -m )
if [ -z "$ARCH" ]; then
  case "$MARCH" in
    i?86)    export ARCH=i586 ;;
    armv7hl) export ARCH=$MARCH ;;
    arm*)    export ARCH=arm ;;
    # Unless $ARCH is already set, use uname -m for all other archs:
    *)       export ARCH=$MARCH ;;
  esac
fi

case "$ARCH" in
  i?86)      SLKCFLAGS="-O2 -march=${ARCH} -mtune=i686"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             ;;
  x86_64)    SLKCFLAGS="-O2 -fPIC"
             SLKLDFLAGS="-L/usr/lib64"; LIBDIRSUFFIX="64"
             ;;
  armv7hl)   SLKCFLAGS="-O2 -march=armv7-a -mfpu=vfpv3-d16"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             ;;
  *)         SLKCFLAGS="-O2"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             ;;
esac

case "$ARCH" in
  arm*)      TARGET=$ARCH-slackware-linux-gnueabi ;;
  *)         TARGET=$ARCH-slackware-linux ;;
esac

# 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}

# Save old umask and set to 0022:
_UMASK_=$(umask)
umask 0022

# 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
  echo "Source '$(basename ${SOURCE})' not available yet..."
  # Check if the $SRCDIR is writable at all - if not, download to $OUTPUT
  [ -w "$SRCDIR" ] || SOURCE="$OUTPUT/$(basename $SOURCE)"
  if [ -f ${SOURCE} ]; then echo "Ah, found it!"; continue; fi
  if ! [ "x${SRCURL}" == "x" ]; then
    echo "Will download file to $(dirname $SOURCE)"
    wget -nv -T 20 -O "${SOURCE}" "${SRCURL}" || true
    if [ $? -ne 0 -o ! -s "${SOURCE}" ]; then
      echo "Downloading '$(basename ${SOURCE})' failed... aborting the build."
      mv -f "${SOURCE}" "${SOURCE}".FAIL
      exit 1
    fi
  else
    echo "File '$(basename ${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 -xvf $SOURCE
cd ${PRGNAM}-${VERSION}
chown -R root:root .
chmod -R u+w,go+r-w,a+rX-st .
touch $OUTPUT/patch-${PRGNAM}.log

# Specify the desired mirror in the update config file
# http://www.iana.org/cctld/cctld-whois.htm
sed -i "s/^\#DatabaseMirror.*/DatabaseMirror db.${ISOCC}.clamav.net/" \
  etc/freshclam.conf.sample
sed \
  -e "s/^Example/#Example/" \
  -e "s/^\#LogSyslog/LogSyslog/" \
  -e "s/^\#LogFacility/LogFacility/" \
  -e "s/^\#PidFile.*/PidFile \/var\/run\/clamav\/freshclam.pid/" \
  -e "s/^\#UpdateLogFile.*/UpdateLogFile \/var\/log\/clamav\/freshclam.log/" \
  -e "s/^\#DatabaseOwner.*/DatabaseOwner clamav/" \
  -e "s/^\#NotifyClamd.*/NotifyClamd \/etc\/clamd.conf/" \
  -i etc/freshclam.conf.sample
sed \
  -e "s/^Example/#Example/" \
  -e "s/^\#LogSyslog/LogSyslog/" \
  -e "s/^\#LogFacility/LogFacility/" \
  -e "s/^\#LogFile\ .*/LogFile \/var\/log\/clamav\/clamd.log/" \
  -e "s/^\#PidFile.*/PidFile \/var\/run\/clamd.pid/" \
  -e "s/^\#LocalSocket\ .*/LocalSocket \/var\/run\/clamav\/clamd.socket/" \
  -e "s/^\#LocalSocketGroup.*/LocalSocketGroup clamav/" \
  -e "s/^\#LocalSocketMode/LocalSocketMode/" \
  -e "s/^\#FixStaleSocket/FixStaleSocket/" \
  -e "s/^\#User.*/User clamav/" \
  -e "s/^\#ExitOnOOM/ExitOnOOM/" \
  -i etc/clamd.conf.sample

chown -R root:root .
chmod -R u+w,go+r-w,a+X-s .

# Compiling the package source:
echo Building ...

# Thanks to SlackBuilds.org, Matteo Bernardini <ponce@slackbuilds.org>:
# Check if json-c is there: if it is, build over it to enable
# the file properties collection and analysis feature
# http://blog.clamav.net/2014/11/intro-to-collection-and-analysis-of.html
if pkg-config --exists json-c ; then
  do_jsonc="--with-libjson"
else
  do_jsonc=""
fi

# Slackware 15.0 and newer have postfix by default, so include milter support
# only if we detect its presence:
if [ -f /usr/lib${LIBDIRSUFFIX}/libmilter.a ]; then
   do_milter="--enable-milter"
else
   do_milter="--disable-milter"
fi

# 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 \
  --enable-id-check \
  --enable-clamdtop \
  --disable-check \
  --disable-static \
  --build=$TARGET \
  $do_jsonc \
  $do_milter \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}.log
  # deprecated:
  #--with-libcurl --with-tcpwrappers \
make 2>&1 | tee $OUTPUT/make-${PRGNAM}.log

# Install all the needed stuff to the package dir;
make DESTDIR=$PKG install 2>&1 |tee $OUTPUT/install-${PRGNAM}.log

# Prepare the config files:
cd $PKG/etc
mv clamd.conf.sample clamd.conf.new
mv freshclam.conf.sample freshclam.conf.new
mv clamav-milter.conf.sample clamav-milter.conf.new
cd -

# Where to store the pid, db and log files:
mkdir -p $PKG/var/run/clamav
mkdir -p $PKG/usr/share/clamav
mkdir -p $PKG/var/log/clamav

# Ensure that any db files are removed along with the package:
touch \
  $PKG/usr/share/clamav/main.cvd \
  $PKG/usr/share/clamav/bytecode.cvd \
  $PKG/usr/share/clamav/daily.cvd \
  $PKG/usr/share/clamav/mirrors.dat

# Our rc.d and logrotate scripts:
mkdir -p $PKG/etc/rc.d/
install -D -m 0755 $SRCDIR/rc.clamav $PKG/etc/rc.d/rc.clamav.new
install -D -m 0644 $SRCDIR/logrotate.clamav $PKG/etc/logrotate.d/clamav.new

# Add a post-install script:
mkdir -p $PKG/install
cat <<EOINS > $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
}

preserve_perms() {
  NEW="\$1"
  OLD="\$(dirname \$NEW)/\$(basename \$NEW .new)"
  if [ -e \$OLD ]; then
    cp -a \$OLD \${NEW}.incoming
    cat \$NEW > \${NEW}.incoming
    mv \${NEW}.incoming \$NEW
  fi
  config \$NEW
}

preserve_perms etc/rc.d/rc.clamav.new
config etc/freshclam.conf.new
config etc/clamd.conf.new
config etc/clamav-milter.conf.new
config etc/logrotate.d/clamav.new

# Create log files
touch var/log/clamav/clamd.log
touch var/log/clamav/freshclam.log

# Only way to create and use the correct uid and gid on the target system,
# is to use chroot:
chroot . <<EOR 2>/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 -R ${CLAMUSR}:${CLAMGRP} var/log/clamav
chmod 770 var/log/clamav
chmod 660 var/log/clamav/*.log
chown -R ${CLAMUSR}:${CLAMGRP} usr/share/clamav
chmod 770 usr/share/clamav
chmod 660 usr/share/clamav/*
EOR

EOINS
# --- End of 'doinst.sh' script -----------

# Add documentation:
cp $SRCDIR/00README.slackware README.slackware
DOCS="COPYING* ChangeLog.md \
      docs/*.pdf docs/html examples \
      README.slackware"
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a $DOCS $PKG/usr/doc/$PRGNAM-$VERSION || true
cat $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:
find $PKG | xargs file | grep -e "executable" -e "shared object" \
  | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

# 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
/sbin/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

# Restore the original umask:
umask ${_UMASK_}