forked from tj-actions/install-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·64 lines (47 loc) · 1.94 KB
/
entrypoint.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
#!/usr/bin/env bash
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 11 and 17 (inclusive)
if (( INPUT_POSTGRESQL_VERSION < 12 || INPUT_POSTGRESQL_VERSION > 17 )); then
echo "Error: $INPUT_POSTGRESQL_VERSION is not between 12 and 17 (inclusive)."
exit 1
fi
echo "Validated postgresql version: $INPUT_POSTGRESQL_VERSION"
echo "Installing postgresql..."
OS=$(uname -s)
echo "OS: $OS"
if [[ "$OS" == "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 [[ "$OS" == "NT"* ]] || [[ "$OS" == "MINGW"* ]] || [[ "$OS" == *"MSYS"* ]]; then
choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress --use-download-cache
elif [[ "$OS" == "Darwin" ]]; then
HOMEBREW_NO_AUTO_UPDATE=1 brew install "postgresql@$INPUT_POSTGRESQL_VERSION"
else
echo "Unsupported OS"
exit 1
fi
echo "Installed postgresql"
echo "Updating PATH..."
if [[ "$OS" == "NT"* ]] || [[ "$OS" == "MINGW"* ]] || [[ "$OS" == *"MSYS"* ]]; then
# shellcheck disable=SC2028
echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> "$GITHUB_PATH"
elif [[ "$OS" == "Darwin" ]]; then
echo "$(brew --prefix postgresql@"${INPUT_POSTGRESQL_VERSION}")/bin" >> "$GITHUB_PATH"
else
echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> "$GITHUB_PATH"
fi
echo "Complete"
echo "::endgroup::"