diff options
Diffstat (limited to 'bin/sns')
| -rwxr-xr-x | bin/sns/mastodon.sh | 17 |
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 | ||
| 4 | MAIL="$(cat)" | ||
| 5 | |||
| 6 | # Only execute the following script when mail receiver is mastodon@topo.tw | ||
| 7 | grep -qE "^X-Original-To: .*mastodon@topo.tw[>]?$" <<<"$MAIL" || exit 0 | ||
| 8 | # A little hacky way to check if mail is sent from me | ||
| 9 | sed -nE '/^Received: /p;/^$/q' <<<"$(MAIL)" | wc -l | xargs -i test {} -lt 2 || exit 0 | ||
| 10 | |||
| 11 | # Leave log | ||
| 12 | date >>~/Downloads/mastodon.log | ||
| 13 | echo $$ >>~/Downloads/mastodon.log | ||
| 14 | awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/mastodon.log | ||
| 15 | |||
| 16 | # Use toot to send message on g0v.social | ||
| 17 | awk -v RS= 'NR>1' <<<"$MAIL" | toot post >>/tmp/mastodon.log | ||