blob: 38842a95e13e3592488f74fc8db30f68cc685108 (
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
|
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org
START=90
STOP=10
USE_PROCD=1
PROG=/usr/sbin/freshclam
FRESHCLAM_CONFIGFILE="/tmp/clamav/freshclam.conf"
validate_freshclam_section() {
uci_load_validate freshclam freshclam "$1" "$2" \
'freshclam_config_file:string' \
'UpdateLogFile:string' \
'DatabaseMirror:string' \
'NotifyClamd:string' \
'DatabaseOwner:string' \
'CompressLocalDatabase:string' \
'DatabaseDirectory:string:'
}
start_freshclam_instance() {
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
[ -f /tmp/freshclam.pid ] && echo "already running" && return 0
mkdir -p "$DatabaseDirectory"
mkdir -p /etc/clamav
touch /tmp/freshclam.log
touch /tmp/freshclam.pid
mkdir -p "$(dirname $FRESHCLAM_CONFIGFILE)"
ln -sf "$freshclam_config_file" "$FRESHCLAM_CONFIGFILE"
{
echo "UpdateLogFile " "$UpdateLogFile"
echo "DatabaseMirror " "$DatabaseMirror"
echo "NotifyClamd " "$NotifyClamd"
echo "DatabaseOwner " "$DatabaseOwner"
echo "CompressLocalDatabase " "$CompressLocalDatabase"
echo "DatabaseDirectory " "$DatabaseDirectory"
} > "$FRESHCLAM_CONFIGFILE"
procd_open_instance
procd_set_param command $PROG -d --config-file=$FRESHCLAM_CONFIGFILE -p /tmp/freshclam.pid --no-warnings
procd_set_param file $FRESHCLAM_CONFIGFILE
procd_close_instance
}
start_service()
{
validate_freshclam_section freshclam start_freshclam_instance
}
stop_service()
{
[ ! -f /tmp/freshclam.pid ] && echo "not running" && return 0
PID=$(cat /tmp/freshclam.pid)
kill "$PID"
rm -f /tmp/freshclam.pid
}
service_triggers()
{
procd_add_reload_trigger "freshclam"
procd_add_validation validate_freshclam_section
}
|