From 6fae25b305d714b3ab7608fa003f1af9bf024545 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 14 Feb 2023 13:33:23 +0800 Subject: Rename tools into bin --- bin/sns/mastodon.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 bin/sns/mastodon.sh (limited to 'bin/sns/mastodon.sh') 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 @@ +#! /bin/bash + +# Restore mail in variable +MAIL="$(cat)" + +# Only execute the following script when mail receiver is mastodon@topo.tw +grep -qE "^X-Original-To: .*mastodon@topo.tw[>]?$" <<<"$MAIL" || exit 0 +# A little hacky way to check if mail is sent from me +sed -nE '/^Received: /p;/^$/q' <<<"$(MAIL)" | wc -l | xargs -i test {} -lt 2 || exit 0 + +# Leave log +date >>~/Downloads/mastodon.log +echo $$ >>~/Downloads/mastodon.log +awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/mastodon.log + +# Use toot to send message on g0v.social +awk -v RS= 'NR>1' <<<"$MAIL" | toot post >>/tmp/mastodon.log -- cgit v1.2.3-70-g09d2