Skip to content

Commit

Permalink
Update install_postgres_json_schema_extension.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
delcroip authored Nov 14, 2024
1 parent e7feb1b commit 0c1dfec
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions install_postgres_json_schema_extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ install_ubuntu() {
apt-get install -y $@
}

# Function to get PostgreSQL version on Ubuntu
get_postgres_version_ubuntu() {
local pg_version=$(ls /usr/share/postgresql/ | grep -E '^[0-9]+$' | sort -rn | head -n1)
echo "$pg_version"
}

# Install packages based on the detected OS
if [[ "$OS" == *"Alpine"* ]]; then
echo "Detected Alpine Linux"
Expand All @@ -40,17 +46,24 @@ cd postgres-json-schema
# Build the extension
make && make install


if [[ "$OS" == *"Alpine"* ]]; then
# Create the extension directory if it doesn't exist
mkdir -p '/usr/local/share/postgresql/extension'
# Set appropriate permissions for the control file
chmod 644 /usr/local/share/postgresql/extension/postgres-json-schema.control
elif [[ "$OS" == *"Ubuntu"* ]]; then
# Get PostgreSQL version
PG_VERSION=$(get_postgres_version_ubuntu)

if [ -z "$PG_VERSION" ]; then
echo "Could not determine PostgreSQL version"
exit 1
fi

# Create the extension directory if it doesn't exist
mkdir -p '/usr/share/postgresql/extension'
mkdir -p "/usr/share/postgresql/$PG_VERSION/extension"
# Set appropriate permissions for the control file
chmod 644 /usr/share/postgresql/extension/postgres-json-schema.control
chmod 644 "/usr/share/postgresql/$PG_VERSION/extension/postgres-json-schema.control"
else
echo "Unsupported operating system: $OS"
exit 1
Expand Down

0 comments on commit 0c1dfec

Please sign in to comment.