From e586bc1a2facb12f5beb14afa5223e2027c64287 Mon Sep 17 00:00:00 2001 From: Jason Mehring Date: Sun, 26 Oct 2014 23:55:21 -0400 Subject: [PATCH] Fixed some issues with Makefile TEMPLATE_* vars that were expected to be arrays or easily importable as one --- functions.sh | 26 +++++++++++++++++++++++--- tests/template-flavors/test.sh | 7 +++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/functions.sh b/functions.sh index c579c87..cf02873 100755 --- a/functions.sh +++ b/functions.sh @@ -146,6 +146,12 @@ templateFlavor() { templateFlavorPrefix() { local template_flavor=${1-$(templateFlavor)} + + # If TEMPLATE_FLAVOR_PREFIX is not already an array, make it one + if ! [[ "$(declare -p TEMPLATE_FLAVOR_PREFIX 2>/dev/null)" =~ ^declare\ -a.* ]] ; then + TEMPLATE_FLAVOR_PREFIX=( ${TEMPLATE_FLAVOR_PREFIX} ) + fi + for element in "${TEMPLATE_FLAVOR_PREFIX[@]}" do if [ "${element%:*}" == "${DIST}+${template_flavor}" ]; then @@ -188,8 +194,11 @@ templateName() { local template_name="$(templateFlavorPrefix ${template_flavor})${template_flavor}${template_options:++}${template_options}" - # Make sure TEMPLATE_LABEL is an array - TEMPLATE_LABEL=( ${TEMPLATE_LABEL} ) + # If TEMPLATE_LABEL is not already an array, make it one + if ! [[ "$(declare -p TEMPLATE_LABEL 2>/dev/null)" =~ ^declare\ -a.* ]] ; then + TEMPLATE_LABEL=( ${TEMPLATE_LABEL} ) + fi + for element in "${TEMPLATE_LABEL[@]}"; do if [ "${element%:*}" == "${template_name}" ]; then template_name="${element#*:}" @@ -212,6 +221,11 @@ templateName() { templateDir() { local template_flavor=${1-$(templateFlavor)} + # If TEMPLATE_FLAVOR_DIR is not already an array, make it one + if ! [[ "$(declare -p TEMPLATE_FLAVOR_DIR 2>/dev/null)" =~ ^declare\ -a.* ]] ; then + TEMPLATE_FLAVOR_DIR=( ${TEMPLATE_FLAVOR_DIR} ) + fi + for element in "${TEMPLATE_FLAVOR_DIR[@]}" do # (wheezy+whonix-gateway / wheezy+whonix-gateway+gnome[+++] / wheezy+gnome ) @@ -332,8 +346,14 @@ getFileLocations() { local function="templateFile" + #IFS_orig="${IFS}}"; IFS=$'\n' + #files=( $(callTemplateFunction "${filename}" "${suffix}" "${function}") ) + #setArrayAsGlobal files $return_global_var + + files=$(callTemplateFunction "${filename}" "${suffix}" "${function}") + IFS_orig="${IFS}}"; IFS=$'\n' - files=( $(callTemplateFunction "${filename}" "${suffix}" "${function}") ) + files=( "${files}" ) setArrayAsGlobal files $return_global_var IFS="${IFS_orig}" diff --git a/tests/template-flavors/test.sh b/tests/template-flavors/test.sh index 43f8fac..51ad768 100755 --- a/tests/template-flavors/test.sh +++ b/tests/template-flavors/test.sh @@ -233,7 +233,7 @@ DIST="wheezy" DISTS_VM="" TEMPLATE_FLAVOR="whonix-gateway" TEMPLATE_FLAVOR_PREFIX="" -TEMPLATE_FLAVOR_DIR="wheezy+whonix-gateway:tests/template-flavors/another_location/whonix gw" +TEMPLATE_FLAVOR_DIR=("wheezy+whonix-gateway:tests/template-flavors/another_location/whonix gw") TEMPLATE_OPTIONS="" header <