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