]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
po-man: improve translation and install scripts
authorKarel Zak <kzak@redhat.com>
Wed, 22 Jan 2025 15:03:50 +0000 (16:03 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 12 Feb 2025 09:52:47 +0000 (10:52 +0100)
install-translations.sh:
 * add uninstall mode
 * add --install and --uninstall options
 * remove $DESTDIR, it has to be used in --mandir argument

translate.sh:
 * add --progress to print info
 * print info about missing man pages translation settings

Signed-off-by: Karel Zak <kzak@redhat.com>
po-man/install-translations.sh
po-man/translate.sh

index 9969d0e00f5e70ca7633c3ed50f4e0440a682eb9..aa31ca0b079d9e1b8ff1fad63cfdba28f855b92a 100755 (executable)
@@ -6,7 +6,7 @@ function usage()
     cat << HEREDOC
 
  Usage:
-  $PROGRAM --mandir <directory> --mansrcdir <directory> [<man page name>...]
+  $PROGRAM --install|--uninstall --mandir <directory> --mansrcdir <directory> [<man page name>...]
 
 Install translated man pages.
 
@@ -17,14 +17,14 @@ Install translated man pages.
 
  Environment Variables:
   MESON_INSTALL_PREFIX               install destination prefix directory
-  DESTDIR                            install destination directory
 
 HEREDOC
 }
 
-DESTDIR="${DESTDIR:-''}"
+MESON_INSTALL_PREFIX="${MESON_INSTALL_PREFIX:-''}"
 MANPAGES=()
 PROGRAM=$(basename "$0")
+MYCMD="install"
 
 while [[ $# -gt 0 ]]; do
   case $1 in
@@ -42,6 +42,14 @@ while [[ $# -gt 0 ]]; do
       shift
       shift
       ;;
+    --install)
+      MYCMD="install"
+      shift
+      ;;
+    --uninstall)
+      MYCMD="uninstall"
+      shift
+      ;;
     --*|-*)
       echo "Unknown option $1"
       usage
@@ -68,10 +76,16 @@ for LOCALEDIR in "$MANSRCDIR"/*/; do
         SECTION="${MANPAGE##*.}"
         PAGE="$LOCALEDIR/man$SECTION/$MANPAGE"
         if [ -f "$PAGE" ]; then
-            if [ -z ${MESON_INSTALL_QUIET+x} ]; then
-                echo "Installing $PAGE to $DESTDIR/$MESON_INSTALL_PREFIX/$MANDIR/$LOCALE/man$SECTION"
-            fi
-            install -D --mode=0644 --target-directory="$DESTDIR/$MESON_INSTALL_PREFIX/$MANDIR/$LOCALE/man$SECTION" "$PAGE"
+
+           if [ "$MYCMD" = "install" ]; then
+                if [ -z ${MESON_INSTALL_QUIET+x} ]; then
+                    echo "Installing $PAGE to $MESON_INSTALL_PREFIX/$MANDIR/$LOCALE/man$SECTION"
+                fi
+                install -D --mode=0644 --target-directory="$DESTDIR/$MESON_INSTALL_PREFIX/$MANDIR/$LOCALE/man$SECTION" "$PAGE"
+
+           elif [ "$MYCMD" = "uninstall" ]; then
+               rm -f "$DESTDIR/$MESON_INSTALL_PREFIX/$MANDIR/$LOCALE/man$SECTION/$PAGE"
+           fi
         fi
     done
 done
index 16cece5fb804bc60c2487bf25b99133119d5b3aa..426e6bfb29d8dcd1e0a39fee8c506a81d6365e6e 100755 (executable)
@@ -11,6 +11,7 @@ Translate Asciidoc man page source files and generate man pages.
 
  Options:
   --help                               show this help message and exit
+  --progress                           report the current progress
   --srcdir <srcdir>                    directory containing the asciidoc files to translate
   --destdir <destdir>                  directory in which to place the translated asciidoc files and man pages
   --asciidoctor-load-path <directory>  value for the --load-path option passed to the Asciidoctor command
@@ -22,6 +23,7 @@ HEREDOC
 }
 
 PROGRAM=$(basename "$0")
+PROGRESS=false
 
 while [[ $# -gt 0 ]]; do
     case $1 in
@@ -54,6 +56,10 @@ while [[ $# -gt 0 ]]; do
           shift
           shift
           ;;
+       --progress)
+         PROGRESS=true
+         shift
+         ;;
         --util-linux-version)
           UTIL_LINUX_VERSION="$2"
           shift
@@ -84,7 +90,8 @@ MANADOCS=()
 PO4A_TRANSLATE_ONLY_FLAGS=()
 for LOCALE in "${LOCALES[@]}"; do
     for ADOC in "${ADOCS[@]}"; do
-        if [[ ! " ${PO4ACFG_TRANSLATIONS[*]} " =~ [[:space:]]${ADOC}[[:space:]] ]]; then
+        if [[ ! " ${PO4ACFG_TRANSLATIONS[*]} " =~ .*${ADOC}[[:space:]] ]]; then
+         echo "Ignore $ADOC"
           continue
         fi
         PO4A_TRANSLATE_ONLY_FLAGS+=("--translate-only")
@@ -109,6 +116,8 @@ if echo "0.72" "$PO4A_VERSION" | sort --check --version-sort; then
   PO4A_TRANSLATE_ONLY_FLAGS=("--no-update")
 fi
 
+[ "$PROGRESS" = true ] && echo "po4a: generate man-pages translations"
+
 DISCARDED_TRANSLATIONS=()
 output=$(po4a --srcdir "$SRCDIR" --destdir "$DESTDIR" "${PO4A_TRANSLATE_ONLY_FLAGS[@]}" "$PO4ACFG")
 while IFS= read -r line; do
@@ -136,6 +145,10 @@ for ADOC in "${TRANSLATED_MANADOCS[@]}"; do
     LOCALE=$(basename "$(dirname "$ADOC")")
     PAGE="${ADOC%.*}"
     SECTION="${PAGE##*.}"
+    if [ "$PROGRESS" = true ]; then
+        PAGENAME=$(basename $PAGE)
+       echo "   GEN     " $LOCALE ": " $PAGENAME
+    fi
     asciidoctor \
         --backend manpage \
         --attribute VERSION="$UTIL_LINUX_VERSION" \