compress-man-pages: skip compressed manpages

Because of bash 4.4 the semantics GLOBIGNORE changed.
This resulted in already compressed manpages to be compressed twice.
Also be careful about symlinks to fix #21777, e.g. the ledger example.

+20 -16
+20 -16
pkgs/build-support/setup-hooks/compress-man-pages.sh
··· 3 3 compressManPages() { 4 4 local dir="$1" 5 5 6 - if [ ! -d "$dir/share/man" ]; then return; fi 7 - echo "gzipping man pages in $dir" 6 + if [ -L "$dir"/share ] || [ -L "$dir"/share/man ] || [ ! -d "$dir/share/man" ] 7 + then return 8 + fi 9 + echo "gzipping man pages under $dir/share/man/" 8 10 9 - GLOBIGNORE=.:..:*.gz:*.bz2 10 - 11 - for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do 12 - if [ -f "$f" -a ! -L "$f" ]; then 13 - if gzip -c -n "$f" > "$f".gz; then 14 - rm "$f" 15 - else 16 - rm "$f".gz 17 - fi 11 + # Compress all uncompressed manpages. Don't follow symlinks, etc. 12 + find "$dir"/share/man/ -type f -a '!' -regex '.*\.\(bz2\|gz\)$' -print0 \ 13 + | while IFS= read -r -d $'\0' f 14 + do 15 + if gzip -c -n "$f" > "$f".gz; then 16 + rm "$f" 17 + else 18 + rm "$f".gz 18 19 fi 19 20 done 20 21 21 - for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do 22 - if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then 23 - ln -sf `readlink "$f"`.gz "$f".gz && rm "$f" 22 + # Point symlinks to compressed manpages. 23 + find "$dir"/share/man/ -type l -a '!' -regex '.*\.\(bz2\|gz\)$' -print0 \ 24 + | while IFS= read -r -d $'\0' f 25 + do 26 + local target 27 + target="$(readlink -f "$f")" 28 + if [ -f "$target".gz ]; then 29 + ln -sf "$target".gz "$f".gz && rm "$f" 24 30 fi 25 31 done 26 - 27 - unset GLOBIGNORE 28 32 }