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.

68 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_load_validate freshclam freshclam "$1" "$2" \
  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_freshclam_instance() {
  19. [ "$2" = 0 ] || {
  20. echo "validation failed"
  21. return 1
  22. }
  23. [ -f /tmp/freshclam.pid ] && echo "already running" && return 0
  24. mkdir -p $DatabaseDirectory
  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. echo "DatabaseDirectory " $DatabaseDirectory >> $FRESHCLAM_CONFIGFILE
  36. procd_open_instance
  37. procd_set_param command $PROG -d --config-file=$FRESHCLAM_CONFIGFILE -p /tmp/freshclam.pid --no-warnings
  38. procd_set_param file $FRESHCLAM_CONFIGFILE
  39. procd_close_instance
  40. }
  41. start_service()
  42. {
  43. validate_freshclam_section freshclam start_freshclam_instance
  44. }
  45. stop_service()
  46. {
  47. [ ! -f /tmp/freshclam.pid ] && echo "not running" && return 0
  48. PID=`cat /tmp/freshclam.pid`
  49. kill $PID
  50. rm -f /tmp/freshclam.pid
  51. }
  52. service_triggers()
  53. {
  54. procd_add_reload_trigger "freshclam"
  55. procd_add_validation validate_freshclam_section
  56. }