summaryrefslogtreecommitdiffstats
path: root/net/clamav/files/freshclam.init
blob: b137462c70430c5abf9f12a8496cfd19a4eccc43 (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
#!/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' \
		'LogTime:string' \
		'LogVerbose:string' \
		'LogSyslog:string' \
		'Debug:string' \
		'LogFacility:string' \
		'Foreground:string' \
		'PidFile:string' \
		'DatabaseMirror:string' \
		'NotifyClamd:string' \
		'DatabaseOwner:string' \
		'CompressLocalDatabase:string' \
		'DatabaseDirectory:string' \
		'DNSDatabaseInfo:string' \
		'ScriptedUpdates:string' \
		'DatabaseCustomURL:string' \
		'ConnectTimeout:string' \
		'ReceiveTimeout:string' \
		'PrivateMirror:string' \
		'Checks:string' \
		'TestDatabases:string' \
		'Bytecode:string' \
		'ExtraDatabase:string' \
		'ExcludeDatabase: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.pid

	mkdir -p "$(dirname $FRESHCLAM_CONFIGFILE)"
	ln -sf "$freshclam_config_file" "$FRESHCLAM_CONFIGFILE"

	{
	[ -n "$LogTime" ] 				&& echo "LogTime " "$LogTime"
	[ -n "$LogVerbose" ] 			&& echo "LogVerbose " "$LogVerbose"
	[ -n "$LogSyslog" ] 			&& echo "LogSyslog " "$LogSyslog"
	[ -n "$Debug" ] 				&& echo "Debug " "$Debug"
	[ -n "$LogFacility" ] 			&& echo "LogFacility " "$LogFacility"
	[ -n "$Foreground" ] 			&& echo "Foreground " "$Foreground"
	[ -n "$PidFile" ] 				&& echo "PidFile " "$PidFile"
	[ -n "$DatabaseMirror" ] 		&& echo "DatabaseMirror " "$DatabaseMirror"
	[ -n "$NotifyClamd" ] 			&& echo "NotifyClamd " "$NotifyClamd"
	[ -n "$DatabaseOwner" ] 		&& echo "DatabaseOwner " "$DatabaseOwner"
	[ -n "$CompressLocalDatabase" ]	&& echo "CompressLocalDatabase " "$CompressLocalDatabase"
	[ -n "$DatabaseDirectory" ] 	&& echo "DatabaseDirectory " "$DatabaseDirectory"
	[ -n "$DNSDatabaseInfo" ] 		&& echo "DNSDatabaseInfo " "$DNSDatabaseInfo"
	[ -n "$ScriptedUpdates" ] 		&& echo "ScriptedUpdates " "$ScriptedUpdates"
	[ -n "$DatabaseCustomURL" ] 	&& echo "DatabaseCustomURL " "$DatabaseCustomURL"
	[ -n "$ConnectTimeout" ] 		&& echo "ConnectTimeout " "$ConnectTimeout"
	[ -n "$ReceiveTimeout" ] 		&& echo "ReceiveTimeout " "$ReceiveTimeout"
	[ -n "$PrivateMirror" ] 		&& echo "PrivateMirror " "$PrivateMirror"
	[ -n "$Checks" ] 				&& echo "Checks " "$Checks"
	[ -n "$TestDatabases" ] 		&& echo "TestDatabases " "$TestDatabases"
	[ -n "$Bytecode" ] 				&& echo "Bytecode " "$Bytecode"
	[ -n "$ExtraDatabase" ] 		&& echo "ExtraDatabase " "$ExtraDatabase"
	[ -n "$ExcludeDatabase" ]		&& echo "ExcludeDatabase " "$ExcludeDatabase"
	} > "$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
}