diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2022-12-14 12:17:50 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2022-12-14 12:17:50 +0800 |
| commit | 17da497733e75d2fdce1d53f03394cf3b72bc5d6 (patch) | |
| tree | 86f0b9b2dfb7480b01092d28dcbd533a333bea85 /tools | |
| parent | 3cea0984eb7d1caed8252ae674ded2c1a97b7ae0 (diff) | |
Update
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/wiki/log.sh | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/wiki/log.sh b/tools/wiki/log.sh new file mode 100755 index 0000000..4ef2c27 --- /dev/null +++ b/tools/wiki/log.sh | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | |||
| 3 | # Restore mail in variable | ||
| 4 | MAIL="$(cat)" | ||
| 5 | |||
| 6 | # Only execute the following script when mail receiver is log@topo.tw | ||
| 7 | grep -qE "^X-Original-To: .*log@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/log.log | ||
| 13 | echo $$ >>~/Downloads/log.log | ||
| 14 | awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/log.log | ||
| 15 | |||
| 16 | LOG=~/log/`date +%y.w%W.md` | ||
| 17 | TODAY="`date '+%a %b.%d'`" | ||
| 18 | |||
| 19 | grep -Eq "^## ${TODAY}$" ${LOG} || \ | ||
| 20 | cat <<EOF >>${LOG} | ||
| 21 | |||
| 22 | |||
| 23 | ## $TODAY | ||
| 24 | EOF | ||
| 25 | |||
| 26 | |||
| 27 | # Save content to log file of current week | ||
| 28 | echo >>${LOG} | ||
| 29 | awk -v RS= 'NR>1' <<<"$MAIL" >>${LOG} | ||
| 30 | |||
| 31 | { cd ~/log && git add `basename ${LOG}` && git commit -m "Update by mail"; } >>~/Downloads/log.log | ||