summaryrefslogtreecommitdiff
path: root/temp-postgres.sh
diff options
context:
space:
mode:
Diffstat (limited to 'temp-postgres.sh')
-rwxr-xr-xtemp-postgres.sh46
1 files changed, 36 insertions, 10 deletions
diff --git a/temp-postgres.sh b/temp-postgres.sh
index 15e169b..6064b66 100755
--- a/temp-postgres.sh
+++ b/temp-postgres.sh
@@ -1,6 +1,6 @@
#! /bin/sh
-# Copyright (c) 2019, 2020, 2022 Stefan Kreutz <mail@skreutz.com>
+# Copyright (c) 2019, 2020, 2022, 2026 Stefan Kreutz <mail@skreutz.com>
#
# Permission to use, copy, modify, and distribute this software for any purpose
# with or without fee is hereby granted, provided that the above copyright
@@ -14,7 +14,7 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
-set -u
+set -o nounset
# Remove the temporary directory before exiting.
trap 'quit' INT
@@ -30,14 +30,40 @@ quit() {
exit "${code}"
}
-# Parse arguments.
-[ $# -eq 2 ] || {
- ( >&2 printf "temp-postgres: invalid arguments\\n" )
- printf "Usage: temp-postgres <dbname> <username>\\n"
- quit 1
-}
-dbname="$1"
-username="$2"
+dbname="$( id -un )"
+username="$( id -un )"
+
+while [ $# -gt 0 ] ; do
+ case "$1" in
+ -h|--help)
+ echo "Usage: temp-postgres [-h|--help] [-d|--dbname <dbname>] [-u|--username <username>]"
+ exit
+ ;;
+ -d|--dbname)
+ dbname="$2"
+ shift 2
+ ;;
+ -u|--username)
+ username="$2"
+ shift 2
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ ( >&2 echo "undefined option: $1" )
+ exit 2
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+if [ $# -gt 0 ] ; then
+ ( >&2 echo "too many arguments" )
+ exit 2
+fi
# Create a temporary directory
tmpdir="$( mktemp -d )" || {
Generated by cgit. See skreutz.com for my tech blog and contact information.