mirror of
https://github.com/Zeckmathederg/glfs.git
synced 2025-02-03 23:07:23 +08:00
applied compressdoc patch
git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@1295 af4574ff-66df-0310-9fd7-8a98e5e911e0
This commit is contained in:
parent
b7d0bb4a52
commit
2fa79e3bf1
@ -13,21 +13,20 @@ to go is to use the script below.
|
||||
<screen><userinput><command>cat > /usr/bin/compressdoc << "EOF"</command>
|
||||
|
||||
#!/bin/bash
|
||||
# VERSION: 20031004.0245
|
||||
#
|
||||
# Compress (with bzip2 or gzip) all man pages in a hierarchy and
|
||||
# update symlinks - By Marc Heerdink <marc@koelkast.net>.
|
||||
# update symlinks - By Marc Heerdink <marc @ koelkast.net>
|
||||
# Modified to be able to gzip or bzip2 files as an option and to deal
|
||||
# with all symlinks properly by Mark Hymers # <markh@linuxfromscratch.org>
|
||||
# with all symlinks properly by Mark Hymers <markh @ linuxfromscratch.org>
|
||||
#
|
||||
# Modified 20030925 by Yann E. Morin <yann.morin.1998 @ # anciens.enib.fr>
|
||||
# Modified 20030930 by Yann E. Morin <yann.morin.1998 @ anciens.enib.fr>
|
||||
# to accept compression/decompression, to correctly handle hard-links,
|
||||
# to allow for changing hard-links into soft- ones, to specify the
|
||||
# compression level, to parse the man.conf for all occurrences of MANPATH,
|
||||
# to allow for a backup, to allow to keep the newest version of a page.
|
||||
#
|
||||
# TODO:
|
||||
# - inverse the quiet option into a verbose one, so as to be silent
|
||||
# by default;
|
||||
# - choose a default compress method to be based on the available
|
||||
# tool : gzip or bzip2;
|
||||
# - when a MANPATH env var exists, use this instead of /etc/man.conf
|
||||
@ -41,7 +40,7 @@ function help ()
|
||||
if [ -n "$1" ]; then
|
||||
echo "Unknown option : $1"
|
||||
fi
|
||||
echo "Usage: $0 <comp_method> [options] [dirs]"
|
||||
( echo "Usage: $0 <comp_method> [options] [dirs]" && \
|
||||
cat << EOT
|
||||
Where comp_method is one of :
|
||||
--gzip, --gz, -g
|
||||
@ -69,10 +68,12 @@ And where options are :
|
||||
a page will not be re-compressed if it ends with the same suffix
|
||||
as the method adds (.bz2 for bzip2, .gz for gzip).
|
||||
|
||||
-s Change hard-links into soft-links. Use with _caution_ as the
|
||||
--soft, -S Change hard-links into soft-links. Use with _caution_ as the
|
||||
first encountered file will be used as a reference. Not used
|
||||
when in backup mode.
|
||||
|
||||
--hard, -H Change soft-links into hard-links. Not used when in backup mode.
|
||||
|
||||
--conf=dir, --conf dir
|
||||
Specify the location of man.conf. Defaults to /etc.
|
||||
|
||||
@ -107,6 +108,7 @@ Note about compression
|
||||
gain space at the expense of a slight overhead in time. Well, my P4-2.5GHz
|
||||
does not even let me notice this... :-)
|
||||
EOT
|
||||
) | less
|
||||
}
|
||||
|
||||
# This function checks that the man page is unique amongst bzip2'd, gzip'd and
|
||||
@ -144,12 +146,12 @@ function check_unique ()
|
||||
}
|
||||
|
||||
# OK, parse the command-line for arguments, and initialize to some sensible
|
||||
# state, that is keep hardlinks, parse /etc/man.conf, be most silent, search
|
||||
# man.conf in /etc, and don't force (re-)compression.
|
||||
# state, that is : don't change links state, parse /etc/man.conf, be most
|
||||
# silent, search man.conf in /etc, and don't force (re-)compression.
|
||||
COMP_METHOD=
|
||||
COMP_SUF=
|
||||
COMP_LVL=
|
||||
FORCE_COMP=no
|
||||
FORCE_OPT=
|
||||
LN_OPT=
|
||||
MAN_DIR=
|
||||
VERBOSE_LVL=0
|
||||
@ -179,11 +181,15 @@ while [ -n "$1" ]; do
|
||||
shift
|
||||
;;
|
||||
--force|-F)
|
||||
FORCE_COMP=yes
|
||||
FORCE_OPT=-F
|
||||
shift
|
||||
;;
|
||||
--soft|-s)
|
||||
LN_OPT=-s
|
||||
--soft|-S)
|
||||
LN_OPT=-S
|
||||
shift
|
||||
;;
|
||||
--hard|-H)
|
||||
LN_OPT=-H
|
||||
shift
|
||||
;;
|
||||
--conf=*)
|
||||
@ -275,15 +281,17 @@ if [ "$FAKE" != "no" ]; then
|
||||
echo " ($COMP_METHOD)"
|
||||
echo "Compression level.: $COMP_LVL"
|
||||
echo "Compression suffix: $COMP_SUF"
|
||||
echo "Force compression.: $FORCE_COMP"
|
||||
echo "man.conf is.......: ${MAN_CONF}/man.conf ($MAN_CONF)"
|
||||
echo -n "Hard links........: "
|
||||
[ "$LN_OPT" = "-s" -o "$LN_OPT" = "--soft" ] && echo -n "Convert to symlinks" || echo -n "Keep hardlinks"
|
||||
echo " ($LN_OPT)"
|
||||
echo -n "Force compression.: "
|
||||
[ "foo$FORCE_OPT" = "foo-F" ] && echo "yes" || echo "no"
|
||||
echo "man.conf is.......: ${MAN_CONF}/man.conf"
|
||||
echo -n "Hard-links........: "
|
||||
[ "foo$LN_OPT" = "foo-S" ] && echo "convert to soft-links" || echo "leave as is"
|
||||
echo -n "Soft-links........: "
|
||||
[ "foo$LN_OPT" = "foo-H" ] && echo "convert to hard-links" || echo "leave as is"
|
||||
echo "Backup............: $BACKUP"
|
||||
echo "Faking (yes!).....: $FAKE"
|
||||
echo "Directories.......: $MAN_DIR"
|
||||
echo "Silence level.....: $VERBOSE_LVL ($VERBOSE_OPT)"
|
||||
echo "Verbosity level...: $VERBOSE_LVL"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@ -309,6 +317,7 @@ fi
|
||||
# I know MAN_DIR has only absolute path names
|
||||
# I need to take into account the localized man, so I'm going recursive
|
||||
for DIR in $MAN_DIR; do
|
||||
MEM_DIR=`pwd`
|
||||
cd "$DIR"
|
||||
for FILE in *; do
|
||||
# Fixes the case were the directory is empty
|
||||
@ -321,19 +330,21 @@ for DIR in $MAN_DIR; do
|
||||
if [ ! -L "$FILE" -a ! -e "$FILE" ]; then continue; fi
|
||||
|
||||
if [ -d "$FILE" ]; then
|
||||
cd "${MEM_DIR}" # Go back to where we ran "$0", in case "$0"=="./compressdoc" ...
|
||||
# We are going recursive to that directory
|
||||
echo "-> Entering ${DIR}/${FILE}..." > $DEST_FD0
|
||||
# I need not pass --conf, as I specify the directory to work on
|
||||
# But I need exit in case of error
|
||||
"$0" ${COMP_METHOD} ${COMP_LVL} ${LN_OPT} ${VERBOSE_OPT} "${DIR}/${FILE}" || exit 1
|
||||
"$0" ${COMP_METHOD} ${COMP_LVL} ${LN_OPT} ${VERBOSE_OPT} ${FORCE_OPT} "${DIR}/${FILE}" || exit 1
|
||||
echo "<- Leaving ${DIR}/${FILE}." > $DEST_FD1
|
||||
cd "$DIR" # Needed for the next iteration of the loop
|
||||
|
||||
else # !dir
|
||||
if ! check_unique "$DIR" "$FILE"; then continue; fi
|
||||
|
||||
# Check if the file is already compressed with the specified method
|
||||
BASE_FILE=`basename \`basename "$FILE" .bz2\` .gz`
|
||||
if [ "${FILE}" = "${BASE_FILE}${COMP_SUF}" -a "${FORCE_COMP}" = "no" ]; then continue; fi
|
||||
if [ "${FILE}" = "${BASE_FILE}${COMP_SUF}" -a "foo${FORCE_OPT}" = "foo" ]; then continue; fi
|
||||
|
||||
# If we have a symlink
|
||||
if [ -h "$FILE" ]; then
|
||||
@ -355,7 +366,14 @@ for DIR in $MAN_DIR; do
|
||||
LINK=`ls -l $FILE | cut -d ">" -f2 | tr -d " "`
|
||||
fi
|
||||
|
||||
rm -f "$FILE" && ln -s "${LINK}$COMP_SUF" "${FILE}$COMP_SUF"
|
||||
if [ "$LN_OPT" = "-H" ]; then
|
||||
# Change this soft-link into a hard- one
|
||||
rm -f "$FILE" && ln "${LINK}$COMP_SUF" "${FILE}$COMP_SUF"
|
||||
chmod --reference "${LINK}$COMP_SUF" "${FILE}$COMP_SUF"
|
||||
else
|
||||
# Keep this soft-link a soft- one.
|
||||
rm -f "$FILE" && ln -s "${LINK}$COMP_SUF" "${FILE}$COMP_SUF"
|
||||
fi
|
||||
echo "Relinked $FILE" > $DEST_FD1
|
||||
|
||||
# else if we have a plain file
|
||||
@ -386,7 +404,7 @@ for DIR in $MAN_DIR; do
|
||||
;;
|
||||
esac
|
||||
|
||||
# Compress the file with the highest compression ratio, if needed
|
||||
# Compress the file with the given compression ratio, if needed
|
||||
case $COMP_SUF in
|
||||
*bz2)
|
||||
bzip2 ${COMP_LVL} "$FILE" && chmod 644 "${FILE}${COMP_SUF}"
|
||||
@ -405,7 +423,13 @@ for DIR in $MAN_DIR; do
|
||||
if [ -n "$HLINKS" ]; then
|
||||
for i in $HLINKS; do
|
||||
NEWFILE=`echo $i | sed s/\.gz$// | sed s/\.bz2$//`
|
||||
ln ${LN_OPT} "${FILE}$COMP_SUF" "${NEWFILE}$COMP_SUF"
|
||||
if [ "$LN_OPT" = "-S" ]; then
|
||||
# Make this hard-link a soft- one
|
||||
ln -s "${FILE}$COMP_SUF" "${NEWFILE}$COMP_SUF"
|
||||
else
|
||||
# Keep the hard-link a hard- one
|
||||
ln "${FILE}$COMP_SUF" "${NEWFILE}$COMP_SUF"
|
||||
fi
|
||||
chmod 644 "${NEWFILE}$COMP_SUF" # Really work only for hard-links. Harmless for soft-links
|
||||
done
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user