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