aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2022-12-03 20:57:27 +0800
committerHsieh Chin Fan <pham@topo.tw>2022-12-03 20:57:27 +0800
commitfeee1a1bdd0afb5657a0e08198b6a35123c0bc38 (patch)
tree561e7a827c7a60c2cdcb5ad1f65929e40d97e0b1
parenta92fd3ae9f2059e115b2a96960bfe54a6ea1f5a9 (diff)
Update script of mastodon
-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