r7392 - in trunk: BOOK/introduction/welcome BOOK/postlfs/config auxfiles

dnicholson at linuxfromscratch.org dnicholson at linuxfromscratch.org
Mon Apr 21 15:39:09 PDT 2008


Author: dnicholson
Date: 2008-04-21 16:39:09 -0600 (Mon, 21 Apr 2008)
New Revision: 7392

Modified:
   trunk/BOOK/introduction/welcome/changelog.xml
   trunk/BOOK/postlfs/config/compressdoc.xml
   trunk/auxfiles/compressdoc
Log:
compressdoc: Automatic compression by file size from Lars Bamberger


Modified: trunk/BOOK/introduction/welcome/changelog.xml
===================================================================
--- trunk/BOOK/introduction/welcome/changelog.xml	2008-04-21 19:11:44 UTC (rev 7391)
+++ trunk/BOOK/introduction/welcome/changelog.xml	2008-04-21 22:39:09 UTC (rev 7392)
@@ -45,7 +45,8 @@
       <para>April 21st, 2008</para>
       <itemizedlist>
         <listitem>
-          <para>[dnicholson] - Bug fixes for the compressdoc script.</para>
+          <para>[dnicholson] - Bug fixes and automatic compression
+          support from Lars Bamberger for the compressdoc script.</para>
         </listitem>
       </itemizedlist>
     </listitem>

Modified: trunk/BOOK/postlfs/config/compressdoc.xml
===================================================================
--- trunk/BOOK/postlfs/config/compressdoc.xml	2008-04-21 19:11:44 UTC (rev 7391)
+++ trunk/BOOK/postlfs/config/compressdoc.xml	2008-04-21 22:39:09 UTC (rev 7392)
@@ -32,7 +32,7 @@
 
 <screen role="root"><?dbfo keep-together="auto"?><userinput>cat > /usr/sbin/compressdoc << "EOF"
 <literal>#!/bin/bash
-# VERSION: 20080421.1121
+# VERSION: 20080421.1320
 #
 # Compress (with bzip2 or gzip) all man pages in a hierarchy and
 # update symlinks - By Marc Heerdink <marc @ koelkast.net>
@@ -65,12 +65,13 @@
 # Modified 20080421 by Dan Nicholson to be more robust with directories
 # that don't exist or don't have sufficient permissions.
 #
+# Modified 20080421 by Lars Bamberger to (sort of) automatically choose
+# a compression method based on the size of the manpage. A couple bug
+# fixes were added by Dan Nicholson.
+#
 # TODO:
 #     - choose a default compress method to be based on the available
 #       tool : gzip or bzip2;
-#     - offer an option to automagically choose the best compression
-#       methed on a per page basis (eg. check which of
-#       gzip/bzip2/whatever is the most effective, page per page);
 #     - when a MANPATH env var exists, use this instead of /etc/man_db.conf
 #       (useful for users to (de)compress their man pages;
 #     - offer an option to restore a previous backup;
@@ -88,6 +89,11 @@
   --gzip, --gz, -g
   --bzip2, --bz2, -b
                 Compress using gzip or bzip2.
+  --automatic
+                Compress using either gzip or bzip2, 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.
 
   --decompress, -d
                 Decompress the man pages.
@@ -219,6 +225,11 @@
       COMP_METHOD=$1
       shift
       ;;
+    --automatic)
+      COMP_SUF=TBD
+      COMP_METHOD=$1
+      shift
+      ;;
     --decompress|-d)
       COMP_SUF=
       COMP_LVL=
@@ -332,7 +343,8 @@
   echo -n "Compression.......: "
   case $COMP_METHOD in
     --bzip2|--bz2|-b) echo -n "bzip2";;
-    --gzip|__gz|-g) echo -n "gzip";;
+    --gzip|--gz|-g) echo -n "gzip";;
+    --automatic) echo -n "compressing";;
     --decompress|-d) echo -n "decompressing";;
     *) echo -n "unknown";;
   esac
@@ -415,6 +427,28 @@
     else # !dir
       if ! check_unique "$DIR" "$FILE"; then continue; fi
 
+      # With automatic compression, get the uncompressed file size of
+      # the file (dereferencing symlinks), and choose an appropriate
+      # compression method.
+      if [ "$COMP_METHOD" = "--automatic" ]; then
+        declare -i SIZE
+        case "$FILE" in
+          *.bz2)
+            SIZE=$(bzcat "$FILE" | wc -c) ;;
+          *.gz)
+            SIZE=$(zcat "$FILE" | wc -c) ;;
+          *)
+            SIZE=$(wc -c < "$FILE") ;;
+        esac
+        if (( $SIZE >= (5 * 2**10) )); then
+          COMP_SUF=.bz2
+        elif (( $SIZE >= (1 * 2**10) )); then
+          COMP_SUF=.gz
+        else
+          COMP_SUF=
+        fi
+      fi
+
       # Check if the file is already compressed with the specified method
       BASE_FILE=`basename "$FILE" .gz`
       BASE_FILE=`basename "$BASE_FILE" .bz2`

Modified: trunk/auxfiles/compressdoc
===================================================================
--- trunk/auxfiles/compressdoc	2008-04-21 19:11:44 UTC (rev 7391)
+++ trunk/auxfiles/compressdoc	2008-04-21 22:39:09 UTC (rev 7392)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# VERSION: 20080421.1121
+# VERSION: 20080421.1320
 # $LastChangedBy$
 # $Date$
 #
@@ -34,12 +34,13 @@
 # Modified 20080421 by Dan Nicholson to be more robust with directories
 # that don't exist or don't have sufficient permissions.
 #
+# Modified 20080421 by Lars Bamberger to (sort of) automatically choose
+# a compression method based on the size of the manpage. A couple bug
+# fixes were added by Dan Nicholson.
+#
 # TODO:
 #     - choose a default compress method to be based on the available
 #       tool : gzip or bzip2;
-#     - offer an option to automagically choose the best compression
-#       methed on a per page basis (eg. check which of
-#       gzip/bzip2/whatever is the most effective, page per page);
 #     - when a MANPATH env var exists, use this instead of /etc/man_db.conf
 #       (useful for users to (de)compress their man pages;
 #     - offer an option to restore a previous backup;
@@ -57,6 +58,11 @@
   --gzip, --gz, -g
   --bzip2, --bz2, -b
                 Compress using gzip or bzip2.
+  --automatic
+                Compress using either gzip or bzip2, 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.
 
   --decompress, -d
                 Decompress the man pages.
@@ -188,6 +194,11 @@
       COMP_METHOD=$1
       shift
       ;;
+    --automatic)
+      COMP_SUF=TBD
+      COMP_METHOD=$1
+      shift
+      ;;
     --decompress|-d)
       COMP_SUF=
       COMP_LVL=
@@ -301,7 +312,8 @@
   echo -n "Compression.......: "
   case $COMP_METHOD in
     --bzip2|--bz2|-b) echo -n "bzip2";;
-    --gzip|__gz|-g) echo -n "gzip";;
+    --gzip|--gz|-g) echo -n "gzip";;
+    --automatic) echo -n "compressing";;
     --decompress|-d) echo -n "decompressing";;
     *) echo -n "unknown";;
   esac
@@ -384,6 +396,28 @@
     else # !dir
       if ! check_unique "$DIR" "$FILE"; then continue; fi
 
+      # With automatic compression, get the uncompressed file size of
+      # the file (dereferencing symlinks), and choose an appropriate
+      # compression method.
+      if [ "$COMP_METHOD" = "--automatic" ]; then
+        declare -i SIZE
+        case "$FILE" in
+          *.bz2)
+            SIZE=$(bzcat "$FILE" | wc -c) ;;
+          *.gz)
+            SIZE=$(zcat "$FILE" | wc -c) ;;
+          *)
+            SIZE=$(wc -c < "$FILE") ;;
+        esac
+        if (( $SIZE >= (5 * 2**10) )); then
+          COMP_SUF=.bz2
+        elif (( $SIZE >= (1 * 2**10) )); then
+          COMP_SUF=.gz
+        else
+          COMP_SUF=
+        fi
+      fi
+
       # Check if the file is already compressed with the specified method
       BASE_FILE=`basename "$FILE" .gz`
       BASE_FILE=`basename "$BASE_FILE" .bz2`




More information about the blfs-book mailing list