Skip to content

Commit

Permalink
Update entrypoint.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Sep 8, 2023
1 parent 6fb704b commit d9fe6a0
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
#!/usr/bin/env bash

set -e
set -euo pipefail

echo "::group::setup-postgresql"

echo "Verifying version"

# Check if the input is an integer
if ! [[ "$INPUT_POSTGRESQL_VERSION" =~ ^[0-9]+$ ]]; then
echo "Error: $INPUT_POSTGRESQL_VERSION is not a valid integer."
exit 1
fi

# Check if the input is between 10 and 15 (inclusive)
if (( INPUT_POSTGRESQL_VERSION < 10 || INPUT_POSTGRESQL_VERSION > 15 )); then
echo "Error: $INPUT_POSTGRESQL_VERSION is not between 10 and 15 (inclusive)."
exit 1
fi

echo "Validated postgresql version: $INPUT_POSTGRESQL_VERSION"

echo "Installing postgresql..."

if [[ "$(uname -s)" == "Linux" ]]; then
# Create the file repository configuration:
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:
sudo apt-get update

# Install PostgreSQL
sudo apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION"
elif [[ "$(uname -s)" == "NT"* ]]; then
choco install postgresql --version="$INPUT_POSTGRESQL_VERSION" -y
elif [[ "$(uname -s)" == "Darwin" ]]; then
brew update
brew install "postgresql@$INPUT_POSTGRESQL_VERSION"
else
echo "Unsupported OS"
exit 1
fi

echo "Installed postgresql"

echo "Verifying installation..."

# Verify installation by running pg_dump directly
if [[ "$(uname -s)" == "NT"* ]]; then
"/Program Files/PostgreSQL/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" --version

echo "/Program Files/PostgreSQL/$INPUT_POSTGRESQL_VERSION/bin" >> $GITHUB_PATH
else
"/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" --version

echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> $GITHUB_PATH
fi

echo "Complete"

echo "::endgroup::"

0 comments on commit d9fe6a0

Please sign in to comment.