aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/sns/mastodon.sh
blob: fb93bcd260e8ddbc181cbda522e647c1799e52db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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