evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / by-name / po / postgresqlTestHook / postgresql-test-hook.sh
blobd09153b2d64414064829e025da6344002e373d17
1 preCheckHooks+=('postgresqlStart')
2 postCheckHooks+=('postgresqlStop')
5 postgresqlStart() {
7 # Add default environment variable values
9 # Client variables:
10 # - https://www.postgresql.org/docs/current/libpq-envars.html
12 # Server variables:
13 # - only PGDATA: https://www.postgresql.org/docs/current/creating-cluster.html
15 if [[ "${PGDATA:-}" == "" ]]; then
16 PGDATA="$NIX_BUILD_TOP/postgresql"
18 export PGDATA
20 if [[ "${PGHOST:-}" == "" ]]; then
21 mkdir -p "$NIX_BUILD_TOP/run/postgresql"
22 PGHOST="$NIX_BUILD_TOP/run/postgresql"
24 export PGHOST
26 if [[ "${PGUSER:-}" == "" ]]; then
27 PGUSER="test_user"
29 export PGUSER
31 if [[ "${PGDATABASE:-}" == "" ]]; then
32 PGDATABASE="test_db"
34 export PGDATABASE
36 if [[ "${postgresqlTestUserOptions:-}" == "" ]]; then
37 postgresqlTestUserOptions="LOGIN"
40 if [[ "${postgresqlTestSetupSQL:-}" == "" ]]; then
41 postgresqlTestSetupSQL="$(cat <<EOF
42 CREATE ROLE "$PGUSER" $postgresqlTestUserOptions;
43 CREATE DATABASE "$PGDATABASE" OWNER '$PGUSER';
44 EOF
48 if [[ "${postgresqlTestSetupCommands:-}" == "" ]]; then
49 postgresqlTestSetupCommands='echo "$postgresqlTestSetupSQL" | PGUSER=postgres psql postgres'
52 if ! type initdb >/dev/null; then
53 echo >&2 'initdb not found. Did you add postgresql to the nativeCheckInputs?'
54 false
56 echo 'initializing postgresql'
57 initdb -U postgres
59 echo "$postgresqlExtraSettings" >>"$PGDATA/postgresql.conf"
61 # Move the socket
62 echo "unix_socket_directories = '$NIX_BUILD_TOP/run/postgresql'" >>"$PGDATA/postgresql.conf"
64 # TCP ports can be a problem in some sandboxes,
65 # so we disable tcp listening by default
66 if ! [[ "${postgresqlEnableTCP:-}" = 1 ]]; then
67 echo "listen_addresses = ''" >>"$PGDATA/postgresql.conf"
70 echo 'starting postgresql'
71 eval "${postgresqlStartCommands:-pg_ctl start}"
73 echo 'setting up postgresql'
74 eval "$postgresqlTestSetupCommands"
76 runHook postgresqlTestSetupPost
80 postgresqlStop() {
81 echo 'stopping postgresql'
82 pg_ctl stop