summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-16 22:21:36 +0300
committerPaul Buetow <paul@buetow.org>2026-06-16 22:21:36 +0300
commit14d041e890765afbab396a29871d6bf6e8097fff (patch)
treee3fcdc084b75bbd7ec294489a72966e03d7f6ed1
parentaca23d3a094cb1bf86db40e42f184fbf88371d42 (diff)
jn0 split bootstrap.source.sh into logging/paths/startup modules
Separate the mixed concerns in bootstrap.source.sh per [SRP]: - logging.source.sh: output_is_quiet, output_is_verbose, log_info, log_verbose, log_warning (the output/logging concern). - paths.source.sh: resolve_default_rc_file, resolve_source_root, resolve_default_template_dir, resolve_default_asset_dir, template_dir_uses_default, apply_template_dir_default, init_config (install/source-root/default-dir + rc-file/template-dir resolution). - bootstrap.source.sh keeps the CLI usage text and the shared resolve_config_array parser used by the config modules. Pure code move, verified byte-identical function bodies. LIB_SOURCES now lists logging.source.sh first, then bootstrap, then paths; matching source directives added to src/shuriken.sh so --check-sourced sees the new modules. just test/shellcheck/check-generated and git diff --check all pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
-rw-r--r--Justfile2
-rwxr-xr-xbin/shuriken73
-rw-r--r--src/lib/bootstrap.source.sh161
-rw-r--r--src/lib/logging.source.sh30
-rw-r--r--src/lib/paths.source.sh138
-rwxr-xr-xsrc/shuriken.sh4
6 files changed, 229 insertions, 179 deletions
diff --git a/Justfile b/Justfile
index da16ed3..042b369 100644
--- a/Justfile
+++ b/Justfile
@@ -7,7 +7,7 @@ PREFIX := env_var_or_default("PREFIX", "/usr")
BINDIR := env_var_or_default("BINDIR", PREFIX + "/bin")
DATADIR := env_var_or_default("DATADIR", PREFIX + "/share")
SYSCONFDIR := env_var_or_default("SYSCONFDIR", "/etc/default")
-LIB_SOURCES := "src/lib/bootstrap.source.sh src/lib/imagemagick.source.sh src/lib/process.source.sh src/lib/archive.source.sh src/lib/template.source.sh src/lib/job-pool.source.sh src/lib/image.source.sh src/lib/random.source.sh src/lib/image-pipeline.source.sh src/lib/album-metadata.source.sh src/lib/album-render.source.sh src/lib/album.source.sh src/lib/stats-aggregate.source.sh src/lib/stats-render.source.sh src/lib/stats-filter-album.source.sh src/lib/config.source.sh src/lib/config.print.source.sh src/lib/config.sync.source.sh src/lib/config.staging.source.sh src/lib/config.validate.source.sh src/lib/config.cli.source.sh src/lib/action.source.sh"
+LIB_SOURCES := "src/lib/logging.source.sh src/lib/bootstrap.source.sh src/lib/paths.source.sh src/lib/imagemagick.source.sh src/lib/process.source.sh src/lib/archive.source.sh src/lib/template.source.sh src/lib/job-pool.source.sh src/lib/image.source.sh src/lib/random.source.sh src/lib/image-pipeline.source.sh src/lib/album-metadata.source.sh src/lib/album-render.source.sh src/lib/album.source.sh src/lib/stats-aggregate.source.sh src/lib/stats-render.source.sh src/lib/stats-filter-album.source.sh src/lib/config.source.sh src/lib/config.print.source.sh src/lib/config.sync.source.sh src/lib/config.staging.source.sh src/lib/config.validate.source.sh src/lib/config.cli.source.sh src/lib/action.source.sh"
default: build
diff --git a/bin/shuriken b/bin/shuriken
index 49d49a6..e7109db 100755
--- a/bin/shuriken
+++ b/bin/shuriken
@@ -86,7 +86,46 @@ declare -r SHURIKEN_SOURCE_DIR
# SHURIKEN_LIB_SOURCES_BEGIN
+# Inlined from src/lib/logging.source.sh
+# Output/logging utilities. Split out of bootstrap.source.sh (task jn0) so the
+# "how do we print to the user" concern lives apart from startup wiring and path
+# resolution. These helpers read the SHURIKEN_OUTPUT_MODE global and are called
+# from nearly every other module, so this file is kept early in LIB_SOURCES.
+# All library modules are sourced before any code runs, so definition order does
+# not affect availability.
+
+output_is_quiet() {
+ [ "$SHURIKEN_OUTPUT_MODE" = quiet ]
+}
+
+output_is_verbose() {
+ [ "$SHURIKEN_OUTPUT_MODE" = verbose ]
+}
+
+log_info() {
+ if ! output_is_quiet; then
+ printf '%s\n' "$*"
+ fi
+}
+
+log_verbose() {
+ if output_is_verbose; then
+ printf 'Verbose: %s\n' "$*"
+ fi
+}
+
+log_warning() {
+ printf 'WARNING: %s\n' "$*" >&2
+}
+
# Inlined from src/lib/bootstrap.source.sh
+# Startup wiring: the CLI usage/help text plus the shared config-array parser.
+# Logging utilities now live in logging.source.sh and path resolution in
+# paths.source.sh (split out by task jn0). resolve_config_array stays here
+# because it is the shared "array or scalar config" parser used by the config
+# modules. All library modules are sourced before any code runs, so definition
+# order does not affect availability.
+
usage() {
cat - <<USAGE >&2
Usage:
@@ -128,30 +167,6 @@ usage() {
USAGE
}
-output_is_quiet() {
- [ "$SHURIKEN_OUTPUT_MODE" = quiet ]
-}
-
-output_is_verbose() {
- [ "$SHURIKEN_OUTPUT_MODE" = verbose ]
-}
-
-log_info() {
- if ! output_is_quiet; then
- printf '%s\n' "$*"
- fi
-}
-
-log_verbose() {
- if output_is_verbose; then
- printf 'Verbose: %s\n' "$*"
- fi
-}
-
-log_warning() {
- printf 'WARNING: %s\n' "$*" >&2
-}
-
# Read a configuration value into the named array, accepting both Bash array
# and whitespace-separated scalar declarations of the same variable.
# This is shared by resolve_tar_opts and resolve_sync_destinations so the
@@ -194,6 +209,16 @@ resolve_config_array() {
esac
}
+# Inlined from src/lib/paths.source.sh
+# Path resolution. Split out of bootstrap.source.sh (task jn0) so the install /
+# source-root / default-directory discovery and the rc-file/template-dir
+# defaulting live apart from startup wiring and logging. These helpers resolve
+# where the packaged config, templates and assets live (both when installed and
+# when running from a source checkout) and initialise a fresh shuriken.conf.
+# All library modules are sourced before any code runs, so definition order does
+# not affect availability (e.g. init_config calls log_info from
+# logging.source.sh).
+
resolve_default_rc_file() {
local source_root
diff --git a/src/lib/bootstrap.source.sh b/src/lib/bootstrap.source.sh
index 2b19e58..52c0599 100644
--- a/src/lib/bootstrap.source.sh
+++ b/src/lib/bootstrap.source.sh
@@ -1,3 +1,10 @@
+# Startup wiring: the CLI usage/help text plus the shared config-array parser.
+# Logging utilities now live in logging.source.sh and path resolution in
+# paths.source.sh (split out by task jn0). resolve_config_array stays here
+# because it is the shared "array or scalar config" parser used by the config
+# modules. All library modules are sourced before any code runs, so definition
+# order does not affect availability.
+
usage() {
cat - <<USAGE >&2
Usage:
@@ -39,30 +46,6 @@ usage() {
USAGE
}
-output_is_quiet() {
- [ "$SHURIKEN_OUTPUT_MODE" = quiet ]
-}
-
-output_is_verbose() {
- [ "$SHURIKEN_OUTPUT_MODE" = verbose ]
-}
-
-log_info() {
- if ! output_is_quiet; then
- printf '%s\n' "$*"
- fi
-}
-
-log_verbose() {
- if output_is_verbose; then
- printf 'Verbose: %s\n' "$*"
- fi
-}
-
-log_warning() {
- printf 'WARNING: %s\n' "$*" >&2
-}
-
# Read a configuration value into the named array, accepting both Bash array
# and whitespace-separated scalar declarations of the same variable.
# This is shared by resolve_tar_opts and resolve_sync_destinations so the
@@ -104,133 +87,3 @@ resolve_config_array() {
;;
esac
}
-
-resolve_default_rc_file() {
- local source_root
-
- if [ -f "$DEFAULTRC" ]; then
- printf '%s\n' "$DEFAULTRC"
- return
- fi
-
- source_root=$(resolve_source_root)
-
- if [ -n "$source_root" ]; then
- printf '%s\n' "$source_root/src/shuriken.default.conf"
- return
- fi
-
- printf '%s\n' "$DEFAULTRC"
-}
-
-resolve_source_root() {
- local script_dir
- local source_root
-
- script_dir="$SHURIKEN_SOURCE_DIR"
- source_root=$(cd "$script_dir/.." && pwd)
-
- if [[ -f "$source_root/src/shuriken.default.conf" \
- && -d "$source_root/share/templates/default" ]]; then
- printf '%s\n' "$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"
-}
-
-resolve_default_asset_dir() {
- local source_root
-
- if [ -d "$DEFAULT_ASSET_DIR" ]; then
- printf '%s\n' "$DEFAULT_ASSET_DIR"
- return
- fi
-
- source_root=$(resolve_source_root)
-
- if [ -n "$source_root" ]; then
- printf '%s\n' "$source_root/assets/site"
- return
- fi
-
- printf '%s\n' "$DEFAULT_ASSET_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=shuriken.conf
- local default_rc_file
- local rewritten_rc_file
- local source_root
- local source_template_dir
-
- if [ -f "$rc_file" ]; then
- printf 'Error: %s already exists\n' "$rc_file" >&2
- exit 1
- fi
-
- default_rc_file=$(resolve_default_rc_file)
-
- if [ ! -f "$default_rc_file" ]; then
- printf 'Error: Can not find config file %s\n' "$default_rc_file" >&2
- exit 1
- fi
-
- cp "$default_rc_file" "$rc_file"
-
- source_root=$(resolve_source_root)
- if [[ -n "$source_root" \
- && "$default_rc_file" = "$source_root/src/shuriken.default.conf" ]]; then
- source_template_dir="$source_root/share/templates/default"
- rewritten_rc_file=$(mktemp "${rc_file}.XXXXXX")
- if ! awk -v template_dir="$source_template_dir" \
- '/^TEMPLATE_DIR=/ {
- print "TEMPLATE_DIR=" template_dir
- next
- }
- { print }' "$rc_file" > "$rewritten_rc_file"; then
- rm -f "$rewritten_rc_file"
- exit 1
- fi
- cat "$rewritten_rc_file" > "$rc_file"
- rm -f "$rewritten_rc_file"
- fi
-
- log_info "Created ./$rc_file"
-}
diff --git a/src/lib/logging.source.sh b/src/lib/logging.source.sh
new file mode 100644
index 0000000..b627b04
--- /dev/null
+++ b/src/lib/logging.source.sh
@@ -0,0 +1,30 @@
+# Output/logging utilities. Split out of bootstrap.source.sh (task jn0) so the
+# "how do we print to the user" concern lives apart from startup wiring and path
+# resolution. These helpers read the SHURIKEN_OUTPUT_MODE global and are called
+# from nearly every other module, so this file is kept early in LIB_SOURCES.
+# All library modules are sourced before any code runs, so definition order does
+# not affect availability.
+
+output_is_quiet() {
+ [ "$SHURIKEN_OUTPUT_MODE" = quiet ]
+}
+
+output_is_verbose() {
+ [ "$SHURIKEN_OUTPUT_MODE" = verbose ]
+}
+
+log_info() {
+ if ! output_is_quiet; then
+ printf '%s\n' "$*"
+ fi
+}
+
+log_verbose() {
+ if output_is_verbose; then
+ printf 'Verbose: %s\n' "$*"
+ fi
+}
+
+log_warning() {
+ printf 'WARNING: %s\n' "$*" >&2
+}
diff --git a/src/lib/paths.source.sh b/src/lib/paths.source.sh
new file mode 100644
index 0000000..d0db74b
--- /dev/null
+++ b/src/lib/paths.source.sh
@@ -0,0 +1,138 @@
+# Path resolution. Split out of bootstrap.source.sh (task jn0) so the install /
+# source-root / default-directory discovery and the rc-file/template-dir
+# defaulting live apart from startup wiring and logging. These helpers resolve
+# where the packaged config, templates and assets live (both when installed and
+# when running from a source checkout) and initialise a fresh shuriken.conf.
+# All library modules are sourced before any code runs, so definition order does
+# not affect availability (e.g. init_config calls log_info from
+# logging.source.sh).
+
+resolve_default_rc_file() {
+ local source_root
+
+ if [ -f "$DEFAULTRC" ]; then
+ printf '%s\n' "$DEFAULTRC"
+ return
+ fi
+
+ source_root=$(resolve_source_root)
+
+ if [ -n "$source_root" ]; then
+ printf '%s\n' "$source_root/src/shuriken.default.conf"
+ return
+ fi
+
+ printf '%s\n' "$DEFAULTRC"
+}
+
+resolve_source_root() {
+ local script_dir
+ local source_root
+
+ script_dir="$SHURIKEN_SOURCE_DIR"
+ source_root=$(cd "$script_dir/.." && pwd)
+
+ if [[ -f "$source_root/src/shuriken.default.conf" \
+ && -d "$source_root/share/templates/default" ]]; then
+ printf '%s\n' "$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"
+}
+
+resolve_default_asset_dir() {
+ local source_root
+
+ if [ -d "$DEFAULT_ASSET_DIR" ]; then
+ printf '%s\n' "$DEFAULT_ASSET_DIR"
+ return
+ fi
+
+ source_root=$(resolve_source_root)
+
+ if [ -n "$source_root" ]; then
+ printf '%s\n' "$source_root/assets/site"
+ return
+ fi
+
+ printf '%s\n' "$DEFAULT_ASSET_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=shuriken.conf
+ local default_rc_file
+ local rewritten_rc_file
+ local source_root
+ local source_template_dir
+
+ if [ -f "$rc_file" ]; then
+ printf 'Error: %s already exists\n' "$rc_file" >&2
+ exit 1
+ fi
+
+ default_rc_file=$(resolve_default_rc_file)
+
+ if [ ! -f "$default_rc_file" ]; then
+ printf 'Error: Can not find config file %s\n' "$default_rc_file" >&2
+ exit 1
+ fi
+
+ cp "$default_rc_file" "$rc_file"
+
+ source_root=$(resolve_source_root)
+ if [[ -n "$source_root" \
+ && "$default_rc_file" = "$source_root/src/shuriken.default.conf" ]]; then
+ source_template_dir="$source_root/share/templates/default"
+ rewritten_rc_file=$(mktemp "${rc_file}.XXXXXX")
+ if ! awk -v template_dir="$source_template_dir" \
+ '/^TEMPLATE_DIR=/ {
+ print "TEMPLATE_DIR=" template_dir
+ next
+ }
+ { print }' "$rc_file" > "$rewritten_rc_file"; then
+ rm -f "$rewritten_rc_file"
+ exit 1
+ fi
+ cat "$rewritten_rc_file" > "$rc_file"
+ rm -f "$rewritten_rc_file"
+ fi
+
+ log_info "Created ./$rc_file"
+}
diff --git a/src/shuriken.sh b/src/shuriken.sh
index 6629c67..4114806 100755
--- a/src/shuriken.sh
+++ b/src/shuriken.sh
@@ -85,8 +85,12 @@ SHURIKEN_SOURCE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
declare -r SHURIKEN_SOURCE_DIR
# SHURIKEN_LIB_SOURCES_BEGIN
+# shellcheck source=src/lib/logging.source.sh
+source "$SHURIKEN_SOURCE_DIR/lib/logging.source.sh"
# shellcheck source=src/lib/bootstrap.source.sh
source "$SHURIKEN_SOURCE_DIR/lib/bootstrap.source.sh"
+# shellcheck source=src/lib/paths.source.sh
+source "$SHURIKEN_SOURCE_DIR/lib/paths.source.sh"
# shellcheck source=src/lib/imagemagick.source.sh
source "$SHURIKEN_SOURCE_DIR/lib/imagemagick.source.sh"
# shellcheck source=src/lib/process.source.sh