source: postlfs/config/compressdoc.xml@ 3597eb6

10.0 10.1 11.0 11.1 11.2 11.3 12.0 12.1 6.2 6.2.0 6.2.0-rc1 6.2.0-rc2 6.3 6.3-rc1 6.3-rc2 6.3-rc3 7.10 7.4 7.5 7.6 7.6-blfs 7.6-systemd 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 9.0 9.1 basic bdubbs/svn elogind gnome kde5-13430 kde5-14269 kde5-14686 kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts krejzi/svn lazarus lxqt nosym perl-modules plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition systemd-11177 systemd-13485 trunk upgradedb xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since 3597eb6 was 3597eb6, checked in by Randy McMurchy <randy@…>, 18 years ago

Added the 'User Notes' wiki link to each package page; changed all instances of .[so,a] to .{so,a} (brackets changed to braces); changed all replaceable tags to use angle brackets instead of square brackets to encapsulate the text - commit #7

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@5835 af4574ff-66df-0310-9fd7-8a98e5e911e0

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