aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-10-06 01:06:30 +0300
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-10-06 01:06:30 +0300
commit94c49df7dd27629d6a28f50028db483085907c96 (patch)
treeaa50cb59510db7a86c435aeccffaac14b194e745
parentad9e7cd5117c965222aae708f660e56d537914fc (diff)
downloadsnippets-94c49df7dd27629d6a28f50028db483085907c96.tar.gz
added scripts used for administration of fmsbw.de
-rwxr-xr-xci.sh73
-rwxr-xr-xgenerate-index-html.sh23
-rwxr-xr-xmlmmj-update-archive.sh43
3 files changed, 139 insertions, 0 deletions
diff --git a/ci.sh b/ci.sh
new file mode 100755
index 0000000..9af50a9
--- /dev/null
+++ b/ci.sh
@@ -0,0 +1,73 @@
+#!/usr/local/bin/zsh
+# Run CI jobs for repositories on git.fmsbw.de.
+# It can be scheduled as a cronjob.
+# This requires Podman on FreeBSD.
+#./ci.sh [<PROJECT> [<CI JOBS>]]
+set -e
+
+cd /var/git
+
+projects=${1:-`echo *`}
+for project in $projects; do
+ test -d $project || continue
+ cd $project
+
+ # We are scheduled by a cronjob, so don't repeat builds that
+ # have already been tried (whether successful or not).
+ # We use a tag to keep track of this.
+ # You can remove this tag to force a rebuild:
+ # git push origin --delete master-fmsbw-ci
+ branch=`git rev-parse --abbrev-ref HEAD`
+ test "`git rev-parse -q --verify $branch-fmsbw-ci || true`" != "`git rev-parse $branch`" || continue
+
+ # The runner can leave the website and other build artifacts there:
+ htdocs="/var/www/htdocs/projects/$project"
+
+ ci_scripts=${2:-`git ls-tree --name-only HEAD .fmsbw/`}
+ for ci_script in $ci_scripts; do
+ # Extract OCI image name by stripping any leading number used for sorting
+ # FIXME: This will cause problems for fully qualified image names.
+ # In practice, you need to prepare images to preinstall stuff anyway, so
+ # short names will be sufficient.
+ # If it turns out to be too inflexible, we could also extract the image name
+ # from an `IMAGE: ...` comment in the file itself.
+ ci_image="`basename $ci_script | sed 's/^[0-9]*\-//'`"
+
+ # Would it make any sense to create a ZFS volume?
+ working_copy="`mktemp -d /var/ci/working-copy.XXXX`"
+ git clone --recurse-submodules . $working_copy
+
+ mkdir -p "$htdocs"
+
+ ci_log="/var/ci/$project:$branch-`basename $ci_script`.log"
+
+ echo "[$project:$branch] Running $ci_script..."
+
+ # NOTE: The operating system should be guessed.
+ set +e
+ podman run -t --rm -v $working_copy:/opt/build -v "$htdocs":/opt/htdocs \
+ -w /opt/build -e FMSBW_CI=1 "$ci_image" "$ci_script" 2>&1 >"$ci_log"
+ rc=$?
+ set -e
+ if [ "$rc" != 0 ]; then
+ echo "[$project:$branch] CI FAILED. See $ci_log"
+ rm -rf $working_copy
+ # The next ci_scripts in the series could depend on build artifacts,
+ # so abort here.
+ break
+ fi
+
+ rm -rf $working_copy
+ done
+
+ # Update the CI tag.
+ # But avoid creating it for repos without any CI configured.
+ test -z "`git ls-tree --name-only HEAD .fmsbw/`" || git tag -f $branch-fmsbw-ci $branch
+
+ # Regenerate index.htmls
+ generate-index-html -R "$htdocs/downloads" || true
+ # Make sure the build artifacts are readable by httpd.
+ chown -R www:www "$htdocs" || true
+
+ cd ..
+done
diff --git a/generate-index-html.sh b/generate-index-html.sh
new file mode 100755
index 0000000..bf6fd3e
--- /dev/null
+++ b/generate-index-html.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# Generates an index.html with support for rendering a README.md if present.
+# With -R an entire directory hierarchy can be converted.
+# generate-index-html [-R] <dir>
+set -e
+
+if [ "x$1" = "x-R" ]; then
+ exec find "$2" -type d -exec "$0" '{}' ';'
+fi
+
+cd "$1"
+
+(echo '<html><head><meta charset="utf-8"><title>Directory listing</title></head><body>'
+ if [ -f README.md ]; then
+ lowdown -thtml --html-no-skiphtml --html-no-escapehtml README.md
+ echo '<hr>'
+ fi
+ echo -n '<pre>'
+ # Assumes a BSD ls.
+ ls -Flha | grep -Ev ' (\./|index\.html|README\.md|\.git/|\.gitignore)$' | \
+ cut -w -f 5- | sed -E 's|^([^\t]+\t+)([^ ]+ +)([^ ]+ +)([^ ]+ +)(.*[^*])\*?$|\1\2\3\4<a href="\5" target="_self">\5</a>|'
+ echo '</pre></body></html>'
+) >index.html
diff --git a/mlmmj-update-archive.sh b/mlmmj-update-archive.sh
new file mode 100755
index 0000000..b160ba5
--- /dev/null
+++ b/mlmmj-update-archive.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+#
+# Updates the mlmmj mailing list archive with new messages since last run based
+# on the last index in $LASTINDEX and the latest index in the $LISTDIR
+#
+# 2006 Martin Leopold <leopold@diku.dk>
+# 2025 Robin Haberkorn <rhaberkorn@fmsbw.de>
+#
+# Based on http://www.leopold.dk/~martin/stuff/update-archive.sh
+
+if [ $# -le 1 ]; then
+ echo "Grrr.."
+ echo "\$1 - name of the archive"
+ echo "\$2 - www dir"
+ echo "\$3 - list dir"
+ exit 0
+fi
+
+LABEL=$1
+WWWDIR=$2
+LISTDIR=$3
+LASTINDEXFILE=$WWWDIR/last
+NEWINDEX=`cat $LISTDIR/index`
+LASTINDEX=`cat $LASTINDEXFILE`
+HYPERMAIL="/usr/local/bin/hypermail"
+
+if [ -z "$LASTINDEX" ]; then
+ LASTINDEX=0
+fi
+
+if [ $LASTINDEX -ge $NEWINDEX ]; then
+ exit
+fi
+
+for IT in `seq $(($LASTINDEX+1)) $NEWINDEX`; do
+ $HYPERMAIL -l $LABEL -i -u -d $WWWDIR < $LISTDIR/archive/$IT
+done
+
+echo $NEWINDEX > $LASTINDEXFILE
+
+# Script should perhaps be run as the www user
+# But we cannot currently read from the mailing list archive.
+chown -R www:www $WWWDIR