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.

70 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_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. {
  31. echo "UpdateLogFile " "$UpdateLogFile"
  32. echo "DatabaseMirror " "$DatabaseMirror"
  33. echo "NotifyClamd " "$NotifyClamd"
  34. echo "DatabaseOwner " "$DatabaseOwner"
  35. echo "CompressLocalDatabase " "$CompressLocalDatabase"
  36. echo "DatabaseDirectory " "$DatabaseDirectory"
  37. } > "$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. start_service()
  44. {
  45. validate_freshclam_section freshclam start_freshclam_instance
  46. }
  47. stop_service()
  48. {
  49. [ ! -f /tmp/freshclam.pid ] && echo "not running" && return 0
  50. PID=$(cat /tmp/freshclam.pid)
  51. kill "$PID"
  52. rm -f /tmp/freshclam.pid
  53. }
  54. service_triggers()
  55. {
  56. procd_add_reload_trigger "freshclam"
  57. procd_add_validation validate_freshclam_section
  58. }