web,tools: Add a list of recent donors
[gnupg-doc.git] / tools / mkkudos.sh
1 #!/bin/sh
2
3 set -e
4
5 htdocs="/var/www/www/www.gnupg.org/htdocs"
6 #htdocs="/home/wk/s/gnupg-doc/web"
7
8 donors="$htdocs/donate/donors.dat"
9 donations="$htdocs/donate/donations.dat"
10
11
12 usage()
13 {
14     cat <<EOF
15 Usage: $0 [OPTIONS]
16 Options:
17         --force    Force re-creation of files.
18 EOF
19     exit $1
20 }
21
22
23 force=no
24 while [ $# -gt 0 ]; do
25     case "$1" in
26         # Set up `optarg'.
27         --*=*)
28             optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
29             ;;
30         *)
31             optarg=""
32             ;;
33     esac
34
35     case $1 in
36         --force)
37             force=yes
38             ;;
39         --help)
40             usage 0
41             ;;
42         *)
43             usage 1 1>&2
44             ;;
45     esac
46     shift
47 done
48
49
50 if [ ! -f "$donors" ]; then
51   echo "mkkudos.sh: '$donors' not found" >&2;
52   exit 1
53 fi
54 if [ ! -f "$donations" ]; then
55   echo "mkkudos.sh: '$donations' not found" >&2;
56   exit 1
57 fi
58
59 tmp=$(head -1 "$donations")
60 monyear=$(echo "$tmp" | awk -F: 'BEGIN { m[1] = "January";
61       m[2] = "February"; m[3] = "March"; m[4] = "April"; m[5] = "May";
62       m[6] = "June"; m[7] = "July"; m[8] = "August"; m[9] = "September";
63       m[10] = "October"; m[11] = "November"; m[12] = "December"; }
64       {printf "%s %d", m[$2] , $1}')
65 euro=$(echo "$tmp" | awk -F: '{printf "%d Euro", int($8 + 0.5)}')
66 euroyr=$(echo "$tmp" | awk -F: '{printf "%d Euro", int($10 + 0.5)}')
67 n=$(echo "$tmp" | awk -F: '{printf "%d", $7}')
68 nyr=$(echo "$tmp" | awk -F: '{printf "%d", $9}')
69
70 for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html \
71             "$htdocs/donate/"index.html; do
72    if [ $force = no ]; then
73      [ "$file" -ot "$donors" ] || continue
74    fi
75    if [ "$file" = "$htdocs/donate/"kudos.html ]; then
76      year=$(date +%Y)
77    else
78      year=${file#$htdocs/donate/kudos-}
79      year=${year%.html}
80    fi
81    echo "processing $file" >&2
82    [ -f "$file.tmp" ] && rm "$file.tmp"
83    awk -F: -v year=$year -v donors="$donors" \
84            -v monyear="$monyear" -v euro="$euro" -v euroyr="$euroyr" \
85            -v n="$n" -v nyr="$nyr" \
86             <"$file"  >"$file.tmp" '
87      /<!--BEGIN-DONATIONS-->/ {indon=1; print; insert("") }
88      /<!--END-DONATIONS-->/ {indon=0}
89      /<!--BEGIN-SOME-DONATIONS-->/ {indon=1; print; insertsome("") }
90      /<!--END-SOME-DONATIONS-->/ {indon=0}
91      /<!--BEGIN-DONATIONS_goteo13-->/ {indon=1; print; insert("goteo13") }
92      /<!--END-DONATIONS_goteo13-->/ {indon=0}
93      /<!--INSERT-MONTH-DATE-->/ {
94            printf "<!--INSERT-MONTH-DATE--> %s\n", monyear;
95            next
96      }
97      /<!--INSERT-MONTH-EURO-->/ {
98            printf "<!--INSERT-MONTH-EURO--> %s\n", euro;
99            next
100      }
101      /<!--INSERT-MONTH-N-->/ {
102            printf "<!--INSERT-MONTH-N--> %s\n", n;
103            next
104      }
105      /<!--INSERT-YEAR-EURO-->/ {
106            printf "<!--INSERT-YEAR-EURO--> %s\n", euroyr;
107            next
108      }
109      /<!--INSERT-YEAR-N-->/ {
110            printf "<!--INSERT-YEAR-N--> %s\n", nyr;
111            next
112      }
113      !indon { print }
114
115      function insert (tag) {
116        while (getline < donors) {
117          if ( $0 ~ /^(#.*)?$/ )
118             continue;
119          if ( $3 == "" )
120             continue;
121          if ($1==year && $4==tag) {
122            printf "<li>%s</li>\n", $3
123          }
124        }
125        close (donors)
126      }
127
128      function insertsome (tag) {
129        i = 0
130        while (getline < donors) {
131          if ( $0 ~ /^(#.*)?$/ )
132             continue;
133          if ( $3 == "" )
134             continue;
135          if ($4==tag) {
136            data[i++] = $3
137          }
138        }
139        close (donors)
140        j = i > 16 ? ( i - 16 ) : 0
141        while (j < i) {
142            printf "<li>%s</li>\n", data[j++]
143        }
144      }
145      '
146    mv "$file.tmp" "$file" || echo "mkkudos.sh: error updating $file" >&2
147 done