Merge remote-tracking branch 'origin/github/pr/145'
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 92-update-freshclam
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/92-update-freshclam
3 # Purpose:       update freshclam database
4 # Authors:       (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 if ifclass NO_ONLINE ; then
10   echo "Ignoring script 92-update-freshclam as NO_ONLINE is set."
11   exit 0
12 fi
13
14 if ! ifclass FRESHCLAM ; then
15   echo "Ignoring script 92-update-freshclam as FRESHCLAM is NOT set."
16   echo "Executing freshclam increases the ISO for ~70MB, not considering as default."
17   exit 0
18 fi
19
20 set -u
21
22 bailout() {
23   if [ "${1:-}" = "124" ] ; then
24     echo "Warning: freshclam returned with exit code 124." >&2
25
26     # be verbose in logs
27     echo "Warning: freshclam returned with exit code 124."
28     echo "-> This might happen when the incremental daily update failed to run, and"
29     echo "   retrieving the full daily.cvd failed as well."
30     echo "   This is known to be a problem in automated builds causing build errors."
31     echo "   Therefore we are ignoring this issue."
32     echo "   If a fresh clamav database is important for you, execute freshclam in the chroot."
33
34     exit 0
35   fi
36
37   exit "${1:-0}"
38 }
39
40 [ -x $target/usr/bin/timeout ] && TIMEOUT="10" || TIMEOUT=""
41
42 if ! [ -x $target/usr/bin/freshclam ] ; then
43   echo "freshclam not installed"
44   exit 0
45 fi
46
47 echo "Updating clamav database via running freshclam"
48 if [ -n "$TIMEOUT" ] ; then
49    $ROOTCMD timeout $TIMEOUT /usr/bin/freshclam
50    bailout $?
51 else
52    $ROOTCMD /usr/bin/freshclam
53    bailout $?
54 fi
55
56 ## END OF FILE #################################################################
57 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2