tools: Update donation tools for recurring donations
authorWerner Koch <wk@gnupg.org>
Fri, 12 May 2017 08:40:10 +0000 (10:40 +0200)
committerWerner Koch <wk@gnupg.org>
Fri, 12 May 2017 08:40:10 +0000 (10:40 +0200)
tools/append-to-donors.sh
tools/mkkudos.sh

index bb17894..1c5667d 100755 (executable)
@@ -23,12 +23,65 @@ LC_CTYPE=C
 RFCDATE="$(date -R)"
 SIGDELIM="-- "
 
-htdocs="/var/www/www/www.gnupg.org/htdocs"
+usage()
+{
+    cat <<EOF
+Usage: $pgm [OPTIONS]
+Options:
+        --verbose  Run in verbose mode
+       --force    Force re-creation of files.
+        --test     Run in test environment (preview.gnupg.org)
+EOF
+    exit $1
+}
+
+
+verbose=no
+force=no
+testmode=no
+while [ $# -gt 0 ]; do
+    case "$1" in
+       # Set up `optarg'.
+       --*=*)
+           optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
+           ;;
+       *)
+           optarg=""
+           ;;
+    esac
+
+    case $1 in
+        --verbose)
+            verbose=yes
+            ;;
+       --force)
+           force=yes
+           ;;
+        --test)
+            testmode=yes
+            ;;
+        --help)
+            usage 0
+            ;;
+       *)
+           usage 1 1>&2
+           ;;
+    esac
+    shift
+done
+
+
+if [ $testmode = yes ]; then
+  htdocs="/var/www/www/preview.gnupg.org/htdocs"
+  journal_dir="/var/log/payproc-test"
+else
+  htdocs="/var/www/www/www.gnupg.org/htdocs"
+  journal_dir="/var/log/payproc"
+fi
 
 donors="$htdocs/donate/donors.dat"
 donations="$htdocs/donate/donations.dat"
 
-journal_dir="/var/log/payproc"
 LOCKFILE="$donors.lock"
 
 if [ ! -f "$donors" ]; then
@@ -151,7 +204,7 @@ lastline=$(echo $tmp | cut -d: -f2)
 
 [ -f "$donors".stamp ] && rm "$donors".stamp
 cat "$donors" > "$donors.tmp"
-find $journal_dir -type f -name 'journal-????????.log' -print \
+find $journal_dir/ -type f -name 'journal-????????.log' -print \
      | sort | while read fname; do
     fname=$(basename "$fname")
     jdate=${fname%.log}
@@ -177,7 +230,7 @@ find $journal_dir -type f -name 'journal-????????.log' -print \
 done
 
 # If we have any new records update the files.
-if [ -f "$donors".stamp ]; then
+if [ -f "$donors".stamp -o $force = yes ]; then
 
   if ! mv "$donors.tmp" "$donors"; then
     echo "$pgm: error updating $donors" >&2
@@ -186,13 +239,13 @@ if [ -f "$donors".stamp ]; then
 
   if [ -f "$donations" ]; then
     payproc-stat -u "$donations" -- > "$donations".tmp  \
-      $(find /var/log/payproc -type f -name 'journal-????????.log' -print|sort)
+      $(find $journal_dir/ -type f -name 'journal-????????.log' -print|sort)
     if ! mv "$donations".tmp "$donations"; then
         echo "$pgm: error updating $donations" >&2
         exit 1
     fi
   else
     payproc-stat -u "$donations" -- > "$donations"  \
-      $(find /var/log/payproc -type f -name 'journal-????????.log' -print|sort)
+      $(find $journal_dir/ -type f -name 'journal-????????.log' -print|sort)
   fi
 fi
index e2b7e92..9858816 100755 (executable)
 #  <p class="doclear" style="clear: both"></p>
 #  #+END_HTML
 #
+# For the 2017 campaign new variables which work slightly different
+# are introduced:
+#
+#  #+BEGIN_HTML
+#  <div class="progress-bar progress-bar-striped active"
+#       role="progressbar"
+#       aria-valuenow="0" A-CMPGN-RECUR-EURO=""
+#       aria-valuemin="0"
+#       aria-valuemax="0" A-CMPGN-RECUR-EURO-GOAL=""
+#       style="width: 0%" A-CMPGN-RECUR-PERCENT=""
+#       >
+#    <span class="sr-only"><!--CMPGN-RECUR-EURO-->
+#                            a month</span>
+#  </div>
+#  <div class="col-xs-12 col-sm-6 col-lg-12 camp-progress-info">
+#    <h3><!--CMPGN-RECUR-EURO-->
+#        a month <small>of
+#        <!--CMPGN-RECUR-EURO-GOAL-->
+#        needed</small>
+#    </h3>
+#    <h4>+ <!--CMPGN-ONCE-EURO-->
+#        <small>in one-time donations</small>
+#    </h4>
+#    <h4><!--CMPGN-RECUR-COUNT-->
+#        <small>Supporters</small>
+#    </h4>
+#  #+END_HTML
+#
 # To use it the code at "Campaign data" below needs to be adjusted as
 # well.
 # ===================================================================
@@ -36,9 +64,9 @@ usage()
     cat <<EOF
 Usage: $0 [OPTIONS]
 Options:
-       --force    Force re-creation of files.
         --verbose  Run in verbose mode
-        --test     Run in test environment
+        --force    Force re-creation of files.
+        --test     Run in test environment (preview.gnupg.org)
 EOF
     exit $1
 }
@@ -78,17 +106,15 @@ while [ $# -gt 0 ]; do
     shift
 done
 
-htdocs="/var/www/www/www.gnupg.org/htdocs"
-donors="$htdocs/donate/donors.dat"
-donations="$htdocs/donate/donations.dat"
-blogheadlinefile="/var/www/www/blog.gnupg.org/htdocs/headlines.txt"
 
 if [ $testmode = yes ]; then
-  htdocs="/home/wk/s/gnupg-doc/stage"
-  donors="$htdocs/../scratch/donors.dat"
-  donations="$htdocs/../scratch/donations.dat"
-  blogheadlinefile="$htdocs/../misc/blog.gnupg.org/headlines.txt"
+  htdocs="/var/www/www/preview.gnupg.org/htdocs"
+else
+  htdocs="/var/www/www/www.gnupg.org/htdocs"
 fi
+donors="$htdocs/donate/donors.dat"
+donations="$htdocs/donate/donations.dat"
+blogheadlinefile="/var/www/www/blog.gnupg.org/htdocs/headlines.txt"
 
 
 if [ ! -f "$donors" ]; then
@@ -116,9 +142,10 @@ monyear=$(echo "$tmp" | awk -F: 'BEGIN { m[1] = "January";
       m[10] = "October"; m[11] = "November"; m[12] = "December"; }
       {printf "%s %d", m[int($2)] , $1}')
 thisyear=$(echo "$tmp" | awk -F: '{print $1}')
-euroyr=$(echo "$tmp" | awk -F: '{printf "%d &euro;", int($10 + 0.5)}')
 nyr=$(echo "$tmp" | awk -F: '{printf "%d", $9}')
-
+euroyr=$(echo "$tmp" | awk -F: '{printf "%d", int($10 + 0.5)}')
+recur_nyr=$(echo "$tmp" | awk -F: '{printf "%d", $13}')
+recur_euroyr=$(echo "$tmp" | awk -F: '{printf "%d", int($14 + 0.5)}')
 
 dontable=$(awk -F: <"$donations" -v thisyear="$thisyear" '
   BEGIN { m[1] = "January";
@@ -164,9 +191,14 @@ dontable=$(awk -F: <"$donations" -v thisyear="$thisyear" '
 
 # Campaign data
 goal="120000"
+recur_goal="15000"
 percent=$(echo "$euroyr:$goal" | awk -F: '{ p = (int($1)*100)/int($2);
                                           if(p > 100) { p = 100 };
                                           printf "%d", p}')
+recur_percent=$(echo "$recur_euroyr:$recur_goal" \
+                               | awk -F: '{ p = (int($1)*100)/int($2);
+                                          if(p > 100) { p = 100 };
+                                          printf "%d", p}')
 
 for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html \
             "$htdocs/donate/"index.html \
@@ -187,6 +219,8 @@ for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html \
            -v monyear="$monyear" -v thisyear="$thisyear" \
            -v euro="$euro" -v euroyr="$euroyr" \
            -v nyr="$nyr" -v goal="$goal" -v percent="$percent" \
+           -v recur_nyr="$recur_nyr" -v recur_euroyr="$recur_euroyr" \
+           -v recur_goal="$recur_goal" -v recur_percent="$recur_percent" \
            -v blogheadline="$blogheadline" \
             <"$file"  >"$file.tmp" '
      /<!--BEGIN-DONATIONS-->/ {indon=1; print; insert("") }
@@ -206,7 +240,7 @@ for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html \
            next
      }
      /<!--INSERT-YEAR-EURO-->/ {
-           printf "<!--INSERT-YEAR-EURO--> %s\n", euroyr;
+           printf "<!--INSERT-YEAR-EURO--> %s&thinsp;&euro;\n", euroyr;
            next
      }
      /<!--INSERT-YEAR-N-->/ {
@@ -231,6 +265,48 @@ for file in "$htdocs/donate/"kudos-????.html "$htdocs/donate/"kudos.html \
            printf "<!--INSERT-BLOG-HEADLINE--> %s\n", blogheadline;
            next
      }
+     /A-CMPGN-RECUR-EURO=""/ {
+           n = index($0,"\"");
+           printf "%s%s\" A-CMPGN-RECUR-EURO=\"\"\n",
+                  substr($0,1,n), recur_euroyr;
+           next
+     }
+     /A-CMPGN-RECUR-EURO-GOAL=""/ {
+           n = index($0,"\"");
+           printf "%s%s\" A-CMPGN-RECUR-EURO-GOAL=\"\"\n",
+                  substr($0,1,n), recur_goal;
+           next
+     }
+     /A-CMPGN-RECUR-PERCENT=""/ {
+           n = index($0,":");
+           printf "%s %s%\" A-CMPGN-RECUR-PERCENT=\"\"\n",
+                  substr($0,1,n), recur_percent;
+           next
+     }
+     /<!--CMPGN-RECUR-EURO-->/ {
+           n = index($0,"<!--CMPGN");
+           printf "%s!--CMPGN-RECUR-EURO-->%s&thinsp;&euro;\n",
+                  substr($0,1,n), recur_euroyr;
+           next
+     }
+     /<!--CMPGN-RECUR-EURO-GOAL-->/ {
+           n = index($0,"<!--CMPGN");
+           printf "%s!--CMPGN-RECUR-EURO-GOAL-->%s&thinsp;&euro;\n",
+                  substr($0,1,n), recur_goal;
+           next
+     }
+     /<!--CMPGN-ONCE-EURO-->/ {
+           n = index($0,"<!--CMPGN");
+           printf "%s!--CMPGN-ONCE-EURO-->%s&thinsp;&euro;\n",
+                  substr($0,1,n), euroyr;
+           next
+     }
+     /<!--CMPGN-RECUR-COUNT-->/ {
+           n = index($0,"<!--CMPGN");
+           printf "%s!--CMPGN-RECUR-COUNT-->%s\n",
+                  substr($0,1,n), recur_nyr;
+           next
+     }
      !indon { print }
 
      function insert (tag) {