]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-compress-doc
- use rpm macros instead of configure.ac gen
[packages/rpm.git] / rpm-compress-doc
1 #!/bin/sh
2 #
3 # Compress documentation files found in $DOCDIR. Omit some files we don't
4 # want to get compressed.
5 #
6 # /etc/rpm/noautocompressdoc and --noautocompressdoc= option can contain
7 # whitespace delimated list of patters to omit.
8 #
9
10 #set -x
11
12 COMPRESS_CMD="gzip -9nf"
13 EXCLUDE_SUFFIXES="htm html jpg jpeg png gif pdf css dia js abw HTM JPG PNG GIF PDF CSS JS"
14 EXCLUDE_MASKS=
15 RECOMPRESS_BZIP2=yes
16
17 nocompressdoc=''
18 while [ $# -gt 0 ]; do
19         case "$1" in
20           --noautocompressdoc=*)
21                 EXCLUDE_MASKS=`echo "${1#--noautocompressdoc=}" | sed -e 's/^ *//;s/ *$//;s/ \+/|/g'`
22         esac
23         shift
24 done
25
26 if [ -r /etc/rpm/noautocompressdoc ]; then
27         exclude=$(cat /etc/rpm/noautocompressdoc | grep -v '^#' | xargs echo | sed -e 's/^ *//;s/ *$//;s/ \+/|/g')
28         if [ -n "${exclude}" ]; then
29                 if [ -n "${EXCLUDE_MASKS}" ]; then
30                         EXCLUDE_MASKS="${EXCLUDE_MASKS}|${exclude}"
31                 else
32                         EXCLUDE_MASKS="${exclude}"
33                 fi
34         fi
35 fi
36
37 if [ "$DOCDIR" = "" ] ; then
38         echo '$DOCDIR not set; exiting.'
39         exit 1
40 fi
41
42 cd $DOCDIR
43
44 echo "Compressing documentation in $DOCDIR..."
45
46 if test "$EXCLUDE_MASKS" ; then
47         echo "Excluding pattern '$EXCLUDE_MASKS'"
48 fi
49
50 FIND_CMD="find . -type f "
51 for SUF in $EXCLUDE_SUFFIXES ; do
52         FIND_CMD="$FIND_CMD -a -not -name '*.$SUF'"
53 done
54
55 eval $FIND_CMD | while read FILENAME ; do
56         if test -n "$EXCLUDE_MASKS" ; then
57                 if eval "case \$(basename \"$FILENAME\") in
58                          $EXCLUDE_MASKS ) true ;;
59                          * ) false ;;
60                          esac" ; then
61                         continue
62                 fi
63         fi
64         case "$FILENAME" in
65         *.gz | *.Z)
66                 gzip -d "$FILENAME"
67                 FILENAME=$(echo "$FILENAME" | sed -e 's/\.gz$//; s/\.Z$//')
68                 ;;
69         *.bz2)
70                 if [ "$RECOMPRESS_BZIP2" = yes ] ; then
71                         bzip2 -d "$FILENAME"
72                         FILENAME=$(echo "$FILENAME" | sed -e 's/\.bz2$//')
73                 else
74                         continue
75                 fi
76                 ;;
77         esac
78
79         $COMPRESS_CMD "$FILENAME"
80
81         echo -n "$FILENAME "
82 done
83
84 echo
85 echo "Documentation compressed."
This page took 0.032799 seconds and 3 git commands to generate.