summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-03 20:05:04 +0300
committerPaul Buetow <paul@buetow.org>2026-06-03 20:05:04 +0300
commita9e9d2db616c4cb1a1fd192e38d53fba69b0102d (patch)
treebdc1e0486fab2478c8d4da2092080a71747b5132 /bin
parent9b3f994be65fe37516c74a60aa158b5bb340b20d (diff)
Resolve default template directory fallback for 1j0
Diffstat (limited to 'bin')
-rwxr-xr-xbin/photoalbum43
1 files changed, 43 insertions, 0 deletions
diff --git a/bin/photoalbum b/bin/photoalbum
index a388e41..cc367c1 100755
--- a/bin/photoalbum
+++ b/bin/photoalbum
@@ -6,6 +6,9 @@ set -euo pipefail
declare -r VERSION='0.6.0'
declare -r DEFAULTRC="${PHOTOALBUM_DEFAULT_RC:-/etc/default/photoalbum}"
+declare -r PACKAGED_TEMPLATE_DIR='/usr/share/photoalbum/templates/default'
+DEFAULT_TEMPLATE_DIR="${PHOTOALBUM_DEFAULT_TEMPLATE_DIR:-$PACKAGED_TEMPLATE_DIR}"
+declare -r DEFAULT_TEMPLATE_DIR
PHOTOALBUM_OUTPUT_MODE="${PHOTOALBUM_OUTPUT_MODE:-normal}"
usage() {
@@ -91,6 +94,45 @@ resolve_source_root() {
fi
}
+resolve_default_template_dir() {
+ local source_root
+
+ if [ -d "$DEFAULT_TEMPLATE_DIR" ]; then
+ printf '%s\n' "$DEFAULT_TEMPLATE_DIR"
+ return
+ fi
+
+ source_root=$(resolve_source_root)
+
+ if [ -n "$source_root" ]; then
+ printf '%s\n' "$source_root/share/templates/default"
+ return
+ fi
+
+ printf '%s\n' "$DEFAULT_TEMPLATE_DIR"
+}
+
+template_dir_uses_default() {
+ if [ -z "${TEMPLATE_DIR+x}" ] || [ -z "$TEMPLATE_DIR" ]; then
+ return 1
+ fi
+
+ case "$TEMPLATE_DIR" in
+ "$PACKAGED_TEMPLATE_DIR"|"$DEFAULT_TEMPLATE_DIR")
+ return 0
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+}
+
+apply_template_dir_default() {
+ if template_dir_uses_default; then
+ TEMPLATE_DIR=$(resolve_default_template_dir)
+ fi
+}
+
init_config() {
local -r rc_file=photoalbum.conf
local default_rc_file
@@ -1413,6 +1455,7 @@ main() {
source "$rc_file"
apply_config_defaults
+ apply_template_dir_default
apply_cli_overrides
PHOTOALBUM_CONFIG_SOURCE="$rc_file"
export PHOTOALBUM_CONFIG_SOURCE