]>
Commit | Line | Data |
---|---|---|
51417291 MM |
1 | #!/bin/sh |
2 | # | |
3 | # Compress documentation files found in $DOCDIR. Omit some files we don't | |
4 | # want to get compressed. | |
5 | # | |
a4852742 JB |
6 | # /etc/rpm/noautocompressdoc and --noautocompressdoc= option can contain |
7 | # whitespace delimated list of patters to omit. | |
51417291 MM |
8 | # |
9 | ||
10 | #set -x | |
11 | ||
12 | COMPRESS_CMD="gzip -9nf" | |
c4cafc90 | 13 | EXCLUDE_SUFFIXES="htm html jpg jpeg png gif pdf css dia js abw HTM JPG PNG GIF PDF CSS JS" |
51417291 MM |
14 | EXCLUDE_MASKS= |
15 | RECOMPRESS_BZIP2=yes | |
16 | ||
a4852742 JB |
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 | |
51417291 MM |
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 | |
ca04d41f | 52 | FIND_CMD="$FIND_CMD -a -not -name '*.$SUF'" |
51417291 MM |
53 | done |
54 | ||
ca04d41f | 55 | eval $FIND_CMD | while read FILENAME ; do |
51417291 MM |
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 | |
c4cafc90 | 64 | case "$FILENAME" in |
51417291 | 65 | *.gz | *.Z) |
c4cafc90 | 66 | gzip -d "$FILENAME" |
67 | FILENAME=$(echo "$FILENAME" | sed -e 's/\.gz$//; s/\.Z$//') | |
51417291 MM |
68 | ;; |
69 | *.bz2) | |
70 | if [ "$RECOMPRESS_BZIP2" = yes ] ; then | |
c4cafc90 | 71 | bzip2 -d "$FILENAME" |
72 | FILENAME=$(echo "$FILENAME" | sed -e 's/\.bz2$//') | |
51417291 MM |
73 | else |
74 | continue | |
75 | fi | |
76 | ;; | |
77 | esac | |
78 | ||
c4cafc90 | 79 | $COMPRESS_CMD "$FILENAME" |
51417291 MM |
80 | |
81 | echo -n "$FILENAME " | |
82 | done | |
83 | ||
84 | echo | |
85 | echo "Documentation compressed." |