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.

63 lines
1.6 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. }
  17. start_service() {
  18. local freshclam_config_file UpdateLogFile DatabaseOwner NotifyClamd DatabaseMirror
  19. validate_freshclam_section freshclam || {
  20. echo "validation failed"
  21. return 1
  22. }
  23. [ -f /tmp/freshclam.pid ] && echo "already running" && return 0
  24. mkdir -p /usr/share/clamav
  25. mkdir -p /etc/clamav
  26. touch /tmp/freshclam.log
  27. touch /tmp/freshclam.pid
  28. mkdir -p $(dirname $FRESHCLAM_CONFIGFILE)
  29. ln -sf $freshclam_config_file $FRESHCLAM_CONFIGFILE
  30. echo "UpdateLogFile " $UpdateLogFile > $FRESHCLAM_CONFIGFILE
  31. echo "DatabaseMirror " $DatabaseMirror >> $FRESHCLAM_CONFIGFILE
  32. echo "NotifyClamd " $NotifyClamd >> $FRESHCLAM_CONFIGFILE
  33. echo "DatabaseOwner " $DatabaseOwner >> $FRESHCLAM_CONFIGFILE
  34. echo "CompressLocalDatabase " $CompressLocalDatabase >> $FRESHCLAM_CONFIGFILE
  35. procd_open_instance
  36. procd_set_param command $PROG -d --config-file=$FRESHCLAM_CONFIGFILE -p /tmp/freshclam.pid --no-warnings
  37. procd_set_param file $FRESHCLAM_CONFIGFILE
  38. procd_close_instance
  39. }
  40. stop_service()
  41. {
  42. [ ! -f /tmp/freshclam.pid ] && echo "not running" && return 0
  43. PID=`cat /tmp/freshclam.pid`
  44. kill $PID
  45. rm -f /tmp/freshclam.pid
  46. }
  47. service_triggers()
  48. {
  49. procd_add_reload_trigger "freshclam"
  50. procd_add_validation validate_freshclam_section
  51. }