From e9bd990587227b29dc6e41e3d43a5cf2ec9dcd5b Mon Sep 17 00:00:00 2001 From: Stefan Kreutz Date: Thu, 16 Apr 2026 01:07:28 +0200 Subject: Add wrapped command option --- temp-postgres.sh | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'temp-postgres.sh') diff --git a/temp-postgres.sh b/temp-postgres.sh index 6064b66..8504257 100755 --- a/temp-postgres.sh +++ b/temp-postgres.sh @@ -20,8 +20,7 @@ set -o nounset trap 'quit' INT quit() { code="${1:-0}" - trap '' INT TERM - kill -TERM 0 + [ -z "$postgres_pid" ] || kill -TERM "$postgres_pid" wait rm -rf "${tmpdir-}" || { ( >&2 printf "temp-postgres: failed to remove temporary directory: %s\\n" "${tmpdir}" ) @@ -36,7 +35,7 @@ username="$( id -un )" while [ $# -gt 0 ] ; do case "$1" in -h|--help) - echo "Usage: temp-postgres [-h|--help] [-d|--dbname ] [-u|--username ]" + echo "Usage: temp-postgres [-h|--help] [-d|--dbname ] [-u|--username ] [--] []" exit ;; -d|--dbname) @@ -60,10 +59,6 @@ while [ $# -gt 0 ] ; do ;; esac done -if [ $# -gt 0 ] ; then - ( >&2 echo "too many arguments" ) - exit 2 -fi # Create a temporary directory tmpdir="$( mktemp -d )" || { @@ -79,6 +74,7 @@ initdb --pgdata="${tmpdir}" --username="${username}" || { # Serve the directory ( postgres -k "${tmpdir}" -D "${tmpdir}" &2 echo "temp-postgres: command exited ${code}" ) + quit "$code" + } + quit +fi -- cgit v1.3