2017-07-08 23:09:15 +00:00
|
|
|
#!/bin/bash --norc
|
|
|
|
|
|
|
|
set -e
|
|
|
|
shopt -s nullglob
|
|
|
|
|
|
|
|
|
|
|
|
nodefault() {
|
|
|
|
# We define a function instead of a variable, as variables could
|
|
|
|
# be predefined in the environment (in theory)
|
|
|
|
eval "gluon_feature_nodefault_$1() {
|
|
|
|
:
|
|
|
|
}"
|
|
|
|
}
|
|
|
|
|
|
|
|
packages() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
for f in package/features packages/*/features; do
|
|
|
|
. "$f"
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Shell variables can't contain minus signs, so we escape them
|
|
|
|
# using underscores (and also escape underscores to avoid mapping
|
|
|
|
# multiple inputs to the same output)
|
|
|
|
sanitize() {
|
|
|
|
local v="$1"
|
|
|
|
v="${v//_/_1}"
|
|
|
|
v="${v//-/_2}"
|
|
|
|
echo -n "$v"
|
|
|
|
}
|
|
|
|
|
2019-09-30 19:38:40 +00:00
|
|
|
vars=()
|
2017-07-08 23:09:15 +00:00
|
|
|
|
|
|
|
for feature in $1; do
|
2019-09-30 19:38:40 +00:00
|
|
|
if [ "$(type -t "gluon_feature_nodefault_${feature}")" != 'function' ]; then
|
2017-07-08 23:09:15 +00:00
|
|
|
echo "gluon-${feature}"
|
|
|
|
fi
|
|
|
|
|
2019-09-30 19:38:40 +00:00
|
|
|
vars+=("$(sanitize "$feature")=1")
|
2017-07-08 23:09:15 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
nodefault() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
2019-09-30 19:38:40 +00:00
|
|
|
# shellcheck disable=SC2086
|
2017-07-08 23:09:15 +00:00
|
|
|
packages() {
|
|
|
|
local cond="$(sanitize "$1")"
|
|
|
|
shift
|
|
|
|
|
|
|
|
# We only allow variable names, parentheses and the operators: & | !
|
2019-09-30 19:38:40 +00:00
|
|
|
if grep -q '[^A-Za-z0-9_()&|! ]' <<< "$cond"; then
|
2017-07-08 23:09:15 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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.
|
2019-09-30 19:38:40 +00:00
|
|
|
local ret="$(env -i "${vars[@]}" bash --norc -ec "let _result_='1+($cond)'; echo -n \"\$_result_\"" 2>/dev/null)"
|
2017-07-08 23:09:15 +00:00
|
|
|
case "$ret" in
|
|
|
|
2)
|
|
|
|
for pkg in "$@"; do
|
|
|
|
echo "$pkg"
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
for f in package/features packages/*/features; do
|
|
|
|
. "$f"
|
|
|
|
done
|