[70919be] | 1 | <sect1 id="postlfs-config-compressdoc" xreflabel="compressdoc">
|
---|
| 2 | <?dbhtml filename="compressdoc.html" dir="postlfs"?>
|
---|
| 3 | <title>Compressing man and info pages</title>
|
---|
| 4 |
|
---|
[78b3cd61] | 5 | <para>Man and info reader programs can transparently process gzip'ed or
|
---|
| 6 | bzip2'ed pages, a feature you can use to free some disk space while keeping
|
---|
[70919be] | 7 | your documentation available. However, things are not that simple: man
|
---|
| 8 | directories tend to contain links - hard and symbolic - which defeat simple
|
---|
[78b3cd61] | 9 | ideas like recursively calling <command>gzip</command> on them. A better way
|
---|
| 10 | to go is to use the script below.
|
---|
[70919be] | 11 | </para>
|
---|
| 12 |
|
---|
[b94cd51] | 13 | <screen><userinput><command>cat > /usr/bin/compressdoc << "EOF"</command>
|
---|
[70919be] | 14 |
|
---|
| 15 | #!/bin/sh
|
---|
| 16 |
|
---|
| 17 | function changefileext
|
---|
| 18 | {
|
---|
[b94cd51] | 19 | # prints the given filename with the new extension instead of
|
---|
| 20 | # the old one. ! - always prints an absolute filename even if
|
---|
| 21 | # the caller provides a relative one.
|
---|
| 22 | # parameters : 1 - file name
|
---|
| 23 | # 2 - old extension
|
---|
| 24 | # 3 - new extension (may be empty)
|
---|
| 25 |
|
---|
| 26 | echo `dirname $1`\/`basename $1 $2`$3
|
---|
[70919be] | 27 | }
|
---|
| 28 |
|
---|
| 29 | # check that the command line is right, if not print a relevant message.
|
---|
| 30 |
|
---|
| 31 | if [ ! -d $1 -o -z $1 ] || [ "$2" != "gz" -a "$2" != "bz2" ]
|
---|
| 32 | then
|
---|
[b94cd51] | 33 | echo "Usage : $0 /path/to/doc/dir gz/bz2"
|
---|
| 34 | echo "e.g. $0 /usr/info gz to compress info pages in gzip format"
|
---|
| 35 | echo "or $0 /usr/X11R6/man bz2 to compact X man pages using bzip2."
|
---|
| 36 | exit 1
|
---|
[70919be] | 37 | fi
|
---|
| 38 |
|
---|
| 39 | # set up a few variables.
|
---|
| 40 |
|
---|
[d7c254a] | 41 | NEWEXT=.$2 # NEWEXT = extension of newly compressed files
|
---|
[70919be] | 42 |
|
---|
| 43 | if [ "$NEWEXT" == ".bz2" ]
|
---|
| 44 | then
|
---|
[b94cd51] | 45 | OLDEXT=".gz" # OLDEXT = extensions of files to recompress
|
---|
[d7c254a] | 46 | DECOMPRESS="gunzip -f" # DECOMPRESS = command to decompress a file
|
---|
| 47 | COMPRESS="bzip2 -f9" # COMPRESS = command to compress a file
|
---|
[70919be] | 48 | else
|
---|
[b94cd51] | 49 | OLDEXT=".bz2"
|
---|
| 50 | DECOMPRESS="bunzip2 -f"
|
---|
| 51 | COMPRESS="gzip -f9"
|
---|
[70919be] | 52 | fi
|
---|
| 53 |
|
---|
| 54 | # process all files not in the target format under the provided root directory.
|
---|
| 55 | # I use cd instead of giving $1 as an argument to find because this causes
|
---|
| 56 | # problems with symbolic links, e.g. /usr/man -> /usr/share/man.
|
---|
| 57 |
|
---|
| 58 | cd $1
|
---|
| 59 |
|
---|
| 60 | for f in `find . \! -name "*$NEWEXT"`
|
---|
| 61 | do
|
---|
[b94cd51] | 62 | # the following test is needed because we have to update links ahead of
|
---|
| 63 | # ourselves, so $f is sometimes a nonexistent file or a link to one.
|
---|
[70919be] | 64 |
|
---|
[b94cd51] | 65 | if [ -f $f -o -L $f ]
|
---|
| 66 | then
|
---|
[d7c254a] | 67 | FILE=$f # the file being processed
|
---|
| 68 | BASEFILE=`basename $FILE` # its basename (see HLINKS)
|
---|
| 69 | INODE=`find $FILE -printf %i` # its inode number (see HLINKS)
|
---|
| 70 | NEWFILE=`changefileext $FILE $OLDEXT $NEWEXT` # new file name
|
---|
[70919be] | 71 |
|
---|
[b94cd51] | 72 | # HLINKS is the list of all hard links to the current file.
|
---|
[70919be] | 73 |
|
---|
[b94cd51] | 74 | HLINKS=`find . \! -name $BASEFILE -inum $INODE`
|
---|
[70919be] | 75 |
|
---|
[b94cd51] | 76 | if [ -L $FILE ]
|
---|
| 77 | then
|
---|
| 78 | # the current file is a symbolic link, so we change
|
---|
| 79 | # its name and the name of its target.
|
---|
[70919be] | 80 |
|
---|
[b94cd51] | 81 | TARGET=`readlink $FILE`
|
---|
| 82 | rm -f $FILE
|
---|
| 83 | ln -sf `changefileext $TARGET $OLDEXT $NEWEXT` $NEWFILE
|
---|
| 84 | elif [ -f $FILE ]
|
---|
| 85 | then
|
---|
| 86 | # the current file is a regular file.
|
---|
[70919be] | 87 |
|
---|
[b94cd51] | 88 | TEMPFILE=`changefileext $FILE $OLDEXT`
|
---|
[70919be] | 89 |
|
---|
| 90 | # if there are several versions of a page (at worst, there can be
|
---|
| 91 | # one uncompressed, one old-compressed and one new-compressed), then
|
---|
| 92 | # we have to make sure that only the most recent file is kept, because
|
---|
| 93 | # it most likely means the user installed several versions of a package.
|
---|
| 94 |
|
---|
[b94cd51] | 95 | # first, if we are dealing with an old-compressed file,
|
---|
| 96 | # expand it if it is more recent than the uncompressed
|
---|
| 97 | # file *and* the new-compressed file, else delete it.
|
---|
| 98 | # (works even if TEMPFILE and/or NEWFILE do not exist)
|
---|
| 99 |
|
---|
| 100 | if [ "$FILE" != "$TEMPFILE" ]
|
---|
| 101 | then
|
---|
| 102 | if [ $FILE -nt $TEMPFILE -a $FILE -nt $NEWFILE ]
|
---|
| 103 | then
|
---|
| 104 | $DECOMPRESS $FILE
|
---|
| 105 | else
|
---|
| 106 | rm -f $FILE
|
---|
| 107 | fi
|
---|
| 108 | FILE=$TEMPFILE
|
---|
| 109 | fi
|
---|
| 110 |
|
---|
| 111 | # now we are dealing with an uncompressed file that may
|
---|
| 112 | # exist or not (because of the above). If it is newer
|
---|
| 113 | # than both the new-compressed and the old-compressed
|
---|
| 114 | # files then it is compressed, else it is deleted.
|
---|
| 115 |
|
---|
| 116 | if [ -f $FILE ]
|
---|
| 117 | then
|
---|
| 118 | if [ $FILE -nt $NEWFILE -a $FILE -nt $FILE$OLDEXT ]
|
---|
| 119 | then
|
---|
| 120 | $COMPRESS $FILE
|
---|
| 121 | else
|
---|
| 122 | rm -f $FILE
|
---|
| 123 | fi
|
---|
| 124 | fi
|
---|
| 125 | fi
|
---|
| 126 |
|
---|
| 127 | # update the hard links to the current files,
|
---|
| 128 | # as the new inode number is now known.
|
---|
| 129 |
|
---|
| 130 | for g in $HLINKS
|
---|
| 131 | do
|
---|
| 132 | rm -f $g
|
---|
| 133 | ln -f $NEWFILE `changefileext $g $OLDEXT $NEWEXT`
|
---|
| 134 | done
|
---|
| 135 | fi
|
---|
[70919be] | 136 | done
|
---|
| 137 |
|
---|
| 138 | <command>EOF
|
---|
[d7c254a] | 139 | chmod 755 /usr/bin/compressdoc</command></userinput></screen>
|
---|
[70919be] | 140 |
|
---|
| 141 | <para>Now, as root, you can issue a
|
---|
[78b3cd61] | 142 | <command>/usr/bin/compressdoc /usr/man bz2</command>
|
---|
[70919be] | 143 | to compress your system man pages. Similarly, you can run it on the
|
---|
| 144 | <filename class="directory">/usr/info</filename> directory. Don't forget
|
---|
| 145 | <filename class="directory">/usr/X11R6/man</filename> if you install the
|
---|
| 146 | <application>X</application> Window system. A few other programs, like
|
---|
| 147 | <application>XEmacs</application>, also install their documentation in
|
---|
| 148 | nonstandard places.</para>
|
---|
| 149 |
|
---|
[b94cd51] | 150 | <para>Generally, package installation systems do not compress man/info pages,
|
---|
| 151 | which means you will need to run the script again if you want to keep the size
|
---|
| 152 | of your documentation as small as possible. Also, note that running the script
|
---|
| 153 | after upgrading a package is safe: when you have several versions of a page
|
---|
| 154 | (for example, one compressed and one uncompressed), the most recent one is kept
|
---|
| 155 | and the others deleted.</para>
|
---|
[70919be] | 156 |
|
---|
| 157 | </sect1>
|
---|
| 158 |
|
---|