rpm-build/scripts/find-package.in

113 lines
3.3 KiB
Plaintext
Raw Normal View History

2002-03-25 20:37:46 +00:00
#!/bin/sh -e
#
2003-04-22 15:11:52 +00:00
# $Id$
# Copyright (C) 2002-2003 Dmitry V. Levin <ldv@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
#
2003-11-09 16:47:45 +00:00
. @RPMCONFIGDIR@/functions
ValidateBuildRoot
2002-03-25 20:37:46 +00:00
FindPackage()
{
2003-04-22 15:11:52 +00:00
local f r rep package
f="$1"
2002-03-25 20:37:46 +00:00
shift
for r in "$@"; do
[ -n "$r" ] || continue
if [ -z "${r##/*}" ]; then
2003-04-22 15:11:52 +00:00
# Dependence name starts with `/'.
# Does it start with buildroot?
if [ -z "${r##$RPM_BUILD_ROOT*}" ]; then
2003-11-09 16:47:45 +00:00
Info "$f: invalid dependence: $r"
2002-03-25 20:37:46 +00:00
return 1
fi
2003-04-22 15:11:52 +00:00
2002-03-25 20:37:46 +00:00
rep="$r"
2003-04-22 15:11:52 +00:00
# Does it belong to buildroot?
if [ -e "$RPM_BUILD_ROOT$rep" ]; then
2002-03-25 20:37:46 +00:00
continue
fi
2003-04-22 15:11:52 +00:00
# Is it an alternative?
2002-11-05 18:49:38 +00:00
if readlink "$rep" |grep -qs '^/etc/alternatives/'; then
printf %s\\n "$rep"
2003-04-22 15:11:52 +00:00
continue
fi
2003-04-22 15:17:53 +00:00
# Check for pkg contents complete index.
2003-06-28 16:46:06 +00:00
if [ -n "$RPM_PKG_CONTENTS_INDEX_ALL" ] && [ -s "$RPM_PKG_CONTENTS_INDEX_ALL" ] && [ -r "$RPM_PKG_CONTENTS_INDEX_ALL" ]; then
2003-04-22 15:11:52 +00:00
package="$(awk -v "f=$rep" '{if ($1 == f) {print $2; exit}}' "$RPM_PKG_CONTENTS_INDEX_ALL")"
if [ -n "$package" ]; then
printf %s\\n "$package"
2003-04-22 15:11:52 +00:00
continue
2002-03-25 20:37:46 +00:00
fi
# Check for pkg contents binary index.
elif [ -n "$RPM_PKG_CONTENTS_INDEX_BIN" ] && [ -s "$RPM_PKG_CONTENTS_INDEX_BIN" ] && [ -r "$RPM_PKG_CONTENTS_INDEX_BIN" ]; then
package="$(awk -v "f=$rep" '{if ($1 == f) {print $2; exit}}' "$RPM_PKG_CONTENTS_INDEX_BIN")"
if [ -n "$package" ]; then
printf %s\\n "$package"
continue
fi
2002-03-25 20:37:46 +00:00
fi
2003-04-22 15:11:52 +00:00
# Check package database.
if package="$(rpmquery --whatprovides --queryformat='%{NAME}\n' -- "$rep" |LC_COLLATE=C sort -u)"; then
if [ -n "$package" ]; then
printf %s\\n "$package"
continue
fi
2003-04-22 15:11:52 +00:00
fi
# Not found; output raw dependence.
printf %s\\n "$rep"
2002-03-25 20:37:46 +00:00
else
2003-04-22 15:11:52 +00:00
# Check buildroot first.
2002-11-05 18:49:38 +00:00
local RPATH
RPATH="$(printf %s "$PATH" |sed -e "s|[^:]\+|$RPM_BUILD_ROOT&|g")"
2002-03-25 20:37:46 +00:00
if [ -n "$(PATH="$RPATH" /usr/bin/which -- "$r" 2>/dev/null)" ]; then
continue
fi
2003-04-22 15:11:52 +00:00
2003-04-22 15:17:53 +00:00
# Check for pkg contents binary index.
2003-06-28 16:46:06 +00:00
if [ -n "$RPM_PKG_CONTENTS_INDEX_BIN" ] && [ -s "$RPM_PKG_CONTENTS_INDEX_BIN" ] && [ -r "$RPM_PKG_CONTENTS_INDEX_BIN" ]; then
for location in /sbin /usr/sbin /bin /usr/bin /usr/X11R6/bin; do
package="$(awk -v "f=$location/$r" '{if ($1 == f) {print $2; exit}}' "$RPM_PKG_CONTENTS_INDEX_BIN")"
if [ -n "$package" ]; then
printf %s\\n "$package"
continue 2
fi
done
2002-03-25 20:37:46 +00:00
fi
2003-04-22 15:11:52 +00:00
# Lookup in host system.
if ! rep="$(/usr/bin/which -- "$r" 2>/dev/null)"; then
2002-03-25 20:37:46 +00:00
continue
fi
2003-04-22 15:11:52 +00:00
# Check package database.
if package="$(rpmquery --whatprovides --queryformat='%{NAME}\n' -- "$rep" |LC_COLLATE=C sort -u)"; then
2003-09-22 12:23:33 +00:00
if [ -n "$package" ]; then
printf %s\\n "$package"
2003-09-22 12:23:33 +00:00
continue
fi
2002-03-25 20:37:46 +00:00
fi
fi
done
}