]> granicus.if.org Git - postgresql/blob - contrib/sepgsql/launcher
Manual cleanup of pgindent results.
[postgresql] / contrib / sepgsql / launcher
1 #!/bin/sh
2 #
3 # A wrapper script to launch psql command in regression test
4 #
5 # Copyright (c) 2010-2015, PostgreSQL Global Development Group
6 #
7 # -------------------------------------------------------------------------
8
9 if [ $# -lt 1 ]; then
10     echo "usage: `basename $0` <command> [options...]"
11     exit 1
12 fi
13
14 RUNCON=`which runcon`
15 if [ ! -e "$RUNCON" ]; then
16     echo "runcon command is not found"
17     exit 1
18 fi
19
20 #
21 # Read SQL from stdin
22 #
23 TEMP=`mktemp`
24 CONTEXT=""
25
26 while IFS='\\n' read LINE
27 do
28     if echo "$LINE" | grep -q "^-- @SECURITY-CONTEXT="; then
29         if [ -s "$TEMP" ]; then
30             if [ -n "$CONTEXT" ]; then
31                 "$RUNCON" "$CONTEXT" $* < "$TEMP"
32             else
33                 $* < $TEMP
34             fi
35             truncate -s0 $TEMP
36         fi
37         CONTEXT=`echo "$LINE" | sed 's/^-- @SECURITY-CONTEXT=//g'`
38         LINE="SELECT sepgsql_getcon();  -- confirm client privilege"
39     fi
40     echo "$LINE" >> $TEMP
41 done
42
43 if [ -s "$TEMP" ]; then
44     if [ -n "$CONTEXT" ]; then
45         "$RUNCON" "$CONTEXT" $* < "$TEMP"
46     else
47         $* < $TEMP
48     fi
49 fi
50
51 # cleanup temp file
52 rm -f $TEMP