2007-03-06 00:40:45 +03:00
#!/bin/sh -efu
2002-03-25 20:37:46 +00:00
#
2003-04-22 14:24:35 +00:00
# Copyright (C) 2000,2003 Dmitry V. Levin <ldv@altlinux.org>
2007-08-28 00:41:17 +04:00
# Copyright (C) 2007 Alexey Tourbin <at@altlinux.org>
2002-03-25 20:37:46 +00: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
#
2007-03-06 00:40:45 +03:00
. @RPMCONFIGDIR@/functions
2007-08-28 00:41:17 +04:00
. @RPMCONFIGDIR@/find-package
2005-06-29 18:21:40 +00:00
2007-10-03 14:04:25 +04:00
workdir=
clean_workdir()
{
local rc=$?
trap - EXIT
[ -z "$workdir" ] || rm -rf "$workdir"
exit $rc
}
init_workdir()
{
[ -z "$workdir" ] || return 0
workdir=$(mktemp -dt "$PROG".XXXXXXXX)
trap clean_workdir EXIT HUP INT QUIT PIPE TERM
: >"$workdir"/req
: >"$workdir"/prov
}
2007-08-28 00:41:17 +04:00
ShellReq()
{
local f="$1"; shift
2005-06-29 18:21:40 +00:00
2007-08-28 00:41:17 +04:00
local t sh
2007-08-28 02:12:58 +04:00
t=$(file -bL "$f") || Fatal "${t:-$f: file type not available}"
2007-08-28 00:41:17 +04:00
case "$t" in
*"Bourne-Again shell script text"*)
sh=/bin/bash ;;
*" bash script text"*)
sh=/bin/bash ;;
*)
sh=/bin/sh ;;
esac
$sh --rpm-requires </dev/null >/dev/null ||
Fatal "$sh interpreter does not support --rpm-requires feature"
2005-06-29 18:21:40 +00:00
2007-08-28 00:41:17 +04:00
local reqs line1
if ! reqs="$($sh --rpm-requires "$f")"; then
# sh --rpm-requires failed, and stderr is already there.
# We are almost dead. The last chance to escape is to see
# if the shell is used only to re-exec another interpreter, e.g.
# exec tclsh "$0" "$@"
if line1=$(egrep -m1 -v '^[[:space:]]*(#|$)' "$f"); then
set -- $line1
if [ $# -gt 1 ] && [ "$1" = exec ]; then
Info "$f is $2 script!"
2007-09-24 02:59:25 +04:00
# We do no more than shebang.req does. If the script
# is not executable, shebang.req.files must have been
# already issued "executable not executable" warning.
if [ -x "$f" ]; then
FindPackage "$f" "$2"
fi
2007-08-28 00:41:17 +04:00
return 0
fi
fi
Fatal "$f: $sh --rpm-requires failed"
2002-03-25 20:37:46 +00:00
fi
2007-10-03 14:04:25 +04:00
[ -n "$reqs" ] || return 0
2007-10-03 14:31:23 +04:00
# Self-requires elimination: first pass.
# Consider e.g. /etc/rc.d/init.d/functions has both
# executable(failure) and function(failure).
# This means that failure() is used before being defined.
# This is okay since it is actually used in another function.
# We want to keep only the function(failure).
reqs=$(printf '%s\n' "$reqs" |sort -t'(' -k1,1r |LC_COLLATE=C sort -t'(' -u -k2)
2007-10-03 14:04:25 +04:00
init_workdir
2007-03-06 00:40:45 +03:00
2007-10-03 14:04:25 +04:00
printf %s "$reqs" |
while IFS='()' read -r t r; do
2003-04-22 14:24:35 +00:00
case "$(type -t -- "$r")" in
alias|keyword|function|builtin)
continue ;;
esac
2007-10-03 14:04:25 +04:00
case "$t" in
executable) printf '%s\t%s\n' "$f" "$r" >>"$workdir"/req ;;
function) printf '%s\t%s\n' "$f" "$r" >>"$workdir"/prov ;;
*) Info "invalid $sh --rpm-requires output: $req" ;;
esac
done
}
ShellReqEND()
{
[ -n "$workdir" ] || return 0
local f r
while IFS=$'\t' read -r f r; do
local self_req=
while IFS=$'\t' read -r f2 r2; do
if [ "$r" = "$r2" ]; then
Verbose "$f: $r() is possibly defined in $f2"
self_req=1
fi
done <"$workdir"/prov
[ -z "$self_req" ] || continue
local dname
dname=${f#${RPM_BUILD_ROOT-}}
dname=${dname%/*}
2007-08-03 19:04:29 +04:00
if grep -qs -Fx -- "$r" "${RPM_BUILD_ROOT-}$dname/.provides.sh"; then
2007-03-06 00:40:45 +03:00
printf %s\\n "$dname($r)"
2007-08-03 19:04:29 +04:00
elif grep -qs -Fx -- "$r" "$dname/.provides.sh"; then
2007-03-06 00:40:45 +03:00
printf %s\\n "$dname($r)"
else
2007-08-28 00:41:17 +04:00
FindPackage "$f" "$r"
2003-04-25 16:51:52 +00:00
fi
2007-10-03 14:04:25 +04:00
done <"$workdir"/req
2002-03-25 20:37:46 +00:00
}
2007-08-28 00:41:17 +04:00
ArgvFileAction ShellReq "$@"
2007-10-03 14:04:25 +04:00
ShellReqEND