usbip: move to github (closes #1259)
[feed/packages.git] / net / clamav / files / clamav.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2015 OpenWrt.org
3
4 START=90
5 STOP=10
6
7 USE_PROCD=1
8 PROG=/usr/sbin/clamd
9 CLAMD_CONFIGFILE="/tmp/clamav/clamd.conf"
10
11 validate_clamav_section() {
12 uci_validate_section clamav clamav "${1}" \
13 'clamd_config_file:string' \
14 'LogFile:string' \
15 'LogFileMaxSize:string' \
16 'LogVerbose:string' \
17 'ExtendedDetectionInfo:string' \
18 'LogTime:string' \
19 'OfficialDatabaseOnly:string' \
20 'StreamMinPort:uinteger' \
21 'StreamMaxPort:uinteger' \
22 'MaxThreads:uinteger' \
23 'ReadTimeout:uinteger' \
24 'CommandReadTimeout:uinteger' \
25 'MaxDirectoryRecursion:uinteger' \
26 'FollowDirectorySymlinks:string' \
27 'FollowFileSymlinks:string' \
28 'SelfCheck:uinteger' \
29 'DetectPUA:string' \
30 'ScanPE:string' \
31 'DisableCertCheck:string' \
32 'ScanELF:string' \
33 'DetectBrokenExecutables:string' \
34 'ScanOLE2:string' \
35 'ScanPDF:string' \
36 'ScanSWF:string' \
37 'ScanMail:string' \
38 'ScanPartialMessages:string' \
39 'ScanArchive:string' \
40 'TemporaryDirectory:string' \
41 'ArchiveBlockEncrypted:string' \
42 'MaxFileSize:string' \
43 'LocalSocket:string' \
44 'User:string' \
45 'ExitOnOOM:string'
46 }
47
48 start_service() {
49 local clamd_config_file LogFile LogTime StreamMinPort \
50 StreamMaxPort MaxThreads ReadTimeout CommandReadTimeout MaxDirectoryRecursion \
51 FollowFileSymlinks FollowDirectorySymlinks SelfCheck DetectPUA ScanPE DisableCertCheck \
52 ScanELF DetectBrokenExecutables ScanOLE2 ScanPDF ScanSWF ScanMail ScanPartialMessages \
53 ScanArchive TemporaryDirectory ArchiveBlockEncrypted MaxFileSize LocalSocket User
54
55 validate_clamav_section clamav || {
56 echo "validation failed"
57 return 1
58 }
59
60 mkdir -p /usr/share/clamav
61 mkdir -p /etc/clamav/
62 mkdir -p /var/run/clamav/
63 chmod a+rw /var/run/clamav
64
65 mkdir -p $(dirname $CLAMD_CONFIGFILE)
66 ln -sf $clamd_config_file $CLAMD_CONFIGFILE
67
68 echo "LogFile " $LogFile > $CLAMD_CONFIGFILE
69 echo "LogFileMaxSize " $LogFileMaxSize >> $CLAMD_CONFIGFILE
70 echo "LogVerbose " $LogVerbose >> $CLAMD_CONFIGFILE
71 echo "ExtendedDetectionInfo " $ExtendedDetectionInfo >> $CLAMD_CONFIGFILE
72 echo "LogTime " $LogTime >> $CLAMD_CONFIGFILE
73 echo "OfficialDatabaseOnly " $OfficialDatabaseOnly >> $CLAMD_CONFIGFILE
74 echo "StreamMinPort " $StreamMinPort >> $CLAMD_CONFIGFILE
75 echo "StreamMaxPort " $StreamMaxPort >> $CLAMD_CONFIGFILE
76 echo "MaxThreads " $MaxThreads >> $CLAMD_CONFIGFILE
77 echo "ReadTimeout " $ReadTimeout >> $CLAMD_CONFIGFILE
78 echo "CommandReadTimeout " $CommandReadTimeout >> $CLAMD_CONFIGFILE
79 echo "MaxDirectoryRecursion " $MaxDirectoryRecursion >> $CLAMD_CONFIGFILE
80 echo "FollowDirectorySymlinks " $FollowDirectorySymlinks >> $CLAMD_CONFIGFILE
81 echo "FollowFileSymlinks " $FollowFileSymlinks >> $CLAMD_CONFIGFILE
82 echo "SelfCheck " $SelfCheck >> $CLAMD_CONFIGFILE
83 echo "DetectPUA " $DetectPUA >> $CLAMD_CONFIGFILE
84 echo "ScanPE " $ScanPE >> $CLAMD_CONFIGFILE
85 echo "DisableCertCheck " $DisableCertCheck >> $CLAMD_CONFIGFILE
86 echo "ScanELF " $ScanELF >> $CLAMD_CONFIGFILE
87 echo "DetectBrokenExecutables " $DetectBrokenExecutables >> $CLAMD_CONFIGFILE
88 echo "ScanOLE2 " $ScanOLE2 >> $CLAMD_CONFIGFILE
89 echo "ScanPDF " $ScanPDF >> $CLAMD_CONFIGFILE
90 echo "ScanSWF " $ScanSWF >> $CLAMD_CONFIGFILE
91 echo "ScanMail " $ScanMail >> $CLAMD_CONFIGFILE
92 echo "ScanPartialMessages " $ScanPartialMessages >> $CLAMD_CONFIGFILE
93 echo "ScanArchive " $ScanArchive >> $CLAMD_CONFIGFILE
94 echo "TemporaryDirectory " $TemporaryDirectory >> $CLAMD_CONFIGFILE
95 echo "ArchiveBlockEncrypted " $ArchiveBlockEncrypted >> $CLAMD_CONFIGFILE
96 echo "MaxFileSize " $MaxFileSize >> $CLAMD_CONFIGFILE
97 echo "LocalSocket " $LocalSocket >> $CLAMD_CONFIGFILE
98 echo "User " $User >> $CLAMD_CONFIGFILE
99 echo "ExitOnOOM " $ExitOnOOM >> $CLAMD_CONFIGFILE
100
101 procd_open_instance
102 procd_set_param command $PROG -c $CLAMD_CONFIGFILE
103 procd_set_param file $CLAMD_CONFIGFILE
104 procd_close_instance
105 }
106
107 stop_service()
108 {
109 service_stop ${PROG}
110 }
111
112 service_triggers()
113 {
114 procd_add_reload_trigger "clamav"
115 procd_add_validation validate_clamav_section
116 }