Skip to content

Commit

Permalink
Look for template.conf in flavor specific dirs too
Browse files Browse the repository at this point in the history
Specifically for Whonix, this allows setting template.conf in
qubes-template-whonix repo, not only in
qubes-builder-debian/template_debian.
The get_file_or_directory_for_current_flavor() function is used only in
two places - for template.conf and for appmenus, and the appmenus call
uses APPMENUS_DIR variable anyway.

QubesOS/qubes-issues#9570
  • Loading branch information
marmarek committed Nov 19, 2024
1 parent 03c9d99 commit cee7b64
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
49 changes: 30 additions & 19 deletions qubesbuilder/plugins/template/scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ error() {
# - packages_${DIST_NAME}_{DIST_VER}_${TEMPLATE_FLAVOR}.list
# - packages_${DIST_NAME}_${TEMPLATE_FLAVOR}.list
# - packages_${DIST_NAME}.list
# - packages.list
#
# Remark: If 'resource' is provided with full path, we use
# its dirname as search directory instead of TEMPLATE_CONTENT_DIR.
# its dirname as search directory instead of flavor dirs and TEMPLATE_CONTENT_DIR.
# ------------------------------------------------------------------------------
get_file_or_directory_for_current_flavor() {
local resource="$1"
Expand All @@ -83,10 +84,14 @@ get_file_or_directory_for_current_flavor() {
# we use its dirname as search directory
# instead of TEMPLATE_CONTENT_DIR
if [ "$(dirname "${resource}")" != "." ]; then
resource_dir="$(dirname "${resource}")"
resource_dirs=( "$(dirname "${resource}")" )
resource="$(basename "${resource}")"
else
resource_dir="${TEMPLATE_CONTENT_DIR}"
resource_dirs="$(templateDirs)"
old_IFS="$IFS"
IFS=$'\n'
resource_dirs=( $resource_dirs )
IFS="$old_IFS"
fi

# Determine if resource has an extension. If it has,
Expand All @@ -98,22 +103,28 @@ get_file_or_directory_for_current_flavor() {
ext=""
resource_without_ext="${resource}"
fi
# shellcheck disable=SC2153
if [ -n "${suffix}" ] && [ -e "${resource_dir}/${resource_without_ext}_${suffix}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${suffix}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_CODENAME}_${TEMPLATE_FLAVOR}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_CODENAME}_${TEMPLATE_FLAVOR}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_CODENAME}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_CODENAME}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_NAME}_${DIST_VER}_${TEMPLATE_FLAVOR}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_NAME}_${DIST_VER}_${TEMPLATE_FLAVOR}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_NAME}_${TEMPLATE_FLAVOR}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_NAME}_${TEMPLATE_FLAVOR}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_NAME}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_NAME}${ext}"
else
file_or_directory=""
fi
file_or_directory=""
for resource_dir in "${resource_dirs[@]}"; do
# shellcheck disable=SC2153
if [ -n "${suffix}" ] && [ -e "${resource_dir}/${resource_without_ext}_${suffix}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${suffix}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_CODENAME}_${TEMPLATE_FLAVOR}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_CODENAME}_${TEMPLATE_FLAVOR}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_CODENAME}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_CODENAME}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_NAME}_${DIST_VER}_${TEMPLATE_FLAVOR}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_NAME}_${DIST_VER}_${TEMPLATE_FLAVOR}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_NAME}_${TEMPLATE_FLAVOR}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_NAME}_${TEMPLATE_FLAVOR}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}_${DIST_NAME}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}_${DIST_NAME}${ext}"
elif [ -e "${resource_dir}/${resource_without_ext}${ext}" ]; then
file_or_directory="${resource_dir}/${resource_without_ext}${ext}"
else
continue
fi
break
done
echo "${file_or_directory}"
}

Expand Down
2 changes: 1 addition & 1 deletion qubesbuilder/plugins/template/scripts/qubeize-image
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ cp -r "${appmenus}" "${ARTIFACTS_DIR}/appmenus"
echo "--> Creating template config file..."
_conf_dir="${CONFIG_DIR:-${TEMPLATE_CONTENT_DIR}}"

template_conf="$(get_file_or_directory_for_current_flavor "${_conf_dir}/template.conf")"
template_conf="$(get_file_or_directory_for_current_flavor "template.conf")"
if [ -z "$template_conf" ]; then
template_conf="${PLUGINS_DIR}/template/template_generic.conf"
fi
Expand Down

0 comments on commit cee7b64

Please sign in to comment.