summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-24 10:14:27 +0300
committerPaul Buetow <paul@buetow.org>2026-06-24 10:14:27 +0300
commit7f7ae1bef10bcf186e21a3e923b9756a50ecf52b (patch)
tree2aab70a937ced49d0a1198544b1d8e4985f2b940 /src/lib
parent6b5281c14393290726442a7ddbfe7576ea203cfc (diff)
Fix: shell-quote rewritten TEMPLATE_DIR so spaced source paths source cleanly
init_config rewrote the TEMPLATE_DIR line via awk as a bare, unquoted literal when running --init from a source checkout. A source-root path containing a space (or any shell metacharacter) produced a config that aborts on source under "set -euo pipefail": the value was word-split, truncating the path and running its tail as a command (exit 127), leaving TEMPLATE_DIR empty and breaking every subsequent action. Emit the rewritten value as a single-quoted assignment, escaping any embedded single quote as '\'', so the generated shuriken.conf round-trips through sourcing regardless of spaces or single quotes. The non-rewrite path (installed /etc/default/shuriken) is unchanged. Regenerated bin/shuriken via just build. Tests: test_init and test_init_with_hash_in_source_path now assert the SOURCED TEMPLATE_DIR (the real contract) instead of the literal line, and a new test_init_with_space_in_source_path covers the spaced-path regression. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/paths.source.sh9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/paths.source.sh b/src/lib/paths.source.sh
index d0db74b..eeea068 100644
--- a/src/lib/paths.source.sh
+++ b/src/lib/paths.source.sh
@@ -121,9 +121,16 @@ init_config() {
&& "$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")
+ # Emit the rewritten TEMPLATE_DIR as a single-quoted assignment so the
+ # generated config sources cleanly under "set -euo pipefail" even when
+ # the source-checkout path contains spaces or other shell metacharacters
+ # (an unquoted value would be word-split on source, truncating the path
+ # and running its tail as a command -> exit 127). Any embedded single
+ # quote is closed, escaped as '\'', and reopened so the literal survives.
if ! awk -v template_dir="$source_template_dir" \
'/^TEMPLATE_DIR=/ {
- print "TEMPLATE_DIR=" template_dir
+ gsub(/'\''/, "'\''\\'\'''\''", template_dir)
+ print "TEMPLATE_DIR='\''" template_dir "'\''"
next
}
{ print }' "$rc_file" > "$rewritten_rc_file"; then