]> git.ipfire.org Git - people/ms/pakfire.git/blob - tools/compress-man-pages
Add a missing command in clean section of a Makefile.
[people/ms/pakfire.git] / tools / compress-man-pages
1 #!/bin/bash
2
3 COMPRESSOR=xz
4 COMPRESS_EXT=.xz
5
6 echo "Compressing man pages..."
7
8 BUILDROOT=${1}
9 shift
10
11 dir="${BUILDROOT}/usr/share/man"
12
13 for file in $(find ${dir} -type f 2>/dev/null); do
14 [ -f "${file}" ] || continue
15
16 case "${file}" in
17 *.gz)
18 gzip -d ${file}
19 file=${file%*.gz}
20 ;;
21 *.bz2)
22 bzip2 -d ${file}
23 file=${file%*.bz2}
24 ;;
25 esac
26
27 echo " Compressing man page ${file//${BUILDROOT}/}..."
28 ${COMPRESSOR} ${file} </dev/null 2>/dev/null || {
29 # Handle files with hardlinks.
30 others=$(find ${dir} -type f -samefile ${file})
31 if [ -n "${others}" ]; then
32 for afile in ${others}; do
33 [ "${afile}" != "${file}" ] && rm -f ${afile}
34 done
35 ${COMPRESSOR} -f ${file}
36 for afile in ${others}; do
37 [ "${afile}" != "${file}" ] && ln ${file}${COMPRESS_EXT} ${afile}${COMPRESS_EXT}
38 done
39 else
40 ${COMPRESSOR} -f ${file}
41 fi
42 }
43 done
44
45 for file in $(find ${dir} -type l 2>/dev/null); do
46 link=$(ls -l ${file} | sed -e 's/.* -> //' -e 's/\.\(gz\|Z\|bz2\|xz\|lzma\)$//')
47 rm -f ${file}
48 b=$(echo ${file} | sed -e 's/\.\(gz\|Z\|bz2\|xz\|lzma\)$//')
49 ln -sf ${link}${COMPRESS_EXT} ${b}${COMPRESS_EXT}
50 done
51
52 exit 0