with-postgres.sh (570B)
1 #!/bin/bash 2 # This file is in the public domain. 3 4 # Runs the commands given at "$@" with a locally started postgres instance 5 6 PG_VER=12 7 PG_DIR=/usr/lib/postgresql/$PG_VER/bin 8 9 # setup little postgres DB for us ... 10 TMP_DB_DIR=`mktemp -d ~/tmpXXXXXX` 11 $PG_DIR/initdb -D $TMP_DB_DIR/ -A trust 12 export PGPORT=5432 13 export PGHOST=localhost 14 $PG_DIR/pg_ctl -D $TMP_DB_DIR/ -o "-c unix_socket_directories=$HOME" -l logfile start 15 $PG_DIR/createdb talercheck 16 $PG_DIR/createdb synccheck 17 18 # Run the commands 19 "$@" 20 21 # Stop postgres 22 $PG_DIR/pg_ctl -D $TMP_DB_DIR/ stop 23 rm -rf $TMP_DB_DIR