Skip to content

Commit e7688c2

Browse files
committed
Fix runtime failures: PostgreSQL PATH, Firebase ~ expansion, and param defaults
1 parent ee6feec commit e7688c2

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

cli/src/pkg/boothinit/compiler/compiler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ func (c *collector) build() (*output.BoothOutput, error) {
242242
for _, seg := range c.startupSegs {
243243
name := fmt.Sprintf("%02d-%s--startup.sh", seg.Order, sanitizeName(seg.SourceName))
244244
content := strings.TrimRight(seg.Content, "\n") + "\n"
245+
// Expand ${PARAM} to ${PARAM:-value} so it's overridable at runtime
246+
content = expandParamsWithDefaults(content, c.params)
245247
out.Startups = append(out.Startups, output.FileContent{
246248
RelPath: name,
247249
Content: content,
@@ -342,6 +344,15 @@ func dedup(items []string) []string {
342344
return result
343345
}
344346

347+
// expandParamsWithDefaults replaces ${PARAM} references with ${PARAM:-value} in a string.
348+
// This keeps the variable overridable at runtime while providing a safe default.
349+
func expandParamsWithDefaults(s string, params map[string]string) string {
350+
for k, v := range params {
351+
s = strings.ReplaceAll(s, "${"+k+"}", "${"+k+":-"+v+"}")
352+
}
353+
return s
354+
}
355+
345356
// expandParams replaces ${PARAM} references in string slices with their values.
346357
func expandParams(items []string, params map[string]string) []string {
347358
if len(params) == 0 || len(items) == 0 {

examples/workspaces/firebase-example/.booth/startup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -euo pipefail
1818
# But Firebase installation creates an JSON-empty files there ("{}").
1919

2020
SEED="/etc/cb-home-seed/.config/configstore/firebase-tools.json"
21-
TRGT="~/.config/configstore/firebase-tools.json"
21+
TRGT="$HOME/.config/configstore/firebase-tools.json"
2222

2323
rm -rf "$TRGT"
2424
if [[ -f "$SEED" ]]; then

examples/workspaces/homebrew-example/.cb-tests/inBooth-test007-postgresql--in-booth.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
echo "=== Testing PostgreSQL ==="
55

6+
# PostgreSQL is keg-only in Homebrew — binaries aren't symlinked to the main bin.
7+
# Add the versioned postgresql bin directory to PATH.
8+
for pg_dir in /home/linuxbrew/.linuxbrew/opt/postgresql@*/bin; do
9+
[ -d "$pg_dir" ] && export PATH="$pg_dir:$PATH" && break
10+
done
11+
612
PGDATA="/tmp/test-pg-$$"
713
PGLOG="/tmp/test-pg-$$.log"
814

prj--test46-init-excalidraw/.booth/startups/65-excalidraw-autostart--startup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
# Adjust with : booth init adjust --select excalidraw:889+expose+autostart
55

66
# Auto-start Excalidraw in background
7-
PORT=${EXCALIDRAW_PORT}
7+
PORT=${EXCALIDRAW_PORT:-889}
88
LOG_FILE="/tmp/excalidraw.log"
99

1010
nohup serve -s --no-clipboard /opt/excalidraw -l "$PORT" > "$LOG_FILE" 2>&1 &

tests/init/test46-init-excalidraw.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ run rm -Rf $prj
3535
mkdir -p $prj
3636
run booth init new $prj --select "excalidraw+autostart"
3737
startup="$prj/.booth/startups/65-excalidraw-autostart--startup.sh"
38-
assert-line "$startup" 'PORT=' '${EXCALIDRAW_PORT}' "startup uses param reference"
38+
assert-line "$startup" 'PORT=' '${EXCALIDRAW_PORT:-15555}' "startup uses param with default"
3939

4040
# Test 6: Excalidraw+expose+autostart with custom port — all consistent
4141
run rm -Rf $prj
@@ -46,6 +46,6 @@ config="$prj/.booth/config.toml"
4646
startup="$prj/.booth/startups/65-excalidraw-autostart--startup.sh"
4747
assert-line "$boothfile" 'arg EXCALIDRAW_PORT=' '889' "full: Boothfile param is 889"
4848
assert-line "$config" 'run-args = ' '["-p", "889:889"]' "full: run-args uses 889"
49-
assert-line "$startup" 'PORT=' '${EXCALIDRAW_PORT}' "full: startup uses param reference"
49+
assert-line "$startup" 'PORT=' '${EXCALIDRAW_PORT:-889}' "full: startup uses param with default 889"
5050

5151
finally

0 commit comments

Comments
 (0)