ac29fd993a
This function provides "standard calling conventions" for req/prov methods. The idea is that the shell script which implements a req/prov method need not know how exactly it was called and how it should process its arguments. Instead, it should impelment a function which takes exactly one argument, which is filename, say MyReq, and finally just call ArgvFileAction MyReq "$@" Standard input to argv conversion is then done automatically and transparently. This will also enable scripts to process real argv arguments, if any, instead of standard input (but fall back to standard input otherwise). I also added --help and -v|--verbose options. Surprisingly enough, the latter increases RPM_SCRIPTS_DEBUG level. Also added non-intrusive canonicalization of pathnames, hence the name ArgvFileAction. This is not going to affect rpm-build, but hopefully this can help when the script is invoked manually.
142 lines
3.2 KiB
Bash
142 lines
3.2 KiB
Bash
#!/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
|
|
# 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
|
|
#
|
|
|
|
unset CDPATH ||:
|
|
PROG="${0##*/}"
|
|
|
|
case "${RPM_SCRIPTS_DEBUG:-0}" in
|
|
0) unset RPM_SCRIPTS_DEBUG ||: ;;
|
|
1|2) ;;
|
|
*) RPM_SCRIPTS_DEBUG=3; set -x ;;
|
|
esac
|
|
|
|
Info()
|
|
{
|
|
echo "${0##*/}: $*" >&2
|
|
}
|
|
|
|
Fatal()
|
|
{
|
|
echo "${0##*/}: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
Verbose()
|
|
{
|
|
[ "${RPM_SCRIPTS_DEBUG:-0}" -ge 1 ] || return 0
|
|
echo "${0##*/}: $*" >&2
|
|
}
|
|
|
|
Debug()
|
|
{
|
|
[ "${RPM_SCRIPTS_DEBUG:-0}" -ge 2 ] || return 0
|
|
echo "${0##*/}: $*" >&2
|
|
}
|
|
|
|
ValidateBuildRoot()
|
|
{
|
|
[ -n "$(printf %s "$RPM_BUILD_ROOT" |tr -d ' /.')" ] ||
|
|
Fatal "invalid \$RPM_BUILD_ROOT"
|
|
}
|
|
|
|
[ -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
|
|
}
|
|
|
|
ArgvFileAction()
|
|
{
|
|
local av_action="$1"; shift
|
|
|
|
if [ $# -gt 0 ]; then
|
|
local av_argv=
|
|
av_argv=$(getopt -n "$PROG" -o v -l help,verbose -- "$@")
|
|
eval set -- "$av_argv"
|
|
while :; do
|
|
case "$1" in
|
|
--help) type Usage >/dev/null 2>&1 && Usage 0 ||
|
|
echo "Usage: $PROG [-v|--verbose] [FILE...]"
|
|
exit 0 ;;
|
|
-v|--verbose)
|
|
export RPM_SCRIPTS_DEBUG=$((${RPM_SCRIPTS_DEBUG:-0}+1))
|
|
shift ;;
|
|
--) shift
|
|
break ;;
|
|
*) Fatal "unrecognized option: $1"
|
|
esac
|
|
done
|
|
[ "${RPM_SCRIPTS_DEBUG:-0}" -lt 3 ] || set -x
|
|
fi
|
|
|
|
local av_f
|
|
if [ $# -gt 0 ]; then
|
|
for av_f; do
|
|
[ -n "$av_f" -a -z "${av_f##/*}" ] || av_f=$(readlink -vm -- "$av_f")
|
|
Debug "processing $av_f"
|
|
"$av_action" "$av_f"
|
|
done
|
|
else
|
|
[ -t 0 ] && Info "reading file list from standard input"
|
|
while IFS= read -r av_f; do
|
|
[ -n "$av_f" -a -z "${av_f##/*}" ] || av_f=$(readlink -vm -- "$av_f")
|
|
Debug "processing $av_f"
|
|
"$av_action" "$av_f"
|
|
done
|
|
fi
|
|
}
|