Skip to content

Commit 0c1dfec

Browse files
authored
Update install_postgres_json_schema_extension.sh
1 parent e7feb1b commit 0c1dfec

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

install_postgres_json_schema_extension.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ install_ubuntu() {
1919
apt-get install -y $@
2020
}
2121

22+
# Function to get PostgreSQL version on Ubuntu
23+
get_postgres_version_ubuntu() {
24+
local pg_version=$(ls /usr/share/postgresql/ | grep -E '^[0-9]+$' | sort -rn | head -n1)
25+
echo "$pg_version"
26+
}
27+
2228
# Install packages based on the detected OS
2329
if [[ "$OS" == *"Alpine"* ]]; then
2430
echo "Detected Alpine Linux"
@@ -40,17 +46,24 @@ cd postgres-json-schema
4046
# Build the extension
4147
make && make install
4248

43-
4449
if [[ "$OS" == *"Alpine"* ]]; then
4550
# Create the extension directory if it doesn't exist
4651
mkdir -p '/usr/local/share/postgresql/extension'
4752
# Set appropriate permissions for the control file
4853
chmod 644 /usr/local/share/postgresql/extension/postgres-json-schema.control
4954
elif [[ "$OS" == *"Ubuntu"* ]]; then
55+
# Get PostgreSQL version
56+
PG_VERSION=$(get_postgres_version_ubuntu)
57+
58+
if [ -z "$PG_VERSION" ]; then
59+
echo "Could not determine PostgreSQL version"
60+
exit 1
61+
fi
62+
5063
# Create the extension directory if it doesn't exist
51-
mkdir -p '/usr/share/postgresql/extension'
64+
mkdir -p "/usr/share/postgresql/$PG_VERSION/extension"
5265
# Set appropriate permissions for the control file
53-
chmod 644 /usr/share/postgresql/extension/postgres-json-schema.control
66+
chmod 644 "/usr/share/postgresql/$PG_VERSION/extension/postgres-json-schema.control"
5467
else
5568
echo "Unsupported operating system: $OS"
5669
exit 1

0 commit comments

Comments
 (0)