rc.uvscan 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
  2. ##
  3. ## rc.uvscan -- Run-Commands
  4. ##
  5. %config
  6. uvscan_enable="$openpkg_rc_def"
  7. uvscan_dat="ftp://ftp.nai.com/pub/antivirus/datfiles/4.x/"
  8. uvscan_update="daily"
  9. %common
  10. uvscan_update () {
  11. # determine information
  12. uvscan_datadir="@l_prefix@/var/uvscan/data"
  13. uvscan_datfile=`@l_prefix@/bin/curl -s "$uvscan_dat" 2>/dev/null |\
  14. grep 'dat-[0-9][0-9]*\.tar' | sort | tail -1 |\
  15. sed -e 's;^.*\(dat-[0-9][0-9]*\.tar\).*$;\1;'`
  16. uvscan_tmpdir=`echo "${uvscan_datfile}" | sed -e 's;\.tar$;;'`
  17. # determine old (installed) and new (available) versions
  18. uvscan_version_new=`echo "${uvscan_datfile}" | sed -e 's;^dat-;;' -e 's;\.tar$;;'`
  19. uvscan_version_old=`(cat "${uvscan_datadir}/VERSION") 2>/dev/null`
  20. if [ ".${uvscan_version_new}" = ".${uvscan_version_old}" ]; then
  21. # still no need for updating
  22. return 0
  23. fi
  24. # download and unpack latest DATs
  25. umask 077
  26. cd ${uvscan_datadir} || return 1
  27. rm -f ${uvscan_datfile} >/dev/null 2>&1 || true
  28. @l_prefix@/bin/curl -s -o ${uvscan_datfile} \
  29. ${uvscan_dat}/${uvscan_datfile} || return 1
  30. rm -rf ${uvscan_tmpdir} >/dev/null 2>&1 || true
  31. mkdir ${uvscan_tmpdir}
  32. ( cd ${uvscan_tmpdir} && \
  33. @l_prefix@/bin/tar -xf ../${uvscan_datfile}
  34. ) || return 1
  35. # update DAT repository by installing updated DAT files
  36. @l_prefix@/lib/openpkg/shtool install -m 644 -o @l_musr@ -g @l_mgrp@ \
  37. ${uvscan_tmpdir}/*.dat .
  38. echo "${uvscan_version_new}" >VERSION
  39. # cleanup
  40. rm -f ${uvscan_datfile} >/dev/null 2>&1 || true
  41. rm -rf ${uvscan_tmpdir} >/dev/null 2>&1 || true
  42. }
  43. %quarterly -u @l_musr@
  44. rcService uvscan enable yes || exit 0
  45. if [ ".$uvscan_update" = .quarterly ]; then
  46. uvscan_update || exit $?
  47. fi
  48. %hourly -u @l_musr@
  49. rcService uvscan enable yes || exit 0
  50. if [ ".$uvscan_update" = .hourly ]; then
  51. uvscan_update || exit $?
  52. fi
  53. %daily -u @l_musr@
  54. rcService uvscan enable yes || exit 0
  55. if [ ".$uvscan_update" = .daily ]; then
  56. uvscan_update || exit $?
  57. fi
  58. %weekly -u @l_musr@
  59. rcService uvscan enable yes || exit 0
  60. if [ ".$uvscan_update" = .weekly ]; then
  61. uvscan_update || exit $?
  62. fi