3 ### Startup for COSclamav package
4 ### (C) 2008-2016 by Jim Klimov, COS&HT
5 ### $Id: freshclam.sh,v 1.6 2016/02/22 20:40:00 jim Exp $
7 ### Use to update ClamAV virus signatures from cron:
8 ### 0,15,30,45 * * * * [ -x /usr/bin/freshclam.sh ] && /usr/bin/freshclam.sh
10 CLAMD_CONFFILE
=/etc
/clamav
/clamd.conf
11 FRESHCLAM_CONFFILE
=/etc
/clamav
/freshclam.conf
12 FRESHCLAM_BINFILE
="/usr/bin/freshclam"
14 ### Clumsy syntax due to portable shells:
15 FRESHCLAMSH_BINFILE_DIR
="`dirname "$0"`" && \
16 FRESHCLAMSH_BINFILE_DIR
="`cd "$FRESHCLAMSH_BINFILE_DIR" && pwd`" && \
17 FRESHCLAMSH_BINFILE
="$FRESHCLAMSH_BINFILE_DIR/`basename "$0"`" && \
18 [ x
"$FRESHCLAMSH_BINFILE" != x
] && [ -x "$FRESHCLAMSH_BINFILE" ] || \
19 FRESHCLAMSH_BINFILE
="/usr/bin/freshclam.sh"
23 PATH
=/usr
/bin
:/bin
:/usr
/sbin
:/bin
:$PATH
27 /usr
/lib
:/lib
:/usr
/ssl
/lib
:\
28 /usr
/sfw
/lib
:/opt
/sfw
/lib
:\
29 /usr
/gnu
/lib
:/opt
/gnu
/lib
:\
31 export LD_LIBRARY_PATH
33 if [ ! -s "$CLAMD_CONFFILE" -o ! -s "$FRESHCLAM_CONFFILE" ]; then
34 # echo "ClamAV-FreshCLAM: No config file!" >&2
41 [ x
"$RES" = x0
] && RES
="$2"
42 [ "$RES_MAX" -lt "$2" ] && RES_MAX
="$2"
46 ( which crontab
>/dev
/null
2>&1 ) || \
47 { echo "ERROR: crontab program not found" >&2; return 1; }
50 # Below we depend on parsing some outputs
55 OUT
="`crontab -l 2>&1`" || RES
=$?
57 if echo "$OUT" |
grep "can't open" >/dev
/null
&& \
58 [ "`echo "$OUT" | wc -l`" -eq 1 ] \
59 ; then OUT
="" ; RES
=0; else return $RES; fi
60 echo "$OUT" |
egrep -v "bin/freshclam|$FRESHCLAMSH_BINFILE|^$" > "/tmp/saved-crontab.$$"
61 if [ -s "/tmp/saved-crontab.$$" ]; then
62 crontab
"/tmp/saved-crontab.$$" || RES
=$?
66 rm -f "/tmp/saved-crontab.$$"
67 [ $RES != 0 ] && echo "ERROR: could not delete freshclam from crontab" >&2
72 [ x
"$1" = x
] && return 1 # Whole cron-schedule spec
73 do_delcron ||
return $?
# Also checks for valid crontab program in PATH
75 # Below we depend on parsing some outputs
80 if [ "$1" = SMF
]; then
81 [ -n "$SMF_FMRI" ] && \
82 SCHED
="`/usr/bin/svcprop -p freshclam/cron-schedule "$SMF_FMRI"`" \
83 && [ -n "$SCHED" ] ||
return $?
87 # SMF escapes our schedule... and shell too...
88 SCHED
="`echo "$SCHED" | sed 's,\\\\ , ,g'`"
89 OUT
="`crontab -l 2>/dev/null`" || OUT
=""
91 $SCHED [ -x '$FRESHCLAMSH_BINFILE' ] && '$FRESHCLAMSH_BINFILE'" > "/tmp/saved-crontab.$$"
93 crontab
"/tmp/saved-crontab.$$" || RES
=$?
94 rm -f "/tmp/saved-crontab.$$"
95 [ $RES != 0 ] && echo "ERROR: could not add freshclam to crontab" >&2
100 --smf-enable) # Initial refresh and a cronjob (with schedule in $2)
101 [ -x "$FRESHCLAM_BINFILE" ] && "$FRESHCLAM_BINFILE"
104 --add-cron) # For CLI user and SMF integration
105 [ x
"$2" = x
-o $# != 2 ] && \
106 echo "ERROR: Option $1 requires a cron-schedule 5-token argument like '0 * * * *'" >&2 && \
111 --del-cron) # For CLI user and SMF integration
115 status
) ### Use "status nowarn" to not return errors for warnings only.
116 ### Use "status nowarnobs" to not return errors for warnings
117 ### and obsolete databases only.
118 [ x
"$2" != x
] && [ "$2" -gt 10 ] && STATUS_LINES
="$2"
119 LOGFILE
="`egrep '^[^#]*UpdateLogFile ' $FRESHCLAM_CONFFILE | awk '{print $NF }'`"
120 if [ x
"$LOGFILE" = x
-o ! -f "$LOGFILE" ]; then
121 echo "ClamAV-FreshCLAM: No log file ($LOGFILE)!" >&2
129 tail -"$STATUS_LINES" "$LOGFILE" |
( while read LINE
; do
131 ClamAV\ update\ process\ started\
at*)
137 *connect\ timing\ out
*|
*Can?t\ connect\ to
*)
138 adderror
"$LINE" 10 ;;
139 *node\ name\ or\ service\ name\ not\ known
*)
140 adderror
"$LINE" 11 ;;
142 adderror
"$LINE" 12 ;;
143 *Your\ ClamAV\ installation\ is\ OUTDATED
*)
144 adderror
"$LINE" 3 ;;
146 adderror
"$LINE" 2 ;;
149 if [ x
"$RES" != x0
]; then
150 [ x
"$BUF_START" != x
] && echo "$BUF_START" >&2
151 echo "$BUF_ERROR" >&2
152 if [ x
"$2" = xnowarn
-a "$RES_MAX" -le 2 ]; then
156 if [ x
"$2" = xnowarnobs
-a "$RES_MAX" -le 3 ]; then
168 *) # Wrapper for the program
169 [ -x "$FRESHCLAM_BINFILE" ] && "$FRESHCLAM_BINFILE" "$@"