function.sh: Allow multiple template directories to be searched

Return all and run matches instead of only one which allows flavors
like salt to have multiple optional modules like mgmt-salt-dev to
run installation scripts in template subdirectories.
pull/1/head jm_b61fdaf8
Jason Mehring 9 years ago
parent 621a21a528
commit b61fdaf843

@ -189,8 +189,9 @@ splitPath() {
setArrayAsGlobal PARTS $return_global_var
}
templateDir() {
templateDirs() {
local template_flavor=${1-${TEMPLATE_FLAVOR}}
local match=0
# If TEMPLATE_FLAVOR_DIR is not already an array, make it one
if ! [[ "$(declare -p TEMPLATE_FLAVOR_DIR 2>/dev/null)" =~ ^declare\ -a.* ]] ; then
@ -202,14 +203,19 @@ templateDir() {
# (wheezy+whonix-gateway / wheezy+whonix-gateway+gnome[+++] / wheezy+gnome )
if [ "${element%:*}" == "$(templateName ${template_flavor})" ]; then
eval echo -e "${element#*:}"
return
match=1
# Very short name compare (+proxy)
elif [ "${element:0:1}" == "+" -a "${element%:*}" == "+${template_flavor}" ]; then
eval echo -e "${element#*:}"
return
match=1
fi
done
if [ "${match}" -eq 1 ]; then
return
fi
local template_flavor_prefix="$(templateFlavorPrefix ${template_flavor})"
if [ -n "${template_flavor}" -a "${template_flavor}" == "+" ]; then
local dir="${SCRIPTSDIR}/${template_flavor_prefix}"
@ -241,10 +247,11 @@ templateFile() {
local file="$1"
local suffix="$2"
local template_flavor="$3"
local template_dir="$(templateDir "${template_flavor}")"
local template_dirs="$(templateDirs "${template_flavor}")"
splitPath "${file}" path_parts
for template_dir in ${template_dirs[@]}; do
# No template flavor
if [ -z "${template_flavor}" ]; then
if [ "${suffix}" ]; then
@ -290,6 +297,7 @@ templateFile() {
# (SCRIPTSDIR/packages_qubes_minimal.list)
exists "${SCRIPTSDIR}/${path_parts[base]}_${template_flavor}${path_parts[dotext]}" || true
fi
done
}
copyTreeExec() {
@ -298,7 +306,9 @@ copyTreeExec() {
local template_flavor="$3"
local target_dir="$4"
local template_dir="$(templateDir ${template_flavor})"
local template_dirs="$(templateDirs ${template_flavor})"
for template_dir in ${template_dirs[@]}; do
local source_dir="$(readlink -m ${source_dir:-${template_dir}}/${dir})"
local target_dir="$(readlink -m ${target_dir:-${INSTALLDIR}})"
@ -319,6 +329,7 @@ copyTreeExec() {
}
popd
fi
done
}
callTemplateFunction() {

Loading…
Cancel
Save