source: postlfs/config/compressdoc.xml@ 70919be

10.0 10.1 11.0 11.1 11.2 11.3 12.0 12.1 6.0 6.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 v5_0 v5_0-pre1 v5_1 v5_1-pre1 xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since 70919be was 70919be, checked in by Larry Lawrence <larry@…>, 21 years ago

add compressing man and info

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

  • Property mode set to 100644
File size: 4.9 KB
Line 
1<sect1 id="postlfs-config-compressdoc" xreflabel="compressdoc">
2<?dbhtml filename="compressdoc.html" dir="postlfs"?>
3<title>Compressing man and info pages</title>
4
5<para>Man and info reader programs can transparently process gzipped or
6bziptwoed pages, a feature you can use to free some disk space while keeping
7your documentation available. However, things are not that simple: man
8directories tend to contain links - hard and symbolic - which defeat simple
9ideas like recursively calling gzip on them. A better way to go is to use the
10script below.
11</para>
12
13<screen><userinput><command>cat &gt; /usr/bin/comprdoc &lt;&lt; "EOF"</command>
14
15#!/bin/sh
16
17function changefileext
18{
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
27}
28
29# check that the command line is right, if not print a relevant message.
30
31if [ ! -d $1 -o -z $1 ] || [ "$2" != "gz" -a "$2" != "bz2" ]
32then
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
37fi
38
39# set up a few variables.
40
41NEWEXT=.$2 # NEWEXT = extension of newly compressed files
42
43if [ "$NEWEXT" == ".bz2" ]
44then
45 OLDEXT=".gz" # OLDEXT = extensions of files to recompress
46 DECOMPRESS="gunzip -f" # DECOMPRESS = command to decompress a file
47 COMPRESS="bzip2 -f9" # COMPRESS = command to compress a file
48else
49 OLDEXT=".bz2"
50 DECOMPRESS="bunzip2 -f"
51 COMPRESS="gzip -f9"
52fi
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
58cd $1
59
60for f in `find . \! -name "*$NEWEXT"`
61do
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.
64
65 if [ -f $f -o -L $f ]
66 then
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
71
72 # HLINKS is the list of all hard links to the current file.
73
74 HLINKS=`find . \! -name $BASEFILE -inum $INODE`
75
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.
80
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.
87
88 TEMPFILE=`changefileext $FILE $OLDEXT`
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
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 \
103 $FILE -nt $NEWFILE ]
104 then
105 $DECOMPRESS $FILE
106 else
107 rm -f $FILE
108 fi
109 FILE=$TEMPFILE
110 fi
111
112 # now we are dealing with an uncompressed file that may
113 # exist or not (because of the above). If it is newer
114 # than both the new-compressed and the old-compressed
115 # files then it is compressed, else it is deleted.
116
117 if [ -f $FILE ]
118 then
119 if [ $FILE -nt $NEWFILE -a \
120 $FILE -nt $FILE$OLDEXT ]
121 then
122 $COMPRESS $FILE
123 else
124 rm -f $FILE
125 fi
126 fi
127 fi
128
129 # update the hard links to the current files,
130 # as the new inode number is now known.
131
132 for g in $HLINKS
133 do
134 rm -f $g
135 ln -f $NEWFILE `changefileext $g $OLDEXT $NEWEXT`
136 done
137 fi
138done
139
140<command>EOF
141chmod 755 /usr/bin/comprdoc</command></userinput></screen>
142
143<para>Now, as root, you can issue a
144<userinput><command>/usr/bin/comprdoc /usr/man bz2</command></userinput>
145to compress your system man pages. Similarly, you can run it on the
146<filename class="directory">/usr/info</filename> directory. Don't forget
147<filename class="directory">/usr/X11R6/man</filename> if you install the
148<application>X</application> Window system. A few other programs, like
149<application>XEmacs</application>, also install their documentation in
150nonstandard places.</para>
151
152<para>Generally, package installation systems do not compress the man/info
153pages, which means you will need to run the script again if you want to keep
154the size of your documentation as small as possible. Also, note that upgrading
155a package is safe: when you have several versions of a page (for example, a
156compressed and an uncompressed file), the script always keeps the most recent
157and deletes the others.</para>
158
159</sect1>
160
Note: See TracBrowser for help on using the repository browser.