Reworked the way template flavor files are found to allow flavors
- This better allows flavors to be within their own packages such as Whonix The previous method of discovering flavor configurations was kind of broke when using a flavor within a different package and including additional options such as +standard.
This commit is contained in:
parent
c0862ed8ea
commit
87d6284d67
113
functions.sh
113
functions.sh
@ -118,7 +118,7 @@ setXtrace() {
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Only output text under certain conditions
|
# Only output text under certain conditions
|
||||||
output() {
|
output() {
|
||||||
if [ "${VERBOSE}" -ge 1 ]; then
|
if [ "${VERBOSE}" -ge 1 ] && [[ -z ${TEST} ]]; then
|
||||||
# Don't echo if -x is set since it will already be displayed via true
|
# Don't echo if -x is set since it will already be displayed via true
|
||||||
[[ ${-/x} != $- ]] || echo -e ""$@""
|
[[ ${-/x} != $- ]] || echo -e ""$@""
|
||||||
fi
|
fi
|
||||||
@ -246,8 +246,10 @@ templateDir() {
|
|||||||
|
|
||||||
exists() {
|
exists() {
|
||||||
filename="${1}"
|
filename="${1}"
|
||||||
if [ -e "${filename}" ]; then
|
|
||||||
echo "${filename}"
|
if [ -e "${filename}" ] && ! elementIn "${filename}" "${GLOBAL_CACHE[@]}"; then
|
||||||
|
# Cache $script
|
||||||
|
GLOBAL_CACHE["${#GLOBAL_CACHE[@]}"]="${filename}"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
@ -262,61 +264,52 @@ templateFile() {
|
|||||||
splitPath "${file}" path_parts
|
splitPath "${file}" path_parts
|
||||||
|
|
||||||
# No template flavor
|
# No template flavor
|
||||||
if [ "X{template_flavor}" == "X" ]; then
|
if [ -z "${template_flavor}" ]; then
|
||||||
if [ -e "${file}" ]; then
|
if [ "${suffix}" ]; then
|
||||||
echo "${file}"
|
exists "${SCRIPTSDIR}/${path_parts[base]}_${suffix}${path_parts[dotext]}" || true
|
||||||
fi
|
else
|
||||||
|
exists "${SCRIPTSDIR}/${path_parts[base]}${path_parts[dotext]}" || true
|
||||||
|
fi
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Locate file in directory named after flavor
|
# Locate file in directory named after flavor
|
||||||
if [ "${suffix}" ]; then
|
if [ "${suffix}" ]; then
|
||||||
# Append suffix to filename (before extension)
|
# Append suffix to filename (before extension)
|
||||||
|
# `minimal` is the template_flavor being used in comment example
|
||||||
|
|
||||||
# (../SCRIPTSDIR/minimal/packages_qubes_suffix.list)
|
# (TEMPLATE_FLAVOR_DIR/minimal/packages_qubes_suffix.list)
|
||||||
|
exists "${template_dir}/${template_flavor}/${path_parts[base]}_${suffix}${path_parts[dotext]}" || true
|
||||||
|
|
||||||
|
# (TEMPLATE_FLAVOR_DIR/minimal/packages_qubes_suffix.list)
|
||||||
|
exists "${template_dir}/${template_flavor}/${path_parts[base]}_${suffix}${path_parts[dotext]}" || true
|
||||||
|
|
||||||
|
# (TEMPLATE_FLAVOR_DIR/packages_qubes_suffix.list)
|
||||||
exists "${template_dir}/${path_parts[base]}_${suffix}${path_parts[dotext]}" || true
|
exists "${template_dir}/${path_parts[base]}_${suffix}${path_parts[dotext]}" || true
|
||||||
|
|
||||||
# (../SCRIPTSDIR/minimal/packages_qubes_minimal_suffix.list)
|
# (TEMPLATE_FLAVOR_DIR/packages_qubes_minimal_suffix.list)
|
||||||
exists "${template_dir}/${path_parts[base]}_${suffix}_${template_flavor}${path_parts[dotext]}" || true
|
exists "${template_dir}/${path_parts[base]}_${suffix}_${template_flavor}${path_parts[dotext]}" || true
|
||||||
|
|
||||||
# (../SCRIPTSDIR/packages_qubes_minimal_suffix.list)
|
# (SCRIPTSDIR/packages_qubes_minimal_suffix.list)
|
||||||
exists "${SCRIPTSDIR}/${path_parts[base]}_${suffix}_${template_flavor}${path_parts[dotext]}" || true
|
exists "${SCRIPTSDIR}/${path_parts[base]}_${suffix}_${template_flavor}${path_parts[dotext]}" || true
|
||||||
else
|
else
|
||||||
# (../SCRIPTSDIR/minimal/packages_qubes.list)
|
# (TEMPLATE_FLAVOR_DIR/minimal/packages_qubes.list)
|
||||||
|
exists "${template_dir}/${template_flavor}/${path_parts[base]}${path_parts[dotext]}" || true
|
||||||
|
|
||||||
|
# (TEMPLATE_FLAVOR_DIR/minimal/packages_qubes_minimal.list)
|
||||||
|
exists "${template_dir}/${template_flavor}/${path_parts[base]}_${template_flavor}${path_parts[dotext]}" || true
|
||||||
|
|
||||||
|
# (TEMPLATE_FLAVOR_DIR/packages_qubes.list)
|
||||||
exists "${template_dir}/${path_parts[base]}${path_parts[dotext]}" || true
|
exists "${template_dir}/${path_parts[base]}${path_parts[dotext]}" || true
|
||||||
|
|
||||||
# (../SCRIPTSDIR/minimal/packages_qubes_minimal.list)
|
# (TEMPLATE_FLAVOR_DIR/packages_qubes_minimal.list)
|
||||||
exists "${template_dir}/${path_parts[base]}_${template_flavor}${path_parts[dotext]}" || true
|
exists "${template_dir}/${path_parts[base]}_${template_flavor}${path_parts[dotext]}" || true
|
||||||
|
|
||||||
# (../SCRIPTSDIR/packages_qubes_minimal.list)
|
# (SCRIPTSDIR/packages_qubes_minimal.list)
|
||||||
exists "${SCRIPTSDIR}/${path_parts[base]}_${template_flavor}${path_parts[dotext]}" || true
|
exists "${SCRIPTSDIR}/${path_parts[base]}_${template_flavor}${path_parts[dotext]}" || true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
buildStepExec() {
|
|
||||||
local filename="$1"
|
|
||||||
local suffix="$2"
|
|
||||||
local template_flavor="$3"
|
|
||||||
|
|
||||||
script="$(templateFile "${filename}" "${suffix}" "${template_flavor}")"
|
|
||||||
|
|
||||||
if [ -f "${script}" ] && [ ! ${GLOBAL_CACHE[$script]+_} ]; then
|
|
||||||
|
|
||||||
# Test module expects raw output back only used to asser test results
|
|
||||||
if [[ -n ${TEST} ]]; then
|
|
||||||
echo "${script}"
|
|
||||||
else
|
|
||||||
output "${bold}${under}INFO: Currently running script: ${script}${reset}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cache $script
|
|
||||||
GLOBAL_CACHE[$script]=1
|
|
||||||
|
|
||||||
# Execute $script
|
|
||||||
"${script}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
copyTreeExec() {
|
copyTreeExec() {
|
||||||
local source_dir="$1"
|
local source_dir="$1"
|
||||||
local dir="$2"
|
local dir="$2"
|
||||||
@ -347,10 +340,6 @@ copyTreeExec() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
callTemplateFunction() {
|
callTemplateFunction() {
|
||||||
# Reset Cache
|
|
||||||
unset GLOBAL_CACHE
|
|
||||||
declare -A -g GLOBAL_CACHE
|
|
||||||
|
|
||||||
local calling_script="$1"
|
local calling_script="$1"
|
||||||
local calling_arg="$2"
|
local calling_arg="$2"
|
||||||
local functionExec="$3"
|
local functionExec="$3"
|
||||||
@ -404,13 +393,18 @@ getFileLocations() {
|
|||||||
local suffix="$3"
|
local suffix="$3"
|
||||||
local function="templateFile"
|
local function="templateFile"
|
||||||
|
|
||||||
files="$(callTemplateFunction "${filename}" "${suffix}" "${function}")"
|
unset GLOBAL_CACHE
|
||||||
|
declare -A -g GLOBAL_CACHE
|
||||||
|
|
||||||
IFS_orig="${IFS}}"; IFS=$'\n'
|
callTemplateFunction "${filename}" "${suffix}" "${function}"
|
||||||
files=( "${files}" )
|
setArrayAsGlobal GLOBAL_CACHE $return_global_var
|
||||||
setArrayAsGlobal files $return_global_var
|
|
||||||
|
|
||||||
IFS="${IFS_orig}"
|
if [ ! ${#GLOBAL_CACHE[@]} -eq 0 ]; then
|
||||||
|
debug "Smart files located for: '${filename##*/}' (suffix: ${suffix}):"
|
||||||
|
for filename in "${GLOBAL_CACHE[@]}"; do
|
||||||
|
debug "${filename}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -432,9 +426,23 @@ getFileLocations() {
|
|||||||
buildStep() {
|
buildStep() {
|
||||||
local filename="$1"
|
local filename="$1"
|
||||||
local suffix="$2"
|
local suffix="$2"
|
||||||
local function="buildStepExec"
|
|
||||||
|
|
||||||
callTemplateFunction "${filename}" "${suffix}" "${function}"
|
info "Locating buildStep files: ${filename##*/} suffix: ${suffix}"
|
||||||
|
getFileLocations "build_step_files" "${filename}" "${suffix}"
|
||||||
|
|
||||||
|
for script in "${build_step_files[@]}"; do
|
||||||
|
if [ -e "${script}" ]; then
|
||||||
|
# Test module expects raw output back only used to asser test results
|
||||||
|
if [[ -n ${TEST} ]]; then
|
||||||
|
echo "${script}"
|
||||||
|
else
|
||||||
|
output "${bold}${under}INFO: Currently running script: ${script}${reset}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Execute $script
|
||||||
|
"${script}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -460,8 +468,13 @@ copyTree() {
|
|||||||
local target_dir="$3"
|
local target_dir="$3"
|
||||||
local function="copyTreeExec"
|
local function="copyTreeExec"
|
||||||
|
|
||||||
if [ "x${source_dir}" == "x" ]; then
|
if [ -z "${source_dir}" ]; then
|
||||||
callTemplateFunction "" "${dir}" "${function}"
|
splitPath "${0}" path_parts
|
||||||
|
if [ -d "${path_parts[dir]}/${dir}" ]; then
|
||||||
|
copyTreeExec "${path_parts[dir]}" "${dir}" "" ""
|
||||||
|
else
|
||||||
|
callTemplateFunction "" "${dir}" "${function}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
copyTreeExec "${source_dir}" "${dir}" "" "${target_dir}"
|
copyTreeExec "${source_dir}" "${dir}" "" "${target_dir}"
|
||||||
fi
|
fi
|
||||||
|
@ -200,7 +200,7 @@ header <<EOF
|
|||||||
and in a bash file use single 'quotes' around string and \${SCRIPTSDIR}
|
and in a bash file use single 'quotes' around string and \${SCRIPTSDIR}
|
||||||
EOF
|
EOF
|
||||||
buildStep "$0" "pre"
|
buildStep "$0" "pre"
|
||||||
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh\ntests/template-flavors/another_location/whonix_gnome/test_pre.sh"
|
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh\ntests/template-flavors/another_location/whonix_gnome/test_pre.sh\ntests/template-flavors/test_pre.sh"
|
||||||
assertEnd
|
assertEnd
|
||||||
|
|
||||||
|
|
||||||
@ -222,7 +222,6 @@ buildStep "$0" "pre"
|
|||||||
assertTest "buildStep $0 pre" "tests/template-flavors/another_location/whonix-gw/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh\ntests/template-flavors/test_pre.sh"
|
assertTest "buildStep $0 pre" "tests/template-flavors/another_location/whonix-gw/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh\ntests/template-flavors/test_pre.sh"
|
||||||
assertEnd
|
assertEnd
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# 8. Custom template directory with space in name
|
# 8. Custom template directory with space in name
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -257,7 +256,7 @@ header <<EOF
|
|||||||
9. Custom template directory for options
|
9. Custom template directory for options
|
||||||
EOF
|
EOF
|
||||||
buildStep "$0" "pre"
|
buildStep "$0" "pre"
|
||||||
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh\ntests/template-flavors/another_location/whonix_gnome/test_pre.sh"
|
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh\ntests/template-flavors/another_location/whonix_gnome/test_pre.sh\ntests/template-flavors/test_pre.sh"
|
||||||
assertEnd
|
assertEnd
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user