8e5ed961cc311e67732c060c6a87a4eb3b1fab49
[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; do
71    if [ $force = no ]; then
72      [ "$file" -ot "$donors" ] || continue
73    fi
74    if [ "$file" = "$htdocs/donate/"kudos.html ]; then
75      year=$(date +%Y)
76    else
77      year=${file#$htdocs/donate/kudos-}
78      year=${year%.html}
79    fi
80    echo "processing $file" >&2
81    [ -f "$file.tmp" ] && rm "$file.tmp"
82    awk -F: -v year=$year -v donors="$donors" \
83            -v monyear="$monyear" -v euro="$euro" -v euroyr="$euroyr" \
84            -v n="$n" -v nyr="$nyr" \
85             <"$file"  >"$file.tmp" '
86      /<!--BEGIN-DONATIONS-->/ {indon=1; print; insert("") }
87      /<!--END-DONATIONS-->/ {indon=0}
88      /<!--BEGIN-DONATIONS_goteo13-->/ {indon=1; print; insert("goteo13") }
89      /<!--END-DONATIONS_goteo13-->/ {indon=0}
90      /<!--INSERT-MONTH-DATE-->/ {
91            printf "<!--INSERT-MONTH-DATE--> %s\n", monyear;
92            next
93      }
94      /<!--INSERT-MONTH-EURO-->/ {
95            printf "<!--INSERT-MONTH-EURO--> %s\n", euro;
96            next
97      }
98      /<!--INSERT-MONTH-N-->/ {
99            printf "<!--INSERT-MONTH-N--> %s\n", n;
100            next
101      }
102      /<!--INSERT-YEAR-EURO-->/ {
103            printf "<!--INSERT-YEAR-EURO--> %s\n", euroyr;
104            next
105      }
106      /<!--INSERT-YEAR-N-->/ {
107            printf "<!--INSERT-YEAR-N--> %s\n", nyr;
108            next
109      }
110      !indon { print }
111
112      function insert (tag) {
113        while (getline < donors) {
114          if ( $0 ~ /^(#.*)?$/ )
115             continue;
116          if ( $3 == "" )
117             continue;
118          if ($1==year && $4==tag) {
119            printf "<li>%s</li>\n", $3
120          }
121        }
122        close (donors)
123      }
124      '
125    mv "$file.tmp" "$file" || echo "mkkudos.sh: error updating $file" >&2
126 done