ALT Linux Team development discussions
 help / color / mirror / Atom feed
* [devel] I: RPM Requires finder
@ 2001-10-24 11:06 Alexander Bokovoy
  0 siblings, 0 replies; only message in thread
From: Alexander Bokovoy @ 2001-10-24 11:06 UTC (permalink / raw)
  To: devel

[-- Attachment #1: Type: text/plain, Size: 1363 bytes --]

Прилагаемый скрипт является (после некоторой обобщающей доработки)
претендентом на включение в rpm-utils. Он принимает в качестве аргумента
либо имя установленного пакета, либо файла с пакетом (*.rpm) и вычисляет
относительно системной базы RPM имена и версии пакетов, которые требуются 
для работы данного пакета. Результат -- строчка, пригодная для вписывания
в SPEC-файл в качестве Requires:.

Скрипт сырой но вполне готовый к применению для прочистки SPEC-файлов с
непроставленными зависимостями. Его можно было бы также включить в
механизм find-requires в RPM. Собственно, вторым прилагается "быстрый хак"
на тему /usr/lib/rpm/find-requires, который оный и реализует. Из имеющихся
недостатков:

- автоматически вставляет "пакет >= версия-сборка". Нужна определенная
  логика по дифференцированию вывода. Например, жесткая индикация
  номеров версий только для определенных пакетов.
  
- не объединяет результат find-requires с Requires:, указанными в
  SPEC-файле, в результате чего получается двойное указание зависимостей,
  например: mnogosearch, mnogosearch >= 3.1.16-alt1


Однако в целом предлагаемый механизм позволяет малой кровью вычистить
Requires: в репозитарии.
-- 
/ Alexander Bokovoy
$ cat /proc/identity >~/.signature
  `Senior software developer and analyst for SaM-Solutions Ltd.`
---
God must have loved calories, she made so many of them.

[-- Attachment #2: rpmreqs --]
[-- Type: text/plain, Size: 661 bytes --]

#!/bin/sh -e
ESSENTIAL="/etc/buildreqs/packages/essential"
IGNORE="/etc/buildreqs/packages/ignore"
CHECKER="/usr/share/buildreqs/check_importance"
RPMARGS=
PNAME="$1"

if test -f "$1" ; then
	RPMARGS="-p"
	PNAME=`rpm -qp --qf='%{name}' $1`
fi

echo -n "Requires: "
REQUIRESLIST=`rpm -q --qf='[%{requirename}\n]' $RPMARGS $1|
grep -ve 'rpmlib\(.*\)'|
xargs rpm -q --whatprovides |sort -u |
xargs rpm -q --qf='%{name}\n'|
while read package ; do
	if test "$PNAME" != "$package" ; then
	    if ! "$CHECKER" "$package" "$ESSENTIAL" "$IGNORE"; then
		rpm -q --qf='%{name} >= %{version}-%{release}, ' "$package"
	    fi
	fi
done| sed -e 's/, $//'`

echo $REQUIRESLIST

[-- Attachment #3: find-requires --]
[-- Type: text/plain, Size: 5582 bytes --]

#!/bin/sh -e
#
# find-requires - generate list of linux-specific package requires.
# Inspired by tool with same name from RPM distribution.
#
# Copyright (C) 2000  Dmitry V. Levin <ldv@fandra.org>
#
# 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##*/}"

Exit()
{
	RETVAL=$?
	trap '' EXIT
	cat &>/dev/null
	exit $RETVAL
}

trap "Exit " EXIT

# If using normal root, avoid changing anything.
if [ -z "$(echo "$RPM_BUILD_ROOT" |tr -d ' /.')" ]; then
	echo "$PROG: non-/ RPM_BUILD_ROOT expected" >&2
	exit 1
fi

FIND_FILES=
FIND_LIBS=
FIND_PAM=
FIND_PERL=
FIND_SHELL=

ParseMethod()
{
	local t
	for t in "$@"; do
		case "${t/%,}" in
			no|none|off|false)
				FIND_FILES=
				FIND_LIBS=
				FIND_PAM=
				FIND_PERL=
				FIND_SHELL=
				;;
			lib|library)
				FIND_LIBS=1
				;;
			nolib|nolibrary)
				FIND_LIBS=
				;;
			files)
				FIND_FILES=1
				;;
			nofiless)
				FIND_FILES=
				;;
			pam)
				FIND_PAM=1
				;;
			nopam)
				FIND_PAM=
				;;
			perl)
				FIND_PERL=1
				;;
			noperl)
				FIND_PERL=
				;;
			sh|shell)
				FIND_SHELL=1
				;;
			nosh|noshell)
				FIND_SHELL=
				;;
			all)
				FIND_FILES=1
				FIND_LIBS=1
				FIND_PAM=1
				FIND_PERL=1
				FIND_SHELL=1
				;;
			default|yes|true)
				ParseMethod $RPM_FINDREQ_DEFAULT_METHOD
				;;
			*)
				echo "Unrecognized find-requires method: $t" >&2
				exit 1
				;;
		esac
	done
}
ParseMethod $RPM_FINDREQ_METHOD

FIND_SCRIPT=
if [ -n "$FIND_SHELL" -o -n "$FIND_PERL" -o -n "$FIND_PAM" ]; then
	FIND_SCRIPT=1
fi

if [ -z "$FIND_LIBS" -a -z "$FIND_SCRIPT" -a -z "$FIND_FILES" ]; then
	# Nothing to do
	exit
fi

. /usr/lib/rpm/find-package

ulimit -c 0

case "$LD_PRELOAD" in
	*libfakeroot*)
		unset LD_PRELOAD
		;;
	*libbuildreq.so*)
		unset LD_PRELOAD
		;;
esac

FOUND_REQS=
LIST_PERL=

ListScriptReqs()
{
	[ -n "$FIND_SCRIPT" ] || return 0
	local f="$1"
	local t="$2"
	if [ -x "$f" ]; then
		local r="$(FindPackage "$f" "$(head -1 "$f" |sed -n 's|^#![ 	]*\(/[^ 	]\+\).*|\1|p')")"
		[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
$r"
	fi
	if [ -z "${t##Bourne* shell script text*}" ]; then
		if [ -n "$FIND_SHELL" -a -x "$f" ]; then
			local r="$(/usr/lib/rpm/shell.req "$f")"
			[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
$r"
		fi
	elif [ -z "${t##ASCII *text*}" -a -z "${f%%$RPM_BUILD_ROOT/etc/pam.d/*}" ]; then
		if [ -n "$FIND_PAM" ]; then
			local r="$(/usr/lib/rpm/pam.req "$f")"
			[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
$r"
		fi
	elif [ -z "${t##perl script text*}" -o -z "${f%%*.p[lmh]}" ]; then
		if [ -n "$FIND_PERL" ]; then
			[ -z "$LIST_PERL" ] && LIST_PERL="$f" || LIST_PERL="$LIST_PERL
$f"
		fi
	fi
}

FindPerlReqs()
{
	if [ -n "$LIST_PERL" ]; then
		local r="$(echo "$LIST_PERL" |/usr/lib/rpm/perl.req)"
		[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
$r"
	fi
}

# Note this works for both a.out and ELF executables.
# It also auto-generates requirements for scripts.

FindLibReqs()
{
	[ -n "$FIND_LIBS" ] || return 0
	local f="$1"
	local d

	if d="$(objdump -p "$f")"; then 
		# Shared library dependencies, glibc version references.
		echo -E "$d" |awk '
			BEGIN {start_shared=0; start_version=0; lib_name="";}
			/^Dynamic Section:$/ {start_shared=1;}
			/^Version References:$/ {start_version=1;}
			(start_version==1) && /^ *required from/ {sub(/:/, "", $3);	lib_name=$3;}
			(start_shared==1) && /^ *NEEDED/ {print $2;}
			(start_version==1) && (lib_name!="") && ($4~/^GLIBC_*/) {print lib_name "(" $4 ")";}
			/^$/ {start_shared=0; start_version=0;}
		'
	fi
}

FindExeReqs()
{
	if [ -x "$1" ]; then
		FindLibReqs "$1"
	fi
}

while IFS= read -r f; do
	if [ -z "${f%%$RPM_BUILD_ROOT/etc/xinetd.d/*}" ]; then
		if [ -n "$FIND_FILES" ]; then
			[ -z "$FOUND_REQS" ] && FOUND_REQS="xinetd" || FOUND_REQS="$FOUND_REQS
xinetd"
		fi
	elif [ -z "${f%%$RPM_BUILD_ROOT/etc/security/console.apps/*}" ]; then
		if [ -n "$FIND_FILES" ]; then
			[ -z "$FOUND_REQS" ] && FOUND_REQS="consolehelper" || FOUND_REQS="$FOUND_REQS
consolehelper"
		fi
	fi
	t="$(file -b "$f")"
	if [ -z "${t##* text*}" ]; then
		ListScriptReqs "$f" "$t"
	elif [ -z "${t##* executable*}" ]; then
		r="$(FindExeReqs "$f")"
		[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
$r"
	elif [ -z "${t##* shared object*}" ]; then
		r="$(FindLibReqs "$f")"
		[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
$r"
	fi
done

# Find requires in listed perl scripts, if any
FindPerlReqs

# Finally sort and print them.
ESSENTIAL="/etc/buildreqs/packages/essential"
IGNORE="/etc/buildreqs/packages/ignore"
CHECKER="/usr/share/buildreqs/check_importance"

echo "$FOUND_REQS" |sort -u|
xargs rpm -q --whatprovides |sort -u |
xargs rpm -q --qf='%{name}\n'|
while read package ; do
# Temporarily ignore essential list
#	if ! "$CHECKER" "$package" "$ESSENTIAL" "$IGNORE"; then
		rpm -q --qf='%{name} >= %{version}-%{release}\n' "$package"
#    fi
done| sort -u

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-10-24 11:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-24 11:06 [devel] I: RPM Requires finder Alexander Bokovoy

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git