scripts/functions: implemented SetupMethods() and RunMethods()

I want some rpm scripts to be modular, so that e.g. adding new automatic
dependencies does not require ad hoc modifications.

The plan is as follows: I am going to manage methods.  Methods
are scripts which e.g. implement particular dependency detection.
The set of methods is defined by its suffix, so that /usr/lib/rpm/*.req
are all "req" methods (the "req" method set).

Hereby I provide two functions which abstract the usage of method sets.

1)
methods=$(SetupMethods SETID WANTED_METHODS)

Returns (prints) the list of active methods identified by SETID.
The SETID argument, according to the above, should be filename suffix.

Performs a check if all WANTED_METHODS are available.  WANTED_METHODS is
a space and/or comma separated list of method basenames, e.g. "perl" for
/usr/lib/rpm/perl.req.  The list of WANTED_METHODS is also interpreted
according to AutoReqProv tag rules, i.e. "yes" to enable all methods,
"no" to disable all methods, "noperl" to exclude "perl" etc.

When no methods are active, the output string is guaranteed to be empty.

2)
RunMethods SETID "$methods" [CMD...]

Executes method set scripts identified by SETID; the list of methods
"$methods" must be obtained from SetupMethods.  CMD can warp method script
execution.
This commit is contained in:
Alexey Tourbin 2007-03-06 17:33:08 +03:00
parent c7a5905b8e
commit 844f420037

View File

@ -1,6 +1,7 @@
#!/bin/sh -e
#
# Copyright (C) 2003 Dmitry V. Levin <ldv@altlinux.org>
# Copyright (C) 2007 Alexey Tourbin <at@altlinux.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
@ -57,3 +58,43 @@ ValidateBuildRoot()
[ -z "${RPM_BUILD_ROOT-}" ] || ValidateBuildRoot
readonly RPM_BUILD_ROOT
SetupMethods()
{
local suffix="$1" inm="$2"; shift 2
# do not stat(2) here so as to bypass buildreq
local allm=$(ls /usr/lib/rpm/ |sed -n "/^[^.]/s/[.]$suffix$//p")
[ -n "$allm" ] || Fatal "no $suffix methods available"
allm=$(echo '' $allm '')
local m= outm="$allm"
for m in $(IFS="$IFS,"; echo '' $inm); do
case "$m" in
*[^0-9A-Za-z_-]*)
Fatal "invalid $suffix method name $m"
;;
yes|auto|all)
outm=$allm
;;
no|none|off|false|skip)
outm=
;;
no*)
m=${m#no}
outm=$(echo "$outm" |sed "s/ $m / /g")
;;
*)
[ -z "${allm##* $m *}" ] || Fatal "$suffix method $m not available"
[ -n "$outm" -a -z "${outm##* $m *}" ] || outm=" $outm $m "
;;
esac
done
echo $outm |tr ' ' ','
}
RunMethods()
{
local m_m= m_suffix="$1" m_inm="$2"; shift 2
for m_m in $(IFS="$IFS,"; echo $m_inm); do
${1+"$@"} /usr/lib/rpm/"$m_m.$m_suffix"
done
}