Code

CData: Use float8 rather than double.
[postrr.git] / pgtest.sh
1 #! /bin/bash
2 #
3 # PostRR test setup helper script
4 #
5 # Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 #    notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 #    notice, this list of conditions and the following disclaimer in the
15 #    documentation and/or other materials provided with the distribution.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 PG_CONFIG=`which pg_config`
30 if test -z "$PG_CONFIG"; then
31         echo "pg_config not found!" >&2
32         exit 1
33 fi
35 BIN_DIR=`pg_config --bindir`
36 if test -z "$TARGET"; then
37         TARGET=`pwd`/target
38 fi
40 PWD_esc="$( echo "$PWD" | sed -e 's/\//\\\//g' )"
41 TARGET_esc="$( echo "$TARGET" | sed -e 's/\//\\\//g' )"
43 set -e
45 case "$1" in
46         setup)
47                 mkdir -p $TARGET/var/lib/postgresql/main
48                 mkdir -p $TARGET/var/run/postgresql
49                 mkdir -p $TARGET/var/log/postgresql/main
50                 $BIN_DIR/initdb -D $TARGET/var/lib/postgresql/main
51                 sed -r -i -e 's/^#port = 5432/port = 5435/' \
52                         $TARGET/var/lib/postgresql/main/postgresql.conf
53                 sed -r -i -e "s/^#dynamic_library_path = '\\\$libdir'/dynamic_library_path = '\$libdir:$PWD_esc\/src'/" $TARGET/var/lib/postgresql/main/postgresql.conf
54                 sed -r -i -e "s/^#unix_socket_directory = ''/unix_socket_directory = '$TARGET_esc\/var\/run\/postgresql'/" $TARGET/var/lib/postgresql/main/postgresql.conf
55                 $0 start -B
56                 $BIN_DIR/createdb -e -h $TARGET/var/run/postgresql/ -p 5435 tokkee
57                 $0 stop
58                 ;;
59         client)
60                 libedit=$( ldd $BIN_DIR/psql 2> /dev/null \
61                         | grep -Eo '=> [^ ]+\/libedit\.so\..? ' | cut -d' ' -f2 )
62                 if test -n "$libedit"; then
63                         libdir=${libedit/libedit.*/}
64                         libreadline=$( ls $libdir/libreadline.so* 2> /dev/null | head -n1 )
65                         if test -n "$libreadline"; then
66                                 export LD_PRELOAD="$LD_PRELOAD:$libreadline"
67                         fi
68                 fi
69                 $BIN_DIR/psql -h $TARGET/var/run/postgresql/ -p 5435
70                 ;;
71         stop)
72                 $BIN_DIR/pg_ctl -D $TARGET/var/lib/postgresql/main stop
73                 ;;
74         start)
75                 if test "$2" = "-B"; then
76                         $BIN_DIR/pg_ctl -D $TARGET/var/lib/postgresql/main -l logfile -w start
77                 else
78                         $BIN_DIR/postgres -D $TARGET/var/lib/postgresql/main
79                 fi
80                 ;;
81         *)
82                 echo "Usage: $0 setup|client|stop|start" >&2
83                 exit 1
84                 ;;
85 esac
87 # vim: set tw=0 :