53 lines
2.0 KiB
Bash
53 lines
2.0 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}"
|
|
readonly PG_HINT_PLAN_REPOSITORY="${PG_HINT_PLAN_REPOSITORY:-ossc-db/pg_hint_plan}"
|
|
|
|
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
|
|
show_help "$0" "Build and install pg_hint_plan for an existing PostgreSQL installation."
|
|
exit 0
|
|
fi
|
|
|
|
POSTGRES_VERSION="$(parse_postgresql_version "$@")"
|
|
readonly POSTGRES_VERSION
|
|
require_tools curl tar make
|
|
readonly PREFIX="${PREFIX:-$POSTGRES_ROOT/$POSTGRES_VERSION}"
|
|
readonly PG_CONFIG="$PREFIX/bin/pg_config"
|
|
require_postgresql_installation "$PREFIX"
|
|
reset_staging_dir "$STAGING_DIR"
|
|
|
|
readonly PG_HINT_PLAN_TAG="${PG_HINT_PLAN_TAG:-$(latest_pg_hint_plan_tag "$PG_HINT_PLAN_REPOSITORY" "${POSTGRES_VERSION%%.*}")}"
|
|
[[ -n "$PG_HINT_PLAN_TAG" ]] || die "could not determine a pg_hint_plan tag"
|
|
readonly PG_HINT_PLAN_DIR="$STAGING_DIR/pg_hint_plan-$PG_HINT_PLAN_TAG"
|
|
|
|
printf 'Building pg_hint_plan %s\n' "$PG_HINT_PLAN_TAG"
|
|
download_source "$STAGING_DIR" "$PG_HINT_PLAN_REPOSITORY" "$PG_HINT_PLAN_TAG" \
|
|
"pg_hint_plan-$PG_HINT_PLAN_TAG.tar.gz" "$PG_HINT_PLAN_DIR"
|
|
record_source_download "pg_hint_plan" "$(github_source_url "$PG_HINT_PLAN_REPOSITORY" "$PG_HINT_PLAN_TAG")" "$PG_HINT_PLAN_TAG"
|
|
cd "$PG_HINT_PLAN_DIR"
|
|
make -j"${JOBS:-$(nproc)}" USE_PGXS=1 PG_CONFIG="$PG_CONFIG"
|
|
make install USE_PGXS=1 PG_CONFIG="$PG_CONFIG"
|
|
test -f "$PREFIX/lib/pg_hint_plan.so"
|
|
test -f "$PREFIX/share/extension/pg_hint_plan.control"
|
|
|
|
readonly SAVED_SOURCE_DIR="$(copy_install_source "$PG_HINT_PLAN_DIR" "$PREFIX" "pg_hint_plan-$PG_HINT_PLAN_TAG")"
|
|
write_install_recipe "$SAVED_SOURCE_DIR" "$POSTGRES_VERSION" "$PREFIX" <<'RECIPE'
|
|
cd "$SCRIPT_DIR"
|
|
|
|
# Configure
|
|
# pg_hint_plan uses PGXS directly and does not require a separate configure step.
|
|
|
|
# Make
|
|
make -j"$JOBS" USE_PGXS=1 PG_CONFIG="$PG_CONFIG"
|
|
|
|
# Make install
|
|
make install USE_PGXS=1 PG_CONFIG="$PG_CONFIG"
|
|
RECIPE
|