Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-08-29 13:17:00 +0200
committerErich Eckner <git@eckner.net>2017-08-29 13:17:00 +0200
commit491308bd4941793699e1185bdb623935f3cdd999 (patch)
tree75b559087ecb41c16f76ae531bdc7081dc45df2a /bin
parentdf6cc11887ef954a6365a4fee958bc2bcfd7d402 (diff)
bin/interpret-mail: new for interpreting email-driven commands
Diffstat (limited to 'bin')
-rwxr-xr-xbin/interpret-mail65
1 files changed, 65 insertions, 0 deletions
diff --git a/bin/interpret-mail b/bin/interpret-mail
new file mode 100755
index 0000000..ff40b22
--- /dev/null
+++ b/bin/interpret-mail
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+# shellcheck source=conf/default.conf
+. "${0%/*}/../conf/default.conf"
+
+tmp_dir=$(mktemp -d)
+trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT
+
+cat > \
+ "${tmp_dir}/mail"
+
+if ! hashcash -qXc -b 20 \
+ -d -f "${tmp_dir}/hashcash.db" \
+ -r 'archlinux32-buildmaster@eckner.net' \
+ -r 'buildmaster@archlinux32.org' < \
+ "${tmp_dir}/mail"; then
+ >&2 echo 'Invalid stamp - ignoring this message.'
+ exit
+fi
+
+if ! sed -n '
+ /^-----BEGIN PGP MESSAGE-----$/{
+ :a
+ /\n-----END PGP MESSAGE-----$/!{
+ N
+ ba
+ }
+ p
+ }
+ ' "${tmp_dir}/mail" | \
+ chronic gpg --batch -q -d -o "${tmp_dir}/plain-content"; then
+ exit
+fi
+
+if grep -q '^From:\s' "${tmp_dir}/plain-content" &&
+ grep -q '^To:\s' "${tmp_dir}/plain-content" &&
+ grep -q '^Subject:\s' "${tmp_dir}/plain-content"; then
+ # the content is / might be "multipart"
+ sed -n '
+ /^$/!b
+ N
+ s/^\n//
+ /^--/b
+ :a
+ N
+ /\n$/!ba
+ s/\n$//
+ p
+ ' "${tmp_dir}/plain-content" > \
+ "${tmp_dir}/raw-content"
+else
+ mv "${tmp_dir}/plain-content" "${tmp_dir}/raw-content"
+fi
+
+sed -n '
+ /^stabilize:/{
+ s/^stabilize:\s*//
+ /\.pkg\.tar\.xz$/!s/$/.pkg.tar.xz/
+ w '"${tmp_dir}/stabilize"'
+ }
+' "${tmp_dir}/raw-content"
+
+if [ -s "${tmp_dir}/stabilize" ]; then
+ chronic "${base_dir}/bin/db-update" -b -f "${tmp_dir}/stabilize"
+fi