compressdoc: Be more robust with directories

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@7391 af4574ff-66df-0310-9fd7-8a98e5e911e0
This commit is contained in:
Dan Nichilson 2008-04-21 19:11:44 +00:00
parent 6deeee2f80
commit 48e6b2a1db

View File

@ -32,7 +32,7 @@
<screen role="root"><?dbfo keep-together="auto"?><userinput>cat &gt; /usr/sbin/compressdoc &lt;&lt; "EOF"
<literal>#!/bin/bash
# VERSION: 20080421.1112
# VERSION: 20080421.1121
#
# Compress (with bzip2 or gzip) all man pages in a hierarchy and
# update symlinks - By Marc Heerdink &lt;marc @ koelkast.net&gt;
@ -62,6 +62,9 @@
# compressdoc when working recursively. This means the same compressdoc
# will be used whether a full path was given or it was resolved from PATH.
#
# Modified 20080421 by Dan Nicholson to be more robust with directories
# that don't exist or don't have sufficient permissions.
#
# TODO:
# - choose a default compress method to be based on the available
# tool : gzip or bzip2;
@ -315,6 +318,14 @@ if [ -z "$MAN_DIR" ]; then
exit 1
fi
# Check that the specified directories actually exist and are readable
for DIR in $MAN_DIR; do
if [ ! -d "$DIR" -o ! -r "$DIR" ]; then
echo "Directory '$DIR' does not exist or is not readable"
exit 1
fi
done
# Fake?
if [ "$FAKE" != "no" ]; then
echo "Actual parameters used:"
@ -354,6 +365,10 @@ fi
if [ "$BACKUP" = "yes" ]; then
for DIR in $MAN_DIR; do
cd "${DIR}/.."
if [ ! -w "`pwd`" ]; then
echo "Directory '`pwd`' is not writable"
exit 1
fi
DIR_NAME=`basename "${DIR}"`
echo "Backing up $DIR..." &gt; $DEST_FD0
[ -f "${DIR_NAME}.tar.old" ] &amp;&amp; rm -f "${DIR_NAME}.tar.old"
@ -368,6 +383,10 @@ fi
# I need to take into account the localized man, so I'm going recursive
for DIR in $MAN_DIR; do
MEM_DIR=`pwd`
if [ ! -w "$DIR" ]; then
echo "Directory '$DIR' is not writable"
exit 1
fi
cd "$DIR"
for FILE in *; do
# Fixes the case were the directory is empty