list

scripts

Repo containing scripts to be used with dovel, and git hooks that powers our web interface.

git clone https://dovel.email/scripts

post-receive

  1. #!/bin/sh
  2. # for debugging
  3. # set -ex
  4. . hooks/aux.sh
  5. # . ./aux.sh
  6. ROOT="$HOME/dovel.email"
  7. REPO="$(basename $PWD)"
  8. OUT="$ROOT/$REPO"
  9. TMP="$(mktemp -d)"
  10. updategit() {
  11. cat <<- EOF > "$ROOT/git.html"
  12. $(pagehead "dovel")
  13. &larr; <a href="/">dovel website</a>
  14. <h1>Dovel project Git home</h1>
  15. Welcome! Here you'll find general info about our projects and how to
  16. contribute to them. We proudly use dovel email technology for our
  17. mailing lists. Its hooks are in the scripts repo. Please read the next
  18. sections before making a contribution.
  19. <p>
  20. To clone a repository use <kbd><b>git clone https://dovel.email/[repo]</b></kbd>,
  21. changing [repo] by the name you want.
  22. </p>
  23. <h2>Repositories</h2>
  24. <dl>
  25. EOF
  26. # TODO: change git folder
  27. for dir in "$HOME/git/dovel.email/"*
  28. do
  29. cat <<- EOF >> "$ROOT/git.html"
  30. <dt><a href=$(basename $dir)/index.html>$(basename $dir)</a></dt>
  31. <dd>$(cat "$dir/description")</dd>
  32. EOF
  33. done
  34. printf '\n</dl>\n<h2>Latest commit</h2>\n' >> "$ROOT/git.html"
  35. hash="$(git show --format='%h' -s)"
  36. cat <<- EOF >> "$ROOT/git.html"
  37. <p><a href="$REPO/log/$hash.html">$hash</a> on $REPO:</p>
  38. <pre>
  39. EOF
  40. git show -s "$hash" >> "$ROOT/git.html"
  41. cat <<- EOF >> "$ROOT/git.html"
  42. </pre>
  43. <h2>Contributing</h2>
  44. The dovel team uses the git email workflow to accept contributions.
  45. All email sent to dovel.email is considered as git mailling lists,
  46. see the next section on how we organize them.
  47. To send email about other subjects please address them to
  48. <a href=mailto:dovel@terminal.pink>dovel _AT_ terminal.pink</a>.
  49. <p>Browse the <a href=mail.html>mailing list</a> online.</p>
  50. <h3>Email addresses</h3>
  51. To send contributions use the repo name as address, i.e. to
  52. contribute to the server project send email to
  53. <kbd>server _AT_ dovel.email</kbd>. Please CC me as well so I
  54. can reply faster: <kbd>dovel _AT_ terminal.pink</kbd>.
  55. Please choose the subject wiselly since it is used to separate
  56. threads, if you choose a taken subject or a too generic one
  57. your email can go to another thread.
  58. <h3>Email etiquette</h3>
  59. We only accept plain text email. More info and recomendations can be
  60. found on <a href=//useplaintext.email>useplaintext.email</a>. Also
  61. <a href=//git-send-email.io>git-send-email.io</a> has instructions on
  62. how to setup git to send email for many platforms.
  63. </body>
  64. </html>
  65. EOF
  66. }
  67. updateindex() {
  68. echo "creating index.html"
  69. cat <<- EOF > "$OUT/index.html"
  70. $(pagehead "$REPO")
  71. $(pagesummary "$REPO")
  72. <hr>
  73. <p>Latest commit: $(git log -n 1 --format="(%h) by %an at %as: %s")</p>
  74. <main>
  75. EOF
  76. [ -f "$TMP/README.md" ] && mdown < "$TMP/README.md" >> "$OUT/index.html"
  77. [ -f "$TMP/README" ] && cat <<- EOF >> "$OUT/index.html"
  78. <pre>$(cat "$TMP/README")</pre>
  79. EOF
  80. printf "\t</main>\n</body>\n</html>\n" >> "$OUT/index.html"
  81. }
  82. createcommitpage() {
  83. cat <<- EOF
  84. $(pagehead "$REPO")
  85. $(pagesummary "$REPO")
  86. <hr>
  87. <h2>$1</h2>
  88. EOF
  89. # print commit
  90. git show --format='%an%n%ae%n%ad%n%p%n%B' -s "$1" | {
  91. read -r name
  92. read -r email
  93. read -r date
  94. read -r parent
  95. cat <<- EOF
  96. <p>Author: $name ($email)</p>
  97. <p>Date: $date</p>
  98. <p>Parent: <a href=$parent.html>$parent</a></p>
  99. <pre>$(cat -)</pre>
  100. EOF
  101. }
  102. # now the diff
  103. echo "<h3>Diff</h3>"
  104. for f in $(git show "$1" --name-only --format='')
  105. do
  106. cat << EOF
  107. <h4>$f</h4>
  108. <pre style="overflow-x:auto;white-space:pre">
  109. $(git show --format='' "$1" -- "$f" | escapehtml)
  110. </pre>
  111. EOF
  112. done
  113. cat <<- EOF
  114. </body>
  115. </html>
  116. EOF
  117. }
  118. updatelog() {
  119. echo "creating log.html"
  120. cat <<- EOF > "$OUT/log.html"
  121. $(pagehead "$REPO")
  122. $(pagesummary "$REPO")
  123. <hr>
  124. <h2>Log</h2>
  125. <table>
  126. <tr><th>Hash</th><th>Author</th><th>Date</th><th>Subject</td></tr>
  127. EOF
  128. git log -n 100 --format='%h%n%ad%n%an%n%s' --date=iso | while read -r h
  129. do
  130. read -r date
  131. read -r name
  132. read -r msg
  133. cat <<- EOF >> "$OUT/log.html"
  134. <tr><td><a href=log/$h.html>$h</a></td><td>$name</td><td>$date</td><td>$msg</td></tr>
  135. EOF
  136. [ -f "$OUT/log/$h.html" ] && continue
  137. echo "creating commit page $h"
  138. createcommitpage "$h" > "$OUT/log/$h.html"
  139. done
  140. cat <<- EOF >> "$OUT/log.html"
  141. </table>
  142. <p>Note: Only showing up to 100 commits, for full log clone the repo.</p>
  143. </body>
  144. </html>
  145. EOF
  146. }
  147. updaterefs() {
  148. echo "creating refs.html"
  149. cat <<- EOF > "$OUT/refs.html"
  150. $(pagehead "$REPO")
  151. $(pagesummary "$REPO")
  152. <hr>
  153. <h2>Branches</h2>
  154. <table>
  155. EOF
  156. git show-ref --heads | while read -r h n
  157. do
  158. echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html"
  159. done
  160. echo "</table>\n<h2>Tags</h2>\n<table>" >> "$OUT/refs.html"
  161. git show-ref --tags | while read -r h n
  162. do
  163. echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html"
  164. done
  165. cat <<- EOF >> "$OUT/refs.html"
  166. </table>
  167. </body>
  168. </html>
  169. EOF
  170. }
  171. filepage() {
  172. cat <<- EOF
  173. $(pagehead "$REPO")
  174. $(pagesummary "$REPO")
  175. <hr>
  176. <h2>$1</h2>
  177. <file>
  178. <pre>
  179. <ol>
  180. EOF
  181. # print file
  182. while IFS= read -r l
  183. do
  184. printf "<li>%s</li>\n" "$(printf "%s" "$l" | escapehtml)"
  185. done < "$TMP/$1"
  186. echo "</ol>\n</pre>\n</file>\n</body>\n</html>"
  187. }
  188. updatetree() {
  189. echo "creating tree.html"
  190. cat <<- EOF > "$OUT/tree.html"
  191. $(pagehead "$REPO")
  192. $(pagesummary "$REPO")
  193. <hr>
  194. <h2>Tree</h2>
  195. <table>
  196. <tr><th>Size</th><th>Name</th></tr>
  197. EOF
  198. (cd "$TMP" && find * -type f -printf '%s %p\n') | while read -r s f
  199. do
  200. cat <<- EOF >> "$OUT/tree.html"
  201. <tr>
  202. <td>$s</td>
  203. <td><a href=tree/$f.html>$f</a></td>
  204. </tr>
  205. EOF
  206. # create html page with file content
  207. read -r op x <<- EOF
  208. $(git show --format='' --name-status "$1" -- "$f")
  209. EOF
  210. case "$op" in
  211. "D") rm "$OUT/tree/$f.html" ;;
  212. "C"|"M") filepage "$f" > "$OUT/tree/$f.html" ;;
  213. "") echo "no change for file $f" ;;
  214. esac
  215. done
  216. cat <<- EOF >> "$OUT/tree.html"
  217. </table>
  218. </body>
  219. </html>
  220. EOF
  221. }
  222. # first argument should be the version, e.g. v0.1.0
  223. creategomod() {
  224. # create page with meta tag
  225. echo "<meta name=\"go-import\" content=\"dovel.email/server mod https://dovel.email\">" > "$OUT?go-get=1"
  226. TMP="$(mktemp -d)"
  227. mkdir -p "$TMP/dovel.email/$REPO@$1"
  228. git --work-tree="$TMP/dovel.email/$REPO@$1/" checkout -f main
  229. PREFIX="${OUT%/*}/dovel.email/$REPO"
  230. [ -d "$PREFIX/@v" ] || mkdir -p "$PREFIX/@v"
  231. (cd "$TMP" && find * -type f -print | zip -@ "$PREFIX/@v/$1.zip")
  232. echo "{\"Version\":\"$1\"}" > "$PREFIX/@v/$1.info"
  233. echo "$1" >> "$PREFIX/@v/list"
  234. cp "$TMP/dovel.email/$REPO@$1/go.mod" "$PREFIX/@v/$1.mod"
  235. rm -rf "$TMP"
  236. }
  237. [ -d "$OUT/log" ] || mkdir -p "$OUT/log"
  238. git clone . "$TMP"
  239. while read oldrev newrev ref
  240. do
  241. case "$ref" in
  242. "refs/heads/main")
  243. updategit
  244. updateindex
  245. updaterefs
  246. updatetree "$newrev"
  247. updatelog
  248. ;;
  249. "refs/tags/v"*)
  250. echo "received version tag $ref"
  251. # check repo for go mod
  252. tag="${ref#refs/tags/}"
  253. for mod in $(find "$TMP/" -name go.mod)
  254. do
  255. creategomod "$tag"
  256. done
  257. ;;
  258. *) echo "$ref received. Doing nothing." ;;
  259. esac
  260. done
  261. rm -rf "$TMP"
  262. git update-server-info