Browse Source

This commit was generated by cvs2svn to compensate for changes in r6,

which included commits to RCS files with non-trunk default branches.
suites/ascii
Petter Reinholdtsen 19 years ago
parent
commit
494aef3de6
  1. 94
      README
  2. 34
      README.examples
  3. 2
      debian/.cvsignore
  4. 95
      debian/changelog
  5. 1
      debian/conffiles
  6. 12
      debian/config
  7. 21
      debian/control
  8. 9
      debian/copyright
  9. 52
      debian/cron.weekly
  10. 37
      debian/popularity-contest.8
  11. 75
      debian/postinst
  12. 16
      debian/postrm
  13. 10
      debian/preinst
  14. 56
      debian/rules
  15. 28
      debian/templates
  16. 226
      popanal.py
  17. 32
      popcon-process.sh
  18. 83
      popularity-contest
  19. 60
      prepop.py

94
README

@ -0,0 +1,94 @@
DEBIAN PACKAGE POPULARITY CONTEST - Avery Pennarun <apenwarr@debian.org>
=================================
This package contains a script, /usr/sbin/popularity-contest, which
generates a list of the packages installed on your system, in order of
most-recently-used to least-recently-used. The simplest way to use this
information is to help clean up your hard drive by removing unused packages.
For example,
popularity-contest | grep '<OLD>'
will show you a list of packages you haven't used in a while. Note that
this output isn't totally accurate: some packages appear "old" but you can't
remove them because other (non-old) packages depend on them. Shared library
packages are particularly bad this way because it's impossible to tell when
a library was last used.
The popularity-contest output looks like this:
POPULARITY-CONTEST-0 TIME:914183330 ID:b92a5fc1809d8a95a12eb3a3c84166dd
914183333 909868335 grep /bin/fgrep
914183333 909868280 findutils /usr/bin/find
914183330 909885698 dpkg-awk /usr/bin/dpkg-awk
914183330 909868577 gawk /usr/bin/gawk
[...more lines...]
END-POPULARITY-CONTEST-0 TIME:914183335
The first and last lines allow you to put more than one set of
popularity-contest results into a single file and then split them up
easily later.
The rest of the lines are package entries, one line for each package
installed on your system. They have the format:
<atime> <ctime> <packagename> <mru-program> <tag>
<packagename> is the name of the Debian package that contains <mru-program>.
<mru-program> is the most recently used program, static library, or header
(.h) file in the package.
<atime> and <ctime> are the access time and creation time of the
<mru-program> on your disk, respectively, represented as the number of
seconds since midnight GMT on January 1, 1970 (ie. in Unix time_t format).
Linux updates <atime> whenever you open the file; <ctime> was set when you
first installed the package.
<tag> is determined by popularity-contest depending on <atime>, <ctime>, and
the current date. <tag> can be RECENT-CTIME, OLD, or NOFILES.
RECENT-CTIME means that atime is very close to ctime; it's impossible to
tell whether the package was used recently or not, since <atime> is also
updated when <ctime> is set. Normally, this happens because you have
recently upgraded the package to a new version, resetting the <ctime>.
OLD means that the <atime> is more than a month ago; you haven't used the
package for more than a month.
NOFILES means that no files in the package seemed to be programs, so
<atime>, <ctime>, and <mru-program> are invalid.
PARTICIPATING IN THE PUBLIC SURVEY
==================================
You can help out the Debian Project by sending your popularity-contest
results to us anonymously. With information from enough people, we can
determine which packages are most often used, which are often installed but
not used, and which are nearly never used. That way, we can help people
make decisions about which packages should fit on the first Debian install
CD, for example, or which packages are most important for an FTP mirror site
to keep.
!!!!
SECURITY NOTE: it's impossible to make a submission completely anonymous,
since Internet servers tend to add headers and log messages along the way.
Our receiver program at debian throws away this information as soon as
possible so no one will see it, but if you're really paranoid you might not
want to participate.
!!!!
The popularity-contest package comes with a cron task to send the
information out to us each night. You can change where the submissions go
by editing /etc/popularity-contest.conf. Normally, you will send the
results to:
apenwarr-survey@debian.org
I periodically post survey results on my web page:
http://www.debian.org/~apenwarr/popcon/
You can find some sample analysis scripts in
/usr/share/doc/popularity-contest as part of this package.

34
README.examples

@ -0,0 +1,34 @@
This directory contains some scripts used to post-process popularity-contest
entries. You should have a lot of submissions from different users (at
least 100 of them, if possible) for these results to be valid.
To collect results, use procmail or some other mail alias to e-mail
submissions to a file called, say, new-popcon-entries.
You should run popcon-process.sh once a day, or so. It calls prepop.py to
split the mailbox file into a directory (popcon-entries) with one file per
submission, and only one submission per participant. (Since each
participant makes a submission only once per day, it's very important to
remove duplicates.)
HINT: if you have an account on master.debian.org, you can find a
pre-processed popcon-entries directory in /home/apenwarr. Feel free to use
these files to generate your own statistics.
Now you can do, for example:
cat popcon-entries/*/* | popanal.py
which creates a bunch of files named results.soemthing-or-other, with one
"results" file per Debian package section. Output lines look like this:
<name> <vote> <old> <recent-ctime> <no-files>
<name> is the package name;
<vote> is the number of people who use this package regularly;
<old> is the number of people who installed, but don't use this package
regularly;
<recent-ctime> is the number of people who upgraded this package recently;
<no-files> is the number of people whose entry didn't contain enough
information (atime and ctime were 0).

2
debian/.cvsignore

@ -0,0 +1,2 @@
tmp
files

95
debian/changelog

@ -0,0 +1,95 @@
popularity-contest (1.3-1.1) unstable; urgency=high
* NMU.
* Do not ship /etc/popularity-contest.conf; don't change it using
debconf if it already exists; don't mark it as a conffile (since we
don't ship it any more). (Closes: #135273)
This should be sufficient to get popularity-contest back into woody.
* #136510 appears to have been fixed in 1.2 or 1.3-1. (Closes: #136510)
(If you want to participate question is now boolean.)
-- Chris Lawrence <lawrencc@debian.org> Mon, 1 Apr 2002 21:21:22 -0600
popularity-contest (1.3-1) unstable; urgency=high
* Change default MAILTO back to apenwarr-survey@debian.org. Oops!
(Closes: #137224)
-- Avery Pennarun <apenwarr@debian.org> Thu, 7 Mar 2002 12:39:49 -0500
popularity-contest (1.2) unstable; urgency=low
* Use debconf.
* use full path in su (Closes: #125701)
* repaired description (Closes: #129539)
* correct handling of sender (sendmail -f) (Closes: #123765)
* Mostly thanks to Erich Schubert <erich@debian.org>
-- Avery Pennarun <apenwarr@debian.org> Thu, 21 Feb 2002 09:11:58 -0500
popularity-contest (1.1-1) unstable; urgency=low
* Allow overriding the From: and Sender: headers in outgoing mail by
adding a new MAIL_FROM variable in /etc/popularity-contest.conf. Also
drop to user "nobody" before running. Closes: #89530, #39501, #69823,
#74809, #57257, #57709, #65218. Okay, this was obviously a popular
request, but if people would just configure their mailers not to use
invalid From: lines by default, they would be a lot happier.
* Added a popularity-contest.8 manpage. Closes: #39501.
* Updated README. Closes: #105668.
-- Avery Pennarun <apenwarr@debian.org> Tue, 6 Nov 2001 21:19:38 -0500
popularity-contest (1.0-1) unstable; urgency=low
* Now runs only once a week instead of once a day. Fixes bug#53768.
* Let sendmail auto-generate the From header. Fixes bug#48195, bug#48200.
* Warnings about Received and Message-Id e-mail lines that may reveal the
sender. Fixes bug#31205.
* Actually even version 0.1-2 saved the popcon results to a log file, so
that fixes bug#44801.
* Uses a more unique ID string than just the hostname, and it persists
across hostname changes.
-- Avery Pennarun <apenwarr@debian.org> Wed, 23 Dec 1998 14:28:37 -0500
popularity-contest (0.1-2) frozen unstable; urgency=low
* Added a missing dependency on mail-transport-agent; fixed bug#31010.
-- Avery Pennarun <apenwarr@debian.org> Wed, 23 Dec 1998 14:28:37 -0500
popularity-contest (0.1) frozen unstable; urgency=low
* Use a valid From_ address for sendmail; fixes bug#30341.
* popularity-contest.8 is a link to the undocumented(8) man page, and we
provide a README file in /usr/doc; downgrades bug#28745.
* Include my post-processing scripts in /usr/doc/popularity-contest/examples
* No longer tries to report on packages that aren't installed.
-- Avery Pennarun <apenwarr@debian.org> Sun, 20 Dec 1998 16:11:02 -0500
popularity-contest (0.00) unstable; urgency=low
* Initial test release.
-- Avery Pennarun <apenwarr@debian.org> Sat, 24 Oct 1998 22:33:58 -0400

1
debian/conffiles

@ -0,0 +1 @@
/etc/cron.weekly/popularity-contest

12
debian/config

@ -0,0 +1,12 @@
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
db_input medium popularity-contest/intro || true
db_go || true
db_input high popularity-contest/participate || true
db_go || true

21
debian/control

@ -0,0 +1,21 @@
Source: popularity-contest
Section: misc
Priority: optional
Maintainer: Avery Pennarun <apenwarr@debian.org>
Build-Depends-Indep: debhelper
Standards-Version: 3.5.6.0
Package: popularity-contest
Architecture: all
Depends: gawk, dpkg-awk, exim | mail-transport-agent, debconf
Recommends: cron
Description: Vote for your favourite packages automatically.
When you install this package, it sets up a cron job that will anonymously
e-mail the Debian developers periodically with statistics about your
most used Debian packages.
.
This information helps us make decisions such as which packages should go
on the first Debian CD. Also, we can improve future versions of Debian
so that the most popular packages are the ones which are installed
automatically for new users.

9
debian/copyright

@ -0,0 +1,9 @@
This Debian package was both written and designed by Avery Pennarun. Here
is the copyright notice from the popularity-contest script.
#
# Copyright (C) 1998 by Avery Pennarun, for the Debian Project.
# Use, modify, and redistribute modified or unmodified versions in any
# way you wish.
#

52
debian/cron.weekly

@ -0,0 +1,52 @@
#!/bin/sh
# don't run if this package is removed but not purged
if [ ! -f /usr/sbin/popularity-contest ]; then
exit 0
fi
unset MAILFROM
unset MAILTO
unset MY_HOSTID
unset PARTICIPATE
# get configuration information
. /etc/popularity-contest.conf
# don't run if MAILTO address is blank!
if [ -z "$MAILTO" ]; then exit 0; fi
# don't run if PARTICIPATE is "no" or unset!
[ "$PARTICIPATE" = "no" -o -z "$PARTICIPATE" ] && exit 0
# keep old logs
cd /var/log
umask 022
savelog -c 7 popularity-contest >/dev/null
run_popcon()
{
if [ -n "$MAILFROM" ]; then
echo "From: <$MAILFROM>"
echo "Sender: <$MAILFROM>"
fi
echo "To: $MAILTO"
echo "Subject: popularity-contest submission"
echo
su nobody -pc "sh -c /usr/sbin/popularity-contest"
}
do_sendmail()
{
if [ -n "$MAILFROM" ]; then
sendmail -oi -f "$MAILFROM" "$MAILTO"
else
sendmail -oi "$MAILTO"
fi
}
# generate and transmit the popularity contest data
run_popcon \
| tee /var/log/popularity-contest \
| do_sendmail

37
debian/popularity-contest.8

@ -0,0 +1,37 @@
.\" Hey, Emacs! This is an -*- nroff -*- source file.
.\"
.\"
.TH POPULARITY-CONTEST 8 "November 2001" "Debian/GNU Linux"
.SH NAME
popularity-contest \- list the most popular Debian packages
.SH SYNOPSIS
.B popularity-contest
.SH DESCRIPTION
The
.B popularity-contest
command gathers information about Debian packages installed on the system,
and prints the name of the most recently used executable program in that
package as well as its last-accessed time (atime) and last-attribute-changed
time (ctime) to stdout.
.PP
When aggregated with the output of
.B popularity-contest
from many other systems, this information is valuable because it can be used
to determine which Debian packages are commonly installed, used, or
installed and never used. This helps Debian maintainers make decisions such
as which packages should be installed by default on new systems.
.PP
Normally,
.B popularity-contest
is run from a
.BR cron (8)
job,
.BR /etc/cron.weekly/popularity-contest ,
which automatically emails the results to Debian package maintainers
according to the settings in
.BR /etc/popularity-contest.conf .
.SH SEE ALSO
Additional documentation is in
.BR /usr/share/doc/popularity-contest/
.SH AUTHOR
Avery Pennarun <apenwarr@debian.org>.

75
debian/postinst

@ -0,0 +1,75 @@
#!/bin/bash
set -e
#DEBHELPER#
if [ "$1" = "configure" ] && [ ! -e /etc/popularity-contest.conf ]; then
. /usr/share/debconf/confmodule
if [ -z "$MAILTO" -o "$MAILTO" = "erich-survey@debian.org" ]; then
MAILTO="apenwarr-survey@debian.org"
fi
if [ -z "$MY_HOSTID" ]; then
MY_HOSTID=`dd if=/dev/urandom bs=1k count=1 2>/dev/null | md5sum`
fi
cat <<-EOF >/etc/popularity-contest.conf
# Config file for Debian's popularity-contest package.
#
# To change this file, remove it and use:
# dpkg-reconfigure popularity-contest
#
# You can also edit it by hand, if you so choose.
# MAILTO specifies the address to e-mail statistics to each week.
#
MAILTO="$MAILTO"
# MY_HOSTID is a secret number that the popularity-contest receiver
# uses to keep track of your submissions. Whenever you send in a
# new entry, it overwrites the last one that had the same HOSTID.
#
# This key was generated automatically so you should normally just
# leave it alone.
#
MY_HOSTID="$MY_HOSTID"
# MAILFROM is the forged sender email address you want to use in
# email submitted to the popularity-contest. If this is commented
# out, no From: or Sender: lines will be added to the outgoing mail,
# and it will be your MTA's job to add them. This is usually what
# you want.
#
# If your MTA is misconfigured or impossible to configure correctly,
# and it always generates invalid From: and/or Sender: lines, you
# can force different results by setting MAILFROM here. This can
# cause problems with spam bouncers, so most people should leave it
# commented out.
#
EOF
if [ -z "$MAILFROM" ]; then
echo '#MAILFROM=root@nowhere.org' >>/etc/popularity-contest.conf
else
echo "MAILFROM=$MAILFROM" >>/etc/popularity-contest.conf
fi
# Get this setting from debconf.
db_get popularity-contest/participate || true
if [ "$RET" = "yes" -o "$RET" = "YES" -o "$RET" = "true" ]; then
PARTICIPATE="yes"
else
PARTICIPATE="no"
fi
cat <<-EOF >>/etc/popularity-contest.conf
# PARTICIPATE can be one of "yes" or "no".
# If you don't want to participate in the contest, say "no"
# and we won't send messages.
#
# If this option is missing, the default is "no".
#
PARTICIPATE=$PARTICIPATE
EOF
fi

16
debian/postrm

@ -0,0 +1,16 @@
#!/bin/sh
# purge the config file which is created in the postinst script
if [ "$1" = purge ] ; then
rm -f /etc/popularity-contest.conf
fi
if [ "$1" = "purge" -a -e /usr/share/debconf/confmodule ]; then
# Source debconf library.
. /usr/share/debconf/confmodule
# Remove my changes to the db.
db_purge
fi
#DEBHELPER#

10
debian/preinst

@ -0,0 +1,10 @@
#!/bin/sh
#DEBHELPER#
# older versions had popularity-contest as a conffile in a different dir, so
# it won't get removed automatically.
#
if [ "$1" = upgrade ]; then
rm -f /etc/cron.daily/popularity-contest
fi

56
debian/rules

@ -0,0 +1,56 @@
#!/usr/bin/make -f
# debian/rules file for the Debian popularity-contest package.
# Derived in 1998 by Avery Pennarun from:
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 by Joey Hess.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
build:
dh_testdir
clean:
dh_testdir
dh_testroot
dh_clean
install:
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/tmp.
install -d debian/tmp/usr/sbin/
install -d debian/tmp/etc/
install popularity-contest debian/tmp/usr/sbin/
# Build architecture-independent files here.
binary-indep: build install
dh_testdir
dh_testroot
dh_installdocs README
dh_installexamples prepop.py popcon-process.sh popanal.py README.examples
dh_installmenu
dh_installcron
dh_installmanpages
dh_installdebconf
dh_undocumented
dh_installchangelogs
dh_strip
dh_compress
dh_fixperms
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
# Build architecture-dependent files here.
binary-arch: build install
source diff:
@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

28
debian/templates

@ -0,0 +1,28 @@
Template: popularity-contest/intro
Type: note
Description: Debian Package Popularity Contest
You can have your system anonymously e-mail the Debian developers
with statistics about your most used Debian packages.
.
This information helps us make decisions such as which packages
should go on the first Debian CD. Also, we can improve future
versions of Debian so that the most popular packages are the ones
which are installed automatically for new users.
.
If you choose to participate, the automatic submission script will
run once every week automatically.
.
You can always change your mind after making this decision:
"dpkg-reconfigure popularity-contest"
.
(NOTE: e-mail servers add their own tracing information and your data won't
be completely anonymous while in transit.)
Template: popularity-contest/participate
Type: boolean
Default: false
Description: Do you want to participate?
If you choose to participate, popularity-contest will run once every week
automatically, e-mailing statistics to the Debian developers.
.
If you want to participate in the contest, select yes.

226
popanal.py

@ -0,0 +1,226 @@
#!/usr/bin/python
#
# Read Debian popularity-contest submission data on stdin and produce
# some statistics about it.
#
import sys, string, time, glob
def ewrite(s):
sys.stderr.write("%s\n" % s)
class Vote:
yes = 0
old_unused = 0
too_recent = 0
empty_package = 0
def vote_for(vote, package, entry):
now = time.time()
if entry.atime == 0: # no atime: empty package
vote.empty_package = vote.empty_package + 1
elif now - entry.atime > 30 * 24*3600: # 30 days since last use: old
vote.old_unused = vote.old_unused + 1
elif now - entry.ctime < 30 * 24* 3600 \
and entry.atime - entry.ctime < 24*3600: # upgraded too recently
vote.too_recent = vote.too_recent + 1
else: # otherwise, vote for this package
vote.yes = vote.yes + 1
UNKNOWN = '**UNKNOWN**'
votelist = {}
sectlist = { UNKNOWN : [] }
deplist = {}
provlist = {}
complained = {}
def parse_depends(depline):
l = []
split = string.split(depline, ',')
for d in split:
x = string.split(d)
if (x):
l.append(x[0])
return l
def read_depends(filename):
file = open(filename, 'r')
package = None
while 1:
line = file.readline()
if line:
if line[0]==' ' or line[0]=='\t': continue # continuation
split = string.split(line, ':')
if not line or split[0]=='Package':
if package and (len(dep) > 0 or len(prov) > 0):
deplist[package] = dep
for d in prov:
if not provlist.has_key(d):
provlist[d] = []
provlist[d].append(package)
if package:
if not sectlist.has_key(section):
sectlist[section] = []
if not votelist.has_key(package):
sectlist[section].append(package)
votelist[package] = Vote()
ewrite(package)
package = None
if line:
package = string.strip(split[1])
section = UNKNOWN
dep = []
prov = []
elif split[0]=='Section':
section = string.strip(split[1])
elif split[0]=='Depends' or split[0]=='Requires':
dep = dep + parse_depends(split[1])
elif split[0]=='Provides':
prov = parse_depends(split[1])
if not line: break
class Entry:
atime = 0;
ctime = 0;
mru_file = '';
def __init__(self, atime, ctime, mru_file):
try:
self.atime = long(atime)
self.ctime = long(ctime)
except:
self.atime = self.ctime = 0
self.mru_file = mru_file
class Submission:
# format: {package: [atime, ctime, mru_file]}
entries = {}
start_date = 0
# initialize a new entry with known data
def __init__(self, version, owner_id, date):
self.entries = {}
self.start_date = long(date)
ewrite('%s:\n\tSTART: %s' % (owner_id, time.ctime(long(date))))
# process a line of input from the survey
def addinfo(self, split):
if len(split) < 4:
ewrite('Invalid input line: ' + `split`)
return
self.entries[split[2]] = Entry(split[0], split[1], split[3])
# update the atime of dependency to that of dependant, if newer
def update_atime(self, dependency, dependant):
if not self.entries.has_key(dependency): return
e = self.entries[dependency]
f = self.entries[dependant]
if e.atime < f.atime:
e.atime = f.atime
e.ctime = f.ctime
# we found the last line of the survey: finish it
def done(self, date):
ewrite('\t STOP: after %d seconds, %d packages'
% (long(date) - self.start_date, len(self.entries)))
for package in self.entries.keys():
e = self.entries[package]
if deplist.has_key(package):
for d in deplist[package]:
self.update_atime(d, package)
if provlist.has_key(d):
for dd in provlist[d]:
self.update_atime(dd, package)
for package in self.entries.keys():
if not votelist.has_key(package):
if not complained.has_key(package):
ewrite(('Warning: package %s not in '
+ '/var/lib/dpkg/available') % package)
complained[package] = 1
votelist[package] = Vote()
sectlist[UNKNOWN].append(package)
votelist[package].vote_for(package, self.entries[package])
def headersplit(pairs):
header = {}
for d in pairs:
list = string.split(d, ':')
try:
key, value = list
header[key] = value
except:
pass
return header
def read_submissions(stream):
subcount = 0
e = None
while 1:
line = stream.readline()
if not line: break
split = string.split(line)
if not split: continue
if split[0]=='POPULARITY-CONTEST-0':
header = headersplit(split[1:])
if not header.has_key('ID') or not header.has_key('TIME'):
ewrite('Invalid header: ' + split)
continue
subcount = subcount + 1
ewrite('#%s' % subcount)
e = Submission(0, header['ID'], header['TIME'])
elif split[0]=='END-POPULARITY-CONTEST-0' and e != None:
header = headersplit(split[1:])
if header.has_key('TIME'):
e.done(header['TIME'])
e = None
elif e != None:
e.addinfo(split)
# end of while loop
ewrite('Processed %d submissions.' % subcount)
# main program
for d in glob.glob('/org/ftp.debian.org/ftp/dists/stable/*/binary-i386/Packages'):
read_depends(d)
for d in glob.glob('/org/ftp.debian.org/ftp/dists/unstable/*/binary-i386/Packages'):
read_depends(d)
read_submissions(sys.stdin)
def nicename(s):
new_s = ''
for c in s:
if c == '/':
new_s = new_s + ',';
elif c in string.letters or c in string.digits or c=='-':
new_s = new_s + c
else:
new_s = new_s + '.'
return new_s
# dump the results
for section in sectlist.keys():
ewrite('Dumping section %s' % nicename(section))
out = open('results.%s' % nicename(section), 'w')
for package in sectlist[section]:
fv = votelist[package]
out.write("%-30s %5d %5d %5d %5d\n"
% (package, fv.yes, fv.old_unused,
fv.too_recent, fv.empty_package))

32
popcon-process.sh

@ -0,0 +1,32 @@
#!/bin/bash
set -e
PATH=$HOME/bin:$PATH
cd $HOME
# rotate files
rm -rf popcon-entries.old
mkdir popcon-entries 2>/dev/null || true
cp -a popcon-entries popcon-entries.old
mv new-popcon-entries new-popcon-entries.old
touch new-popcon-entries
chmod og-rwx new-popcon-entries
# process entries
prepop.py <new-popcon-entries.old >$HOME/prepop.out
# delete outdated entries
find $HOME/popcon-entries -type f -mtime +10 | xargs rm -f
# analyze results
cd public_html/popcon/results
rm -f results.*
find $HOME/popcon-entries -type f | wc -l >../num-submissions
find $HOME/popcon-entries -type f | xargs cat \
| nice -15 popanal.py >$HOME/popanal.out 2>&1
cd ..
make clean >/dev/null
make >/dev/null
# upload web page to www.debian.org
cd $HOME
rsync -aze ssh public_html people.debian.org: </dev/null

83
popularity-contest

@ -0,0 +1,83 @@
#!/bin/bash
#
# Copyright (C) 1998,2000 by Avery Pennarun, for the Debian Project.
# Use, modify, and redistribute modified or unmodified versions in any
# way you wish.
#
# the set of installed packages is the set of all .list files in
# /var/lib/dpkg/info, with pathnames and .list suffix removed.
#
# Store that list in $PACKAGES.
#
. /etc/popularity-contest.conf
if [ -z "$MY_HOSTID" ]; then
echo "You must set MY_HOSTID in /etc/popularity-contest.conf!" >&2
exit 1
fi
DI=/var/lib/dpkg/info
PACKAGES=$(dpkg-awk "Status: .* installed" -- Package \
| grep '^Package:' | sed 's/^Package: //')
# Now, for each package, get the list of FILES that we are interested in,
# producing output lines of the format "atime ctime package pathname".
#
for d in $PACKAGES; do
FILES=$(egrep '/\.*bin/|/sbin/|^/usr/games/|\.[ah]$' $DI/$d.list)
if [ -n "$FILES" ]; then
find $FILES -follow -prune -type f \
-printf "%A@ %C@ $d %p\\n" 2>/dev/null
else
echo "0 0 $d <NOFILES>"
fi
done | gawk '
# pass the resulting list through this awk script.
# we require gawk, because we use "time" functions.
BEGIN {
lastpack = ""
now = systime()
daylen = 24 * 60 * 60
monthlen = (24 * 60 * 60) * 30
lastmonth = now - monthlen
}
lastpack != $3 {
if (mostrecent != "")
print mostrecent
lastpack = $3
lastacc=0
mostrecent=""
}
{
if ($1 >= lastacc) {
lastacc = $1
if ($1 > 0 && $1 < lastmonth)
mostrecent = sprintf("%s %s %s %s <OLD>",
$1, $2, $3, $4);
else {
if ($1 > 0 && $2 > lastmonth && $1 - $2 < daylen)
mostrecent = sprintf("%s %s %s %s <RECENT-CTIME>",
$1, $2, $3, $4);
else
mostrecent = $0
}
}
}
END {
print mostrecent
}
' |
# We're not done yet. Sort the output in reverse by atime, and
# add a header/footer.
( echo "POPULARITY-CONTEST-0" "TIME:$(date +%s)" \
"ID:$MY_HOSTID"
sort -n -r;
echo "END-POPULARITY-CONTEST-0" "TIME:$(date +%s)" )

60
prepop.py

@ -0,0 +1,60 @@
#!/usr/bin/python
# Accept popularity-contest entries on stdin and drop them into a
# subdirectory with a name based on their MD5 ID.
#
# Only the most recent entry with a given MD5 ID is kept.
#
import sys, string, os, time
dirname = 'popcon-entries'
output = None
now = time.time()
while 1:
line = sys.stdin.readline()
if not line: break
split = string.split(line)
if not split: continue
if split[0] == 'POPULARITY-CONTEST-0':
if output != None:
output.close()
output = None
mtime = 0
for s in split[1:]:
list = string.split(s, ':')
try:
key, value = list
except:
continue
if key == 'ID' and len(value) > 2:
md5 = value
subdir = dirname + '/' + value[0:2]
try:
os.mkdir(subdir)
except os.error: # already exists
pass
fname = subdir + '/' + md5
output = open(fname, "w")
output.write(line)
elif key == 'TIME':
mtime = float(value)
if (mtime > now):
mtime = now
elif split[0] == 'END-POPULARITY-CONTEST-0':
if output != None:
print "%s: %s" % (md5, time.ctime(mtime))
output.write(line)
output.close()
output = None
os.utime(fname, (mtime, mtime))
elif output != None:
output.write(line)
Loading…
Cancel
Save