fix(scripts): make setup_testdb.sh runnable on Linux#22350
Open
ozpool wants to merge 1 commit intosmartcontractkit:developfrom
Open
fix(scripts): make setup_testdb.sh runnable on Linux#22350ozpool wants to merge 1 commit intosmartcontractkit:developfrom
ozpool wants to merge 1 commit intosmartcontractkit:developfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #16179.
./core/scripts/setup_testdb.shcurrently fails out of the box on Linux with the errors reported in the issue:Three problems combine to produce this:
#/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-onlyfunctionkeyword on line 3.mktemp -d -t db-dev-useronly works under BSD mktemp. GNU coreutils mktemp requires the template to containXXXXXX, hence "too few X's".pushd/popd), so reverting the shebang to plain/bin/shwould just shift the failure to those lines.This PR:
/bin/bashso bashisms (pushd,popd,<<heredocs with the existing escapes) keep working.functionkeyword inexit_errorand routes its message to stderr.mktemp -d -t db-dev-userwithmktemp -d "${TMPDIR:-/tmp}/db-dev-user.XXXXXX", which is accepted by both BSD and GNU mktemp.echo "\n!Success!\n"withprintf '\n!Success!\n\n'. Bash'sechodoes not interpret\nwithout-e, so the original prints literal backslash-n.set -euo pipefailso failures (e.g. a badpsqlinvocation) abort the script instead of continuing into the export step.Testing
I do not have a Postgres-enabled CI environment locally to run
make setup-testdbend-to-end, so I have not exercised the SQL path; the changes are limited to the failure modes described in the issue.Author Checklist
develop