44 lines
1.3 KiB
Bash
44 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -Eeuo pipefail
|
|
|
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck source=install_common.sh
|
|
source "$SCRIPT_DIR/install_common.sh"
|
|
|
|
readonly STAGING_DIR="${STAGING_DIR:-$SCRIPT_DIR/tmp}"
|
|
readonly POSTGRES_ROOT="${POSTGRES_ROOT:-/app/postgres/rdbms}"
|
|
|
|
[[ $# -eq 1 ]] || die "Usage: $0 <postgresql-version>"
|
|
readonly POSTGRES_VERSION="$1"
|
|
validate_postgresql_version "$POSTGRES_VERSION"
|
|
require_tools curl tar make gcc
|
|
|
|
readonly PREFIX="$POSTGRES_ROOT/$POSTGRES_VERSION"
|
|
readonly PG_BIN="$PREFIX/bin"
|
|
readonly PG_CONFIG="$PG_BIN/pg_config"
|
|
[[ "$PREFIX" != "/" ]] || die "PREFIX must not be the filesystem root"
|
|
reset_staging_dir "$STAGING_DIR"
|
|
rm -rf -- "$PREFIX"
|
|
mkdir -p "$STAGING_DIR" "$PREFIX"
|
|
|
|
printf 'Building PostgreSQL %s\n' "$POSTGRES_VERSION"
|
|
readonly POSTGRES_ARCHIVE="$STAGING_DIR/postgresql-$POSTGRES_VERSION.tar.gz"
|
|
readonly POSTGRES_SOURCE="$STAGING_DIR/postgresql-$POSTGRES_VERSION"
|
|
curl -fL --retry 3 --retry-delay 2 \
|
|
-o "$POSTGRES_ARCHIVE" \
|
|
"https://ftp.postgresql.org/pub/source/v$POSTGRES_VERSION/postgresql-$POSTGRES_VERSION.tar.gz"
|
|
tar -xzf "$POSTGRES_ARCHIVE" -C "$STAGING_DIR"
|
|
|
|
cd "$POSTGRES_SOURCE"
|
|
./configure \
|
|
--prefix="$PREFIX" \
|
|
--with-ssl=openssl \
|
|
--with-lz4
|
|
make -j"${JOBS:-$(nproc)}"
|
|
make install
|
|
|
|
printf '\nVerification:\n'
|
|
"$PG_BIN/postgres" --version
|
|
"$PG_CONFIG" --version
|