summaryrefslogtreecommitdiff
path: root/buildbot/make_auditor_reports.sh
blob: 56ee802337b40d752e63db21bf7ba13335f07739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash

# Logic that creates auditor reports, respecting
# the config file that lives under ${HOME}/.config/taler.conf.
# The results will be found under ${HOME}/reports/

set -eu
echo "Running taler-deployment bootstrap"
source ${HOME}/activate
taler-deployment bootstrap

echo "Running taler-deployment build"
source ${HOME}/activate
taler-deployment build

echo "Running taler-deployment-prepare"
taler-deployment-prepare

DATE=$(date +%Y-%m-%d)
REPORT_FILE_NOEXT=${HOME}/audit_report.${DATE}
WIRE_REPORT_FILE_NOEXT=${HOME}/wire_audit_report.${DATE}
JINJA_TEMPLATE="auditor-report.tex.j2"
REPORTS_DIRECTORY=$(taler-config -s auditor -o reports -f)

clean_files () {
  # Remove garbage and set permissions.
  echo Removing "${REPORT_FILE_NOEXT}.aux"
  rm -f "${REPORT_FILE_NOEXT}.aux"
  echo Removing "${REPORT_FILE_NOEXT}.tex"
  rm -f "${REPORT_FILE_NOEXT}.tex"
  echo Removing "${REPORT_FILE_NOEXT}.log"
  rm -f "${REPORT_FILE_NOEXT}.log"
  echo Removing "${REPORT_FILE_NOEXT}.txt", "${WIRE_REPORT_FILE_NOEXT}.txt"
  rm -f "${REPORT_FILE_NOEXT}.txt" "${WIRE_REPORT_FILE_NOEXT}.txt"
}


if test -a ${REPORTS_DIRECTORY}/$(basename "${REPORT_FILE_NOEXT}.pdf"); then
  echo "Today's report already compiled!"
  exit 0
fi

echo "Adding exchange to auditor's list"
taler-auditor-exchange \
  -c ${HOME}/.config/taler.conf \
  -m $(taler-config -s exchange -o master_public_key) \
  -u $(taler-config -s exchange -o base_url) || true

# Generate first report.
echo "Running taler-auditor"
if ! taler-auditor > "${REPORT_FILE_NOEXT}.txt"; then
  clean_files
  exit 1
fi

# Generate "wire" report.
echo "Running taler-wire-auditor"
if ! taler-wire-auditor > "${WIRE_REPORT_FILE_NOEXT}.txt"; then
  clean_files
  exit 1
fi

echo "Rendering report"
if ! python ${PWD}/render_auditor_reports.py \
  "${REPORT_FILE_NOEXT}.txt" \
  "${WIRE_REPORT_FILE_NOEXT}.txt" \
  > "${REPORT_FILE_NOEXT}.tex" \
  < "${JINJA_TEMPLATE}"; then

  clean_files
  exit 1
fi

cd ${HOME}
echo "TeXing report"
if ! pdflatex "${REPORT_FILE_NOEXT}.tex" && pdflatex "${REPORT_FILE_NOEXT}.tex"; then
  clean_files
  exit 1
fi

clean_files

if ! test -f "${REPORT_FILE_NOEXT}.pdf"; then
  echo Could not produce the report
  exit 1
fi

# Group to assign the file.
GROUP="test"
if echo $(whoami) | grep demo; then
  GROUP="demo"
fi

chgrp ${GROUP} "${REPORT_FILE_NOEXT}.pdf"
chmod 040 "${REPORT_FILE_NOEXT}.pdf"

mv "${REPORT_FILE_NOEXT}.pdf" "${REPORTS_DIRECTORY}"

echo Reports moved in "${REPORTS_DIRECTORY}".