rc.uvscan 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. i=0
  13. while [ $i -lt 3 ]; do
  14. uvscan_datfile=`@l_prefix@/bin/curl -s "${uvscan_dat}" 2>/dev/null |\
  15. grep 'dat-[0-9][0-9]*\.tar' | sort | tail -1 |\
  16. sed -e 's;^.*\(dat-[0-9][0-9]*\.tar\).*$;\1;'`
  17. if [ ".${uvscan_datfile}" != . ]; then
  18. break
  19. else
  20. sleep 10
  21. fi
  22. i=$(($i + 1))
  23. done
  24. if [ ".${uvscan_datfile}" = . ]; then
  25. echo "rc:uvscan:ERROR: unable to determine latest DAT file version" 1>&2
  26. return 1
  27. fi
  28. uvscan_tmpdir=`echo "${uvscan_datfile}" | sed -e 's;\.tar$;;'`
  29. uvscan_datadir="@l_prefix@/var/uvscan/data"
  30. # determine old (installed) and new (available) versions
  31. uvscan_version_new=`echo "${uvscan_datfile}" | sed -e 's;^dat-;;' -e 's;\.tar$;;'`
  32. uvscan_version_old=`(cat "${uvscan_datadir}/VERSION") 2>/dev/null`
  33. if [ ".${uvscan_version_new}" = ".${uvscan_version_old}" ]; then
  34. # still no need for updating
  35. return 0
  36. fi
  37. # download and unpack latest DATs
  38. umask 077
  39. cd ${uvscan_datadir} || return 1
  40. rm -f ${uvscan_datfile} >/dev/null 2>&1 || true
  41. i=0
  42. while [ $i -lt 3 ]; do
  43. @l_prefix@/bin/curl -s -o ${uvscan_datfile} \
  44. ${uvscan_dat}/${uvscan_datfile} || return 1
  45. if [ $? -eq 0 ]; then
  46. break
  47. else
  48. rm -f ${uvscan_datfile} >/dev/null 2>&1 || true
  49. sleep 10
  50. fi
  51. i=$(($i + 1))
  52. done
  53. if [ ! -f ${uvscan_datfile} ]; then
  54. echo "rc:uvscan:ERROR: unable to download latest DAT file" 1>&2
  55. return 1
  56. fi
  57. rm -rf ${uvscan_tmpdir} >/dev/null 2>&1 || true
  58. mkdir ${uvscan_tmpdir}
  59. ( cd ${uvscan_tmpdir} && \
  60. @l_prefix@/bin/tar -xf ../${uvscan_datfile}
  61. ) || return 1
  62. # update DAT repository by installing updated DAT files
  63. @l_prefix@/lib/openpkg/shtool install -m 644 -o @l_musr@ -g @l_mgrp@ \
  64. ${uvscan_tmpdir}/*.dat .
  65. echo "${uvscan_version_new}" >VERSION
  66. # cleanup
  67. rm -f ${uvscan_datfile} >/dev/null 2>&1 || true
  68. rm -rf ${uvscan_tmpdir} >/dev/null 2>&1 || true
  69. }
  70. %quarterly -u @l_musr@
  71. rcService uvscan enable yes || exit 0
  72. if [ ".$uvscan_update" = .quarterly ]; then
  73. uvscan_update || exit $?
  74. fi
  75. %hourly -u @l_musr@
  76. rcService uvscan enable yes || exit 0
  77. if [ ".$uvscan_update" = .hourly ]; then
  78. uvscan_update || exit $?
  79. fi
  80. %daily -u @l_musr@
  81. rcService uvscan enable yes || exit 0
  82. if [ ".$uvscan_update" = .daily ]; then
  83. uvscan_update || exit $?
  84. fi
  85. %weekly -u @l_musr@
  86. rcService uvscan enable yes || exit 0
  87. if [ ".$uvscan_update" = .weekly ]; then
  88. uvscan_update || exit $?
  89. fi