From c3eb3d7264fd77ef88320251f910accd6df8164a Mon Sep 17 00:00:00 2001 From: Stefan Kreutz Date: Thu, 16 Apr 2026 01:33:34 +0200 Subject: Add --symlink option --- temp-postgres.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'temp-postgres.sh') diff --git a/temp-postgres.sh b/temp-postgres.sh index 8504257..96f90d2 100755 --- a/temp-postgres.sh +++ b/temp-postgres.sh @@ -26,6 +26,10 @@ quit() { ( >&2 printf "temp-postgres: failed to remove temporary directory: %s\\n" "${tmpdir}" ) [ "${code}" -ne 0 ] || code=1 } + [ -z "${symlink:-}" ] || ! [ -L "$symlink" ] || unlink "$symlink" || { + ( >&2 printf "temp-postgres: failed to unlink %s\\n" "$symlink" ) + [ "${code}" -ne 0 ] || code=1 + } exit "${code}" } @@ -35,7 +39,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 ] [--symlink ] [--] []" exit ;; -d|--dbname) @@ -46,6 +50,10 @@ while [ $# -gt 0 ] ; do username="$2" shift 2 ;; + --symlink) + symlink="$2" + shift 2 + ;; --) shift break @@ -89,6 +97,13 @@ createdb --host="${tmpdir}" --username="${username}" --no-password "${dbname}" | quit 1 } +if [ -n "${symlink:-}" ] ; then + ln -sf "${tmpdir}" "$symlink" || { + ( >&2 printf "temp-postgres: failed to create symlink %s\\n" "$symlink" ) + quit 1 + } +fi + printf ' Connect with the following command: -- cgit v1.3