home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / cron.weekly / popularity-contest < prev    next >
Encoding:
Text File  |  2007-02-05  |  1.9 KB  |  89 lines

  1. #!/bin/sh
  2.  
  3. # don't run if this package is removed but not purged
  4. if [ ! -f /usr/sbin/popularity-contest ]; then
  5.     exit 0
  6. fi
  7.  
  8. unset MAILFROM
  9. unset MAILTO
  10. unset MY_HOSTID
  11. unset PARTICIPATE
  12. unset SUBMITURLS
  13. unset USEHTTP
  14.  
  15. # get configuration information
  16. . /usr/share/popularity-contest/default.conf
  17. . /etc/popularity-contest.conf
  18.  
  19. # don't run if MAILTO address is blank, and not configured to use HTTP POST!
  20. if [ -z "$MAILTO" ] && [ "yes" != "$USEHTTP" ]; then exit 0; fi
  21.  
  22. # don't run if PARTICIPATE is "no" or unset!
  23. [ "$PARTICIPATE" = "no" ] || [ -z "$PARTICIPATE" ] && exit 0
  24.  
  25. # keep old logs
  26. cd /var/log
  27. umask 022
  28. savelog -c 7 popularity-contest >/dev/null
  29. POPCON=/var/log/popularity-contest
  30.  
  31. run_popcon()
  32. {
  33.     # Set HOME to avoid bug #212013.
  34.     HOME=/tmp su -pc "sh -c /usr/sbin/popularity-contest" nobody
  35. }
  36.  
  37. do_sendmail()
  38. {
  39.     if [ -n "$MAILFROM" ]; then
  40.         sendmail -oi -f "$MAILFROM" $MAILTO
  41.     else
  42.         sendmail -oi $MAILTO
  43.     fi
  44. }
  45.  
  46. # generate the popularity contest data
  47.  
  48. run_popcon > $POPCON
  49.  
  50. SUBMITTED=no
  51.  
  52. # try to post the report through http POST
  53. if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
  54.     for URL in $SUBMITURLS ; do
  55.     if setsid /usr/share/popularity-contest/popcon-upload \
  56.         -u $URL -f $POPCON -C 2>/dev/null ; then
  57.         SUBMITTED=yes
  58.     else
  59.         logger -t popularity-contest "unable to submit report to $URL."
  60.     fi
  61.     done
  62. fi
  63.  
  64. # try to email the popularity contest data
  65.  
  66. if [ yes != "$SUBMITTED" ] && [ -n "$MAILTO" ]; then
  67.     if [ -x "`which sendmail 2>/dev/null`" ]; then
  68.     (
  69.         if [ -n "$MAILFROM" ]; then
  70.                 echo "From: <$MAILFROM>"
  71.             echo "Sender: <$MAILFROM>"
  72.         fi
  73.         echo "To: $MAILTO"
  74.         echo "Subject: popularity-contest submission"
  75.         echo "MIME-Version: 1.0"
  76.         echo "Content-Type: text/plain"
  77.         echo
  78.         cat $POPCON
  79.     ) | do_sendmail
  80.     SUBMITTED=yes
  81.     else
  82.     logger -t popularity-contest "unable to submit report using sendmail."
  83.     fi
  84. fi
  85.  
  86. if [ "yes" != "$SUBMITTED" ] ; then
  87.     logger -t popularity-contest "unable to submit report."
  88. fi
  89.