Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/interpret-mail
diff options
context:
space:
mode:
Diffstat (limited to 'bin/interpret-mail')
-rwxr-xr-xbin/interpret-mail77
1 files changed, 70 insertions, 7 deletions
diff --git a/bin/interpret-mail b/bin/interpret-mail
index 5d3cc51..92725b6 100755
--- a/bin/interpret-mail
+++ b/bin/interpret-mail
@@ -31,6 +31,51 @@ if [ $# -ne 0 ]; then
exit 1
fi
+log() {
+ # shellcheck disable=SC2059
+ >&2 printf "$@"
+ {
+ cat "${webserver_directory}/mail-log.html"
+ # shellcheck disable=SC2059
+ printf "$@" | \
+ sed '
+ s|$|<br>|
+ s|^|'"$(date)"': |
+ '
+ } | \
+ tail -n "${max_mail_log_lines}" | \
+ sponge "${webserver_directory}/mail-log.html"
+}
+
+log_from_file() {
+ >&2 cat "$@"
+ {
+ cat "${webserver_directory}/mail-log.html"
+ sed '
+ s|$|<br>|
+ s|^|'"$(date)"': |
+ ' "$@"
+ } | \
+ tail -n "${max_mail_log_lines}" | \
+ sponge "${webserver_directory}/mail-log.html"
+}
+
+run_and_log_on_error() {
+ err=0
+ "$@" 2> "${tmp_dir}/stderr" > "${tmp_dir}/stdout" || \
+ err=$?
+ if [ "${err}" -eq 0 ]; then
+ return 0
+ fi
+ log_from_file "${tmp_dir}/stderr" "${tmp_dir}/stdout"
+ if [ "${err}" -eq 1 ]; then
+ log '^ temporary error - I keep the message.\n'
+ exit 1
+ else
+ return 1
+ fi
+}
+
tmp_dir=$(mktemp -d)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT
@@ -42,7 +87,7 @@ if ! hashcash -qXc -b 20 \
-r 'archlinux32-buildmaster@eckner.net' \
-r 'buildmaster@archlinux32.org' < \
"${tmp_dir}/mail"; then
- >&2 echo 'Invalid stamp - ignoring this message.'
+ log 'Invalid stamp - ignoring this message.\n'
exit
fi
@@ -56,7 +101,9 @@ if ! sed -n '
p
}
' "${tmp_dir}/mail" | \
- chronic gpg --batch --status-file "${tmp_dir}/gpg-status" -q -d -o "${tmp_dir}/plain-content"; then
+ gpg --batch --status-file "${tmp_dir}/gpg-status" -q -d -o "${tmp_dir}/plain-content" > /dev/null 2>&1; then
+ log 'Invalid encryption/signature - ignoring this message.\n'
+ log_from_file "${tmp_dir}/gpg-status"
exit
fi
@@ -79,10 +126,14 @@ join -j 1 -o 2.2 \
"${tmp_dir}/allowed-actions"
if [ ! -s "${tmp_dir}/allowed-actions" ]; then
- >&2 echo 'No valid signature found.'
+ log 'No known signature found - I found:\n'
grep '^\[GNUPG:] VALIDSIG ' "${tmp_dir}/gpg-status" | \
cut -d' ' -f3 | \
- sort -u >&2
+ sort -u | \
+ sed 's|^|> |' > \
+ "${tmp_dir}/log"
+ log_from_file "${tmp_dir}/log"
+ log 'ignoring this message.\n'
exit
fi
@@ -127,16 +178,28 @@ sed -n "$(
)" "${tmp_dir}/raw-content"
if [ -s "${tmp_dir}/block" ]; then
- chronic "${base_dir}/bin/block-package" "${tmp_dir}/block"
+ if run_and_log_on_error "${base_dir}/bin/block-package" "${tmp_dir}/block"; then
+ log 'Successfully blocked %s packages.\n' "$(wc -l < "${tmp_dir}/block")"
+ else
+ log 'There was an error while blocking the packages - ignoring this message.\n'
+ fi
fi
if [ -s "${tmp_dir}/stabilize" ]; then
sed -i '
/\.pkg\.tar\.xz$/!s/$/.pkg.tar.xz/
' "${tmp_dir}/stabilize"
-# chronic "${base_dir}/bin/db-update" -b -f "${tmp_dir}/stabilize"
+ if run_and_log_on_error "${base_dir}/bin/db-update" -b -f "${tmp_dir}/stabilize"; then
+ log 'Successfully stabilized %s packages.\n' "$(wc -l < "${tmp_dir}/stabilize")"
+ else
+ log 'There was an error while stabilizing the packages - ignoring this message.\n'
+ fi
fi
if [ -s "${tmp_dir}/unblock" ]; then
- chronic "${base_dir}/bin/block-package" -u "${tmp_dir}/unblock"
+ if run_and_log_on_error "${base_dir}/bin/block-package" -u "${tmp_dir}/unblock"; then
+ log 'Successfully unblocked %s packages.\n' "$(wc -l < "${tmp_dir}/unblock")"
+ else
+ log 'There was an error while unblocking the packages - ignoring this message.\n'
+ fi
fi