Skip to content

fix(scripts): make setup_testdb.sh runnable on Linux#22350

Open
ozpool wants to merge 1 commit intosmartcontractkit:developfrom
ozpool:fix/16179-setup-testdb-shell
Open

fix(scripts): make setup_testdb.sh runnable on Linux#22350
ozpool wants to merge 1 commit intosmartcontractkit:developfrom
ozpool:fix/16179-setup-testdb-shell

Conversation

@ozpool
Copy link
Copy Markdown

@ozpool ozpool commented May 8, 2026

Description

Closes #16179.

./core/scripts/setup_testdb.sh currently fails out of the box on Linux with the errors reported in the issue:

./core/scripts/setup_testdb.sh: 3: function: not found
mktemp: too few X's in template 'db-dev-user'

Three problems combine to produce this:

  1. The shebang on line 1 is #/bin/sh — the leading ! is missing, so the kernel won't honor it and the file is interpreted by the calling shell (dash on Ubuntu), which then trips on the bash-only function keyword on line 3.
  2. mktemp -d -t db-dev-user only works under BSD mktemp. GNU coreutils mktemp requires the template to contain XXXXXX, hence "too few X's".
  3. The script also relies on bash builtins (pushd/popd), so reverting the shebang to plain /bin/sh would just shift the failure to those lines.

This PR:

  • Switches the shebang to /bin/bash so bashisms (pushd, popd, << heredocs with the existing escapes) keep working.
  • Drops the redundant function keyword in exit_error and routes its message to stderr.
  • Replaces mktemp -d -t db-dev-user with mktemp -d "${TMPDIR:-/tmp}/db-dev-user.XXXXXX", which is accepted by both BSD and GNU mktemp.
  • Replaces echo "\n!Success!\n" with printf '\n!Success!\n\n'. Bash's echo does not interpret \n without -e, so the original prints literal backslash-n.
  • Adds set -euo pipefail so failures (e.g. a bad psql invocation) abort the script instead of continuing into the export step.

Testing

$ bash -n core/scripts/setup_testdb.sh    # syntax check
$ tdir=$(mktemp -d "${TMPDIR:-/tmp}/db-dev-user.XXXXXX") && echo "$tdir" && rmdir "$tdir"
/var/folders/.../db-dev-user.XXXXXX

I do not have a Postgres-enabled CI environment locally to run make setup-testdb end-to-end, so I have not exercised the SQL path; the changes are limited to the failure modes described in the issue.

Author Checklist

  • PR title uses Conventional Commits prefix
  • Targeted develop
  • Linked the relevant issue
  • Reviewed Files changed
  • Unit tests — n/a, shell script with no test harness

setup_testdb.sh failed out of the box on Linux with "function: not
found" and "mktemp: too few X's in template". Three issues:

1. Shebang was "#/bin/sh" (missing !), so the kernel handed the file
   to whatever shell was current (dash on Ubuntu), which then choked
   on the bash-only `function` keyword on line 3.
2. `mktemp -d -t db-dev-user` works on BSD mktemp but GNU coreutils
   mktemp rejects the template because it has no X placeholders.
3. The script also uses bash builtins (pushd/popd) elsewhere, so
   leaving the shebang as plain sh would just shift the failure.

Switch the shebang to /bin/bash, drop the redundant `function`
keyword, give mktemp an explicit "${TMPDIR:-/tmp}/db-dev-user.XXXXXX"
template that works on both BSD and GNU mktemp, replace the
literal-backslash `echo "\n!Success!\n"` with printf so the
newlines actually print on bash (which doesn't interpret \n in echo
without -e), route exit_error to stderr, and add `set -euo pipefail`
so failures abort instead of silently continuing past a bad psql.

Closes smartcontractkit#16179
@ozpool ozpool requested review from a team as code owners May 8, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DEVEL] setup-testdb invalid function syntax, mktemp: too few X's in template

2 participants