-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg-add-extension.sh
executable file
·53 lines (40 loc) · 1.2 KB
/
pg-add-extension.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
# This script adds the extension to the PostgreSQL installation under the current
# path
set -e
set -o nounset
JSON_QUERY_DIR="`readlink -f $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/`"
if [ -n "${1+isset}" ]; then
if [ "$1" = "--help" ]; then
echo "Install the JSON Query PostgreSQL extension. The optional path argument can be used to provide "
echo "an alternate path to use to locate the pg_config command to use."
echo ""
echo "Usage: pg-add-extension.sh {path}"
exit 1
fi;
if [ ! -d "$1" ]; then
echo "No such directory: $1"
exit 1
fi;
EXTRA_PATH="$(cd $1 && pwd)"
export PATH="$EXTRA_PATH:$PATH"
fi
if ! PG_CONFIG="$(which pg_config)"; then
echo "pg_config not found. Unable to install JSON Query."
exit 1
fi;
read -r -p "Install JSON Query extension (pg_config=$PG_CONFIG)? [y/N]" RESP
if [[ ! "$RESP" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "Cancelled."
exit 1
fi
# Give a brief chance to kill.
echo "Installing extension... "
sleep 1
if cd "$JSON_QUERY_DIR" && sudo env "PATH=$PATH" make install; then
echo "done."
exit 0
else
echo "install failed."
echo 1;
fi;