diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-12-03 17:33:13 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-12-03 17:33:13 +0800 |
commit | d1b57c1d68fa60a4a67c208f29b739ef0f20d5c5 (patch) | |
tree | cb7d281af1ae22efe00a2f10394d6680aab9dfbf /bin | |
parent | 152ecc894dd24cac6934a10f26f0fcce8445c2ea (diff) |
Update
Diffstat (limited to 'bin')
-rw-r--r-- | bin/log/shellrc | 2 | ||||
-rwxr-xr-x | bin/mail/append_authorized_key.sh | 2 | ||||
-rwxr-xr-x | bin/mail/comment.sh | 41 |
3 files changed, 43 insertions, 2 deletions
diff --git a/bin/log/shellrc b/bin/log/shellrc index a39e291..b3c95fc 100644 --- a/bin/log/shellrc +++ b/bin/log/shellrc | |||
@@ -1,7 +1,7 @@ | |||
1 | # about vimwiki | 1 | # about vimwiki |
2 | alias cdl='cd ~/log' | 2 | alias cdl='cd ~/log' |
3 | alias chw='tig -C ~/log' | 3 | alias chw='tig -C ~/log' |
4 | ww() { entry="${1:-plan.context}"; vim ~/log/${entry%%.md}.md; } | 4 | ww() { entry="${1:-inbox}"; vim ~/log/${entry%%.md}.md; } |
5 | wj() { echo "$@" >>~/log/buffer.md; } | 5 | wj() { echo "$@" >>~/log/buffer.md; } |
6 | wg() { grep -r "$@" --color --exclude-dir={logseq,.git,.obsidian} ~/log; } | 6 | wg() { grep -r "$@" --color --exclude-dir={logseq,.git,.obsidian} ~/log; } |
7 | wi() { cat ~/log/${1%%.md}.md; } | 7 | wi() { cat ~/log/${1%%.md}.md; } |
diff --git a/bin/mail/append_authorized_key.sh b/bin/mail/append_authorized_key.sh index 950be90..3686959 100755 --- a/bin/mail/append_authorized_key.sh +++ b/bin/mail/append_authorized_key.sh | |||
@@ -13,7 +13,7 @@ MAIL="$(cat)" | |||
13 | test -f ~/.config/passphase || exit 1 | 13 | test -f ~/.config/passphase || exit 1 |
14 | PASSPHASE="$(cat ~/.config/passphase)" | 14 | PASSPHASE="$(cat ~/.config/passphase)" |
15 | 15 | ||
16 | # Only execute the following script when header matched | 16 | # Check passphase, or exit 0 |
17 | grep -qE "^Passphase: ${PASSPHASE}" <<<"$MAIL" || exit 0 | 17 | grep -qE "^Passphase: ${PASSPHASE}" <<<"$MAIL" || exit 0 |
18 | 18 | ||
19 | # Append comment and last line to ~/.ssh/authorized_keys | 19 | # Append comment and last line to ~/.ssh/authorized_keys |
diff --git a/bin/mail/comment.sh b/bin/mail/comment.sh new file mode 100755 index 0000000..807bcb2 --- /dev/null +++ b/bin/mail/comment.sh | |||
@@ -0,0 +1,41 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | output_dir=${output_dir:-/srv/http} | ||
4 | |||
5 | # Restore mail into variable | ||
6 | MAIL="$(tr -d '\r')" | ||
7 | headers="$(<<<"$MAIL" sed '/^$/ q')" | ||
8 | contents="$(<<<"$MAIL" sed -n '/^$/,$ p' | sed '1d')" | ||
9 | |||
10 | # enable execute last command in pipe under current shell | ||
11 | shopt -s lastpipe; set +m; | ||
12 | |||
13 | # get route (target page of comment) and id | ||
14 | <<<"$MAIL" sed -En '/^To: comment+/ {s/^To: comment\+([^+]+)\+?(.*)@.*$/\1 \2/p; q}; /^$/q' \ | ||
15 | | read route id | ||
16 | |||
17 | # sender want comment on some page, but find no route for this | ||
18 | if [ $route = "" ]; then | ||
19 | echo 'rcpt "comment+<ROUTE>" not matched' >&2 | ||
20 | exit 1 | ||
21 | fi | ||
22 | |||
23 | output=$output_dir/${route#/}.comment | ||
24 | exec 1>>$output | ||
25 | |||
26 | # check mail includes multiple part | ||
27 | <<<"$headers" grep '^Content-Type:.*mixed' >/dev/null | ||
28 | if [ $? -eq 0 ]; then | ||
29 | boundary="$(<<<"$headers" sed -En 's/^Content-Type:.*boundary="(.*)".*$/\1/p')" | ||
30 | if [ $boundary = "" ]; then | ||
31 | echo 'cannot get boundary from mail header' >&2 | ||
32 | exit 1 | ||
33 | fi | ||
34 | |||
35 | # print content of first mail part | ||
36 | pattern="\\@^--${boundary}\$@" | ||
37 | <<<"$contents" sed -n "${pattern},${pattern} p" | sed -n "1,4d; ${pattern} q; p" | ||
38 | else | ||
39 | # print content | ||
40 | <<<"$contents" sed '/^$/,$ p' | ||
41 | fi | ||