aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/sns/mastodon.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sns/mastodon.sh')
-rwxr-xr-xbin/sns/mastodon.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/bin/sns/mastodon.sh b/bin/sns/mastodon.sh
new file mode 100755
index 0000000..fb93bcd
--- /dev/null
+++ b/bin/sns/mastodon.sh
@@ -0,0 +1,17 @@
1#! /bin/bash
2
3# Restore mail in variable
4MAIL="$(cat)"
5
6# Only execute the following script when mail receiver is mastodon@topo.tw
7grep -qE "^X-Original-To: .*mastodon@topo.tw[>]?$" <<<"$MAIL" || exit 0
8# A little hacky way to check if mail is sent from me
9sed -nE '/^Received: /p;/^$/q' <<<"$(MAIL)" | wc -l | xargs -i test {} -lt 2 || exit 0
10
11# Leave log
12date >>~/Downloads/mastodon.log
13echo $$ >>~/Downloads/mastodon.log
14awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/mastodon.log
15
16# Use toot to send message on g0v.social
17awk -v RS= 'NR>1' <<<"$MAIL" | toot post >>/tmp/mastodon.log