| 1 | #!/bin/sh |
| 2 | # |
| 3 | # list-manpages - Find man pages available for translation |
| 4 | # Copyright © 2020 Rafael Fontenelle <[email protected]> |
| 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation, either version 3 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | prog="./$(basename $0)" |
| 20 | distros=$(find '../../upstream/' -maxdepth 1 -type d | sed 's|../../upstream/||' | tr '\n' ' ') |
| 21 | untranslatedflag=0 |
| 22 | |
| 23 | |
| 24 | while getopts 'hd:f:u' arg; do |
| 25 | case $arg in |
| 26 | h) |
| 27 | echo "Usage: $prog [options]" |
| 28 | echo "List man pages available for translation with or without filters;" |
| 29 | echo "List all by default, unless a filter is used." |
| 30 | echo "" |
| 31 | echo "Options supported:" |
| 32 | echo " -d DISTRO filter by distribution name DISTRO; valid names:" |
| 33 | echo " $distros" |
| 34 | echo " -f FILE filter by FILE, which is a part or the whole man page filename" |
| 35 | echo " -u filter by untranslated man pages (i.e. no po file yet)" |
| 36 | echo " -h show this message and quit" |
| 37 | echo "" |
| 38 | echo "Example of uses:" |
| 39 | echo " $prog (to list all man pages available)" |
| 40 | echo " $prog -d debian-buster (to list debian-buster's man pages)" |
| 41 | echo " $prog -f ext4 (to list man pages with 'ext4' in filename)" |
| 42 | echo " $prog -uf intro (to list untranslated 'intro' man pages)" |
| 43 | echo "" |
| 44 | exit |
| 45 | ;; |
| 46 | d) |
| 47 | for distro in $distros; do |
| 48 | if [ "$distro" = "$OPTARG" ]; then |
| 49 | distrofilter=$OPTARG |
| 50 | break |
| 51 | fi |
| 52 | done |
| 53 | |
| 54 | if [ -z "$distrofilter" ]; then |
| 55 | echo "Invalid distribution name \"$distrofilter\". Valid name: $distros" >&2 |
| 56 | exit 1 |
| 57 | fi |
| 58 | ;; |
| 59 | f) |
| 60 | filenamefilter=$OPTARG |
| 61 | ;; |
| 62 | u) |
| 63 | untranslatedflag=1 |
| 64 | ;; |
| 65 | esac |
| 66 | done |
| 67 | |
| 68 | |
| 69 | # If -d passed, filter by distribution name, or get all man page filenames |
| 70 | if [ -n "$distrofilter" ]; then |
| 71 | manpages=$(find "../../upstream/$distrofilter"/man* -type f | cut -d/ -f4- | LC_ALL=C sort) |
| 72 | else |
| 73 | manpages=$(find "../../upstream"/*/man* -type f | cut -d/ -f4- | LC_ALL=C sort) |
| 74 | fi |
| 75 | |
| 76 | |
| 77 | # If -f passed, filter by man page filename |
| 78 | if [ -n "$filenamefilter" ]; then |
| 79 | manpages=$(echo "$manpages" | tr ' ' '\n' | grep "$filenamefilter") |
| 80 | fi |
| 81 | |
| 82 | |
| 83 | # If -u passed, show only untranslated man pages (i.e. not complete neither incomplete) |
| 84 | if [ $untranslatedflag -eq 1 ]; then |
| 85 | |
| 86 | # store man pages in temporary file |
| 87 | tmpfile=$(mktemp) |
| 88 | echo "$manpages" > "$tmpfile" |
| 89 | |
| 90 | # list translation files |
| 91 | translatedfiles=$(find man?/ -type f -name '*.po') |
| 92 | |
| 93 | for translatedfile in $translatedfiles; do |
| 94 | filename=$(echo "${translatedfile%%.po}" | sed 's|/|\\/|g') |
| 95 | sed -i "/$filename/d" "$tmpfile" |
| 96 | done |
| 97 | |
| 98 | manpages=$(cat $tmpfile) |
| 99 | fi |
| 100 | |
| 101 | echo "$manpages" | tr ' ' '\n' |