2002-03-25 23:37:46 +03:00
#!/bin/sh
#
# brp-compress - compress info and manpages.
2003-11-08 22:52:04 +03:00
#
# $Id$
2002-07-21 18:14:51 +04:00
# Copyright (C) 2000-2002 Dmitry V. Levin <ldv@altlinux.org>
2002-03-25 23:37:46 +03:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
PROG="${0##*/}"
2002-08-28 19:06:42 +04:00
RPM_COMPRESS_METHOD="${RPM_COMPRESS_METHOD## }"
RPM_COMPRESS_METHOD="${RPM_COMPRESS_METHOD%% }"
2002-07-21 17:51:55 +04:00
echo "Compressing files in $RPM_BUILD_ROOT ($RPM_COMPRESS_METHOD)"
if [ "$RPM_COMPRESS_METHOD" = skip ]; then
exit 0
fi
2002-03-25 23:37:46 +03:00
# If using normal root, avoid changing anything.
2003-11-07 20:45:11 +03:00
if [ -z "$(printf %s "$RPM_BUILD_ROOT" |tr -d ' /.')" ]; then
2002-03-25 23:37:46 +03:00
echo "$PROG: non-/ \$RPM_BUILD_ROOT expected" >&2
exit 1
fi
cd "$RPM_BUILD_ROOT" || exit
2002-09-27 17:41:26 +04:00
: ${RPM_COMPRESS_TOPDIR:=}
[ -d "$RPM_BUILD_ROOT$RPM_COMPRESS_TOPDIR" ] || exit 0
2002-03-25 23:37:46 +03:00
StripSuffix()
{
for s in gz bz2 Z; do
f="${1%.$s}"
if [ "$f" != "$1" ]; then
2003-11-07 20:45:11 +03:00
printf %s "$f"
2002-03-25 23:37:46 +03:00
return
fi
done
2003-11-07 20:45:11 +03:00
printf %s "$1"
2002-03-25 23:37:46 +03:00
}
2002-09-27 17:41:26 +04:00
for d in `find "$RPM_BUILD_ROOT$RPM_COMPRESS_TOPDIR" -type d -name info`; do
2002-03-25 23:37:46 +03:00
find "$d" -type f \( -name \*.gz -o -name \*.Z \) -print0 |xargs -r0 gunzip
find "$d" -type f -name \*.bz2 -print0 |xargs -r0 bunzip2
find "$d" -type f -a \! -name dir -print0 |xargs -r0 @RPMCONFIGDIR@/compress_files
done
2002-09-27 17:41:26 +04:00
for d in `find "$RPM_BUILD_ROOT$RPM_COMPRESS_TOPDIR" -type d -name man`; do
2002-03-25 23:37:46 +03:00
find "$d" -type f -size 0 -print0 |xargs -r0 rm -fv
find "$d" -type f -print0 |xargs -r0 chmod a-x
# Uncompress everything.
find "$d" -type f \( -name \*.gz -o -name \*.Z \) -print0 |xargs -r0 gunzip
find "$d" -type f -name \*.bz2 -print0 |xargs -r0 bunzip2
# First, compress normal files.
for f in `find "$d" -type f -a \! -name whatis -print0 |xargs -r0 file |grep ':[^:]*troff or preprocessor input text' |sed -e 's/:[^:]*troff or preprocessor input text.*//g'`; do
[ -f "$f" ] || continue
if ! head -1 "$f" |grep -q '^.so '; then
@RPMCONFIGDIR@/compress_files "$f"
fi
done
# Second, convert .so links into symlinks.
for f in `find "$d" -type f -a \! -name whatis -print0 |xargs -r0 file |grep ':[^:]*troff or preprocessor input text' |sed -e 's/:[^:]*troff or preprocessor input text.*//g'`; do
[ -f "$f" ] || continue
if head -1 "$f" |grep -q '^.so '; then
f_dir="${f%/*}"
f_dir_name="${f_dir##*/}"
TARGET_orig="$(head -1 "$f" |sed -e 's/^.so\([[:space:]]\)\+//')"
TARGET="$TARGET_orig"
TARGET_base="${TARGET##*/}"
TARGET_dir="$(dirname "$TARGET")"
if [ "." = "$TARGET_dir" -o "$f_dir_name" = "$TARGET_dir" ]; then
TO="$(basename "$f_dir/$TARGET_base"*)"
else
if [ -z "${TARGET##/*}" ]; then
# TARGET starts with /
TARGET_root="/$(relative "$TARGET" "$RPM_BUILD_ROOT/")"
if [ -z "${TARGET_root##/../*}" ]; then
TARGET_root="$TARGET"
fi
f_root="/$(relative "$f" "$RPM_BUILD_ROOT/")"
TARGET="$(relative "$TARGET_root" "$f_root")"
2003-11-07 20:45:11 +03:00
TO="$(cd $f_dir; printf %s\\n "$TARGET"*)"
2002-03-25 23:37:46 +03:00
else
TO="../$TARGET_dir/$(basename "$f_dir/../$TARGET"*)"
fi
fi
if [ ! -e "$f_dir/$TO" ]; then
# link to nothing
echo "$PROG: file $f points to non-existent file $TARGET_orig"
exit 1
fi
FROM="$f${TO##*$TARGET_base}"
rm -fv "$f"
ln -sv "$TO" "$FROM"
fi
done
# Third, correct symlinks.
for f in `find "$d" -type l`; do
f_orig="$f"
TARGET_orig="$(StripSuffix "$(/bin/ls -l "$f" |awk '{print $11}')")"
f="$(StripSuffix "$f")"
if [ -z "${TARGET_orig##/*}" ]; then
# TARGET_orig starts with /
TARGET_root="/$(relative "$TARGET_orig" "$RPM_BUILD_ROOT/")"
if [ -z "${TARGET_root##/../*}" ]; then
TARGET_root="$TARGET_orig"
fi
else
TARGET_root="$TARGET_orig"
fi
f_root="/$(relative "$f" "$RPM_BUILD_ROOT/")"
TARGET="$(relative "$TARGET_root" "$f_root")"
DIR="$(dirname "$f")"
2003-11-07 20:45:11 +03:00
TO="$(relative "$(printf %s\\n "$DIR/$TARGET"*)" "$f")"
2002-03-25 23:37:46 +03:00
if [ ! -e "$DIR/$TO" ]; then
# Found link to nothing.
echo "$PROG: file $f points to non-existent file $TARGET_orig"
exit 1
fi
FROM="$f${TO#$TARGET}"
rm -fv "$f_orig"
ln -sv "$TO" "$FROM"
done
done
: