Author: jfs
Date: Wed Nov  6 21:07:27 2013
New Revision: 10332

URL: http://svn.debian.org/wsvn/?sc=1&rev=10332
Log:

- Import configuration from absolute path, not relative
- Add support of debugging through DEBUG variable, uncomment debug printf calls
- Try to not create cruft under /tmp but do it in a controlled location instead
- Extract contents using a tar file
- Only extract manpages under usr/share/man or usr/X11R6/man


Modified:
    man-cgi/static-repository/bin/fetch-man-pages.sh

Modified: man-cgi/static-repository/bin/fetch-man-pages.sh
URL: 
http://svn.debian.org/wsvn/man-cgi/static-repository/bin/fetch-man-pages.sh?rev=10332&op=diff
==============================================================================
--- man-cgi/static-repository/bin/fetch-man-pages.sh    (original)
+++ man-cgi/static-repository/bin/fetch-man-pages.sh    Wed Nov  6 21:07:27 2013
@@ -25,7 +25,10 @@
 # License can be found in /usr/share/common-licenses/GPL-3
 ###############################################################################
 
-. ./config
+ME=$0
+MYDIR="`dirname $ME`"
+
+. ${MYDIR}/config
 
 DIST="$1"
 PKG="$2"
@@ -38,11 +41,11 @@
 export W3MMAN_MAN='man --no-hyphenation'
 export MAN_KEEP_FORMATTING=1
 
-#printf "%s\n" "INFO: Looking for manpages in [$DEB]"
+[ -n "$DEBUG" ] && printf "%s\n" "INFO: Looking for manpages in [$DEB]"
 # The .*man bit is to handle postgres' inane manpage installation
 man=`dpkg-deb -c "$DEB" | egrep " 
\./usr/share.*/man/.*\.[0-9][a-zA-Z0-9\.\-]*\.gz$" | sed -e "s/^.*\.\//\.\//" 
-e "s/ \-> /\->/"`
 if [ -z "$man" ]; then
-       #printf "%s\n" "INFO: No manpages: [$DIST] [$PKG]"
+       [ -n "$DEBUG" ] && printf "%s\n" "INFO: No manpages: [$DIST] [$PKG]"
        # Touch the cache file so we don't look again until package updated
        touch $DESTDIR/.cache/$NAME
        # Exit immediately if this package does not contain manpages
@@ -50,30 +53,33 @@
 fi
 src_pkg=`dpkg -I "$DEB" | egrep "^ Package: |^ Source: " | tail -n1 | sed 
"s/^.*: //"`
 
-# BUG: Cruft gets created in /tmp/, it would be better to use a location 
specific for the script (work directory)
-#printf "%s\n" "INFO: Extracting manpages from [$DEB]"
-TEMPDIR=`mktemp -d -t doc-XXXXXX`
-trap "rm -rf $TEMPDIR 2>/dev/null || true" EXIT HUP INT QUIT TERM
+[ -n "$DEBUG" ] && printf "%s\n" "INFO: Extracting manpages from [$DEB]"
+TMPDIR=$TEMPDIR
+export TMPDIR
+EXTRACTDIR=`mktemp -d -t manpages-XXXXXX`
+trap "rm -rf $EXTRACTDIR 2>/dev/null || true" EXIT HUP INT QUIT TERM
 
-# BUG: script uses dpkg-deb -x which extracts the full package, should try to 
use --fsys-tarfile instead 
-# (see Debian's extractor script)
-dpkg-deb -x "$DEB" "$TEMPDIR"
+
+# Extract only manpages from the package
+dpkg-deb --fsys-tarfile "$DEB" | tar -C "$EXTRACTDIR" usr/share/man 
./usr/share/man usr/X11R6/man ./usr/X11R6/man 2>/dev/null
+# This extracts *all* the contents of the package
+# dpkg-deb -x "$DEB" "$EXTRACTDIR"
 for i in $man; do
-       #printf "%s\n" "INFO: Considering entry [$i]"
+        [ -n "$DEBUG" ] && printf "%s\n" "INFO: Considering entry [$i]"
        i=`printf "%s" "$i" | sed "s/^.*\.\///"`
        if printf "%s" "$i" | grep -qs "\->"; then
                SYMLINK=1
                symlink_src_html=`printf "%s" "$i" | sed -e "s/^.*\->//" -e 
"s/\.gz$/\.html/"`
                i=`printf "%s" "$i" | sed "s/\->.*$//" `
-               #printf "%s\n" "INFO: [$i] is a symbolic link"
+               [ -n "$DEBUG" ] &&  printf "%s\n" "INFO: [$i] is a symbolic 
link"
        else
                SYMLINK=0
        fi
-       manpage="$TEMPDIR/$i"
+        manpage="$EXTRACTDIR/$i"
        i=`printf "%s" "$i" | sed -e "s/usr\/share.*\/man\///i" -e "s/\.gz$//"`
-       #printf "%s\n" "INFO: Considering manpage [$i]"
+        [ -n "$DEBUG" ] && printf "%s\n" "INFO: Considering manpage [$i]"
        if [ ! -s "$manpage" -o -z "$i" ] && [ "$SYMLINK" = "0" ]; then
-               #printf "%s\n" "INFO: Skipping empty manpage [$manpage]"
+                [ -n "$DEBUG" ] && printf "%s\n" "INFO: Skipping empty manpage 
[$manpage]"
                continue
        fi
        out="$DESTDIR"/"$i".html
@@ -86,7 +92,7 @@
                if LN=`zcat "$manpage" | head -n1 | grep "^\.so "`; then
                        LN=`printf "%s" "$LN" | sed -e 's/^\.so /\.\.\//' -e 
's/\/\.\.\//\//g' -e 's/$/\.html/'`
                        ln -f -s "$LN" "$out"
-                       printf "INFO: Created symlink [$out]"
+                       [ -n "$DEBUG" ] && printf "INFO: Created symlink [$out]"
                 else
                        #man "$manpage" 2>/dev/null | col -b > "$out".txt
                        #man2html -r "$manpage" > "$out"
@@ -110,7 +116,7 @@
                        printf "%s\n" "$BODY" >> "$out"
                        printf "%s\n" "</pre><!--#include virtual='/below.html' 
-->" >> "$out"
 
-                       printf "%s\n" "INFO: Created manpage [$out]"
+                       [ -n "$DEBUG" ] && printf "%s\n" "INFO: Created manpage 
[$out]"
                fi
        fi
        mv -f "$manpage" "$outgz"
@@ -121,5 +127,5 @@
        fi
 done
 # In the case of freakish package permissions, fix them on rm failure.
-rm -rf "$TEMPDIR" 2>/dev/null || ( chmod -R 700 "$TEMPDIR" && rm -rf 
"$TEMPDIR" ) || true
+rm -rf "$EXTRACTDIR" 2>/dev/null || ( chmod -R 700 "$EXTRACTDIR" && rm -rf 
"$EXTRACTDIR" ) || true
 exit 0


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive: http://lists.debian.org/[email protected]

Reply via email to