Hello everybody,

I've been working on updating the compressdoc script to include xz  
support.

Since I deal mostly with CLFS, and we aren't using man_db at the  
moment, I've added a section for if man_db isn't on the host to use man.

This is a rough draft but any input is greatly appreciated to fix any  
errors. Granted, to only update the current compressdoc for man_db  
only systems requires the removal of the conditional statments of the  
portions which deal with man.

I've tested it and it is working well so far.

The following patch can be applied to the svn blfs book's current  
compressdoc.

--- compressdoc.orig    2008-04-21 23:33:32.000000000 +0000
+++ compressdoc 2013-02-23 21:09:06.967017222 +0000
@@ -1,7 +1,11 @@
#!/bin/bash
-# VERSION: 20080421.1623
-# $LastChangedBy: dnicholson $
-# $Date: 2008-04-21 16:27:43 -0700 (Mon, 21 Apr 2008) $
+# VERSION: 20130222.2300
+# $LastChangedBy: William Harrington $
+# $Date: 2013-02-22 23:00:00 -0600 (Fri, 22 Feb 2013) $
+#
+# Add xz (lzma2) compression options and add options for hosts
+# using man rather than man_db. - By William Harrington
+# <kb0iic @ cross-lfs.org>
#
# Compress (with bzip2 or gzip) all man pages in a hierarchy and
# update symlinks - By Marc Heerdink <marc @ koelkast.net>
@@ -57,11 +61,12 @@
   ( echo "Usage: $MY_NAME <comp_method> [options] [dirs]" && \
   cat << EOT
Where comp_method is one of :
+  --xz, --lzma, -x
   --gzip, --gz, -g
   --bzip2, --bz2, -b
-                Compress using gzip or bzip2.
+                Compress using gzip or bzip2 or xz.
   --automatic
-                Compress using either gzip or bzip2, depending on the
+                Compress using either gzip or xz, depending on the
                 size of the file to be compressed. Files larger than 5
                 kB are bzipped, files larger than 1 kB are gzipped and
                 files smaller than 1 kB are not compressed.
@@ -76,11 +81,11 @@
                 In backup mode, no other action is performed.

And where options are :
-  -1 to -9, --fast, --best
+  -1 to -9, --fast, --best, -e
                 The compression level, as accepted by gzip and bzip2.
                 When not specified, uses the default compression level
-                for the given method (-6 for gzip, and -9 for bzip2).
-                Not used when in backup or decompress modes.
+                for the given method (-6 for gzip, -9 for bzip2, -e
+                for xz). Not used when in backup or decompress modes.

   --force, -F   Force (re-)compression, even if the previous one was
                 the same method. Useful when changing the compression
@@ -96,18 +101,8 @@
                 backup mode.

   --conf=dir, --conf dir
-                Specify the location of man_db.conf. Defaults to /etc.
-
-  --verbose, -v Verbose mode, print the name of the directory being
-                processed. Double the flag to turn it even more  
verbose,
-                and to print the name of the file being processed.
-
-  --fake, -f    Fakes it. Print the actual parameters compressdoc  
will use.
-
-  dirs          A list of space-separated _absolute_ pathnames to the
-                man directories. When empty, and only then, use manpath
-                to parse ${MAN_CONF}/man_db.conf for all valid  
occurrences
-                of MANDATORY_MANPATH.
+                Specify the location of man_db.conf or man.conf.
+                Defaults to /etc.

Note about compression:
   There has been a discussion on blfs-support about compression  
ratios of
@@ -124,6 +119,10 @@
   gzip -9 compressed them down to 20372KB (57.28%), bzip2 -9 got down  
to
   19812KB (55.71%). That is a 1.57% gain in space. YMMV.

+  By William Harrington - With a Sun Ultra 60 system using ext4, the  
original
+  size for a default clfs dev install was 49048KB before compression.  
xz -e
+  compressed them to 25840KB.
+
   What was not taken into consideration was the decompression speed.  
But
   does it make sense to? You gain fast access with uncompressed man
   pages, or you gain space at the expense of a slight overhead in time.
@@ -153,11 +152,12 @@
   BASENAME=`basename "${BASENAME}" .gz`
   GZ_FILE="$BASENAME".gz
   BZ_FILE="$BASENAME".bz2
+  XZ_FILE="$BASENAME".xz

   # Look for, and keep, the most recent one
   LATEST=`(cd "$DIR"; ls -1rt "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}" \
-         2>/dev/null | tail -n 1)`
-  for i in "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}"; do
+         "${XZ_FILE}" 2>/dev/null | tail -n 1)`
+  for i in "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}" "${XZ_FILE}"; do
     [ "$LATEST" != "$i" ] && rm -f "$DIR"/"$i"
   done

@@ -186,7 +186,12 @@
MAN_CONF=/etc
while [ -n "$1" ]; do
   case $1 in
-    --gzip|--gz|-g)
+   --xz|--lzma|-x)
+      COMP_SUF=.xz
+      COMP_METHOD=$1
+      shift
+      ;;
+   --gzip|--gz|-g)
       COMP_SUF=.gz
       COMP_METHOD=$1
       shift
@@ -207,7 +212,7 @@
       COMP_METHOD=$1
       shift
       ;;
-    -[1-9]|--fast|--best)
+    -[1-9]|--fast|--best|-e)
       COMP_LVL=$1
       shift
       ;;
@@ -287,14 +292,23 @@
# Note: on my machine, 'man --path' gives /usr/share/man twice, once
# with a trailing '/', once without.
if [ -z "$MAN_DIR" ]; then
+  if [ -x "/usr/bin/manpath" ]; then
   MAN_DIR=`manpath -q -C "$MAN_CONF"/man_db.conf \
             | sed 's/:/\\n/g' \
             | while read foo; do dirname "$foo"/.; done \
             | sort -u \
             | while read bar; do echo -n "$bar "; done`
+  fi
+  if [ ! -f "/usr/bin/manpath" ]; then
+  MAN_DIR=`man --path -C "$MAN_CONF"/man.conf \
+            | sed 's/:/\\n/g' \
+            | while read foo; do dirname "$foo"/.; done \
+            | sort -u \
+            | while read bar; do echo -n "$bar "; done`
+  fi
fi

-# If no MANDATORY_MANPATH in ${MAN_CONF}/man_db.conf, abort as well
+# If no MANDATORY_MANPATH in ${MAN_CONF}/man_db.conf or man.conf,  
abort as well
if [ -z "$MAN_DIR" ]; then
   echo "No directory specified, and no directory found with \`manpath'"
   exit 1
@@ -313,6 +327,7 @@
   echo "Actual parameters used:"
   echo -n "Compression.......: "
   case $COMP_METHOD in
+    --xz|--lzma|-x) echo -n "xz";;
     --bzip2|--bz2|-b) echo -n "bzip2";;
     --gzip|--gz|-g) echo -n "gzip";;
     --automatic) echo -n "compressing";;
@@ -423,6 +438,7 @@
       # Check if the file is already compressed with the specified  
method
       BASE_FILE=`basename "$FILE" .gz`
       BASE_FILE=`basename "$BASE_FILE" .bz2`
+      BASE_FILE=`basename "$BASE_FILE" .xz`
       if [ "${FILE}" = "${BASE_FILE}${COMP_SUF}" \
          -a "foo${FORCE_OPT}" = "foo" ]; then continue; fi

@@ -433,6 +449,8 @@
             EXT=bz2 ;;
           *.gz)
             EXT=gz ;;
+          *.xz)
+            EXT=xz ;;
           *)
             EXT=none ;;
         esac
@@ -484,6 +502,10 @@
             gunzip $FILE
             FILE=`basename "$FILE" .gz`
           ;;
+          *.xz)
+            unxz $FILE
+            FILE=`basename "$FILE" .xz`
+          ;;
         esac

         # Compress the file with the given compression ratio, if needed
@@ -496,6 +518,10 @@
             gzip ${COMP_LVL} "$FILE" && chmod 644 "${FILE}${COMP_SUF}"
             echo "Compressed $FILE" > $DEST_FD1
             ;;
+          *xz)
+            xz ${COMP_LVL} "$FILE" && chmod 644 "${FILE}${COMP_SUF}"
+            echo "Compressed $FILE" > $DEST_FD1
+            ;;
           *)
             echo "Uncompressed $FILE" > $DEST_FD1
             ;;
@@ -504,7 +530,7 @@
         # If the file had hard-links, recreate those (either hard or  
soft)
         if [ -n "$HLINKS" ]; then
           for i in $HLINKS; do
-            NEWFILE=`echo "$i" | sed s/\.gz$// | sed s/\.bz2$//`
+            NEWFILE=`echo "$i" | sed s/\.gz$// | sed s/\.bz2$// | sed  
s/\.xz$//`
             if [ "$LN_OPT" = "-S" ]; then
               # Make this hard-link a soft- one
               ln -s "${FILE}$COMP_SUF" "${NEWFILE}$COMP_SUF"

Sincerely,

William Harrington
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to