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:28:10 2023 -0300
Parent: f88ab2e
Improved diff
GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
# Dovel Scripts This repo has shell scripts that are part of the dovel project, some are meant only for deployment on our website. Some explanation: - post-receive: git hook to build html pages - update*: used by git to creat html pages - receive-localhost: saves emails and create html pages ## Contributing Scripts are super welcome, as well as full programs to be compiled. Add here anything that may help saving emails the way you like.
#!/bin/sh pagehead() { cat <<- EOF <!DOCTYPE html> <html> <head> <title>$1's git</title> <meta charset="UTF-8"> <meta name="author" content="Brian Lee Mayer"> <meta name="description" content="This is the development homepage of the Dovel project. Find here all repos mailing lists. And latest development changes."> <meta name="language" content="english"> <meta name="keywords" content="email, dovel, blmayer, self host, software, smtp, web, interface"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="color-scheme" content="light dark"> $([ "$1" ] && echo "<meta name=\"go-import\" content=\"/$1 mod https://dovel.email\">") <style> body { max-width: 43em; margin: 60px auto; padding: 20px; font-family: sans-serif; } pre { font-family: monospace; white-space: pre-line; font-weight: bold; background: lightgray; padding: 8px; border-radius: 8px; } file > pre { white-space: pre; line-height: 0.5; overflow-x: auto } table {width: 100%} th {text-align: left} ol li {padding-bottom: 10px} li::marker { color: gray; content: counter(list-item, decimal-leading-zero) " " } ol {margin: 0} tt {font-weight: bold} @media (prefers-color-scheme: dark) { pre {background: darkslategray} } </style> </head> <body> EOF } pagesummary() { cat <<- EOF ← <a href=/git.html>list</a> <center> <h1>$1</h1> <nav> <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/$1.tar</kbd> <a style="float:right" href=/$1.tar filename=$1.tar>tar</a> EOF } escapehtml() { printf "%s" "$1" | sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g' }
From derp.herp@example.com Thu Jan 1 00:00:01 2015 From: derp.herp@example.com (Derp Herp) To: test@localhost Date: Thu, 02 Jan 2015 00:00:01 +0100 Subject: Another test This is another simple test. Bye.
#!/bin/sh # for debugging # set -ex . hooks/aux.sh # . ./aux.sh ROOT="$HOME/www/dovel.email" REPO="$(basename $PWD)" OUT="$ROOT/$REPO" updategit() { cat <<- EOF > "$ROOT/git.html" $(pagehead "dovel") ← <a href="/">dovel website</a> <h1>Dovel project Git home</h1> Welcome! Here you'll find general info about our projects and how to contribute to them. We proudly use dovel email technology for our mailing lists. Its hooks are in the scripts repo. Please read the next sections before making a contribution. <h2>Repositories</h2> <dl> EOF for dir in "$HOME/git/dovel.email/"* do cat <<- EOF >> "$ROOT/git.html" <dt><a href=$(basename $dir)/index.html>$(basename $dir)</a></dt> <dd>$(cat "$dir/description")</dd> EOF done cat <<- EOF >> "$ROOT/git.html" </dl> <h2>Contributing</h2> The dovel team uses the git email workflow to accept contributions. All email sent to dovel.email is considered as git mailling lists, check each repository for email to a specific project. To send email about other subjects please address them to <a href=mailto:dovel@myr.sh>dovel@myr.sh</a>. <h3>Email addresses</h3> To send contributions use the repo name as the email's recipient, i.e. to contribute to the server project send email to <kbd>server@dovel.email</kbd>. Please CC me as well so I can reply faster: <kbd>dovel@myr.sh</kbd>. <h3>Email etiquette</h3> We only accept plain text email. More info and recomendations can be found on <a href=//useplaintext.email>useplaintext.email</a>. Also <a href=//git-send-email.io>git-send-email.io</a> has instructions on how to setup git to send email for many platforms. </body> </html> EOF } updateindex() { echo "creating archives" tar -C "$OUT" -cz tree/ --xform="s/tree/$REPO/" > "$OUT.tar.gz" echo "creating index.html" cat <<- EOF > "$OUT/index.html" $(pagehead "$REPO") $(pagesummary "$REPO") <hr> <p>Latest commit: $(git log -n 1 --format="(%h) by %an at %as: %s")</p> <pre>$(cat "$OUT/tree/README"*)</pre> </body> </html> EOF } filepage() { cat <<- EOF $(pagehead "$REPO") $(pagesummary "$REPO") <hr> <h2>$1</h2> <file> <pre> <ol> EOF # print file while IFS= read -r l do printf "<li>%s</li>\n" "$(escapehtml "$l")" done < "$OUT/tree/$1" echo "</ol>\n</pre>\n</file>\n</body>\n</html>" } createcommitpage() { cat <<- EOF $(pagehead "$REPO") $(pagesummary "$REPO") <hr> <h2>$1</h2> EOF # print commit git show --format='%an%n%ae%n%ad%n%p%n%B' -s "$1" | { read -r name read -r email read -r date read -r parent cat <<- EOF <p>Author: $name ($email)</p> <p>Date: $date</p> <p>Parent: <a href=$parent.html>$parent</a></p> <p><pre> EOF # the rest is the message cat - } # now the diff cat <<- EOF </pre> <h3>Diff</h3> EOF for f in $(git diff "$1" --name-only) do cat <<- EOF <h4>$f</h4> <pre style="overflow-x:auto;white-space:pre"> EOF git show --format='' "$1:$f" | while read -r l do printf "%s\n" "$(escapehtml "$l")" done echo "</pre>" done cat <<- EOF </body> </html> EOF } updatelog() { echo "creating log.html" cat <<- EOF > "$OUT/log.html" $(pagehead "$REPO") $(pagesummary "$REPO") <hr> <h2>Log</h2> <table> <tr><th>Hash</th><th>Author</th><th>Date</th><th>Subject</td></tr> EOF git log -n 100 --format='%h%n%ad%n%an%n%s' --date=iso | while read -r h do read -r date read -r name read -r msg cat <<- EOF >> "$OUT/log.html" <tr><td><a href=log/$h.html>$h</a></td><td>$name</td><td>$date</td><td>$msg</td></tr> EOF [ -f "$OUT/log/$h.html" ] && continue echo "creating commit page $h" createcommitpage "$h" > "$OUT/log/$h.html" done cat <<- EOF >> "$OUT/log.html" </table> <p>Note: Only showing up to 100 commits, for full log clone the repo.</p> </body> </html> EOF } updaterefs() { echo "creating refs.html" cat <<- EOF > "$OUT/refs.html" $(pagehead "$REPO") $(pagesummary "$REPO") <hr> <h2>Branches</h2> <table> EOF git show-ref --heads | while read -r h n do echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html" done echo "</table>\n<h2>Tags</h2>\n<table>" >> "$OUT/refs.html" git show-ref --tags | while read -r h n do echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html" done cat <<- EOF >> "$OUT/refs.html" </table> </body> </html> EOF } updatetree() { echo "creating tree.html" cat <<- EOF > "$OUT/tree.html" $(pagehead "$REPO") $(pagesummary "$REPO") <hr> <h2>Tree</h2> <table> <tr><th>Size</th><th>Name</th><th>Raw</th></tr> EOF (cd "$OUT/tree" && find * -type f -printf '%s %p\n') | while read -r s f do echo "updating file $f" cat <<- EOF >> "$OUT/tree.html" <tr> <td>$s</td> <td><a href=tree/$f.html>$f</a></td> <td><a href=tree/$f>raw</a></td> </tr> EOF filepage "$f" > "$OUT/tree/$f.html" done cat <<- EOF >> "$OUT/tree.html" </table> </body> </html> EOF } # first argument should be the version, e.g. v0.1.0 creategomod() { [ -d "$OUT/@latest" ] || mkdir -p "$OUT/@latest" [ -d "$OUT/@v/$1" ] || mkdir -p "$OUT/@v/$1" find "$OUT/tree/"* -print | sed "s:$OUT/tree/:dovel.email/$REPO@v$1/" | zip -@ > "$OUT/@v/$1.zip" cp "$OUT/$1.zip" "$OUT/@latest/" } [ -d "$OUT/tree" ] && rm -rf "$OUT/tree" [ -d "$OUT/log" ] || mkdir -p "$OUT/log" git clone . "$OUT/tree" while read oldrev newrev ref do case "$ref" in "refs/heads/main") updategit updateindex updaterefs updatetree updatelog ;; "refs/tags/v"*) echo "received version tag $ref" # check repo for go mod tag="${ref#refs/tags/}" find "$OUT/tree/" -name go.mod && creategomod "$tag" ;; *) echo "$ref received. Doing nothing." ;; esac done
#!/bin/sh #for debugging #set -ex echo "copying scritps" TMP="$(mktemp -d)" git --work-tree="$TMP" checkout -f ${BRANCH} # copy main scripts to projects for dir in ../* do cp "$TMP/post-receive" "$dir/hooks/" 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 echo "cleaning up TMP" rm -fr "$TMP" echo "running post-receive-all" . hooks/post-receive-all
#!/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
#!/bin/sh # update index page index() { cat <<- EOF <!DOCTYPE html> <html> <head> <title>dovel</title> <link rel=icon href=/assets/favicon.ico> <meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="color-scheme" content="light dark"/> <style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif;}a{color:#888}small{float:right;}</style> <link rel="manifest" href="/assets/manifest.json"> <link rel="apple-touch-icon" sizes="200x200" href="/logo.png"> </head> <body> <center> <pre> _________ ______ ______ /________ _________ / _ __ /_ __ \_ | / / _ \_ / / /_/ / / /_/ /_ |/ // __/ / \__,_/ \____/_____/ \___//_/ </pre> </center> <a href=compose.html>compose</a>  <a href=logout.html>logout</a> EOF ls -ogdt --time-style long-iso * | while read -r g x s d t f do cat <<- EOF <p> <a href="$f/index.html">$f</a> <small>$t $d</small> </p> EOF done cat <<- EOF </body> </html> EOF } # update inbox page inbox() { cat <<- EOF <!DOCTYPE html> <html> <head> <title>dovel</title> <link rel=icon href=/assets/favicon.ico> <meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="color-scheme" content="light dark"/> <style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif}a{color:#888}small{float:right}</style> <link rel="manifest" href="/assets/manifest.json"> <link rel="apple-touch-icon" sizes="200x200" href="/logo.png"> </head> <body> <h1>$to</h1> <a href=/index.html>go back</a> EOF ls -ogdt --time-style long-iso "$to"/* | while read -r g x s d t f do f="$(basename "$f")" qty="$(ls -1 "$to/$f" | wc -l)" cat <<- EOF <p> <a href="$f/index.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 <!DOCTYPE html> <html> <head> <title>dovel</title> <link rel=icon href=/assets/favicon.ico> <meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="color-scheme" content="light dark"/> <style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif}a{color:#888}small{float:right}</style> <link rel="manifest" href="/assets/manifest.json"> <link rel="apple-touch-icon" sizes="200x200" href="/logo.png"> </head> <body> <h1>$subj</h1> <a href="/$to/$subj/index.html">go back</a><br><br> EOF # print each email ls -1rt "$to/$subj"/* | 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)}" # now the rest is a body cat - > /dev/null # move temp file mkdir -p "$to/$subj" mv "$tmp" "$to/$subj/$eid.mbox" # create html pages mkdir -p "out/$to/$subj" index > out/index.html inbox > "out/$to/index.html" emails > "out/$to/$subj/index.html" } # copy to temp file tmp="$(mktemp)" tee "$tmp" | save
#!/bin/sh # for debugging # set -ex echo "updating repo refs" . ./hooks/aux.sh OUT="$HOME/www/dovel.email/$REPO" echo "creating refs.html" cat << EOF > "$OUT/refs.html" $(pagehead "$REPO") $(pagesummary) <hr> <h2>Branches</h2> <table> EOF git show-ref --heads | while read -r h n do echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html" done echo "</table>\n<h2>Tags</h2>\n<table>" >> "$OUT/refs.html" git show-ref --tags | while read -r h n do echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html" done cat << EOF >> "$OUT/refs.html" </table> </body> </html> EOF
#!/bin/sh # for debugging # set -ex echo "updating git tree" . ./hooks/aux.sh OUT="$HOME/www/dovel.email/$REPO" createfilepage() { cat <<- EOF $(pagehead "$REPO") $(pagesummary) <hr> <h2>$1</h2> <file> <pre> <ol> EOF # print file while IFS= read -r l do printf "<li>%s</li>\n" "$(escapehtml "$l")" done < "$OUT/tree/$1" echo "</ol>\n</pre>\n</file>\n</body>\n</html>" } echo "creating tree.html" cat << EOF > "$OUT/tree.html" $(pagehead "$REPO") $(pagesummary) <hr> <h2>Tree</h2> <table> <tr><th>Size</th><th>Name</th><th>Raw</th></tr> EOF (cd "$OUT/tree" && find * -type f -printf '%s %p\n') | while read -r s f do echo "updating file $f" cat <<- EOF >> "$OUT/tree.html" <tr> <td>$s</td> <td><a href=tree/$f.html>$f</a></td> <td><a href=tree/$f>raw</a></td> </tr> EOF createfilepage "$f" > "$OUT/tree/$f.html" done cat << EOF >> "$OUT/tree.html" </table> </body> </html> EOF