aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xtools/sns/mastodon.sh9
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/sns/mastodon.sh b/tools/sns/mastodon.sh
index 1118c20..fb93bcd 100755
--- a/tools/sns/mastodon.sh
+++ b/tools/sns/mastodon.sh
@@ -1,12 +1,17 @@
1#! /bin/bash 1#! /bin/bash
2 2
3# Restore mail in variable
3MAIL="$(cat)" 4MAIL="$(cat)"
4 5
5# Only execute the following script when mail receiver is mastodon@topo.tw 6# Only execute the following script when mail receiver is mastodon@topo.tw
6grep -qE "^To: .*mastodon@topo.tw[>]?$" <<<"$MAIL" || exit 0 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
7 10
11# Leave log
8date >>~/Downloads/mastodon.log 12date >>~/Downloads/mastodon.log
9echo $$ >>~/Downloads/mastodon.log 13echo $$ >>~/Downloads/mastodon.log
10awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/mastodon.log 14awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/mastodon.log
11 15
12#awk -v RS= 'NR>1' <<<"$MAIL" | toot post >/tmp/mastodon.log 16# Use toot to send message on g0v.social
17awk -v RS= 'NR>1' <<<"$MAIL" | toot post >>/tmp/mastodon.log