Debian Codegraph @

tools/update_popcon

raw
1 #!/bin/sh
2 #
3 # update_popcon
4 #
5 # Simple helper script to update our popularity-contest generated task
6 # list from the data available at popcon.debian.org
7
8 DATE=`date`
9
10 dir=/etc/ssl/ca-debian
11 if [ -d $dir ]; then
12 capath="--capath $dir"
13 fi
14
15 # Determine temp dir to use
16 if [ "$BDIR"x = ""x ] ; then
17 if [ "$TMPDIR"x != ""x ] ; then
18 BDIR=$TMPDIR
19 else
20 BDIR=/tmp
21 fi
22 echo "update_popcon not given a temp dir, using $BDIR" >&2
23 fi
24 if [ ! -d "$BDIR" ] ; then
25 echo "update_popcon: temp dir '$BDIR' does not exist" >&2
26 exit 1
27 fi
28
29 # Create temp dir and ensure cleanup
30 TDIR=$BDIR/update_popcon.$$
31 mkdir -p $TDIR
32 trap 'rm -rf $TDIR' EXIT HUP INT QUIT TERM
33
34 dl_file () {
35 # Grab the headers for each file so that we can check the size.
36 # We've had problems in the past with download failures causing issues,
37 # so let's make sure that we get the complete file in each case
38 DIST=$1
39 SITE="https://popcon.debian.org/"
40
41 curl -L $capath -s --head $SITE/$DIST/by_inst > $TDIR/$DIST.head
42 error=$?
43 if [ $error -ne 0 ] ; then
44 echo "Failed to download correctly: curl error $error on HEAD" >&2
45 exit 1
46 fi
47 HEAD_SIZE=`cat $TDIR/$DIST.head | \
48 awk '/^.ontent-.ength/ {gsub("\r","");print $2}'`
49
50 curl -L $capath -s $SITE/$DIST/by_inst > $TDIR/$DIST
51 error=$?
52 DL_SIZE=`stat -c %s $TDIR/$DIST`
53 if [ $error -ne 0 ] ; then
54 echo "Failed to download correctly: curl error $error" >&2
55 exit 1
56 fi
57
58 if [ "$DL_SIZE"x != "$HEAD_SIZE"x ] ; then
59 echo "Failed to download correctly: expected $HEAD_SIZE bytes, but got $DL_SIZE bytes" >&2
60 exit 1
61 fi
62
63 LASTMOD=`awk '/^.ast-.odified:/ {
64 gsub("\r","")
65 gsub("^.ast-.odified: ","")
66 print $0}' $TDIR/$DIST.head`
67 echo "$LASTMOD"
68 }
69
70 MAIN_DATE=`dl_file main`
71 error=$?
72 if [ $error -ne 0 ]; then
73 exit $error
74 fi
75 CONTRIB_DATE=`dl_file contrib`
76 error=$?
77 if [ $error -ne 0 ]; then
78 exit $error
79 fi
80
81 OUT=$1
82 rm -f $OUT
83
84 echo "/*" >> $OUT
85 echo " Popularity Contest results" >> $OUT
86 echo " See the README for details on updating." >> $OUT
87 echo "" >> $OUT
88 echo " Last update: $DATE" >> $OUT
89 echo " Based on main data from $MAIN_DATE" >> $OUT
90 echo " Based on contrib data from $CONTRIB_DATE" >> $OUT
91 echo "*/" >> $OUT
92 echo "" >> $OUT
93
94 cat $TDIR/main $TDIR/contrib | \
95 egrep -v '(^#|Total|-----|kernel-source)' | \
96 sort -rn -k3,3 -k7,7 -k4,4 | awk '{print $2}' >> $OUT
97
98 if [ $? -ne 0 ]; then
99 exit $?
100 fi