PageRenderTime 40ms CodeModel.GetById 28ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/cron.daily/popularity-contest

http://github.com/brinkman83/bashrc
Shell | 96 lines | 69 code | 17 blank | 10 comment | 22 complexity | e5712443c40fa3780de7ae77692caeb7 MD5 | raw file
 1#!/bin/sh
 2
 3# don't run if this package is removed but not purged
 4if [ ! -f /usr/sbin/popularity-contest ]; then
 5	exit 0
 6fi
 7
 8unset MAILFROM
 9unset MAILTO
10unset MY_HOSTID
11unset PARTICIPATE
12unset SUBMITURLS
13unset 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!
20if [ -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
25if [ -n "$HTTP_PROXY" ]; then
26  export http_proxy="$HTTP_PROXY";
27fi
28
29# Only run on the given day, to spread the load on the server a bit
30if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
31  exit 0
32fi
33
34# keep old logs
35cd /var/log
36umask 022
37savelog -c 7 popularity-contest >/dev/null
38POPCON=/var/log/popularity-contest
39
40run_popcon()
41{
42	su -s /bin/sh -c "/usr/sbin/popularity-contest" nobody
43}
44
45do_sendmail()
46{
47	if [ -n "$MAILFROM" ]; then
48		sendmail -oi -f "$MAILFROM" $MAILTO
49	else
50		sendmail -oi $MAILTO
51	fi
52}
53
54# generate the popularity contest data
55
56run_popcon > $POPCON
57
58SUBMITTED=no
59
60# try to post the report through http POST
61if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
62    for URL in $SUBMITURLS ; do
63	if setsid /usr/share/popularity-contest/popcon-upload \
64	    -u $URL -f $POPCON -C 2>/dev/null ; then
65		SUBMITTED=yes
66	else
67		logger -t popularity-contest "unable to submit report to $URL."
68	fi
69    done
70fi
71
72# try to email the popularity contest data
73
74if [ yes != "$SUBMITTED" ] && [ -n "$MAILTO" ]; then
75    if [ -x "`which sendmail 2>/dev/null`" ]; then
76	(
77	    if [ -n "$MAILFROM" ]; then
78	        	echo "From: <$MAILFROM>"
79	    	echo "Sender: <$MAILFROM>"
80	    fi
81	    echo "To: $MAILTO"
82	    echo "Subject: popularity-contest submission"
83	    echo "MIME-Version: 1.0"
84	    echo "Content-Type: text/plain"
85	    echo
86	    cat $POPCON
87	) | do_sendmail
88	SUBMITTED=yes
89    else
90	logger -t popularity-contest "unable to submit report using sendmail."
91    fi
92fi
93
94if [ "yes" != "$SUBMITTED" ] ; then
95	logger -t popularity-contest "unable to submit report."
96fi