web: More updates to the donation pages.
[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 "$htdocs/donate/"kudos.html; do
16    [ "$file" -ot "$donors" ] || continue
17    if [ "$file" = "$htdocs/donate/"kudos.html ]; then
18      year=$(date +%Y)
19    else
20      year=${file#$htdocs/donate/kudos-}
21      year=${year%.html}
22    fi
23    echo "processing $file" >&2
24    [ -f "$file.tmp" ] && rm "$file.tmp"
25    awk -F: -v year=$year -v donors="$donors" <"$file"  >"$file.tmp" '
26      /<!--BEGIN-DONATIONS-->/ {indon=1; print; insert("") }
27      /<!--END-DONATIONS-->/ {indon=0}
28      /<!--BEGIN-DONATIONS_goteo13-->/ {indon=1; print; insert("goteo13") }
29      /<!--END-DONATIONS_goteo13-->/ {indon=0}
30      !indon { print }
31
32      function insert (tag) {
33        while (getline < donors) {
34          if ( $0 ~ /^(#.*)?$/ )
35             continue;
36          if ($1==year && $4==tag) {
37            printf "<li>%s</li>\n", $3
38          }
39        }
40        close (donors)
41      }
42      '
43    mv "$file.tmp" "$file" || echo "mkkudos.sh: error updating $file" >&2
44 done