libspec.lib: rework rpmvars.init() in order to support rpm macro expressions
Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>
This commit is contained in:
parent
e2514c2fac
commit
e642fb425e
@ -1,5 +1,5 @@
|
|||||||
Changes in version 1.8.3
|
Changes in version 1.9.0
|
||||||
... ... .. .... Davide Madrisan <davide.madrisan(a)gmail.com>
|
Sun Jan 15 2012 Davide Madrisan <davide.madrisan(a)gmail.com>
|
||||||
|
|
||||||
+ update
|
+ update
|
||||||
* templates/kde4 - Davide Madrisan:
|
* templates/kde4 - Davide Madrisan:
|
||||||
@ -33,6 +33,11 @@ Changes in version 1.8.3
|
|||||||
po/it/test02_pkgsecurity.po - Davide Madrisan:
|
po/it/test02_pkgsecurity.po - Davide Madrisan:
|
||||||
Updated.
|
Updated.
|
||||||
|
|
||||||
|
* libspec.lib - Davide Madrisan:
|
||||||
|
Rework rpmvars.init() in order to support rpm macro expressions.
|
||||||
|
(Feature asked ages ago by Silvan Calarco...)
|
||||||
|
Modify debug output to get it more readable.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
Changes in version 1.8.2
|
Changes in version 1.8.2
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
# libspec.lib -- @package@ library to manage rpm specfiles
|
# libspec.lib -- @package@ library to manage rpm specfiles
|
||||||
# Copyright (C) 2004-2010 Davide Madrisan <davide.madrisan@gmail.com>
|
# Copyright (C) 2004-2010,2012 Davide Madrisan <davide.madrisan@gmail.com>
|
||||||
|
|
||||||
[ -z "$BASH" ] || [ ${BASH_VERSION:0:1} -lt 2 ] &&
|
[ -z "$BASH" ] || [ ${BASH_VERSION:0:1} -lt 2 ] &&
|
||||||
echo $"this script requires bash version 2 or better" >&2 && exit 1
|
echo $"this script requires bash version 2 or better" >&2 && exit 1
|
||||||
@ -369,7 +369,7 @@ $FUNCNAME: "$"FIXME: sorry, not implemented yet..."" (\`%{!?<VAR>:<DEFVALUE>')"
|
|||||||
|
|
||||||
# [1] variable expansion using user `--define' values
|
# [1] variable expansion using user `--define' values
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: * variable expansion using user \`--define' values..."
|
$FUNCNAME: [1] variable expansion using user's \`--define' values..."
|
||||||
local define_applied
|
local define_applied
|
||||||
for i in `seq 0 1 $(( ${#define_list_name[*]} - 1 ))`; do
|
for i in `seq 0 1 $(( ${#define_list_name[*]} - 1 ))`; do
|
||||||
let "define_applied = 0"
|
let "define_applied = 0"
|
||||||
@ -379,9 +379,9 @@ $FUNCNAME: * variable expansion using user \`--define' values..."
|
|||||||
let "define_applied = 1"
|
let "define_applied = 1"
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: ${rpmvar_name[$j]} = \"${define_list_value[$i]}\" (forced by user)"
|
$FUNCNAME: ${rpmvar_name[$j]} = \"${define_list_value[$i]}\" (forced by user)"
|
||||||
# FIXME : advanced users may --define variables by
|
# FIXME : advanced users may --define variables by using
|
||||||
# expressions, but for now expression are not supported by
|
# expressions, but for now expressions are unsupported by
|
||||||
# autospec, so we force '0' value
|
# autospec, so we set 'rpmvar_expr' to '0'
|
||||||
rpmvar_expr[$j]="0"; }
|
rpmvar_expr[$j]="0"; }
|
||||||
done
|
done
|
||||||
if [[ "$define_applied" = "0" ]]; then
|
if [[ "$define_applied" = "0" ]]; then
|
||||||
@ -393,22 +393,19 @@ $FUNCNAME: added not existing user defined variable \`%${define_list_name[$i]}'"
|
|||||||
rpmvar_expr[${#rpmvar_expr[*]}]="0"
|
rpmvar_expr[${#rpmvar_expr[*]}]="0"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
notify.debug "$FUNCNAME: [1] rpmvar_name[], rpmvar_value[]"
|
||||||
|
for i in `seq 0 1 $(( ${#rpmvar_name[*]} - 1 ))`; do
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: [1] rpmvar_name = [ \
|
$FUNCNAME: \"%${rpmvar_name[$i]}\", \"${rpmvar_value[$i]}\""
|
||||||
$(for i in `seq 0 1 $(( ${#rpmvar_name[*]} - 1 ))`; do
|
done
|
||||||
echo -n "\"%${rpmvar_name[$i]}\" "; done)]"
|
|
||||||
notify.debug "\
|
|
||||||
$FUNCNAME: [1] rpmvar_value = [ \
|
|
||||||
$(for i in `seq 0 1 $(( ${#rpmvar_value[*]} - 1 ))`; do
|
|
||||||
echo -n "\"${rpmvar_value[$i]}\" "; done)]"
|
|
||||||
|
|
||||||
# [2] variable expansion using 'rpmvar_value[]'
|
# [2] variable expansion using 'rpmvar_value[]'
|
||||||
local tmpvar tmpval
|
local tmpvar tmpval
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: * variable expansion using user \`rpmvar_value[]'..."
|
$FUNCNAME: [2] variable expansion using user \`rpmvar_value[]'..."
|
||||||
for i in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
for i in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
||||||
for j in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
for j in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
||||||
# do not expand one variable with itself
|
# never expand a variable with itself
|
||||||
[[ $i -eq $j ]] && continue
|
[[ $i -eq $j ]] && continue
|
||||||
|
|
||||||
# use 'pck_newver' if defined
|
# use 'pck_newver' if defined
|
||||||
@ -418,13 +415,9 @@ $FUNCNAME: * variable expansion using user \`rpmvar_value[]'..."
|
|||||||
echo ${rpmvar_value[$i]} | sed "s#%[{]*version[}]*#$pck_newver#g")"
|
echo ${rpmvar_value[$i]} | sed "s#%[{]*version[}]*#$pck_newver#g")"
|
||||||
continue; } ;;
|
continue; } ;;
|
||||||
esac
|
esac
|
||||||
# NOTE: old code
|
|
||||||
# rpmvar_value[$i]="$(\
|
|
||||||
#echo ${rpmvar_value[$i]} | sed "\
|
|
||||||
#s#%[{]*[?]*${rpmvar_name[$j]}[}]*#${rpmvar_value[$j]}#g")"
|
|
||||||
tmpvar="${rpmvar_name[$j]}"; tmpvalue="${rpmvar_value[$j]}"
|
tmpvar="${rpmvar_name[$j]}"; tmpvalue="${rpmvar_value[$j]}"
|
||||||
notify.debug "\
|
# notify.debug "\
|
||||||
$FUNCNAME: * \`${rpmvar_value[$i]}' : \`$tmpvar' --> \`$tmpvalue'..."
|
#$FUNCNAME: * \`${rpmvar_value[$i]}' : \`$tmpvar' --> \`$tmpvalue'..."
|
||||||
rpmvar_value[$i]="$(\
|
rpmvar_value[$i]="$(\
|
||||||
echo ${rpmvar_value[$i]} | sed -n "\
|
echo ${rpmvar_value[$i]} | sed -n "\
|
||||||
/%{?$tmpvar:%$tmpvar.*}/{s#%{?$tmpvar:%$tmpvar\(.*\)}#$tmpvalue\1#gp;q};
|
/%{?$tmpvar:%$tmpvar.*}/{s#%{?$tmpvar:%$tmpvar\(.*\)}#$tmpvalue\1#gp;q};
|
||||||
@ -434,36 +427,64 @@ echo ${rpmvar_value[$i]} | sed -n "\
|
|||||||
p")"
|
p")"
|
||||||
done
|
done
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: result: \`${rpmvar_value[$i]}'"
|
$FUNCNAME: * ${rpmvar_name[$i]} --> ${rpmvar_value[$i]}"
|
||||||
done
|
done
|
||||||
|
notify.debug "$FUNCNAME: [2] rpmvar_name[], rpmvar_value[]"
|
||||||
|
for i in `seq 0 1 $(( ${#rpmvar_name[*]} - 1 ))`; do
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: [2] rpmvar_name = [ \
|
$FUNCNAME: \"%${rpmvar_name[$i]}\", \"${rpmvar_value[$i]}\""
|
||||||
$(for i in `seq 0 1 $(( ${#rpmvar_name[*]} - 1 ))`; do
|
done
|
||||||
echo -n "\"%${rpmvar_name[$i]}\" "; done)]"
|
|
||||||
notify.debug "\
|
local rpmvar_value_unexpanded
|
||||||
$FUNCNAME: [2] rpmvar_value = [ \
|
|
||||||
$(for i in `seq 0 1 $(( ${#rpmvar_value[*]} - 1 ))`; do
|
|
||||||
echo -n "\"${rpmvar_value[$i]}\" "; done)]"
|
|
||||||
|
|
||||||
# [3] expand rpm variables using 'rpm --eval=<rpm_var>'
|
# [3] expand rpm variables using 'rpm --eval=<rpm_var>'
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: * variable expansion using \`rpm --eval=<rpm_var>'..."
|
$FUNCNAME: [3] variable expansion using \`rpm --eval=<rpm_var>'..."
|
||||||
local rpmvar_value_unexpanded
|
|
||||||
for i in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
for i in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
||||||
case "${rpmvar_value[$i]}" in
|
case "${rpmvar_value[$i]}" in
|
||||||
%*) rpmvar_value_unexpanded="${rpmvar_value[$i]}"
|
%*) rpmvar_value_unexpanded="${rpmvar_value[$i]}"
|
||||||
rpmvar_value[$i]=$(\
|
rpmvar_value[$i]=$(\
|
||||||
rpm --eval="${rpmvar_value[$i]}" 2>/dev/null) ;;
|
rpm --eval="${rpmvar_value[$i]}" 2>/dev/null)
|
||||||
|
notify.debug "\
|
||||||
|
$FUNCNAME: * rpm --eval=\"$rpmvar_value_unexpanded\"\
|
||||||
|
--> ${rpmvar_value[$i]}" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
notify.debug "$FUNCNAME: [3] rpmvar_name[], rpmvar_value[]"
|
||||||
|
for i in `seq 0 1 $(( ${#rpmvar_name[*]} - 1 ))`; do
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: [3] rpmvar_name = [ \
|
$FUNCNAME: \"%${rpmvar_name[$i]}\", \"${rpmvar_value[$i]}\""
|
||||||
$(for i in `seq 0 1 $(( ${#rpmvar_name[*]} - 1 ))`; do
|
done
|
||||||
echo -n "\"%${rpmvar_name[$i]}\" "; done)]"
|
|
||||||
|
# [4] expand rpm variables using 'eval'
|
||||||
notify.debug "\
|
notify.debug "\
|
||||||
$FUNCNAME: [3] rpmvar_value = [ \
|
$FUNCNAME: [4] variable expansion using \`eval'..."
|
||||||
$(for i in `seq 0 1 $(( ${#rpmvar_value[*]} - 1 ))`; do
|
for i in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
||||||
echo -n "\"${rpmvar_value[$i]}\" "; done)]"
|
[ "${rpmvar_expr[$i]}" = "1" ] || continue
|
||||||
|
|
||||||
|
# FIXME : the eval command could lead to security issues!
|
||||||
|
# ex. %define foo %(rm -f <a_writable_file>)
|
||||||
|
# it's also a problem for rpm itself (at least for rpm 4.0.4)
|
||||||
|
eval "${rpmvar_value[$i]}" &>/dev/null
|
||||||
|
# note: %define BUILD_CC ccache gcc33
|
||||||
|
# --> eval "ccache gcc33" --> $? == 1
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
tmpvalue="$(eval "${rpmvar_value[$i]}" 2>/dev/null)"
|
||||||
|
notify.debug "\
|
||||||
|
$FUNCNAME: * eval \"${rpmvar_value[$i]}\" --> $tmpvalue"
|
||||||
|
rpmvar_value[$i]="$tmpvalue"
|
||||||
|
# we assume all the expressions are now evaluated
|
||||||
|
rpmvar_expr[$i]="0"
|
||||||
|
else
|
||||||
|
notify.warning $"\
|
||||||
|
cannot evaluate:"" \"${rpmvar_value[$i]}\""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
notify.debug "$FUNCNAME: [4] rpmvar_name[], rpmvar_value[]"
|
||||||
|
for i in `seq 0 1 $(( ${#rpmvar_name[*]} - 1 ))`; do
|
||||||
|
notify.debug "\
|
||||||
|
$FUNCNAME: \"%${rpmvar_name[$i]}\", \"${rpmvar_value[$i]}\""
|
||||||
|
done
|
||||||
|
|
||||||
for i in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
for i in $( seq 0 1 $(( ${#rpmvar_name[*]} - 1 )) ); do
|
||||||
# note: we strip the '"' chars from 'rpmvar_value' because
|
# note: we strip the '"' chars from 'rpmvar_value' because
|
||||||
@ -475,18 +496,6 @@ echo -n "\"${rpmvar_value[$i]}\" "; done)]"
|
|||||||
rpmvar_name[$i]=\"${rpmvar_name[$i]}\"
|
rpmvar_name[$i]=\"${rpmvar_name[$i]}\"
|
||||||
rpmvar_value[$i]=\"${rpmvar_value[$i]//\"/}\"
|
rpmvar_value[$i]=\"${rpmvar_value[$i]//\"/}\"
|
||||||
rpmvar_expr[$i]=\"${rpmvar_expr[$i]}\"" >> ${infofile:-/dev/null} # `
|
rpmvar_expr[$i]=\"${rpmvar_expr[$i]}\"" >> ${infofile:-/dev/null} # `
|
||||||
|
|
||||||
if [[ "${rpmvar_expr[$i]}" = "1" ]]; then
|
|
||||||
notify.debug "$FUNCNAME: eval \"${rpmvar_value[$i]}\""
|
|
||||||
# FIXME : the eval command could lead to security issues!
|
|
||||||
# ex. %define foo %(rm -f <a_file_in_HOME_dir>)
|
|
||||||
# it's also a problem for rpm itself (at least for rpm 4.0.4)
|
|
||||||
eval "${rpmvar_value[$i]}" &>/dev/null
|
|
||||||
# note: %define BUILD_CC ccache gcc33
|
|
||||||
# --> eval "ccache gcc33" --> $? == 1
|
|
||||||
[[ $? -eq 0 ]] || notify.warning $"\
|
|
||||||
cannot evaluate:"" \"${rpmvar_value[$i]}\""
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user