rc.fetchmail 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!@l_prefix@/bin/openpkg rc
  2. ##
  3. ## rc.fetchmail -- Run-Commands
  4. ##
  5. %config
  6. fetchmail_enable="$openpkg_rc_def"
  7. fetchmail_daemon="no"
  8. fetchmail_log_prolog="true"
  9. fetchmail_log_epilog="true"
  10. fetchmail_log_numfiles="10"
  11. fetchmail_log_minsize="1M"
  12. fetchmail_log_complevel="9"
  13. fetchmail_log_file="@l_prefix@/var/fetchmail/fetchmail.log"
  14. fetchmail_rc="@l_prefix@/etc/fetchmail/fetchmailrc"
  15. fetchmail_rc_master="@l_prefix@/etc/fetchmail/fetchmail.master"
  16. fetchmail_rc_numfiles="100"
  17. fetchmail_users="@l_prefix@/etc/fetchmail/fetchmail.users"
  18. fetchmail_pidfile="@l_prefix@/var/fetchmail/fetchmail.pid"
  19. %common
  20. fetchmail_signal () {
  21. [ -f $fetchmail_pidfile ] && kill -$1 `cat $fetchmail_pidfile`
  22. }
  23. %status -u @l_susr@ -o
  24. fetchmail_usable="unknown"
  25. fetchmail_active="no"
  26. rcService fetchmail enable yes && \
  27. fetchmail_signal 0 && fetchmail_active="yes"
  28. echo "fetchmail_enable=\"$fetchmail_enable\""
  29. echo "fetchmail_usable=\"$fetchmail_usable\""
  30. echo "fetchmail_active=\"$fetchmail_active\""
  31. %start -p 200 -u @l_susr@
  32. rcService fetchmail enable yes || exit 0
  33. rcService fetchmail active yes && exit 0
  34. rcVarIsYes fetchmail_daemon || exit 0
  35. rc fetchmail quarterly
  36. @l_prefix@/bin/fetchmail -f ${fetchmail_rc} -L ${fetchmail_log_file}
  37. %stop -p 800 -u @l_susr@
  38. rcService fetchmail enable yes || exit 0
  39. rcService fetchmail active no && exit 0
  40. rcVarIsYes fetchmail_daemon || exit 0
  41. @l_prefix@/bin/fetchmail --quit
  42. rm -f ${fetchmail_pidfile} 2>/dev/null || true
  43. %restart -p 200 -u @l_susr@
  44. rcService fetchmail enable yes || exit 0
  45. rcService fetchmail active no && exit 0
  46. rcVarIsYes fetchmail_daemon || exit 0
  47. rc fetchmail stop start
  48. %reload -p 200 -u @l_susr@
  49. rcService fetchmail enable yes || exit 0
  50. rcService fetchmail active no && exit 0
  51. rcVarIsYes fetchmail_daemon || exit 0
  52. @l_prefix@/bin/fetchmail
  53. %quarterly -p 800 -u @l_susr@
  54. rcService fetchmail enable yes || exit 0
  55. rcVarIsYes fetchmail_daemon || exit 0
  56. if [ -s ${fetchmail_users} ] ; then
  57. cat ${fetchmail_users} | shtool subst \
  58. -e '/^[[:space:]]*#.*/d' | while read user comment
  59. do
  60. urc=`eval echo ~$user`/.fetchmailrc
  61. if [ -s $urc ] ; then
  62. cat $urc | shtool subst \
  63. -e '/^[[:space:]]*set[[:space:]].*/s;^;X##FORBIDDEN##;' \
  64. -e '/.*[[:space:]]preconnect[[:space:]].*/s;^;X##FORBIDDEN##;' \
  65. -e '/.*[[:space:]]postconnect[[:space:]].*/s;^;X##FORBIDDEN##;' \
  66. -e '/.*[[:space:]]idle[[:space:]].*/s;^;X##FORBIDDEN##;' \
  67. -e '/.*[[:space:]]monitor[[:space:]].*/s;^;X##FORBIDDEN##;' \
  68. -e '/.*[[:space:]]plugin[[:space:]].*/s;^;X##FORBIDDEN##;' \
  69. -e '/.*[[:space:]]plugout[[:space:]].*/s;^;X##FORBIDDEN##;' \
  70. -e '/^[[:space:]]*poll[[:space:]].*/s;\(.*\);X\1;' \
  71. -e '/^[[:space:]]*server[[:space:]].*/s;\(.*\);X\1;' \
  72. -e '/^[[:space:]]*#.*/s;\(.*\);X\1;' \
  73. -e '/^X.*/!d' \
  74. -e '/^X.*/s;^X;;' \
  75. >/tmp/$user.$$
  76. chmod 0600 /tmp/$user.$$
  77. if @l_prefix@/bin/fetchmail --configdump -f /tmp/$user.$$ >/dev/null 2>&1; then
  78. cat /tmp/$user.$$
  79. fi
  80. rm /tmp/$user.$$
  81. fi
  82. done >${fetchmail_rc}.tmp
  83. cat ${fetchmail_rc_master} ${fetchmail_rc}.tmp >${fetchmail_rc}.new
  84. rm ${fetchmail_rc}.tmp
  85. chmod 0600 ${fetchmail_rc}.new
  86. if ! cmp -s ${fetchmail_rc} ${fetchmail_rc}.new ; then
  87. shtool rotate -f \
  88. -n ${fetchmail_rc_numfiles} -m 644 -o @l_susr@ -g @l_mgrp@ \
  89. ${fetchmail_rc}
  90. mv ${fetchmail_rc}.new ${fetchmail_rc}
  91. fi
  92. rm -f ${fetchmail_rc}.new
  93. else
  94. if [ -s ${fetchmail_rc_master} ] ; then
  95. cp ${fetchmail_rc_master} ${fetchmail_rc}
  96. chmod 0600 ${fetchmail_rc}
  97. fi
  98. fi
  99. exit 0
  100. %daily -p 800 -u @l_susr@
  101. rcService fetchmail enable yes || exit 0
  102. rcVarIsYes fetchmail_daemon || exit 0
  103. shtool rotate -f \
  104. -n ${fetchmail_log_numfiles} -s ${fetchmail_log_minsize} -d \
  105. -z ${fetchmail_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
  106. -P "${fetchmail_log_prolog}" \
  107. -E "${fetchmail_log_epilog}; rc fetchmail restart" \
  108. ${fetchmail_log_file}
  109. exit 0