Add tools and files to create a list of 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
10 if [ ! -f "$donors" ]; then
11   echo "mkkudos.sh: '$donors' not found" >&2;
12   exit 1
13 fi
14
15 for file in "$htdocs/donate/"kudos-????.html; do
16    [ "$file" -ot "$donors" ] || continue
17    year=${file#$htdocs/donate/kudos-}
18    year=${year%.html}
19    echo "processing $file" >&2
20    [ -f "$file.tmp" ] && rm "$file.tmp"
21    awk -F: -v year=$year -v donors="$donors" <"$file"  >"$file.tmp" '
22      /<!--BEGIN-DONATIONS-->/ {indon=1; print; insert("") }
23      /<!--END-DONATIONS-->/ {indon=0}
24      /<!--BEGIN-DONATIONS_goteo13-->/ {indon=1; print; insert("goteo13") }
25      /<!--END-DONATIONS_goteo13-->/ {indon=0}
26      !indon { print }
27
28      function insert (tag) {
29        while (getline < donors) {
30          if ( $0 ~ /^(#.*)?$/ )
31             continue;
32          if ($1==year && $4==tag) {
33            printf "<li>%s</li>\n", $3
34          }
35        }
36        close (donors)
37      }
38      '
39    mv "$file.tmp" "$file" || echo "mkkudos.sh: error updating $file" >&2
40 done