aboutsummaryrefslogtreecommitdiff
path: root/aux/workflow
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-07-27 14:24:01 -0300
committerEuAndreh <eu@euandre.org>2021-07-27 15:44:45 -0300
commit7bf0f2319442ee153cc656b72fa660c709f6a0cd (patch)
treeddae5f4ed3a7431bf026d3a64f9ff06615231804 /aux/workflow
parentaux/: Update, adjust Makefile (diff)
downloadgistatic-7bf0f2319442ee153cc656b72fa660c709f6a0cd.tar.gz
gistatic-7bf0f2319442ee153cc656b72fa660c709f6a0cd.tar.xz
Re-setup repository using C over Rust
Diffstat (limited to 'aux/workflow')
-rwxr-xr-xaux/workflow/assert-manpages.sh220
-rwxr-xr-xaux/workflow/installcheck.sh61
-rwxr-xr-xaux/workflow/l10n.sh70
-rwxr-xr-xaux/workflow/manpages.sh68
4 files changed, 419 insertions, 0 deletions
diff --git a/aux/workflow/assert-manpages.sh b/aux/workflow/assert-manpages.sh
new file mode 100755
index 0000000..f9a6807
--- /dev/null
+++ b/aux/workflow/assert-manpages.sh
@@ -0,0 +1,220 @@
+#!/bin/sh
+set -eu
+
+TLD="$(cat aux/tld.txt)"
+. aux/lib.sh
+
+IN_PLACE=false
+while getopts 'l:n:m:i' flag; do
+ case "$flag" in
+ n)
+ PROJECT="$OPTARG"
+ ;;
+ m)
+ MAILING_LIST="$OPTARG"
+ ;;
+ i)
+ IN_PLACE=true
+ ;;
+ l)
+ LANGS="$OPTARG"
+ ;;
+ *)
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+assert_arg() {
+ if [ -z "$1" ]; then
+ echo "Missing $2" >&2
+ exit 2
+ fi
+}
+
+assert_arg "${PROJECT:-}" '-n PROJECT'
+assert_arg "${MAILING_LIST:-}" '-m MAILING_LIST'
+assert_arg "${LANGS:-}" '-l LANGS'
+
+
+EXPECTED_EN="$(mkstemp)"
+cat <<EOF | sed 's|-|\\-|g' >> "$EXPECTED_EN"
+
+
+.SH AUTHORS
+
+.MT eu@euandre.org
+EuAndreh
+.ME
+and contributors.
+
+
+.SH BUGS
+
+.IP \(bu
+Report bugs to the
+.MT ~euandreh/$MAILING_LIST@lists.sr.ht
+mailing list
+.ME .
+Use the subject "\f(CR[$PROJECT] BUG or TASK:
+<description>\fR".
+.IP \(bu
+Browse bugs
+.UR https://$TLD/$PROJECT/TODOs.html
+online
+.UE .
+.IP \(bu
+.UR https://$TLD/$PROJECT/en/
+Homepage
+.UE .
+.IP \(bu
+.UR https://lists.sr.ht/~euandreh/$MAILING_LIST?search=%5B$PROJECT%5D
+Comments and discussions
+.UE .
+EOF
+
+EXPECTED_PT="$(mkstemp)"
+cat <<EOF | sed 's|-|\\-|g' >> "$EXPECTED_PT"
+
+
+.SH AUTORES
+
+.MT eu@euandre.org
+EuAndreh
+.ME
+e colaboradores.
+
+
+.SH BUGS
+
+.IP \(bu
+Relate bugs na
+.MT ~euandreh/$MAILING_LIST@lists.sr.ht
+lista de discussão
+.ME .
+Use o assunto "\f(CR[$PROJECT] BUG ou TASK:
+<descrição>\fR".
+.IP \(bu
+Veja os bugs
+.UR https://$TLD/$PROJECT/TODOs.html
+online
+.UE .
+.IP \(bu
+.UR https://$TLD/$PROJECT/pt/
+Página inicial
+.UE .
+.IP \(bu
+.UR https://lists.sr.ht/~euandreh/$MAILING_LIST?search=%5B$PROJECT%5D
+Comentários e discussões
+.UE .
+EOF
+
+EXPECTED_FR="$(mkstemp)"
+cat <<EOF | sed 's|-|\\-|g' >> "$EXPECTED_FR"
+
+
+.SH AUTEURS
+
+.MT eu@euandre.org
+EuAndreh
+.ME
+et les contributeurs.
+
+
+.SH BUGS
+
+.IP \(bu
+Soumettre un bogue dans la
+.MT ~euandreh/$MAILING_LIST@lists.sr.ht
+liste
+de diffusion
+.ME .
+Utilise le sujet "\f(CR[$PROJECT] BUG ou TASK:
+<description>\fR".
+.IP \(bu
+Parcourir les bogues
+.UR https://$TLD/$PROJECT/TODOs.html
+en
+ligne
+.UE .
+.IP \(bu
+.UR https://$TLD/$PROJECT/fr/
+Page d'accueil
+.UE .
+.IP \(bu
+.UR https://lists.sr.ht/~euandreh/$MAILING_LIST?search=%5B$PROJECT%5D
+Commentaires et discussions
+.UE .
+EOF
+
+EXPECTED_EO="$(mkstemp)"
+cat <<EOF | sed 's|-|\\-|g' >> "$EXPECTED_EO"
+
+
+.SH AŬTOROJ
+
+.MT eu@euandre.org
+EuAndreh
+.ME
+kaj la kontribuuloj.
+
+
+.SH MISFUNKCIOJ
+
+.IP \(bu
+Raportu misfunkcioj al la
+.MT ~euandreh/$MAILING_LIST@lists.sr.ht
+dissendolisto
+.ME .
+Uzu la subjekton "\f(CR[$PROJECT] BUG aŭ TASK:
+<priskribo>\fR".
+.IP \(bu
+Foliumu misfunkcioj
+.UR https://$TLD/$PROJECT/TODOs.html
+rete
+.UE .
+.IP \(bu
+.UR https://$TLD/$PROJECT/eo/
+Ĉefpaĝo
+.UE .
+.IP \(bu
+.UR https://lists.sr.ht/~euandreh/$MAILING_LIST?search=%5B$PROJECT%5D
+Komentoj kaj diskutoj
+.UE .
+EOF
+
+
+for from_f in "$@"; do
+ for lang in $LANGS; do
+ case "$lang" in
+ en)
+ EXPECTED="$EXPECTED_EN"
+ ;;
+ pt)
+ EXPECTED="$EXPECTED_PT"
+ ;;
+ fr)
+ EXPECTED="$EXPECTED_FR"
+ ;;
+ eo)
+ EXPECTED="$EXPECTED_EO"
+ ;;
+ *)
+ printf 'Unsupported lang: %s\n' "$lang" >&2
+ exit 2
+ ;;
+ esac
+
+ f="$(echo "$from_f" | sed "s/\.en\./.$lang./")"
+ if ! tail -n "$(wc -l < "$EXPECTED")" "$f" |
+ diff - "$EXPECTED"; then
+ echo "Missing metadata at the end of \"$f\" file"
+ if [ "$IN_PLACE" = true ]; then
+ cat "$EXPECTED" >> "$f"
+ else
+ exit 1
+ fi
+ fi
+ done
+done
diff --git a/aux/workflow/installcheck.sh b/aux/workflow/installcheck.sh
new file mode 100755
index 0000000..0aae391
--- /dev/null
+++ b/aux/workflow/installcheck.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+set -eu
+
+while getopts 'p:x:l:f:u' flag; do
+ case "$flag" in
+ p)
+ PREFIX="$OPTARG"
+ ;;
+ x)
+ EXECUTABLES_EXPECTED="$OPTARG"
+ ;;
+ l)
+ SYMLINKS_EXPECTED="$OPTARG"
+ ;;
+ f)
+ FILES_EXPECTED="$OPTARG"
+ ;;
+ u)
+ UNINSTALL=1
+ ;;
+ *)
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+if [ -n "${UNINSTALL:-}" ]; then
+ if [ "$(find "$PREFIX" -type f | wc -l)" != 0 ]; then
+ printf 'When uninstalling, left over files in the'
+ printf 'PREFIX directory:\n'
+ find "$PREFIX" -type f
+ exit 1
+ fi
+ exit
+fi
+
+EXECUTABLES_ACTUAL="$(find "$PREFIX" -type f -perm -a=x | wc -l)"
+if [ "${EXECUTABLES_EXPECTED:-0}" != "$EXECUTABLES_ACTUAL" ]; then
+ printf 'Expected %s executables, found %s:\n' \
+ "$EXECUTABLES_EXPECTED" "$EXECUTABLES_ACTUAL" >&2
+ find "$PREFIX" -type f -perm -a=x
+ exit 1
+fi
+
+SYMLINKS_ACTUAL="$(find "$PREFIX" -type l | wc -l)"
+if [ "${SYMLINKS_EXPECTED:-0}" != "$SYMLINKS_ACTUAL" ]; then
+ printf 'Expected %s symlinks, found %s:\n' \
+ "$SYMLINKS_EXPECTED" "$SYMLINKS_ACTUAL" >&2
+ find "$PREFIX" -type l
+ exit 1
+fi
+
+FILES_ACTUAL="$(find "$PREFIX" -type f | wc -l)"
+if [ "${FILES_EXPECTED:-0}" != "$FILES_ACTUAL" ]; then
+ printf 'Expected %s files, found %s:\n' \
+ "$FILES_EXPECTED" "$FILES_ACTUAL" >&2
+ find "$PREFIX" -type f
+ exit 1
+fi
diff --git a/aux/workflow/l10n.sh b/aux/workflow/l10n.sh
new file mode 100755
index 0000000..683758f
--- /dev/null
+++ b/aux/workflow/l10n.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+set -eu
+
+LANGS=
+while getopts 'l:L:' flag; do
+ case "$flag" in
+ l)
+ LANGS="$OPTARG"
+ ;;
+ L)
+ CONTRIBLANGS="$OPTARG"
+ ;;
+ *)
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+assert_arg() {
+ if [ -z "$1" ]; then
+ echo "Missing $2" >&2
+ exit 2
+ fi
+}
+
+assert_arg "${LANGS:-}" '-l LANGS'
+
+for from_f in "$@"; do
+ for lang in $LANGS ${CONTRIBLANGS:-}; do
+ to_f="$(echo "$from_f" | sed "s/\.en\./.$lang./")"
+ printf 'Generating %s...\n' "$to_f"
+ pofile="po/LC_MESSAGES/$from_f/$lang.po"
+ mkdir -p "$(dirname "$pofile")"
+
+ case "$from_f" in
+ *.en.[1-9].in)
+ po4a-updatepo -f man -m "$from_f" -p "$pofile"
+ po4a-translate -f man -m "$from_f" \
+ -p "$pofile" -l "$to_f" -k 0 -v >&2
+ ;;
+ *.en.md)
+ touch "$pofile"
+ md2po --include-codeblocks --quiet --save \
+ --po-filepath "$pofile" < "$from_f"
+ po2md --pofiles "$pofile" --save "$to_f" \
+ --quiet --wrapwidth 999 < "$from_f"
+ ;;
+ *)
+ echo "Unsupported file format: $from_f" >&2
+ exit 2
+ ;;
+ esac
+ done
+done
+
+end="\033[0m"
+yellowb="\033[1;33m"
+for lang in $LANGS; do
+ # shellcheck disable=2044
+ for pofile in $(find po/ -type f -name "$lang.po"); do
+ if ! LANG=POSIX msgfmt --statistics "$pofile" 2>&1 |
+ grep untranslated; then
+ continue
+ fi
+ # shellcheck disable=2059
+ printf "\n ${yellowb}WARNING${end}!" >&2
+ printf "\n Missing translations for %s\n\n" "$pofile" >&2
+ done
+done
diff --git a/aux/workflow/manpages.sh b/aux/workflow/manpages.sh
new file mode 100755
index 0000000..5c83a37
--- /dev/null
+++ b/aux/workflow/manpages.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+set -eu
+
+while getopts 'iuHo:p:' flag; do
+ case "$flag" in
+ i)
+ ACTION=install
+ ;;
+ u)
+ ACTION=uninstall
+ ;;
+ H)
+ ACTION=html
+ ;;
+ o)
+ OUTDIR="$OPTARG"
+ ;;
+ p)
+ MANPREFIX="$OPTARG"
+ ;;
+ *)
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+assert_arg() {
+ if [ -z "$1" ]; then
+ echo "Missing $2" >&2
+ exit 2
+ fi
+}
+
+assert_arg "${ACTION:-}" '-[iuH] for choosing action'
+
+for f in "$@"; do
+ l="$(echo "$f" | awk -F. '{print $(NF-1)}')"
+ n="$(echo "$f" | awk -F. '{print $NF}')"
+ case "$ACTION" in
+ html)
+ assert_arg "${OUTDIR:-}" '-o OUTDIR'
+ to_name="$(basename "${f%.$l.$n}.$n.html")"
+ mkdir -p "$OUTDIR/$l"
+ pandoc -s -r man -w html --metadata "lang=$l" \
+ < "$f" > "$OUTDIR/$l/$to_name"
+ ;;
+ install)
+ assert_arg "${MANPREFIX:-}" '-p MANPREFIX'
+ to_name="$(basename "${f%.$l.$n}.$n")"
+ mkdir -p "$MANPREFIX/$l/man$n" "$MANPREFIX/man$n"
+ cp "$f" "$MANPREFIX/$l/man$n/$to_name"
+ ln -fs "../en/man$n/$to_name" \
+ "$MANPREFIX/man$n/$to_name"
+ ;;
+ uninstall)
+ assert_arg "${MANPREFIX:-}" '-p MANPREFIX'
+ to_name="$(basename "${f%.$l.$n}.$n")"
+ rm -f \
+ "$MANPREFIX/$l/man$n/$to_name" \
+ "$MANPREFIX/man$n/$to_name"
+ ;;
+ *)
+ echo "Bad ACTION: $ACTION"
+ exit 1
+ ;;
+ esac
+done