tools: Add --test option to mkkudos and include the main page.
authorWerner Koch <wk@gnupg.org>
Mon, 15 Dec 2014 19:48:41 +0000 (20:48 +0100)
committerWerner Koch <wk@gnupg.org>
Mon, 15 Dec 2014 19:48:41 +0000 (20:48 +0100)
tools/mkkudos.sh

index ae1831e..d477d69 100755 (executable)
@@ -2,25 +2,20 @@
 
 set -e
 
-htdocs="/var/www/www/www.gnupg.org/htdocs"
-#htdocs="/home/wk/s/gnupg-doc/web"
-
-donors="$htdocs/donate/donors.dat"
-donations="$htdocs/donate/donations.dat"
-
-
 usage()
 {
     cat <<EOF
 Usage: $0 [OPTIONS]
 Options:
        --force    Force re-creation of files.
+        --test     Run in test environment
 EOF
     exit $1
 }
 
 
 force=no
+testmode=no
 while [ $# -gt 0 ]; do
     case "$1" in
        # Set up `optarg'.
@@ -36,6 +31,9 @@ while [ $# -gt 0 ]; do
        --force)
            force=yes
            ;;
+        --test)
+            testmode=yes
+            ;;
         --help)
             usage 0
             ;;
@@ -46,6 +44,16 @@ while [ $# -gt 0 ]; do
     shift
 done
 
+htdocs="/var/www/www/www.gnupg.org/htdocs"
+donors="$htdocs/donate/donors.dat"
+donations="$htdocs/donate/donations.dat"
+
+if [ $testmode = yes ]; then
+  htdocs="/home/wk/s/gnupg-doc/stage"
+  donors="$htdocs/../scratch/donors.dat"
+  donations="$htdocs/../scratch/donations.dat"
+fi
+
 
 if [ ! -f "$donors" ]; then
   echo "mkkudos.sh: '$donors' not found" >&2;
@@ -62,13 +70,17 @@ monyear=$(echo "$tmp" | awk -F: 'BEGIN { m[1] = "January";
       m[6] = "June"; m[7] = "July"; m[8] = "August"; m[9] = "September";
       m[10] = "October"; m[11] = "November"; m[12] = "December"; }
       {printf "%s %d", m[$2] , $1}')
-euro=$(echo "$tmp" | awk -F: '{printf "%d Euro", int($8 + 0.5)}')
-euroyr=$(echo "$tmp" | awk -F: '{printf "%d Euro", int($10 + 0.5)}')
+euro=$(echo "$tmp" | awk -F: '{printf "%d &euro;", int($8 + 0.5)}')
+euroyr=$(echo "$tmp" | awk -F: '{printf "%d &euro;", int($10 + 0.5)}')
 n=$(echo "$tmp" | awk -F: '{printf "%d", $7}')
 nyr=$(echo "$tmp" | awk -F: '{printf "%d", $9}')
+goal="120000"
+percent=$(echo "$euro:$goal" | awk -F: '{printf "%d",(int($1)*100)/int($2)}')
 
 for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html \
-            "$htdocs/donate/"index.html; do
+            "$htdocs/donate/"index.html \
+            "$htdocs/"index.html
+ do
    if [ $force = no ]; then
      [ "$file" -ot "$donors" ] || continue
    fi
@@ -82,7 +94,7 @@ for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html \
    [ -f "$file.tmp" ] && rm "$file.tmp"
    awk -F: -v year=$year -v donors="$donors" \
            -v monyear="$monyear" -v euro="$euro" -v euroyr="$euroyr" \
-           -v n="$n" -v nyr="$nyr" \
+           -v n="$n" -v nyr="$nyr" -v goal="$goal" -v percent="$percent" \
             <"$file"  >"$file.tmp" '
      /<!--BEGIN-DONATIONS-->/ {indon=1; print; insert("") }
      /<!--END-DONATIONS-->/ {indon=0}
@@ -110,6 +122,20 @@ for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html \
            printf "<!--INSERT-YEAR-N--> %s\n", nyr;
            next
      }
+     /<!--INSERT-PROGRESS-LEFT-->/ {
+           printf "<!--INSERT-PROGRESS-LEFT-->%s\n",
+                  euro;
+           next
+     }
+     /<!--INSERT-PROGRESS-RIGHT-->/ {
+           printf "<!--INSERT-PROGRESS-RIGHT-->goal: %s &euro;\n", goal;
+           next
+     }
+     /<!--REPLACE-PROGRESS-PERCENT-->/ {
+           printf "style=\"width: %d%%\"<!--REPLACE-PROGRESS-PERCENT-->\n",
+                  percent;
+           next
+     }
      !indon { print }
 
      function insert (tag) {