Repo containing scripts to be used with dovel, and git hooks that powers our web interface.
Author: blmayer (bleemayer@gmail.com)
Date: Tue Oct 3 00:06:25 2023 -0300
Parent: f8d262b
Added dovel hook - Passing repo as parameter to function
diff --git a/aux.sh b/aux.sh index 58cf8ce..29aedd3 100755 --- a/aux.sh +++ b/aux.sh @@ -56,18 +56,18 @@ pagesummary() { cat <<- EOF ← <a href=/git.html>list</a> <center> - <h1>$REPO</h1> + <h1>$1</h1> <nav> - <a href=/$REPO/index.html>index</a>   - <a href=/$REPO/refs.html>refs</a>   - <a href=/$REPO/log.html>log</a>   - <a href=/$REPO/tree.html>tree</a>   - <a href=/$REPO/mail.html>mail</a> + <a href=/$1/index.html>index</a>   + <a href=/$1/refs.html>refs</a>   + <a href=/$1/log.html>log</a>   + <a href=/$1/tree.html>tree</a>   + <a href=/$1/mail.html>mail</a> </nav> <p><i>$(cat description)</i></p> </center> - <kbd>curl https://dovel.email/$REPO.tar</kbd> - <a style="float:right" href=/$REPO.tar filename=$REPO.tar>tar</a> + <kbd>curl https://dovel.email/$1.tar</kbd> + <a style="float:right" href=/$1.tar filename=$1.tar>tar</a> EOF } diff --git a/post-receive b/post-receive index 00e949b..9786296 100755 --- a/post-receive +++ b/post-receive @@ -65,7 +65,7 @@ updateindex() { echo "creating index.html" cat <<- EOF > "$OUT/index.html" $(pagehead "$REPO") - $(pagesummary) + $(pagesummary "$REPO") <hr> <p>Latest commit: $(git log -n 1 --format="(%h) by %an at %as: %s")</p> <pre>$(cat "$OUT/tree/README"*)</pre> @@ -77,7 +77,7 @@ updateindex() { filepage() { cat <<- EOF $(pagehead "$REPO") - $(pagesummary) + $(pagesummary "$REPO") <hr> <h2>$1</h2> <file> @@ -97,7 +97,7 @@ filepage() { createcommitpage() { cat <<- EOF $(pagehead "$REPO") - $(pagesummary) + $(pagesummary "$REPO") <hr> <h2>$1</h2> EOF @@ -143,7 +143,7 @@ updatelog() { echo "creating log.html" cat <<- EOF > "$OUT/log.html" $(pagehead "$REPO") - $(pagesummary) + $(pagesummary "$REPO") <hr> <h2>Log</h2> <table> @@ -176,7 +176,7 @@ updaterefs() { echo "creating refs.html" cat <<- EOF > "$OUT/refs.html" $(pagehead "$REPO") - $(pagesummary) + $(pagesummary "$REPO") <hr> <h2>Branches</h2> <table> @@ -205,7 +205,7 @@ updatetree() { echo "creating tree.html" cat <<- EOF > "$OUT/tree.html" $(pagehead "$REPO") - $(pagesummary) + $(pagesummary "$REPO") <hr> <h2>Tree</h2> <table> diff --git a/post-receive-scripts b/post-receive-scripts index 8e5c4d5..135f62f 100755 --- a/post-receive-scripts +++ b/post-receive-scripts @@ -14,6 +14,9 @@ do cp "$TMP/aux.sh" "$dir/hooks/" done +# copy dovel hook +cp "$TMP/receive-dovel.email" "$HOME/.config/dovel/hooks/" + # for this repo copy scripts mv hooks/post-receive hooks/post-receive-all cp "$TMP/post-receive-scripts" hooks/post-receive diff --git a/receive-dovel.email b/receive-dovel.email new file mode 100755 index 0000000..1f21c3e --- /dev/null +++ b/receive-dovel.email @@ -0,0 +1,115 @@ +#!/bin/sh + +inbox() { + cat <<- EOF + $(pagehead "$repo") + $(pagesummary "$repo") + <hr> + <h2>mail</h2> + EOF + + ls -ogdt --time-style long-iso "$root/$repo/mail"/* | while read -r g x s d t f + do + [ -d "$f" ] || continue + + f="$(basename "$f")" + qty="$(ls -1 "$root/$repo/mail/$f" | wc -l)" + cat <<- EOF + <p> + <a href="mail/$f.html">$f</a> + <small>$t $d</small><br> + <i>$qty emails</i> + </p> + EOF + done + cat <<- EOF + </body> + </html> + EOF +} + +# update emails page +emails() { + cat <<- EOF + $(pagehead "$repo") + $(pagesummary "$repo") + <hr> + <h2>$subj</h2> + EOF + + # print each email + ls -1rt "$root/$repo/mail/$subj"/*.mbox | while read -r f + do + { + # print headers + read -r foo from date + cat <<- EOF + <details> + <summary> + From: $from<br> + Date: $date + </summary> + <ul> + EOF + + while read -r k v + do + case "$k" in + "") break ;; + *) printf "<li>$k $v</li>\n" ;; + esac + done + + # print body + cat <<- EOF + </ul> + </details> + <pre> + EOF + cat - + printf "</pre>\n<br>\n" + } < "$f" + done + + # finish + cat <<- EOF + </body> + </html> + EOF +} + +save() { + # first line is From email date: + read -r foo from date + + # read headers + while read -r k v + do + case "$k" in + "To:") to="$v" ;; + "Subject:") subj="$v" ;; + "Message-ID:") eid="$v" ;; + "") break ;; + esac + done + eid="${eid:-$(date -Iseconds)}" + repo="${to%@*}" + + # now the rest is a body + cat - > /dev/null + + # move temp file + [ -d "$root/$repo/mail/$subj" ] || mkdir -p "$root/$repo/mail/$subj" + mv "$tmp" "$root/$repo/mail/$subj/$eid.mbox" + + # create html pages + inbox > "$root/$repo/mail.html" + emails > "$root/$repo/mail/$subj.html" +} + +root="$HOME/www/dovel.email" + +# copy to temp file +tmp="$(mktemp)" +tee "$tmp" | save +