2011-04-26 21:39:44 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# config-getvar -- plugin for @package@
|
2012-11-08 20:33:11 +01:00
|
|
|
# Copyright (C) 2007,2008,2010-2012 Davide Madrisan <davide.madrisan@gmail.com>
|
2011-04-26 21:39:44 +02:00
|
|
|
|
|
|
|
[ -z "$BASH" ] || [ ${BASH_VERSION:0:1} -lt 3 ] &&
|
|
|
|
{ echo $"this script requires bash version 3 or better" >&2 && exit 1; }
|
|
|
|
|
|
|
|
me=(${0##*/} "@version@" "@date@")
|
|
|
|
|
|
|
|
[ -r @libdir@/libmsgmng.lib ] ||
|
|
|
|
{ echo "$me: "$"library not found"": @libdir@/libmsgmng.lib" 1>&2
|
|
|
|
exit 1; }
|
|
|
|
. @libdir@/libmsgmng.lib
|
|
|
|
|
|
|
|
# default values:
|
|
|
|
# - output verbosity
|
|
|
|
let "verbose = 1"
|
|
|
|
|
|
|
|
# load the configuration file(s)
|
|
|
|
[ -r @libdir@/libcfg.lib ] ||
|
|
|
|
{ echo "$me: "$"library not found"": @libdir@/libcfg.lib" 1>&2
|
|
|
|
exit 1; }
|
|
|
|
. @libdir@/libcfg.lib
|
|
|
|
|
|
|
|
if [[ -z "$LANG" && -r /etc/sysconfig/i18n ]]; then
|
|
|
|
. /etc/sysconfig/i18n
|
|
|
|
[ "$LANG" ] && export LANG
|
|
|
|
fi
|
2012-11-25 15:54:34 +01:00
|
|
|
TEXTDOMAIN="@package@"; export TEXTDOMAIN
|
2011-04-26 21:39:44 +02:00
|
|
|
|
|
|
|
function copying() {
|
|
|
|
echo "\
|
|
|
|
"$"This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License version 2 as published by the
|
|
|
|
Free Software Foundation. There is NO warranty; not even for MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE."
|
|
|
|
}
|
|
|
|
|
|
|
|
function version() {
|
|
|
|
echo "\
|
|
|
|
${me[0]} ${me[1]}
|
|
|
|
Copyright (C) 2004-2008,2010,2011 Davide Madrisan <davide.madrisan@gmail.com>"
|
|
|
|
}
|
|
|
|
|
|
|
|
# $1: optional exit code (default is '1')
|
|
|
|
function usage() {
|
|
|
|
version
|
|
|
|
echo "\
|
|
|
|
"$"Print the value of a given configuration variable"".
|
|
|
|
|
|
|
|
"$"Usage"":
|
|
|
|
@frontend@ [-C <conf_file>] --eval=<var>
|
|
|
|
|
|
|
|
"$"where the above options mean"":
|
2012-11-14 22:42:08 +01:00
|
|
|
--eval "$"Print the value of the configuration variable <var>""
|
|
|
|
--colors "$"Select the theme to be used for the colorized output""
|
|
|
|
-C, --config "$"Use an alternate user configuration file"" <conf_file>""
|
|
|
|
"$"Default files:"" $default_cfg_strlist""
|
|
|
|
"$"Default user files:"" $default_cfg_user_strlist""
|
2011-04-26 21:39:44 +02:00
|
|
|
|
|
|
|
"$"Operation modes"":
|
2012-11-14 22:42:08 +01:00
|
|
|
-h, --help "$"Print this help, then exit""
|
|
|
|
-V, --version "$"Print version number, then exit""
|
|
|
|
-q, --quiet "$"Run in quiet mode""
|
|
|
|
-D, --debug "$"Run in debugging mode (very verbose output)""
|
2011-04-26 21:39:44 +02:00
|
|
|
|
|
|
|
"$"Samples"":
|
2012-11-14 22:42:08 +01:00
|
|
|
@frontend@ -q -C ${default_cfg_list[0]} --eval=\"logging_dir\"
|
2011-04-26 21:39:44 +02:00
|
|
|
|
|
|
|
"$"Report bugs to <davide.madrisan@gmail.com>."
|
|
|
|
|
|
|
|
exit ${1:-1}
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
--autospec-args-file*)
|
|
|
|
if [[ "$1" =~ = ]]; then
|
|
|
|
argsfile=`echo $1 | sed 's/^--autospec-args-file=//'`
|
|
|
|
else
|
|
|
|
argsfile=$2
|
|
|
|
fi
|
|
|
|
[ -r "$argsfile" ] || notify.error $"cannot read"": \`$argsfile'"
|
|
|
|
. $argsfile && rm -f $argsfile
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
for arg in $@; do
|
|
|
|
case $arg in
|
|
|
|
-h|--help) usage 0 ;;
|
|
|
|
-V|--version) version; echo; copying; exit 0 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2012-01-02 21:16:48 +01:00
|
|
|
exec_options=`LC_ALL=C getopt \
|
2011-04-26 21:39:44 +02:00
|
|
|
-o C:DqrhV \
|
|
|
|
--long eval:,config:,\
|
2012-11-11 18:56:52 +01:00
|
|
|
debug,quiet,colors:,help,version,\
|
2011-04-26 21:39:44 +02:00
|
|
|
frontend_opts: \
|
|
|
|
-n "$me" -- "$@"`
|
|
|
|
[ $? = 0 ] || exit 1
|
|
|
|
|
|
|
|
notify.debug "[ ${0} ${exec_options} ]\n"
|
|
|
|
eval set -- "$exec_options"
|
|
|
|
|
|
|
|
while :; do
|
|
|
|
case $1 in
|
|
|
|
--eval)
|
|
|
|
autospecvar="$2"; shift ;;
|
2012-11-14 22:42:08 +01:00
|
|
|
--colors)
|
|
|
|
color_scheme="$2"; shift ;;
|
|
|
|
-C|--config)
|
|
|
|
cfg_file=$2; shift ;;
|
2011-04-26 21:39:44 +02:00
|
|
|
-D|--debug)
|
|
|
|
let "verbose = 2" ;;
|
|
|
|
-q|--quiet)
|
|
|
|
let "verbose = 0" ;;
|
|
|
|
-h|--help)
|
|
|
|
usage 0 ;;
|
|
|
|
-V|--version)
|
|
|
|
version; echo; copying; exit 0 ;;
|
|
|
|
--) shift; break ;;
|
|
|
|
*) notify.error $"unrecognized option"" -- \`$1'" ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
for arg in $@; do
|
|
|
|
[[ -z "$s_rpm_pck" ]] && s_rpm_pck=$arg ||
|
|
|
|
notify.error $"unrecognized option"" -- \`$arg'"
|
|
|
|
done
|
|
|
|
|
2012-11-11 18:56:52 +01:00
|
|
|
notify.enable_colors "$color_scheme"
|
2011-04-26 21:39:44 +02:00
|
|
|
|
|
|
|
# config.getvar()
|
|
|
|
# Parameters:
|
|
|
|
# $1 : the configuration file where to look at
|
|
|
|
# $2 : the configuration variable to expand
|
|
|
|
# Description:
|
|
|
|
# Expand the configuration variable `$2' looking in the file `$1'
|
|
|
|
function config.getvar() {
|
|
|
|
notify.debug "[ ${0}${exec_options} ]\n"
|
|
|
|
|
|
|
|
local cfg_file="$1"
|
|
|
|
local autospecvar="$2"
|
|
|
|
local cfg_file_lst
|
|
|
|
|
|
|
|
if [ "$cfg_file" ]; then
|
2012-11-15 22:55:31 +01:00
|
|
|
for f in $(ls $cfg_file 2>/dev/null); do
|
|
|
|
[ -r "$f" ] ||
|
|
|
|
notify.error $"configuration file not found"" -- \`$f'"
|
|
|
|
done
|
|
|
|
cfg_file_lst="$(ls $cfg_file 2>/dev/null)"
|
2011-04-26 21:39:44 +02:00
|
|
|
else
|
2012-11-14 22:42:08 +01:00
|
|
|
cfg_file_lst="${default_cfg_list[*]}"
|
2011-04-26 21:39:44 +02:00
|
|
|
fi
|
|
|
|
notify.debug "cfg_file_lst = \"$cfg_file_lst\""
|
|
|
|
|
|
|
|
unset value autospecvar_val autospecvar_file autospecvar_sed
|
|
|
|
autospecvar_sed=$(\
|
|
|
|
echo "$autospecvar" | sed 's,\[,\\[,g;s,\],\\],g')
|
|
|
|
|
|
|
|
for f in $cfg_file_lst; do
|
|
|
|
[ -r $f ] || continue
|
|
|
|
|
|
|
|
confvar_1stline=$(\
|
|
|
|
sed -n "/^[ \t]*$autospecvar_sed[[]*[0-9]*[]]*=/p" $f)
|
|
|
|
if [[ "$confvar_1stline" ]]; then
|
|
|
|
autospecvar_file="$f"
|
|
|
|
notify.debug "variable \`$autospecvar' found in \`$f'"
|
|
|
|
notify.debug "confvar_1stline = \`$confvar_1stline'"
|
|
|
|
|
|
|
|
[ "$verbose" = 0 ] || notify.note "#[$autospecvar_file]"
|
|
|
|
|
|
|
|
confvar_1stline=$(\
|
|
|
|
sed -n "/^[ \t]*$autospecvar_sed[[]*[0-9]*[]]*=/p" $autospecvar_file)
|
|
|
|
notify.debug "confvar_1stline = \`$confvar_1stline'"
|
|
|
|
|
|
|
|
case "$confvar_1stline" in
|
|
|
|
*[\[0-9*\]]=*)
|
|
|
|
# an entry like: ftp_rw_srpms_dir[0]="/devel/SRPMS"
|
|
|
|
case "$autospecvar" in
|
|
|
|
*[\[0-9*\]])
|
|
|
|
sed -n "/^$autospecvar_sed=/{s|.*|&;|p}" \
|
|
|
|
$autospecvar_file |
|
|
|
|
while read line; do notify.note "$line"; done
|
|
|
|
;;
|
|
|
|
*) sed -n "/^$autospecvar_sed\[[0-9*]\]=/{s|.*|&;|p}" \
|
|
|
|
$autospecvar_file |
|
|
|
|
while read line; do notify.note "$line"; done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*=\"*\"|*=%*|*=[0-9a-zA-Z]*|*=\$*|*=\(*\))
|
|
|
|
# entries like:
|
|
|
|
# - rpm_macro_make="%make"
|
|
|
|
# - rpm_macro_make=%make
|
|
|
|
# - ftp_rw_rpms_dir[0]="/devel/RPMS"
|
|
|
|
# - arch_list="i586 ppc"
|
|
|
|
notify.note "${confvar_1stline};"
|
|
|
|
;;
|
|
|
|
*=\(*)
|
|
|
|
# a variable like:
|
|
|
|
# rpm_approved_licenses=(\
|
|
|
|
# ... <list of entries, one per line>
|
|
|
|
sed -e '/./{H;$!d;}' -e "x;/$autospecvar_sed=(/!d;" \
|
|
|
|
$autospecvar_file |
|
|
|
|
while read line; do
|
|
|
|
case "$line" in
|
|
|
|
\#*|"") ;;
|
|
|
|
*\)) notify.note "${line};" ;;
|
|
|
|
*) notify.note "$line" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*=\"\\)
|
|
|
|
# a variable like:
|
|
|
|
# format_extra_rules="\
|
|
|
|
sed -e '/./{H;$!d;}' -e "x;/$autospecvar_sed=\"/!d;" \
|
|
|
|
$autospecvar_file |
|
|
|
|
while read line; do
|
|
|
|
case "$line" in
|
|
|
|
\#*|"") ;;
|
|
|
|
*\") notify.note "${line};" ;;
|
|
|
|
*) notify.note "$line" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*) notify.error $"(bug)"" -- $FUNCNAME: "$"unknown variable type"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
config.getvar "$cfg_file" "$autospecvar"
|