-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
101 lines (83 loc) · 2.93 KB
/
install.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# Exit immediately if a command exits with a non-zero status or if an unset variable is used.
set -exu
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if cargo is on the path
if ! command_exists cargo; then
echo "cargo is not installed. Please install it and try again."
echo "See https://www.rust-lang.org/tools/install"
exit 1
fi
# Check if git is on the path
if ! command_exists git; then
echo "git is not installed. Please install it and try again."
echo "See https://git-scm.com/downloads"
exit 1
fi
# Check if jq is on the path
if ! command_exists jq; then
echo "jq is not installed. Please install it and try again."
echo "See https://jqlang.github.io/jq/download/"
exit 1
fi
# Check if a C compiler is on the path
if ! command_exists cc; then
echo "cc is not installed. Please install a C compiler and try again."
exit 1
fi
# Parse command-line arguments for pg_config path and revision
PG_CONFIG_PATH=""
REVISION=""
while [[ "$#" -gt 0 ]]; do
case $1 in
--pg-config) PG_CONFIG_PATH="$2"; shift ;;
--revision) REVISION="$2"; shift ;;
*) echo "Unknown parameter: $1"; exit 1 ;;
esac
shift
done
# Create a temporary directory for compilation
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_DIR"' EXIT
# Clone the project
git clone https://github.com/kaspermarstal/plprql "${TEMP_DIR}"
# Change to the temporary directory
cd "${TEMP_DIR}"
# If a revision is specified, checkout that revision
if [[ -n "$REVISION" ]]; then
git checkout "$REVISION"
fi
# Fetch PL/PRQL version for pgrx
PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name=="pgrx") | .version')
# Check if cargo pgrx is installed
if ! cargo --list | grep -q 'pgrx' >/dev/null 2>&1; then
echo "cargo pgrx is not installed. Please install version $PGRX_VERSION and try again."
echo "See https://github.com/pgcentralfoundation/pgrx"
exit 1
fi
# Check if the required version of pgrx is installed
PGRX_VERSION_INSTALLED=$(cargo pgrx --version | awk '{print $2}')
if [[ "$PGRX_VERSION_INSTALLED" != "$PGRX_VERSION" ]]; then
echo "Installed version of pgrx $PGRX_VERSION_INSTALLED does not match PL/PRQL version $PGRX_VERSION."
echo "Please install version $PGRX_VERSION and try again."
exit 1
fi
# Check if pg_config path is provided and exists
if [[ -n "$PG_CONFIG_PATH" ]] && ! command -v "$PG_CONFIG_PATH" &>/dev/null; then
echo "The specified pg_config path does not exist."
exit 1
fi
# Fallback to default pg_config if not provided or doesn't exist
if [[ -z "$PG_CONFIG_PATH" ]] && ! command -v pg_config &>/dev/null; then
echo "pg_config is not installed or not found in PATH."
exit 1
fi
# Use the provided pg_config path or fallback to the default
PG_CONFIG_PATH="${PG_CONFIG_PATH:-$(which pg_config)}"
# Install PL/PRQL
cd plprql
cargo pgrx install --no-default-features --release --sudo --pg-config="${PG_CONFIG_PATH}"
echo "PL/PRQL installed successfully."