1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
5 | %general-entities;
|
---|
6 | ]>
|
---|
7 |
|
---|
8 | <sect1 id="compressdoc" xreflabel="Compressing man and info pages">
|
---|
9 | <?dbhtml filename="compressdoc.html"?>
|
---|
10 |
|
---|
11 |
|
---|
12 | <title>Compressing Man and Info Pages</title>
|
---|
13 |
|
---|
14 | <indexterm zone="compressdoc">
|
---|
15 | <primary sortas="b-compressdoc">compressdoc</primary>
|
---|
16 | </indexterm>
|
---|
17 |
|
---|
18 | <para>Man and info reader programs can transparently process files compressed
|
---|
19 | with <command>gzip</command> or <command>bzip2</command>, a feature you can
|
---|
20 | use to free some disk space while keeping your documentation
|
---|
21 | available. However, things are not that simple; man directories tend to
|
---|
22 | contain links—hard and symbolic—which defeat simple ideas like
|
---|
23 | recursively calling <command>gzip</command> on them. A better way to go is
|
---|
24 | to use the script below. If you would prefer to download the file instead of
|
---|
25 | creating it by typing or copy-and-pasting, you can find it at
|
---|
26 | <ulink url="&files-anduin;/compressdoc"/> (the file should be installed in
|
---|
27 | the <filename class="directory">/usr/sbin</filename> directory).</para>
|
---|
28 |
|
---|
29 | <screen role="root"><?dbfo keep-together="auto"?><userinput>cat > /usr/sbin/compressdoc << "EOF"
|
---|
30 | <literal>#!/bin/bash
|
---|
31 | # VERSION: 20080421.1623
|
---|
32 | #
|
---|
33 | # Compress (with bzip2 or gzip) all man pages in a hierarchy and
|
---|
34 | # update symlinks - By Marc Heerdink <marc @ koelkast.net>
|
---|
35 | #
|
---|
36 | # Modified to be able to gzip or bzip2 files as an option and to deal
|
---|
37 | # with all symlinks properly by Mark Hymers <markh @ &lfs-domainname;>
|
---|
38 | #
|
---|
39 | # Modified 20030930 by Yann E. Morin <yann.morin.1998 @ anciens.enib.fr>
|
---|
40 | # to accept compression/decompression, to correctly handle hard-links,
|
---|
41 | # to allow for changing hard-links into soft- ones, to specify the
|
---|
42 | # compression level, to parse the man.conf for all occurrences of MANPATH,
|
---|
43 | # to allow for a backup, to allow to keep the newest version of a page.
|
---|
44 | #
|
---|
45 | # Modified 20040330 by Tushar Teredesai to replace $0 by the name of the
|
---|
46 | # script.
|
---|
47 | # (Note: It is assumed that the script is in the user's PATH)
|
---|
48 | #
|
---|
49 | # Modified 20050112 by Randy McMurchy to shorten line lengths and
|
---|
50 | # correct grammar errors.
|
---|
51 | #
|
---|
52 | # Modified 20060128 by Alexander E. Patrakov for compatibility with Man-DB.
|
---|
53 | #
|
---|
54 | # Modified 20060311 by Archaic to use Man-DB manpath utility which is a
|
---|
55 | # replacement for man --path from Man.
|
---|
56 | #
|
---|
57 | # Modified 20080421 by Dan Nicholson to properly execute the correct
|
---|
58 | # compressdoc when working recursively. This means the same compressdoc
|
---|
59 | # will be used whether a full path was given or it was resolved from PATH.
|
---|
60 | #
|
---|
61 | # Modified 20080421 by Dan Nicholson to be more robust with directories
|
---|
62 | # that don't exist or don't have sufficient permissions.
|
---|
63 | #
|
---|
64 | # Modified 20080421 by Lars Bamberger to (sort of) automatically choose
|
---|
65 | # a compression method based on the size of the manpage. A couple bug
|
---|
66 | # fixes were added by Dan Nicholson.
|
---|
67 | #
|
---|
68 | # Modified 20080421 by Dan Nicholson to suppress warnings from manpath
|
---|
69 | # since these are emitted when $MANPATH is set. Removed the TODO for
|
---|
70 | # using the $MANPATH variable since manpath(1) handles this already.
|
---|
71 | #
|
---|
72 | # TODO:
|
---|
73 | # - choose a default compress method to be based on the available
|
---|
74 | # tool : gzip or bzip2;
|
---|
75 | # - offer an option to restore a previous backup;
|
---|
76 | # - add other compression engines (compress, zip, etc?). Needed?
|
---|
77 |
|
---|
78 | # Funny enough, this function prints some help.
|
---|
79 | function help ()
|
---|
80 | {
|
---|
81 | if [ -n "$1" ]; then
|
---|
82 | echo "Unknown option : $1"
|
---|
83 | fi
|
---|
84 | ( echo "Usage: $MY_NAME <comp_method> [options] [dirs]" && \
|
---|
85 | cat << EOT
|
---|
86 | Where comp_method is one of :
|
---|
87 | --gzip, --gz, -g
|
---|
88 | --bzip2, --bz2, -b
|
---|
89 | Compress using gzip or bzip2.
|
---|
90 | --automatic
|
---|
91 | Compress using either gzip or bzip2, depending on the
|
---|
92 | size of the file to be compressed. Files larger than 5
|
---|
93 | kB are bzipped, files larger than 1 kB are gzipped and
|
---|
94 | files smaller than 1 kB are not compressed.
|
---|
95 |
|
---|
96 | --decompress, -d
|
---|
97 | Decompress the man pages.
|
---|
98 |
|
---|
99 | --backup Specify a .tar backup shall be done for all directories.
|
---|
100 | In case a backup already exists, it is saved as .tar.old
|
---|
101 | prior to making the new backup. If a .tar.old backup
|
---|
102 | exists, it is removed prior to saving the backup.
|
---|
103 | In backup mode, no other action is performed.
|
---|
104 |
|
---|
105 | And where options are :
|
---|
106 | -1 to -9, --fast, --best
|
---|
107 | The compression level, as accepted by gzip and bzip2.
|
---|
108 | When not specified, uses the default compression level
|
---|
109 | for the given method (-6 for gzip, and -9 for bzip2).
|
---|
110 | Not used when in backup or decompress modes.
|
---|
111 |
|
---|
112 | --force, -F Force (re-)compression, even if the previous one was
|
---|
113 | the same method. Useful when changing the compression
|
---|
114 | ratio. By default, a page will not be re-compressed if
|
---|
115 | it ends with the same suffix as the method adds
|
---|
116 | (.bz2 for bzip2, .gz for gzip).
|
---|
117 |
|
---|
118 | --soft, -S Change hard-links into soft-links. Use with _caution_
|
---|
119 | as the first encountered file will be used as a
|
---|
120 | reference. Not used when in backup mode.
|
---|
121 |
|
---|
122 | --hard, -H Change soft-links into hard-links. Not used when in
|
---|
123 | backup mode.
|
---|
124 |
|
---|
125 | --conf=dir, --conf dir
|
---|
126 | Specify the location of man_db.conf. Defaults to /etc.
|
---|
127 |
|
---|
128 | --verbose, -v Verbose mode, print the name of the directory being
|
---|
129 | processed. Double the flag to turn it even more verbose,
|
---|
130 | and to print the name of the file being processed.
|
---|
131 |
|
---|
132 | --fake, -f Fakes it. Print the actual parameters compressdoc will use.
|
---|
133 |
|
---|
134 | dirs A list of space-separated _absolute_ pathnames to the
|
---|
135 | man directories. When empty, and only then, use manpath
|
---|
136 | to parse ${MAN_CONF}/man_db.conf for all valid occurrences
|
---|
137 | of MANDATORY_MANPATH.
|
---|
138 |
|
---|
139 | Note about compression:
|
---|
140 | There has been a discussion on blfs-support about compression ratios of
|
---|
141 | both gzip and bzip2 on man pages, taking into account the hosting fs,
|
---|
142 | the architecture, etc... On the overall, the conclusion was that gzip
|
---|
143 | was much more efficient on 'small' files, and bzip2 on 'big' files,
|
---|
144 | small and big being very dependent on the content of the files.
|
---|
145 |
|
---|
146 | See the original post from Mickael A. Peters, titled
|
---|
147 | "Bootable Utility CD", dated 20030409.1816(+0200), and subsequent posts:
|
---|
148 | https://&lfs-domainname;/pipermail/blfs-support/2003-April/038817.html
|
---|
149 |
|
---|
150 | On my system (x86, ext3), man pages were 35564KB before compression.
|
---|
151 | gzip -9 compressed them down to 20372KB (57.28%), bzip2 -9 got down to
|
---|
152 | 19812KB (55.71%). That is a 1.57% gain in space. YMMV.
|
---|
153 |
|
---|
154 | What was not taken into consideration was the decompression speed. But
|
---|
155 | does it make sense to? You gain fast access with uncompressed man
|
---|
156 | pages, or you gain space at the expense of a slight overhead in time.
|
---|
157 | Well, my P4-2.5GHz does not even let me notice this... :-)
|
---|
158 |
|
---|
159 | EOT
|
---|
160 | ) | less
|
---|
161 | }
|
---|
162 |
|
---|
163 | # This function checks that the man page is unique amongst bzip2'd,
|
---|
164 | # gzip'd and uncompressed versions.
|
---|
165 | # $1 the directory in which the file resides
|
---|
166 | # $2 the file name for the man page
|
---|
167 | # Returns 0 (true) if the file is the latest and must be taken care of,
|
---|
168 | # and 1 (false) if the file is not the latest (and has therefore been
|
---|
169 | # deleted).
|
---|
170 | function check_unique ()
|
---|
171 | {
|
---|
172 | # NB. When there are hard-links to this file, these are
|
---|
173 | # _not_ deleted. In fact, if there are hard-links, they
|
---|
174 | # all have the same date/time, thus making them ready
|
---|
175 | # for deletion later on.
|
---|
176 |
|
---|
177 | # Build the list of all man pages with the same name
|
---|
178 | DIR=$1
|
---|
179 | BASENAME=`basename "${2}" .bz2`
|
---|
180 | BASENAME=`basename "${BASENAME}" .gz`
|
---|
181 | GZ_FILE="$BASENAME".gz
|
---|
182 | BZ_FILE="$BASENAME".bz2
|
---|
183 |
|
---|
184 | # Look for, and keep, the most recent one
|
---|
185 | LATEST=`(cd "$DIR"; ls -1rt "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}" \
|
---|
186 | 2>/dev/null | tail -n 1)`
|
---|
187 | for i in "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}"; do
|
---|
188 | [ "$LATEST" != "$i" ] && rm -f "$DIR"/"$i"
|
---|
189 | done
|
---|
190 |
|
---|
191 | # In case the specified file was the latest, return 0
|
---|
192 | [ "$LATEST" = "$2" ] && return 0
|
---|
193 | # If the file was not the latest, return 1
|
---|
194 | return 1
|
---|
195 | }
|
---|
196 |
|
---|
197 | # Name of the script
|
---|
198 | MY_NAME=`basename $0`
|
---|
199 |
|
---|
200 | # OK, parse the command-line for arguments, and initialize to some
|
---|
201 | # sensible state, that is: don't change links state, parse
|
---|
202 | # /etc/man_db.conf, be most silent, search man_db.conf in /etc, and don't
|
---|
203 | # force (re-)compression.
|
---|
204 | COMP_METHOD=
|
---|
205 | COMP_SUF=
|
---|
206 | COMP_LVL=
|
---|
207 | FORCE_OPT=
|
---|
208 | LN_OPT=
|
---|
209 | MAN_DIR=
|
---|
210 | VERBOSE_LVL=0
|
---|
211 | BACKUP=no
|
---|
212 | FAKE=no
|
---|
213 | MAN_CONF=/etc
|
---|
214 | while [ -n "$1" ]; do
|
---|
215 | case $1 in
|
---|
216 | --gzip|--gz|-g)
|
---|
217 | COMP_SUF=.gz
|
---|
218 | COMP_METHOD=$1
|
---|
219 | shift
|
---|
220 | ;;
|
---|
221 | --bzip2|--bz2|-b)
|
---|
222 | COMP_SUF=.bz2
|
---|
223 | COMP_METHOD=$1
|
---|
224 | shift
|
---|
225 | ;;
|
---|
226 | --automatic)
|
---|
227 | COMP_SUF=TBD
|
---|
228 | COMP_METHOD=$1
|
---|
229 | shift
|
---|
230 | ;;
|
---|
231 | --decompress|-d)
|
---|
232 | COMP_SUF=
|
---|
233 | COMP_LVL=
|
---|
234 | COMP_METHOD=$1
|
---|
235 | shift
|
---|
236 | ;;
|
---|
237 | -[1-9]|--fast|--best)
|
---|
238 | COMP_LVL=$1
|
---|
239 | shift
|
---|
240 | ;;
|
---|
241 | --force|-F)
|
---|
242 | FORCE_OPT=-F
|
---|
243 | shift
|
---|
244 | ;;
|
---|
245 | --soft|-S)
|
---|
246 | LN_OPT=-S
|
---|
247 | shift
|
---|
248 | ;;
|
---|
249 | --hard|-H)
|
---|
250 | LN_OPT=-H
|
---|
251 | shift
|
---|
252 | ;;
|
---|
253 | --conf=*)
|
---|
254 | MAN_CONF=`echo $1 | cut -d '=' -f2-`
|
---|
255 | shift
|
---|
256 | ;;
|
---|
257 | --conf)
|
---|
258 | MAN_CONF="$2"
|
---|
259 | shift 2
|
---|
260 | ;;
|
---|
261 | --verbose|-v)
|
---|
262 | let VERBOSE_LVL++
|
---|
263 | shift
|
---|
264 | ;;
|
---|
265 | --backup)
|
---|
266 | BACKUP=yes
|
---|
267 | shift
|
---|
268 | ;;
|
---|
269 | --fake|-f)
|
---|
270 | FAKE=yes
|
---|
271 | shift
|
---|
272 | ;;
|
---|
273 | --help|-h)
|
---|
274 | help
|
---|
275 | exit 0
|
---|
276 | ;;
|
---|
277 | /*)
|
---|
278 | MAN_DIR="${MAN_DIR} ${1}"
|
---|
279 | shift
|
---|
280 | ;;
|
---|
281 | -*)
|
---|
282 | help $1
|
---|
283 | exit 1
|
---|
284 | ;;
|
---|
285 | *)
|
---|
286 | echo "\"$1\" is not an absolute path name"
|
---|
287 | exit 1
|
---|
288 | ;;
|
---|
289 | esac
|
---|
290 | done
|
---|
291 |
|
---|
292 | # Redirections
|
---|
293 | case $VERBOSE_LVL in
|
---|
294 | 0)
|
---|
295 | # O, be silent
|
---|
296 | DEST_FD0=/dev/null
|
---|
297 | DEST_FD1=/dev/null
|
---|
298 | VERBOSE_OPT=
|
---|
299 | ;;
|
---|
300 | 1)
|
---|
301 | # 1, be a bit verbose
|
---|
302 | DEST_FD0=/dev/stdout
|
---|
303 | DEST_FD1=/dev/null
|
---|
304 | VERBOSE_OPT=-v
|
---|
305 | ;;
|
---|
306 | *)
|
---|
307 | # 2 and above, be most verbose
|
---|
308 | DEST_FD0=/dev/stdout
|
---|
309 | DEST_FD1=/dev/stdout
|
---|
310 | VERBOSE_OPT="-v -v"
|
---|
311 | ;;
|
---|
312 | esac
|
---|
313 |
|
---|
314 | # Note: on my machine, 'man --path' gives /usr/share/man twice, once
|
---|
315 | # with a trailing '/', once without.
|
---|
316 | if [ -z "$MAN_DIR" ]; then
|
---|
317 | MAN_DIR=`manpath -q -C "$MAN_CONF"/man_db.conf \
|
---|
318 | | sed 's/:/\\n/g' \
|
---|
319 | | while read foo; do dirname "$foo"/.; done \
|
---|
320 | | sort -u \
|
---|
321 | | while read bar; do echo -n "$bar "; done`
|
---|
322 | fi
|
---|
323 |
|
---|
324 | # If no MANDATORY_MANPATH in ${MAN_CONF}/man_db.conf, abort as well
|
---|
325 | if [ -z "$MAN_DIR" ]; then
|
---|
326 | echo "No directory specified, and no directory found with \`manpath'"
|
---|
327 | exit 1
|
---|
328 | fi
|
---|
329 |
|
---|
330 | # Check that the specified directories actually exist and are readable
|
---|
331 | for DIR in $MAN_DIR; do
|
---|
332 | if [ ! -d "$DIR" -o ! -r "$DIR" ]; then
|
---|
333 | echo "Directory '$DIR' does not exist or is not readable"
|
---|
334 | exit 1
|
---|
335 | fi
|
---|
336 | done
|
---|
337 |
|
---|
338 | # Fake?
|
---|
339 | if [ "$FAKE" != "no" ]; then
|
---|
340 | echo "Actual parameters used:"
|
---|
341 | echo -n "Compression.......: "
|
---|
342 | case $COMP_METHOD in
|
---|
343 | --bzip2|--bz2|-b) echo -n "bzip2";;
|
---|
344 | --gzip|--gz|-g) echo -n "gzip";;
|
---|
345 | --automatic) echo -n "compressing";;
|
---|
346 | --decompress|-d) echo -n "decompressing";;
|
---|
347 | *) echo -n "unknown";;
|
---|
348 | esac
|
---|
349 | echo " ($COMP_METHOD)"
|
---|
350 | echo "Compression level.: $COMP_LVL"
|
---|
351 | echo "Compression suffix: $COMP_SUF"
|
---|
352 | echo -n "Force compression.: "
|
---|
353 | [ "foo$FORCE_OPT" = "foo-F" ] && echo "yes" || echo "no"
|
---|
354 | echo "man_db.conf is....: ${MAN_CONF}/man_db.conf"
|
---|
355 | echo -n "Hard-links........: "
|
---|
356 | [ "foo$LN_OPT" = "foo-S" ] &&
|
---|
357 | echo "convert to soft-links" || echo "leave as is"
|
---|
358 | echo -n "Soft-links........: "
|
---|
359 | [ "foo$LN_OPT" = "foo-H" ] &&
|
---|
360 | echo "convert to hard-links" || echo "leave as is"
|
---|
361 | echo "Backup............: $BACKUP"
|
---|
362 | echo "Faking (yes!).....: $FAKE"
|
---|
363 | echo "Directories.......: $MAN_DIR"
|
---|
364 | echo "Verbosity level...: $VERBOSE_LVL"
|
---|
365 | exit 0
|
---|
366 | fi
|
---|
367 |
|
---|
368 | # If no method was specified, print help
|
---|
369 | if [ -z "${COMP_METHOD}" -a "${BACKUP}" = "no" ]; then
|
---|
370 | help
|
---|
371 | exit 1
|
---|
372 | fi
|
---|
373 |
|
---|
374 | # In backup mode, do the backup solely
|
---|
375 | if [ "$BACKUP" = "yes" ]; then
|
---|
376 | for DIR in $MAN_DIR; do
|
---|
377 | cd "${DIR}/.."
|
---|
378 | if [ ! -w "`pwd`" ]; then
|
---|
379 | echo "Directory '`pwd`' is not writable"
|
---|
380 | exit 1
|
---|
381 | fi
|
---|
382 | DIR_NAME=`basename "${DIR}"`
|
---|
383 | echo "Backing up $DIR..." > $DEST_FD0
|
---|
384 | [ -f "${DIR_NAME}.tar.old" ] && rm -f "${DIR_NAME}.tar.old"
|
---|
385 | [ -f "${DIR_NAME}.tar" ] &&
|
---|
386 | mv "${DIR_NAME}.tar" "${DIR_NAME}.tar.old"
|
---|
387 | tar -cvf "${DIR_NAME}.tar" "${DIR_NAME}" > $DEST_FD1
|
---|
388 | done
|
---|
389 | exit 0
|
---|
390 | fi
|
---|
391 |
|
---|
392 | # I know MAN_DIR has only absolute path names
|
---|
393 | # I need to take into account the localized man, so I'm going recursive
|
---|
394 | for DIR in $MAN_DIR; do
|
---|
395 | MEM_DIR=`pwd`
|
---|
396 | if [ ! -w "$DIR" ]; then
|
---|
397 | echo "Directory '$DIR' is not writable"
|
---|
398 | exit 1
|
---|
399 | fi
|
---|
400 | cd "$DIR"
|
---|
401 | for FILE in *; do
|
---|
402 | # Fixes the case were the directory is empty
|
---|
403 | if [ "foo$FILE" = "foo*" ]; then continue; fi
|
---|
404 |
|
---|
405 | # Fixes the case when hard-links see their compression scheme change
|
---|
406 | # (from not compressed to compressed, or from bz2 to gz, or from gz
|
---|
407 | # to bz2)
|
---|
408 | # Also fixes the case when multiple version of the page are present,
|
---|
409 | # which are either compressed or not.
|
---|
410 | if [ ! -L "$FILE" -a ! -e "$FILE" ]; then continue; fi
|
---|
411 |
|
---|
412 | # Do not compress whatis files
|
---|
413 | if [ "$FILE" = "whatis" ]; then continue; fi
|
---|
414 |
|
---|
415 | if [ -d "$FILE" ]; then
|
---|
416 | # We are going recursive to that directory
|
---|
417 | echo "-> Entering ${DIR}/${FILE}..." > $DEST_FD0
|
---|
418 | # I need not pass --conf, as I specify the directory to work on
|
---|
419 | # But I need exit in case of error. We must change back to the
|
---|
420 | # original directory so $0 is resolved correctly.
|
---|
421 | (cd "$MEM_DIR" && eval "$0" ${COMP_METHOD} ${COMP_LVL} ${LN_OPT} \
|
---|
422 | ${VERBOSE_OPT} ${FORCE_OPT} "${DIR}/${FILE}") || exit $?
|
---|
423 | echo "<- Leaving ${DIR}/${FILE}." > $DEST_FD1
|
---|
424 |
|
---|
425 | else # !dir
|
---|
426 | if ! check_unique "$DIR" "$FILE"; then continue; fi
|
---|
427 |
|
---|
428 | # With automatic compression, get the uncompressed file size of
|
---|
429 | # the file (dereferencing symlinks), and choose an appropriate
|
---|
430 | # compression method.
|
---|
431 | if [ "$COMP_METHOD" = "--automatic" ]; then
|
---|
432 | declare -i SIZE
|
---|
433 | case "$FILE" in
|
---|
434 | *.bz2)
|
---|
435 | SIZE=$(bzcat "$FILE" | wc -c) ;;
|
---|
436 | *.gz)
|
---|
437 | SIZE=$(zcat "$FILE" | wc -c) ;;
|
---|
438 | *)
|
---|
439 | SIZE=$(wc -c < "$FILE") ;;
|
---|
440 | esac
|
---|
441 | if (( $SIZE >= (5 * 2**10) )); then
|
---|
442 | COMP_SUF=.bz2
|
---|
443 | elif (( $SIZE >= (1 * 2**10) )); then
|
---|
444 | COMP_SUF=.gz
|
---|
445 | else
|
---|
446 | COMP_SUF=
|
---|
447 | fi
|
---|
448 | fi
|
---|
449 |
|
---|
450 | # Check if the file is already compressed with the specified method
|
---|
451 | BASE_FILE=`basename "$FILE" .gz`
|
---|
452 | BASE_FILE=`basename "$BASE_FILE" .bz2`
|
---|
453 | if [ "${FILE}" = "${BASE_FILE}${COMP_SUF}" \
|
---|
454 | -a "foo${FORCE_OPT}" = "foo" ]; then continue; fi
|
---|
455 |
|
---|
456 | # If we have a symlink
|
---|
457 | if [ -h "$FILE" ]; then
|
---|
458 | case "$FILE" in
|
---|
459 | *.bz2)
|
---|
460 | EXT=bz2 ;;
|
---|
461 | *.gz)
|
---|
462 | EXT=gz ;;
|
---|
463 | *)
|
---|
464 | EXT=none ;;
|
---|
465 | esac
|
---|
466 |
|
---|
467 | if [ ! "$EXT" = "none" ]; then
|
---|
468 | LINK=`ls -l "$FILE" | cut -d ">" -f2 \
|
---|
469 | | tr -d " " | sed s/\.$EXT$//`
|
---|
470 | NEWNAME=`echo "$FILE" | sed s/\.$EXT$//`
|
---|
471 | mv "$FILE" "$NEWNAME"
|
---|
472 | FILE="$NEWNAME"
|
---|
473 | else
|
---|
474 | LINK=`ls -l "$FILE" | cut -d ">" -f2 | tr -d " "`
|
---|
475 | fi
|
---|
476 |
|
---|
477 | if [ "$LN_OPT" = "-H" ]; then
|
---|
478 | # Change this soft-link into a hard- one
|
---|
479 | rm -f "$FILE" && ln "${LINK}$COMP_SUF" "${FILE}$COMP_SUF"
|
---|
480 | chmod --reference "${LINK}$COMP_SUF" "${FILE}$COMP_SUF"
|
---|
481 | else
|
---|
482 | # Keep this soft-link a soft- one.
|
---|
483 | rm -f "$FILE" && ln -s "${LINK}$COMP_SUF" "${FILE}$COMP_SUF"
|
---|
484 | fi
|
---|
485 | echo "Relinked $FILE" > $DEST_FD1
|
---|
486 |
|
---|
487 | # else if we have a plain file
|
---|
488 | elif [ -f "$FILE" ]; then
|
---|
489 | # Take care of hard-links: build the list of files hard-linked
|
---|
490 | # to the one we are {de,}compressing.
|
---|
491 | # NB. This is not optimum has the file will eventually be
|
---|
492 | # compressed as many times it has hard-links. But for now,
|
---|
493 | # that's the safe way.
|
---|
494 | inode=`ls -li "$FILE" | awk '{print $1}'`
|
---|
495 | HLINKS=`find . \! -name "$FILE" -inum $inode`
|
---|
496 |
|
---|
497 | if [ -n "$HLINKS" ]; then
|
---|
498 | # We have hard-links! Remove them now.
|
---|
499 | for i in $HLINKS; do rm -f "$i"; done
|
---|
500 | fi
|
---|
501 |
|
---|
502 | # Now take care of the file that has no hard-link
|
---|
503 | # We do decompress first to re-compress with the selected
|
---|
504 | # compression ratio later on...
|
---|
505 | case "$FILE" in
|
---|
506 | *.bz2)
|
---|
507 | bunzip2 $FILE
|
---|
508 | FILE=`basename "$FILE" .bz2`
|
---|
509 | ;;
|
---|
510 | *.gz)
|
---|
511 | gunzip $FILE
|
---|
512 | FILE=`basename "$FILE" .gz`
|
---|
513 | ;;
|
---|
514 | esac
|
---|
515 |
|
---|
516 | # Compress the file with the given compression ratio, if needed
|
---|
517 | case $COMP_SUF in
|
---|
518 | *bz2)
|
---|
519 | bzip2 ${COMP_LVL} "$FILE" && chmod 644 "${FILE}${COMP_SUF}"
|
---|
520 | echo "Compressed $FILE" > $DEST_FD1
|
---|
521 | ;;
|
---|
522 | *gz)
|
---|
523 | gzip ${COMP_LVL} "$FILE" && chmod 644 "${FILE}${COMP_SUF}"
|
---|
524 | echo "Compressed $FILE" > $DEST_FD1
|
---|
525 | ;;
|
---|
526 | *)
|
---|
527 | echo "Uncompressed $FILE" > $DEST_FD1
|
---|
528 | ;;
|
---|
529 | esac
|
---|
530 |
|
---|
531 | # If the file had hard-links, recreate those (either hard or soft)
|
---|
532 | if [ -n "$HLINKS" ]; then
|
---|
533 | for i in $HLINKS; do
|
---|
534 | NEWFILE=`echo "$i" | sed s/\.gz$// | sed s/\.bz2$//`
|
---|
535 | if [ "$LN_OPT" = "-S" ]; then
|
---|
536 | # Make this hard-link a soft- one
|
---|
537 | ln -s "${FILE}$COMP_SUF" "${NEWFILE}$COMP_SUF"
|
---|
538 | else
|
---|
539 | # Keep the hard-link a hard- one
|
---|
540 | ln "${FILE}$COMP_SUF" "${NEWFILE}$COMP_SUF"
|
---|
541 | fi
|
---|
542 | # Really work only for hard-links. Harmless for soft-links
|
---|
543 | chmod 644 "${NEWFILE}$COMP_SUF"
|
---|
544 | done
|
---|
545 | fi
|
---|
546 |
|
---|
547 | else
|
---|
548 | # There is a problem when we get neither a symlink nor a plain
|
---|
549 | # file. Obviously, we shall never ever come here... :-(
|
---|
550 | echo -n "Whaooo... \"${DIR}/${FILE}\" is neither a symlink "
|
---|
551 | echo "nor a plain file. Please check:"
|
---|
552 | ls -l "${DIR}/${FILE}"
|
---|
553 | exit 1
|
---|
554 | fi
|
---|
555 | fi
|
---|
556 | done # for FILE
|
---|
557 | done # for DIR</literal>
|
---|
558 |
|
---|
559 | EOF</userinput></screen>
|
---|
560 |
|
---|
561 | <note>
|
---|
562 | <para>
|
---|
563 | Doing a very large copy/paste directly to a terminal may result in a
|
---|
564 | corrupted file. Copying to an editor may overcome this issue.
|
---|
565 | </para>
|
---|
566 | </note>
|
---|
567 |
|
---|
568 | <para>As <systemitem class="username">root</systemitem>, make
|
---|
569 | <command>compressdoc</command> executable for all users:</para>
|
---|
570 |
|
---|
571 | <screen><userinput>chmod -v 755 /usr/sbin/compressdoc</userinput></screen>
|
---|
572 |
|
---|
573 | <para>Now, as <systemitem class="username">root</systemitem>, you can issue
|
---|
574 | the command <command>compressdoc --bz2</command> to compress all your system man
|
---|
575 | pages. You can also run <command>compressdoc --help</command> to get
|
---|
576 | comprehensive help about what the script is able to do.</para>
|
---|
577 |
|
---|
578 | <para>Don't forget that a few programs, like the <application>X Window
|
---|
579 | System</application> and <application>XEmacs</application> also
|
---|
580 | install their documentation in non-standard places (such as
|
---|
581 | <filename class="directory">/usr/X11R6/man</filename>, etc.). Be sure
|
---|
582 | to add these locations to the file <filename>/etc/man_db.conf</filename>, as
|
---|
583 | <envar>MANDATORY_MANPATH</envar> <replaceable></path></replaceable>
|
---|
584 | lines.</para>
|
---|
585 |
|
---|
586 | <para>Example:</para>
|
---|
587 |
|
---|
588 | <screen><literal> ...
|
---|
589 | MANDATORY_MANPATH /usr/share/man
|
---|
590 | MANDATORY_MANPATH /usr/X11R6/man
|
---|
591 | MANDATORY_MANPATH /usr/local/man
|
---|
592 | MANDATORY_MANPATH /opt/qt/doc/man
|
---|
593 | ...</literal></screen>
|
---|
594 |
|
---|
595 | <para>Generally, package installation systems do not compress man/info pages,
|
---|
596 | which means you will need to run the script again if you want to keep the size
|
---|
597 | of your documentation as small as possible. Also, note that running the script
|
---|
598 | after upgrading a package is safe; when you have several versions of a page
|
---|
599 | (for example, one compressed and one uncompressed), the most recent one is kept
|
---|
600 | and the others are deleted.</para>
|
---|
601 |
|
---|
602 | </sect1>
|
---|