diff options
-rwxr-xr-x | tools/sns/mastodon.sh | 9 |
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 | ||
3 | MAIL="$(cat)" | 4 | MAIL="$(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 |
6 | grep -qE "^To: .*mastodon@topo.tw[>]?$" <<<"$MAIL" || exit 0 | 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 | ||
7 | 10 | ||
11 | # Leave log | ||
8 | date >>~/Downloads/mastodon.log | 12 | date >>~/Downloads/mastodon.log |
9 | echo $$ >>~/Downloads/mastodon.log | 13 | echo $$ >>~/Downloads/mastodon.log |
10 | awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/mastodon.log | 14 | awk -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 |
17 | awk -v RS= 'NR>1' <<<"$MAIL" | toot post >>/tmp/mastodon.log | ||