scripts/features.sh: use bash array for parameter parsing to avoid globbing

This commit is contained in:
Jan-Tarek Butt 2019-12-08 23:38:52 +01:00
parent 62a60e4c7a
commit 6dbabad49f

View File

@ -31,14 +31,14 @@ sanitize() {
echo -n "$v" echo -n "$v"
} }
vars= vars=()
for feature in $1; do for feature in $1; do
if [ "$(type -t gluon_feature_nodefault_"${feature}")" != 'function' ]; then if [ "$(type -t gluon_feature_nodefault_"${feature}")" != 'function' ]; then
echo "gluon-${feature}" echo "gluon-${feature}"
fi fi
vars="$vars $(sanitize "$feature")=1" vars+=("$(sanitize "$feature")=1")
done done
@ -46,18 +46,21 @@ nodefault() {
: :
} }
# shellcheck disable=SC2086
packages() { packages() {
local cond="$(sanitize "$1")" local cond="$(sanitize "$1")"
shift shift
# We only allow variable names, parentheses and the operators: & | ! # We only allow variable names, parentheses and the operators: & | !
if grep -q ".*[^A-Za-z0-9_()&|! ].*" <<< "$cond"; then if grep -q '[^A-Za-z0-9_()&|! ]' <<< "$cond"; then
exit 1 exit 1
fi fi
# Let will return false when the result of the passed expression is 0, # Let will return false when the result of the passed expression is 0,
# so we always add 1. This way false is only returned for syntax errors. # so we always add 1. This way false is only returned for syntax errors.
local ret="$(env -i "$vars" bash --norc -ec "let _result_='1+($cond)'; echo -n \"\$_result_\"" 2>/dev/null)" set -A
local ret="$(env -i "${vars[@]}" bash --norc -ec "let _result_='1+($cond)'; echo -n \"\$_result_\"" 2>/dev/null)"
set +A
case "$ret" in case "$ret" in
2) 2)
for pkg in "$@"; do for pkg in "$@"; do