2002-10-05 02:45:05 +04:00
#!/bin/sh -ef
2002-03-25 23:37:46 +03:00
#
2004-01-25 14:46:22 +03:00
# Copyright (C) 2000-2004 Dmitry V. Levin <ldv@altlinux.org>
2003-04-22 17:48:31 +04:00
# $Id$
#
2002-03-25 23:37:46 +03:00
# find-provides - generate list of linux-specific package provides.
# Inspired by tool with same name from RPM distribution.
#
# 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
#
2003-07-02 18:20:10 +04:00
[ -z "$RPM_SCRIPTS_DEBUG" ] || set -x
2003-06-20 15:20:08 +04:00
2002-03-25 23:37:46 +03:00
PROG="${0##*/}"
# 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
2003-05-26 01:58:45 +04:00
# Normalize buildroot.
2003-06-17 18:20:37 +04:00
real_buildroot=$(readlink -fv "$RPM_BUILD_ROOT") || exit 1
2003-05-26 01:58:45 +04:00
2002-03-25 23:37:46 +03:00
FIND_LIBS=
FIND_PAM=
FIND_PERL=
2003-04-25 19:53:21 +04:00
FIND_SHELL=
2002-03-25 23:37:46 +03:00
ParseMethod()
{
local t
for t in "$@"; do
case "${t/%,}" in
no|none|off|false)
FIND_LIBS=
FIND_PAM=
FIND_PERL=
2003-04-25 19:53:21 +04:00
FIND_SHELL=
2002-03-25 23:37:46 +03:00
;;
lib)
FIND_LIBS=1
;;
nolib)
FIND_LIBS=
;;
pam)
FIND_PAM=1
;;
nopam)
FIND_PAM=
;;
perl)
FIND_PERL=1
;;
noperl)
FIND_PERL=
;;
2003-04-25 19:53:21 +04:00
sh|shell)
FIND_SHELL=1
;;
nosh|noshell)
FIND_SHELL=
;;
2002-03-25 23:37:46 +03:00
all)
FIND_LIBS=1
FIND_PAM=1
FIND_PERL=1
2003-04-25 19:53:21 +04:00
FIND_SHELL=1
2002-03-25 23:37:46 +03:00
;;
default|yes|true)
2002-11-05 21:04:52 +03:00
ParseMethod $RPM_FINDPROV_DEFAULT_METHOD || return 1
2002-03-25 23:37:46 +03:00
;;
*)
echo "Unrecognized find-provides method: $t" >&2
exit 1
;;
esac
done
}
ParseMethod $RPM_FINDPROV_METHOD
2003-04-25 19:53:21 +04:00
if [ -z "$FIND_LIBS" -a -z "$FIND_PAM" -a -z "$FIND_PERL" -a -z "$FIND_SHELL" ]; then
2002-03-25 23:37:46 +03:00
# Nothing to do
2003-04-22 17:48:31 +04:00
cat >/dev/null 2>&1
2002-03-25 23:37:46 +03:00
exit 0
fi
ulimit -c 0
case "$LD_PRELOAD" in
*libfakeroot*)
unset LD_PRELOAD
;;
*libbuildreq.so*)
unset LD_PRELOAD
;;
esac
FOUND_PROVS=
LIST_PERL=
ListScriptProvs()
{
2003-04-22 17:48:31 +04:00
local f t
f="$1"
t="$2"
2003-04-25 19:53:21 +04:00
if [ -z "${t##ASCII *text*}" ]; then
if [ -z "${f%%$RPM_BUILD_ROOT/etc/pam.d/*}" ]; then
if [ -n "$FIND_PAM" ]; then
local r
r="$(@RPMCONFIGDIR@/pam.prov "$f")" || return 1
[ -z "$FOUND_PROVS" ] && FOUND_PROVS="$r" || FOUND_PROVS="$FOUND_PROVS
$r"
fi
2003-05-01 19:46:30 +04:00
return 0
2003-07-02 20:48:24 +04:00
fi
# Ignore symlinks for non-PAM scripts.
[ ! -L "$f" ] || return 0
if [ "${f##*/}" = ".provides.sh" ]; then
2003-04-25 19:53:21 +04:00
if [ -n "$FIND_SHELL" ]; then
local r
r="$(@RPMCONFIGDIR@/shell.prov "$f")" || return 1
[ -z "$FOUND_PROVS" ] && FOUND_PROVS="$r" || FOUND_PROVS="$FOUND_PROVS
2002-03-25 23:37:46 +03:00
$r"
2003-04-25 19:53:21 +04:00
fi
2003-05-01 19:46:30 +04:00
return 0
2002-03-25 23:37:46 +03:00
fi
2003-05-01 19:46:30 +04:00
fi
2003-07-02 20:48:24 +04:00
# Ignore symlinks for non-PAM scripts.
[ ! -L "$f" ] || return 0
2004-01-19 16:42:57 +03:00
if [ -z "${t##perl script text*}" -o -z "${t##Perl5 module source text}" -o -z "${f%%*.p[lmh]}" ]; then
2002-03-25 23:37:46 +03:00
if [ -n "$FIND_PERL" ]; then
[ -z "$LIST_PERL" ] && LIST_PERL="$f" || LIST_PERL="$LIST_PERL
$f"
fi
fi
}
FindPerlProvs()
{
2003-04-22 17:48:31 +04:00
[ -n "$LIST_PERL" ] || return 0
local r
2003-11-07 20:45:11 +03:00
r="$(printf %s\\n "$LIST_PERL" |@RPMCONFIGDIR@/perl.prov)" || return 1
2003-04-22 17:48:31 +04:00
[ -z "$FOUND_PROVS" ] && FOUND_PROVS="$r" || FOUND_PROVS="$FOUND_PROVS
2002-03-25 23:37:46 +03:00
$r"
}
2004-01-25 14:46:22 +03:00
DEF_RPM_FINDPROV_LIB_PATH='/lib:/usr/lib:/usr/X11R6/lib'
: ${RPM_FINDPROV_LIB_PATH:=$DEF_RPM_FINDPROV_LIB_PATH}
lookup_path()
{
local d dir path found=
dir="$1" && shift
path="$1" && shift
for d in $(printf %s "$path" |tr : ' '); do
[ "$d" = "$dir" ] || continue
found="$d"
break
done
[ -n "$found" ] && return 0 || return 1
}
2002-03-25 23:37:46 +03:00
2003-05-13 16:44:12 +04:00
# Note this works for both a.out and ELF executables.
2002-03-25 23:37:46 +03:00
FindLibProvs()
{
[ -n "$FIND_LIBS" ] || return 0
2003-04-22 17:48:31 +04:00
2004-01-25 14:46:22 +03:00
local f dir name dump
2003-04-22 17:48:31 +04:00
f="$1"
2003-05-13 16:44:12 +04:00
dir="${fname%/*}"
[ -n "$dir" ] || return 0
2003-05-26 01:58:45 +04:00
name="${fname##*/}"
[ -n "$name" ] || return 0
2003-05-13 16:44:12 +04:00
2004-01-25 14:46:22 +03:00
lookup_path "$dir" "$RPM_FINDPROV_LIB_PATH" || return 0
2003-04-22 17:48:31 +04:00
2004-01-25 14:46:22 +03:00
if dump="$(objdump -p "$f")"; then
2002-11-05 21:04:52 +03:00
local soname
2004-01-25 14:46:22 +03:00
soname="$(printf %s\\n "$dump" |awk '/SONAME/ {print $2}')" || return 1
2002-03-25 23:37:46 +03:00
if [ -n "$soname" ]; then
2003-05-26 01:58:45 +04:00
while :; do
# For libraries with soname, ignore all but files named as soname.
[ "$soname" = "$name" ] || break
# Treat symlinks specially.
if [ -L "$f" ]; then
2004-02-02 17:26:50 +03:00
local real realpath realdir
2003-05-26 01:58:45 +04:00
realpath=$(readlink -fv "$f") || break
2003-06-17 18:20:37 +04:00
real="${realpath#$real_buildroot}"
2003-05-26 01:58:45 +04:00
# Ignore symlinks leading out of buildroot.
[ "$real" != "$realpath" ] || break
2004-02-02 17:26:50 +03:00
realdir="${real%/*}"
# Ignore symlinks to shorter locations.
[ "${#dir}" -le "${#realdir}" ] || break
2003-05-26 01:58:45 +04:00
fi
2004-01-25 14:46:22 +03:00
# Check for non-default path.
local nondefdir=
lookup_path "$dir" "$DEF_RPM_FINDPROV_LIB_PATH" || nondefdir="$dir"
2003-05-26 01:58:45 +04:00
# Output soname.
2003-11-07 20:45:11 +03:00
printf %s\\n "$soname"
2004-01-29 15:27:23 +03:00
[ -z "$nondefdir" ] || printf "$nondefdir/%s\\n" "$soname"
2002-03-25 23:37:46 +03:00
2003-05-26 01:58:45 +04:00
# Output version definitions.
2004-01-25 14:46:22 +03:00
printf %s\\n "$dump" | awk "-vsoname=$soname" "-vnondefdir=$nondefdir" '
BEGIN {start=0;}
/^Version definitions:$/ {start=1;}
/^[0-9]/ && (start==1) && ($4!="") && ($4!=soname) {
printf("%s(%s)\n",soname,$4)
if (nondefdir!="")
2004-01-29 15:27:23 +03:00
printf("%s/%s(%s)\n",nondefdir,soname,$4)
2004-01-25 14:46:22 +03:00
}
/^$/ {start=0;}
2002-11-05 21:04:52 +03:00
' || return 1
2003-05-26 01:58:45 +04:00
break
done
2002-03-25 23:37:46 +03:00
else
2003-05-26 01:58:45 +04:00
# Ignore symlinks for libraries without soname.
2003-11-07 20:45:11 +03:00
[ -L "$f" ] || printf %s\\n "${f##*/}"
2002-03-25 23:37:46 +03:00
fi
fi
}
2002-09-27 17:41:26 +04:00
: ${RPM_FINDPROV_TOPDIR:=}
: ${RPM_FINDPROV_SKIPLIST:=}
2002-03-25 23:37:46 +03:00
while IFS= read -r f; do
2002-12-30 02:33:01 +03:00
fname="${f#$RPM_BUILD_ROOT}"
fname="${fname#.}"
if [ -n "$RPM_FINDPROV_TOPDIR" ] && [ -z "${fname%%$RPM_FINDPROV_TOPDIR/*}" ]; then
2002-09-27 17:41:26 +04:00
continue;
fi
if [ -n "$RPM_FINDPROV_SKIPLIST" ]; then
for skip in $RPM_FINDPROV_SKIPLIST; do
2004-01-25 20:19:42 +03:00
if [ -z "${fname##$skip}" ]; then
2002-09-27 17:41:26 +04:00
continue 2
fi
done
fi
2003-05-26 01:58:45 +04:00
# Find out file type (dereference symlinks).
2002-03-25 23:37:46 +03:00
if t="$(file -bL "$f")"; then
if [ -z "${t##* text*}" ]; then
2003-07-02 20:48:24 +04:00
ListScriptProvs "$f" "$t"
2002-03-25 23:37:46 +03:00
elif [ -z "${t##* shared object*}" ]; then
r="$(FindLibProvs "$f")"
[ -z "$FOUND_PROVS" ] && FOUND_PROVS="$r" || FOUND_PROVS="$FOUND_PROVS
$r"
fi
else
echo "Not found: $f" >&2
fi
done
# Find provides in listed perl scripts, if any
FindPerlProvs
# Finally sort and print them.
2003-11-07 20:45:11 +03:00
printf %s "$FOUND_PROVS" |LC_COLLATE=C sort -u