You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. START=90
  4. STOP=10
  5. USE_PROCD=1
  6. PROG=/usr/sbin/freshclam
  7. FRESHCLAM_CONFIGFILE="/tmp/clamav/freshclam.conf"
  8. validate_freshclam_section() {
  9. uci_validate_section freshclam freshclam "${1}" \
  10. 'freshclam_config_file:string' \
  11. 'UpdateLogFile:string' \
  12. 'DatabaseMirror:string' \
  13. 'NotifyClamd:string' \
  14. 'DatabaseOwner:string' \
  15. 'CompressLocalDatabase:string' \
  16. 'DatabaseDirectory:string:'
  17. }
  18. start_service() {
  19. local freshclam_config_file UpdateLogFile DatabaseOwner NotifyClamd DatabaseMirror \
  20. DatabaseDirectory
  21. validate_freshclam_section freshclam || {
  22. echo "validation failed"
  23. return 1
  24. }
  25. [ -f /tmp/freshclam.pid ] && echo "already running" && return 0
  26. mkdir -p $DatabaseDirectory
  27. mkdir -p /etc/clamav
  28. touch /tmp/freshclam.log
  29. touch /tmp/freshclam.pid
  30. mkdir -p $(dirname $FRESHCLAM_CONFIGFILE)
  31. ln -sf $freshclam_config_file $FRESHCLAM_CONFIGFILE
  32. echo "UpdateLogFile " $UpdateLogFile > $FRESHCLAM_CONFIGFILE
  33. echo "DatabaseMirror " $DatabaseMirror >> $FRESHCLAM_CONFIGFILE
  34. echo "NotifyClamd " $NotifyClamd >> $FRESHCLAM_CONFIGFILE
  35. echo "DatabaseOwner " $DatabaseOwner >> $FRESHCLAM_CONFIGFILE
  36. echo "CompressLocalDatabase " $CompressLocalDatabase >> $FRESHCLAM_CONFIGFILE
  37. echo "DatabaseDirectory " $DatabaseDirectory >> $FRESHCLAM_CONFIGFILE
  38. procd_open_instance
  39. procd_set_param command $PROG -d --config-file=$FRESHCLAM_CONFIGFILE -p /tmp/freshclam.pid --no-warnings
  40. procd_set_param file $FRESHCLAM_CONFIGFILE
  41. procd_close_instance
  42. }
  43. stop_service()
  44. {
  45. [ ! -f /tmp/freshclam.pid ] && echo "not running" && return 0
  46. PID=`cat /tmp/freshclam.pid`
  47. kill $PID
  48. rm -f /tmp/freshclam.pid
  49. }
  50. service_triggers()
  51. {
  52. procd_add_reload_trigger "freshclam"
  53. procd_add_validation validate_freshclam_section
  54. }