diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-12 15:28:39 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-12 15:28:39 +0300 |
| commit | d5a58a1115bb3faa45caefeb053a5808406afa35 (patch) | |
| tree | 013229daf22e5c062fdf5e860c457eb9d0c976bc /bin | |
| parent | 81a3be6379198c697de2f8639dcaa1cdc9d66a53 (diff) | |
Harden status-tested validation paths for bm0
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/shuriken | 117 |
1 files changed, 95 insertions, 22 deletions
diff --git a/bin/shuriken b/bin/shuriken index d3db424..3c815ed 100755 --- a/bin/shuriken +++ b/bin/shuriken @@ -741,7 +741,6 @@ source_template_file() { local -r output_path="$1"; shift local -r render_vars_name="$1"; shift local context_file - local restore_errexit=no local -i status=0 context_file=$(mktemp) @@ -750,18 +749,16 @@ source_template_file() { return "$status" fi - if [[ "$-" == *e* ]]; then - restore_errexit=yes - set +e - fi - ( - set -e - serialize_template_render_context "$render_vars_name" - printf 'unset BASH_ENV\n' - ) > "$context_file" - status=$? - if [ "$restore_errexit" = yes ]; then - set -e + if { + declare -p TEMPLATE_RENDER_FIELD_SPECS + declare -p "$render_vars_name" + declare -f + printf 'serialize_template_render_context %q\n' "$render_vars_name" + printf "printf 'unset BASH_ENV\\\\n'\n" + } | bash -euo pipefail > "$context_file"; then + status=0 + else + status=$? fi if (( status != 0 )); then rm -f "$context_file" @@ -3168,12 +3165,87 @@ run_simple_action() { esac } +run_action_body_context() { + local name + local -a variable_names=( + VERSION + DEFAULTRC + PACKAGED_TEMPLATE_DIR + PACKAGED_ASSET_DIR + DEFAULT_TEMPLATE_DIR + DEFAULT_ASSET_DIR + SHURIKEN_SOURCE_DIR + SHURIKEN_OUTPUT_MODE + SHURIKEN_ACTIVE_GENERATION_PID + SHURIKEN_FORCE_GENERATE + SHURIKEN_CURRENT_DATE_TEXT + SHURIKEN_CONFIG_SOURCE + SHURIKEN_FINAL_DIST_DIR + INCOMING_DIR + DIST_DIR + TEMPLATE_DIR + TITLE + HEIGHT + THUMBHEIGHT + MAXPREVIEWS + IMAGE_JOBS + IMAGEMAGICK_TIMEOUT + TAR_TIMEOUT + ORIGINAL_BASEPATH + RANDOM_SEED + SHUFFLE + SPLASH_PAGE + TARBALL_INCLUDE + TARBALL_SUFFIX + TAR_OPTS + SYNC_DELETE + SYNC_DESTINATIONS + TEMPLATE_RENDER_FIELD_SPECS + ) + + for name in "${variable_names[@]}"; do + declare -p "$name" 2>/dev/null || true + done + declare -f +} + run_action_body() { - if [[ "$-" == *e* ]]; then - "$@" + local -r action_name="$1"; shift + local -i status=0 + + if { + run_action_body_context + printf '%q "$@"\n' "$action_name" + } | bash -euo pipefail -s -- "$@"; then + status=0 + else + status=$? + fi + + return "$status" +} + +run_action_body_direct() { + "$@" +} + +run_configured_action_body() { + local -r action_name="$1"; shift + local -r runner="${SHURIKEN_ACTION_BODY_RUNNER:-run_action_body}" + local -i status=0 + + if [ "$runner" = run_action_body_direct ]; then + "$runner" "$action_name" "$@" + return + fi + + if "$runner" "$action_name" "$@"; then + status=0 else - ( set -e; "$@" ) + status=$? fi + + return "$status" } load_configured_action() { @@ -3268,7 +3340,7 @@ run_configured_action() { return "$status" fi - run_action_body generate_staged + run_configured_action_body generate_staged status=$? if (( status != 0 )); then return "$status" @@ -3281,7 +3353,7 @@ run_configured_action() { return "$status" fi - run_action_body refresh_splash + run_configured_action_body refresh_splash status=$? if (( status != 0 )); then return "$status" @@ -3294,7 +3366,7 @@ run_configured_action() { return "$status" fi - run_action_body sync_dist + run_configured_action_body sync_dist status=$? if (( status != 0 )); then return "$status" @@ -3307,7 +3379,7 @@ run_configured_action() { return "$status" fi - run_action_body dry_run + run_configured_action_body dry_run status=$? if (( status != 0 )); then return "$status" @@ -3320,7 +3392,7 @@ run_configured_action() { return "$status" fi - run_action_body print_config + run_configured_action_body print_config status=$? if (( status != 0 )); then return "$status" @@ -3341,7 +3413,8 @@ run_action() { fi ;; --clean|--generate|--refresh-splash|--sync|--dry-run|--print-config) - run_configured_action + SHURIKEN_ACTION_BODY_RUNNER=run_action_body_direct \ + run_configured_action status=$? if (( status != 0 )); then return "$status" |
