1 |
#!/bin/bash |
#!/bin/bash |
2 |
# VERSION: 20040320.0026 |
# VERSION: 20080421.1623 |
3 |
|
# $LastChangedBy: dnicholson $ |
4 |
|
# $Date: 2008-04-21 16:27:43 -0700 (Mon, 21 Apr 2008) $ |
5 |
# |
# |
6 |
# Compress (with bzip2 or gzip) all man pages in a hierarchy and |
# Compress (with bzip2 or gzip) all man pages in a hierarchy and |
7 |
# update symlinks - By Marc Heerdink <marc @ koelkast.net> |
# update symlinks - By Marc Heerdink <marc @ koelkast.net> |
8 |
|
# |
9 |
# Modified to be able to gzip or bzip2 files as an option and to deal |
# Modified to be able to gzip or bzip2 files as an option and to deal |
10 |
# with all symlinks properly by Mark Hymers <markh @ linuxfromscratch.org> |
# with all symlinks properly by Mark Hymers <markh @ linuxfromscratch.org> |
11 |
# |
# |
14 |
# to allow for changing hard-links into soft- ones, to specify the |
# to allow for changing hard-links into soft- ones, to specify the |
15 |
# compression level, to parse the man.conf for all occurrences of MANPATH, |
# compression level, to parse the man.conf for all occurrences of MANPATH, |
16 |
# to allow for a backup, to allow to keep the newest version of a page. |
# to allow for a backup, to allow to keep the newest version of a page. |
17 |
# Modified 20040330 by Tushar Teredesai to replace $0 by the name of the script. |
# |
18 |
|
# Modified 20040330 by Tushar Teredesai to replace $0 by the name of the |
19 |
|
# script. |
20 |
# (Note: It is assumed that the script is in the user's PATH) |
# (Note: It is assumed that the script is in the user's PATH) |
21 |
# |
# |
22 |
|
# Modified 20050112 by Randy McMurchy to shorten line lengths and |
23 |
|
# correct grammar errors. |
24 |
|
# |
25 |
|
# Modified 20060128 by Alexander E. Patrakov for compatibility with Man-DB. |
26 |
|
# |
27 |
|
# Modified 20060311 by Archaic to use Man-DB manpath utility which is a |
28 |
|
# replacement for man --path from Man. |
29 |
|
# |
30 |
|
# Modified 20080421 by Dan Nicholson to properly execute the correct |
31 |
|
# compressdoc when working recursively. This means the same compressdoc |
32 |
|
# will be used whether a full path was given or it was resolved from PATH. |
33 |
|
# |
34 |
|
# Modified 20080421 by Dan Nicholson to be more robust with directories |
35 |
|
# that don't exist or don't have sufficient permissions. |
36 |
|
# |
37 |
|
# Modified 20080421 by Lars Bamberger to (sort of) automatically choose |
38 |
|
# a compression method based on the size of the manpage. A couple bug |
39 |
|
# fixes were added by Dan Nicholson. |
40 |
|
# |
41 |
|
# Modified 20080421 by Dan Nicholson to suppress warnings from manpath |
42 |
|
# since these are emitted when $MANPATH is set. Removed the TODO for |
43 |
|
# using the $MANPATH variable since manpath(1) handles this already. |
44 |
|
# |
45 |
# TODO: |
# TODO: |
46 |
# - choose a default compress method to be based on the available |
# - choose a default compress method to be based on the available |
47 |
# tool : gzip or bzip2; |
# tool : gzip or bzip2; |
48 |
# - offer an option to automagically choose the best compression method |
# - offer an option to restore a previous backup; |
49 |
# on a per page basis (eg. check which ofgzip/bzip2/whatever is the |
# - add other compression engines (compress, zip, etc?). Needed? |
|
# most effective, page per page); |
|
|
# - when a MANPATH env var exists, use this instead of /etc/man.conf |
|
|
# (useful for users to (de)compress their man pages; |
|
|
# - offer an option to restore a previous backup; |
|
|
# - add other compression engines (compress, zip, etc?). Needed? |
|
|
|
|
|
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/compressdoc,v 1.6 2005-06-01 15:47:41 niro Exp $ |
|
50 |
|
|
51 |
# Funny enough, this function prints some help. |
# Funny enough, this function prints some help. |
52 |
function help () |
function help () |
60 |
--gzip, --gz, -g |
--gzip, --gz, -g |
61 |
--bzip2, --bz2, -b |
--bzip2, --bz2, -b |
62 |
Compress using gzip or bzip2. |
Compress using gzip or bzip2. |
63 |
|
--automatic |
64 |
|
Compress using either gzip or bzip2, depending on the |
65 |
|
size of the file to be compressed. Files larger than 5 |
66 |
|
kB are bzipped, files larger than 1 kB are gzipped and |
67 |
|
files smaller than 1 kB are not compressed. |
68 |
|
|
69 |
--decompress, -d |
--decompress, -d |
70 |
Decompress the man pages. |
Decompress the man pages. |
71 |
|
|
72 |
--backup Specify a .tar backup shall be done for every directories. |
--backup Specify a .tar backup shall be done for all directories. |
73 |
In case a backup already exists, it is saved as .tar.old prior |
In case a backup already exists, it is saved as .tar.old |
74 |
to making the new backup. If an .tar.old backup exist, it is |
prior to making the new backup. If a .tar.old backup |
75 |
removed prior to saving the backup. |
exists, it is removed prior to saving the backup. |
76 |
In backup mode, no other action is performed. |
In backup mode, no other action is performed. |
77 |
|
|
78 |
And where options are : |
And where options are : |
79 |
-1 to -9, --fast, --best |
-1 to -9, --fast, --best |
80 |
The compression level, as accepted by gzip and bzip2. When not |
The compression level, as accepted by gzip and bzip2. |
81 |
specified, uses the default compression level for the given |
When not specified, uses the default compression level |
82 |
method (-6 for gzip, and -9 for bzip2). Not used when in backup |
for the given method (-6 for gzip, and -9 for bzip2). |
83 |
or decompress modes. |
Not used when in backup or decompress modes. |
84 |
|
|
85 |
--force, -F Force (re-)compression, even if the previous one was the same |
--force, -F Force (re-)compression, even if the previous one was |
86 |
method. Useful when changing the compression ratio. By default, |
the same method. Useful when changing the compression |
87 |
a page will not be re-compressed if it ends with the same suffix |
ratio. By default, a page will not be re-compressed if |
88 |
as the method adds (.bz2 for bzip2, .gz for gzip). |
it ends with the same suffix as the method adds |
89 |
|
(.bz2 for bzip2, .gz for gzip). |
90 |
--soft, -S Change hard-links into soft-links. Use with _caution_ as the |
|
91 |
first encountered file will be used as a reference. Not used |
--soft, -S Change hard-links into soft-links. Use with _caution_ |
92 |
when in backup mode. |
as the first encountered file will be used as a |
93 |
|
reference. Not used when in backup mode. |
94 |
|
|
95 |
--hard, -H Change soft-links into hard-links. Not used when in backup mode. |
--hard, -H Change soft-links into hard-links. Not used when in |
96 |
|
backup mode. |
97 |
|
|
98 |
--conf=dir, --conf dir |
--conf=dir, --conf dir |
99 |
Specify the location of man.conf. Defaults to /etc. |
Specify the location of man_db.conf. Defaults to /etc. |
100 |
|
|
101 |
--verbose, -v Verbose mode, print the name of the directory being processed. |
--verbose, -v Verbose mode, print the name of the directory being |
102 |
Double the flag to turn it even more verbose, and to print the |
processed. Double the flag to turn it even more verbose, |
103 |
name of the file being processed. |
and to print the name of the file being processed. |
104 |
|
|
105 |
--fake, -f Fakes it. Print the actual parameters compman will use. |
--fake, -f Fakes it. Print the actual parameters compressdoc will use. |
106 |
|
|
107 |
dirs A list of space-separated _absolute_ pathname to the man |
dirs A list of space-separated _absolute_ pathnames to the |
108 |
directories. |
man directories. When empty, and only then, use manpath |
109 |
When empty, and only then, parse ${MAN_CONF}/man.conf for all |
to parse ${MAN_CONF}/man_db.conf for all valid occurrences |
110 |
occurrences of MANPATH. |
of MANDATORY_MANPATH. |
111 |
|
|
112 |
Note about compression |
Note about compression: |
113 |
There has been a discussion on blfs-support about compression ratios of |
There has been a discussion on blfs-support about compression ratios of |
114 |
both gzip and bzip2 on man pages, taking into account the hosting fs, |
both gzip and bzip2 on man pages, taking into account the hosting fs, |
115 |
the architecture, etc... On the overall, the conclusion was that gzip |
the architecture, etc... On the overall, the conclusion was that gzip |
116 |
was much efficient on 'small' files, and bzip2 on 'big' files, small and |
was much more efficient on 'small' files, and bzip2 on 'big' files, |
117 |
big being very dependent on the content of the files. |
small and big being very dependent on the content of the files. |
118 |
|
|
119 |
See the original post from Mickael A. Peters, titled "Bootable Utility CD", |
See the original post from Mickael A. Peters, titled |
120 |
and dated 20030409.1816(+0200), and subsequent posts: |
"Bootable Utility CD", dated 20030409.1816(+0200), and subsequent posts: |
121 |
http://linuxfromscratch.org/pipermail/blfs-support/2003-April/038817.html |
http://linuxfromscratch.org/pipermail/blfs-support/2003-April/038817.html |
122 |
|
|
123 |
On my system (x86, ext3), man pages were 35564kiB before compression. gzip -9 |
On my system (x86, ext3), man pages were 35564KB before compression. |
124 |
compressed them down to 20372kiB (57.28%), bzip2 -9 got down to 19812kiB |
gzip -9 compressed them down to 20372KB (57.28%), bzip2 -9 got down to |
125 |
(55.71%). That is a 1.57% gain in space. YMMV. |
19812KB (55.71%). That is a 1.57% gain in space. YMMV. |
126 |
|
|
127 |
What was not taken into consideration was the decompression speed. But does |
What was not taken into consideration was the decompression speed. But |
128 |
it make sense to? You gain fast access with uncompressed man pages, or you |
does it make sense to? You gain fast access with uncompressed man |
129 |
gain space at the expense of a slight overhead in time. Well, my P4-2.5GHz |
pages, or you gain space at the expense of a slight overhead in time. |
130 |
does not even let me notice this... :-) |
Well, my P4-2.5GHz does not even let me notice this... :-) |
131 |
|
|
132 |
EOT |
EOT |
133 |
) | less |
) | less |
134 |
} |
} |
135 |
|
|
136 |
# This function checks that the man page is unique amongst bzip2'd, gzip'd and |
# This function checks that the man page is unique amongst bzip2'd, |
137 |
# uncompressed versions. |
# gzip'd and uncompressed versions. |
138 |
# $1 the directory in which the file resides |
# $1 the directory in which the file resides |
139 |
# $2 the file name for the man page |
# $2 the file name for the man page |
140 |
# Returns 0 (true) if the file is the latest and must be taken care of, and 1 |
# Returns 0 (true) if the file is the latest and must be taken care of, |
141 |
# (false) if the file is not the latest (and has therefore been deleted). |
# and 1 (false) if the file is not the latest (and has therefore been |
142 |
|
# deleted). |
143 |
function check_unique () |
function check_unique () |
144 |
{ |
{ |
145 |
# NB. When there are hard-links to this file, these are |
# NB. When there are hard-links to this file, these are |
155 |
BZ_FILE="$BASENAME".bz2 |
BZ_FILE="$BASENAME".bz2 |
156 |
|
|
157 |
# Look for, and keep, the most recent one |
# Look for, and keep, the most recent one |
158 |
LATEST=`(cd "$DIR"; ls -1rt "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}" 2>/dev/null | tail -n 1)` |
LATEST=`(cd "$DIR"; ls -1rt "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}" \ |
159 |
|
2>/dev/null | tail -n 1)` |
160 |
for i in "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}"; do |
for i in "${BASENAME}" "${GZ_FILE}" "${BZ_FILE}"; do |
161 |
[ "$LATEST" != "$i" ] && rm -f "$DIR"/"$i" |
[ "$LATEST" != "$i" ] && rm -f "$DIR"/"$i" |
162 |
done |
done |
170 |
# Name of the script |
# Name of the script |
171 |
MY_NAME=`basename $0` |
MY_NAME=`basename $0` |
172 |
|
|
173 |
# OK, parse the command-line for arguments, and initialize to some sensible |
# OK, parse the command-line for arguments, and initialize to some |
174 |
# state, that is : don't change links state, parse /etc/man.conf, be most |
# sensible state, that is: don't change links state, parse |
175 |
# silent, search man.conf in /etc, and don't force (re-)compression. |
# /etc/man_db.conf, be most silent, search man_db.conf in /etc, and don't |
176 |
|
# force (re-)compression. |
177 |
COMP_METHOD= |
COMP_METHOD= |
178 |
COMP_SUF= |
COMP_SUF= |
179 |
COMP_LVL= |
COMP_LVL= |
196 |
COMP_METHOD=$1 |
COMP_METHOD=$1 |
197 |
shift |
shift |
198 |
;; |
;; |
199 |
|
--automatic) |
200 |
|
COMP_SUF=TBD |
201 |
|
COMP_METHOD=$1 |
202 |
|
shift |
203 |
|
;; |
204 |
--decompress|-d) |
--decompress|-d) |
205 |
COMP_SUF= |
COMP_SUF= |
206 |
COMP_LVL= |
COMP_LVL= |
256 |
exit 1 |
exit 1 |
257 |
;; |
;; |
258 |
*) |
*) |
259 |
echo "\"$1\" is not an absolute path name" |
echo "\"$1\" is not an absolute path name" |
260 |
exit 1 |
exit 1 |
261 |
;; |
;; |
262 |
esac |
esac |
284 |
;; |
;; |
285 |
esac |
esac |
286 |
|
|
287 |
# Note: on my machine, 'man --path' gives /usr/share/man twice, once with a trailing '/', once without. |
# Note: on my machine, 'man --path' gives /usr/share/man twice, once |
288 |
|
# with a trailing '/', once without. |
289 |
if [ -z "$MAN_DIR" ]; then |
if [ -z "$MAN_DIR" ]; then |
290 |
MAN_DIR=`man --path -C "$MAN_CONF"/man.conf \ |
MAN_DIR=`manpath -q -C "$MAN_CONF"/man_db.conf \ |
291 |
| sed 's/:/\\n/g' \ |
| sed 's/:/\\n/g' \ |
292 |
| while read foo; do dirname "$foo"/.; done \ |
| while read foo; do dirname "$foo"/.; done \ |
293 |
| sort -u \ |
| sort -u \ |
294 |
| while read bar; do echo -n "$bar "; done` |
| while read bar; do echo -n "$bar "; done` |
295 |
fi |
fi |
296 |
|
|
297 |
# If no MANPATH in ${MAN_CONF}/man.conf, abort as well |
# If no MANDATORY_MANPATH in ${MAN_CONF}/man_db.conf, abort as well |
298 |
if [ -z "$MAN_DIR" ]; then |
if [ -z "$MAN_DIR" ]; then |
299 |
echo "No directory specified, and no directory found with \`man --path'" |
echo "No directory specified, and no directory found with \`manpath'" |
300 |
exit 1 |
exit 1 |
301 |
fi |
fi |
302 |
|
|
303 |
|
# Check that the specified directories actually exist and are readable |
304 |
|
for DIR in $MAN_DIR; do |
305 |
|
if [ ! -d "$DIR" -o ! -r "$DIR" ]; then |
306 |
|
echo "Directory '$DIR' does not exist or is not readable" |
307 |
|
exit 1 |
308 |
|
fi |
309 |
|
done |
310 |
|
|
311 |
# Fake? |
# Fake? |
312 |
if [ "$FAKE" != "no" ]; then |
if [ "$FAKE" != "no" ]; then |
313 |
echo "Actual parameters used:" |
echo "Actual parameters used:" |
314 |
echo -n "Compression.......: " |
echo -n "Compression.......: " |
315 |
case $COMP_METHOD in |
case $COMP_METHOD in |
316 |
--bzip2|--bz2|-b) echo -n "bzip2";; |
--bzip2|--bz2|-b) echo -n "bzip2";; |
317 |
--gzip|__gz|-g) echo -n "gzip";; |
--gzip|--gz|-g) echo -n "gzip";; |
318 |
|
--automatic) echo -n "compressing";; |
319 |
--decompress|-d) echo -n "decompressing";; |
--decompress|-d) echo -n "decompressing";; |
320 |
*) echo -n "unknown";; |
*) echo -n "unknown";; |
321 |
esac |
esac |
324 |
echo "Compression suffix: $COMP_SUF" |
echo "Compression suffix: $COMP_SUF" |
325 |
echo -n "Force compression.: " |
echo -n "Force compression.: " |
326 |
[ "foo$FORCE_OPT" = "foo-F" ] && echo "yes" || echo "no" |
[ "foo$FORCE_OPT" = "foo-F" ] && echo "yes" || echo "no" |
327 |
echo "man.conf is.......: ${MAN_CONF}/man.conf" |
echo "man_db.conf is....: ${MAN_CONF}/man_db.conf" |
328 |
echo -n "Hard-links........: " |
echo -n "Hard-links........: " |
329 |
[ "foo$LN_OPT" = "foo-S" ] && echo "convert to soft-links" || echo "leave as is" |
[ "foo$LN_OPT" = "foo-S" ] && |
330 |
|
echo "convert to soft-links" || echo "leave as is" |
331 |
echo -n "Soft-links........: " |
echo -n "Soft-links........: " |
332 |
[ "foo$LN_OPT" = "foo-H" ] && echo "convert to hard-links" || echo "leave as is" |
[ "foo$LN_OPT" = "foo-H" ] && |
333 |
|
echo "convert to hard-links" || echo "leave as is" |
334 |
echo "Backup............: $BACKUP" |
echo "Backup............: $BACKUP" |
335 |
echo "Faking (yes!).....: $FAKE" |
echo "Faking (yes!).....: $FAKE" |
336 |
echo "Directories.......: $MAN_DIR" |
echo "Directories.......: $MAN_DIR" |
348 |
if [ "$BACKUP" = "yes" ]; then |
if [ "$BACKUP" = "yes" ]; then |
349 |
for DIR in $MAN_DIR; do |
for DIR in $MAN_DIR; do |
350 |
cd "${DIR}/.." |
cd "${DIR}/.." |
351 |
|
if [ ! -w "`pwd`" ]; then |
352 |
|
echo "Directory '`pwd`' is not writable" |
353 |
|
exit 1 |
354 |
|
fi |
355 |
DIR_NAME=`basename "${DIR}"` |
DIR_NAME=`basename "${DIR}"` |
356 |
echo "Backing up $DIR..." > $DEST_FD0 |
echo "Backing up $DIR..." > $DEST_FD0 |
357 |
[ -f "${DIR_NAME}.tar.old" ] && rm -f "${DIR_NAME}.tar.old" |
[ -f "${DIR_NAME}.tar.old" ] && rm -f "${DIR_NAME}.tar.old" |
358 |
[ -f "${DIR_NAME}.tar" ] && mv "${DIR_NAME}.tar" "${DIR_NAME}.tar.old" |
[ -f "${DIR_NAME}.tar" ] && |
359 |
tar cfv "${DIR_NAME}.tar" "${DIR_NAME}" > $DEST_FD1 |
mv "${DIR_NAME}.tar" "${DIR_NAME}.tar.old" |
360 |
|
tar -cvf "${DIR_NAME}.tar" "${DIR_NAME}" > $DEST_FD1 |
361 |
done |
done |
362 |
exit 0 |
exit 0 |
363 |
fi |
fi |
366 |
# I need to take into account the localized man, so I'm going recursive |
# I need to take into account the localized man, so I'm going recursive |
367 |
for DIR in $MAN_DIR; do |
for DIR in $MAN_DIR; do |
368 |
MEM_DIR=`pwd` |
MEM_DIR=`pwd` |
369 |
|
if [ ! -w "$DIR" ]; then |
370 |
|
echo "Directory '$DIR' is not writable" |
371 |
|
exit 1 |
372 |
|
fi |
373 |
cd "$DIR" |
cd "$DIR" |
374 |
for FILE in *; do |
for FILE in *; do |
375 |
# Fixes the case were the directory is empty |
# Fixes the case were the directory is empty |
376 |
if [ "foo$FILE" = "foo*" ]; then continue; fi |
if [ "foo$FILE" = "foo*" ]; then continue; fi |
377 |
|
|
378 |
# Fixes the case when hard-links see their compression scheme change |
# Fixes the case when hard-links see their compression scheme change |
379 |
# (from not compressed to compressed, or from bz2 to gz, or from gz to bz2) |
# (from not compressed to compressed, or from bz2 to gz, or from gz |
380 |
# Also fixes the case when multiple version of the page are present, which |
# to bz2) |
381 |
# are either compressed or not. |
# Also fixes the case when multiple version of the page are present, |
382 |
|
# which are either compressed or not. |
383 |
if [ ! -L "$FILE" -a ! -e "$FILE" ]; then continue; fi |
if [ ! -L "$FILE" -a ! -e "$FILE" ]; then continue; fi |
384 |
|
|
385 |
# Do not compress whatis files |
# Do not compress whatis files |
386 |
if [ "$FILE" = "whatis" ]; then continue; fi |
if [ "$FILE" = "whatis" ]; then continue; fi |
387 |
|
|
388 |
if [ -d "$FILE" ]; then |
if [ -d "$FILE" ]; then |
|
cd "${MEM_DIR}" # Go back to where we ran "$0", in case "$0"=="./compressdoc" ... |
|
389 |
# We are going recursive to that directory |
# We are going recursive to that directory |
390 |
echo "-> Entering ${DIR}/${FILE}..." > $DEST_FD0 |
echo "-> Entering ${DIR}/${FILE}..." > $DEST_FD0 |
391 |
# I need not pass --conf, as I specify the directory to work on |
# I need not pass --conf, as I specify the directory to work on |
392 |
# But I need exit in case of error |
# But I need exit in case of error. We must change back to the |
393 |
"$MY_NAME" ${COMP_METHOD} ${COMP_LVL} ${LN_OPT} ${VERBOSE_OPT} ${FORCE_OPT} "${DIR}/${FILE}" || exit 1 |
# original directory so $0 is resolved correctly. |
394 |
|
(cd "$MEM_DIR" && eval "$0" ${COMP_METHOD} ${COMP_LVL} ${LN_OPT} \ |
395 |
|
${VERBOSE_OPT} ${FORCE_OPT} "${DIR}/${FILE}") || exit $? |
396 |
echo "<- Leaving ${DIR}/${FILE}." > $DEST_FD1 |
echo "<- Leaving ${DIR}/${FILE}." > $DEST_FD1 |
|
cd "$DIR" # Needed for the next iteration of the loop |
|
397 |
|
|
398 |
else # !dir |
else # !dir |
399 |
if ! check_unique "$DIR" "$FILE"; then continue; fi |
if ! check_unique "$DIR" "$FILE"; then continue; fi |
400 |
|
|
401 |
|
# With automatic compression, get the uncompressed file size of |
402 |
|
# the file (dereferencing symlinks), and choose an appropriate |
403 |
|
# compression method. |
404 |
|
if [ "$COMP_METHOD" = "--automatic" ]; then |
405 |
|
declare -i SIZE |
406 |
|
case "$FILE" in |
407 |
|
*.bz2) |
408 |
|
SIZE=$(bzcat "$FILE" | wc -c) ;; |
409 |
|
*.gz) |
410 |
|
SIZE=$(zcat "$FILE" | wc -c) ;; |
411 |
|
*) |
412 |
|
SIZE=$(wc -c < "$FILE") ;; |
413 |
|
esac |
414 |
|
if (( $SIZE >= (5 * 2**10) )); then |
415 |
|
COMP_SUF=.bz2 |
416 |
|
elif (( $SIZE >= (1 * 2**10) )); then |
417 |
|
COMP_SUF=.gz |
418 |
|
else |
419 |
|
COMP_SUF= |
420 |
|
fi |
421 |
|
fi |
422 |
|
|
423 |
# Check if the file is already compressed with the specified method |
# Check if the file is already compressed with the specified method |
424 |
BASE_FILE=`basename "$FILE" .gz` |
BASE_FILE=`basename "$FILE" .gz` |
425 |
BASE_FILE=`basename "$BASE_FILE" .bz2` |
BASE_FILE=`basename "$BASE_FILE" .bz2` |
426 |
if [ "${FILE}" = "${BASE_FILE}${COMP_SUF}" -a "foo${FORCE_OPT}" = "foo" ]; then continue; fi |
if [ "${FILE}" = "${BASE_FILE}${COMP_SUF}" \ |
427 |
|
-a "foo${FORCE_OPT}" = "foo" ]; then continue; fi |
428 |
|
|
429 |
# If we have a symlink |
# If we have a symlink |
430 |
if [ -h "$FILE" ]; then |
if [ -h "$FILE" ]; then |
438 |
esac |
esac |
439 |
|
|
440 |
if [ ! "$EXT" = "none" ]; then |
if [ ! "$EXT" = "none" ]; then |
441 |
LINK=`ls -l "$FILE" | cut -d ">" -f2 | tr -d " " | sed s/\.$EXT$//` |
LINK=`ls -l "$FILE" | cut -d ">" -f2 \ |
442 |
|
| tr -d " " | sed s/\.$EXT$//` |
443 |
NEWNAME=`echo "$FILE" | sed s/\.$EXT$//` |
NEWNAME=`echo "$FILE" | sed s/\.$EXT$//` |
444 |
mv "$FILE" "$NEWNAME" |
mv "$FILE" "$NEWNAME" |
445 |
FILE="$NEWNAME" |
FILE="$NEWNAME" |
461 |
elif [ -f "$FILE" ]; then |
elif [ -f "$FILE" ]; then |
462 |
# Take care of hard-links: build the list of files hard-linked |
# Take care of hard-links: build the list of files hard-linked |
463 |
# to the one we are {de,}compressing. |
# to the one we are {de,}compressing. |
464 |
# NB. This is not optimum has the file will eventually be compressed |
# NB. This is not optimum has the file will eventually be |
465 |
# as many times it has hard-links. But for now, that's the safe way. |
# compressed as many times it has hard-links. But for now, |
466 |
|
# that's the safe way. |
467 |
inode=`ls -li "$FILE" | awk '{print $1}'` |
inode=`ls -li "$FILE" | awk '{print $1}'` |
468 |
HLINKS=`find . \! -name "$FILE" -inum $inode` |
HLINKS=`find . \! -name "$FILE" -inum $inode` |
469 |
|
|
512 |
# Keep the hard-link a hard- one |
# Keep the hard-link a hard- one |
513 |
ln "${FILE}$COMP_SUF" "${NEWFILE}$COMP_SUF" |
ln "${FILE}$COMP_SUF" "${NEWFILE}$COMP_SUF" |
514 |
fi |
fi |
515 |
chmod 644 "${NEWFILE}$COMP_SUF" # Really work only for hard-links. Harmless for soft-links |
# Really work only for hard-links. Harmless for soft-links |
516 |
|
chmod 644 "${NEWFILE}$COMP_SUF" |
517 |
done |
done |
518 |
fi |
fi |
519 |
|
|
520 |
else |
else |
521 |
# There is a problem when we get neither a symlink nor a plain file |
# There is a problem when we get neither a symlink nor a plain |
522 |
# Obviously, we shall never ever come here... :-( |
# file. Obviously, we shall never ever come here... :-( |
523 |
echo "Whaooo... \"${DIR}/${FILE}\" is neither a symlink nor a plain file. Please check:" |
echo -n "Whaooo... \"${DIR}/${FILE}\" is neither a symlink " |
524 |
|
echo "nor a plain file. Please check:" |
525 |
ls -l "${DIR}/${FILE}" |
ls -l "${DIR}/${FILE}" |
526 |
exit 1 |
exit 1 |
527 |
fi |
fi |