diff options
author | Pavel Raiskup <praiskup@redhat.com> | 2014-06-21 20:37:33 +0200 |
---|---|---|
committer | Pavel Raiskup <praiskup@redhat.com> | 2014-07-01 09:20:41 +0200 |
commit | 9c800a8f50b1b3736aa81e646d66a4a1c6812773 (patch) | |
tree | 715f8e803e9d671f63a9e1c2c9e4ce1373b78030 | |
parent | 1a206187ca761c75e13989eab92430df689e1eca (diff) | |
download | postgresql-setup-9c800a8f50b1b3736aa81e646d66a4a1c6812773.tar.gz postgresql-setup-9c800a8f50b1b3736aa81e646d66a4a1c6812773.tar.xz postgresql-setup-9c800a8f50b1b3736aa81e646d66a4a1c6812773.zip |
configury: prepare for autotools
-rw-r--r-- | .gitignore | 11 | ||||
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | configure.ac | 131 | ||||
-rw-r--r-- | postgresql-setup.in (renamed from postgresql-setup) | 40 |
4 files changed, 160 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2cd6e87 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +config.log +config.status +configure +install-sh +missing +*.log +postgresql-setup diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..ba79058 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +bin_SCRIPTS = postgresql-setup diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..64cfbd3 --- /dev/null +++ b/configure.ac @@ -0,0 +1,131 @@ +AC_INIT([postgresql-setup], [0.9], [praiskup@redhat.com]) +AM_INIT_AUTOMAKE([foreign -Wall -Werror]) +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([postgresql-setup], [chmod +x postgresql-setup]) + +# For SELinux purposes use rather runuser +AC_PATH_PROG([SU], [runuser]) +test -z "$ac_cv_path_SU" && + AC_PATH_PROG([SU], [su]) +test -z "$ac_cv_path_SU" && + AC_MSG_ERROR([Neither 'runuser' nor 'su' program found]) + +distro_family=redhat +test -r /etc/redhat-release || + AC_MSG_ERROR([This still works for Red Hat distributions only]) + +# Check package manager is installed +case "$distro_family" in +redhat) + AC_PATH_PROG([RPM], [rpm]) + test -z "$ac_cv_path_RPM" && + AC_MSG_ERROR([RPM package manager is required]) + ;; +esac + +# Make sure that the variable is in './configure --help' output and that it is +# not empty. +m4_define([subst_required_var], [ + AC_ARG_VAR([$1], [$2]) + test -z "$[]$1" && + AC_MSG_ERROR([the \$$1 variable is not set]) +]) + +# Check for main PostgreSQL binary +# -------------------------------- + +AC_ARG_VAR([POSTGRES_BIN], [full path to postgres binary]) +AC_PATH_PROG([POSTGRES_BIN], [postgres]) + + +# PGVERSION & PGMAJORVERSION +# -------------------------- + +if test -z "$PGVERSION" -a -z "$PGMAJORVERSION"; then + test -z "$ac_cv_path_POSTGRES_BIN" && + AC_MSG_ERROR([no postgres binary, can not detect version]) + + AC_MSG_CHECKING([for full version PostgreSQL server]) + raw_version=$("$POSTGRES_BIN" --version) || + AC_MSG_ERROR([command $POSTGRES_BIN --version failed]) + + PGVERSION=${raw_version##* } + AC_MSG_RESULT($PGVERSION) + + PGMAJORVERSION=${PGVERSION%%.[[0-9]]} +fi + +# Detect PGENGINE location +# ------------------------ + +if test -z "$PGENGINE"; then + test -z "$ac_cv_path_POSTGRES_BIN" && + AC_MSG_ERROR([no postgres binary, can not detect PGENGINE]) + PGENGINE=`AS_DIRNAME($POSTGRES_BIN)` +fi + +# pg_upgrade binary +# ----------------- + +AC_PATH_PROG([PG_UPGRADE_BIN], [pg_upgrade]) + +# Detect PREVMAJORVERSION +# ----------------------- +# This sets as a side effect PREV_POSTGRES_BIN, which is used later on. + +if test -z "$PREVMAJORVERSION"; then + case "$distro_family" in + redhat) + AC_MSG_CHECKING([for prev major version]) + test -z "$ac_cv_path_PG_UPGRADE_BIN" && + AC_MSG_ERROR([no pg_upgrade found]) + + PREV_POSTGRES_BIN=$(rpm -ql \ + $(rpm -qf "$ac_cv_path_PG_UPGRADE_BIN") \ + | grep 'bin/postgres' ) + + PREVMAJORVERSION=$(echo $PREV_POSTGRES_BIN \ + | sed 's/.*postgresql-\([[0-9\.]]\+\).*/\1/') + AC_MSG_RESULT($PREVMAJORVERSION) + ;; + esac +fi + +# Detect PREVPGENGINE +# ------------------- + +if test -z "$PREVPGENGINE"; then + PREVPGENGINE=`AS_DIRNAME($PREV_POSTGRES_BIN)` +fi + +# Detect where distribution-like README is +# ---------------------------------------- + +case "$distro_family" in +redhat) + README_DIST=`rpm -ql postgresql | grep README | grep dist` + ;; +esac + +test -z "$INITDB_LOG" && + INITDB_LOG=/var/lib/pgsql/initdb.log + +test -z "$UPGRADE_LOG" && + UPGRADE_LOG=/var/lib/pgsql/pgupgrade.log + +if test -z "$SYSCONFIG_DIR" -a "$distro_family" = redhat; then + SYSCONFIG_DIR=/etc/sysconfig +fi + +# Deal with previous versions +subst_required_var([PGVERSION], [full PG version]) +subst_required_var([PGMAJORVERSION], [major PG version]) +subst_required_var([PGENGINE], [directory where PG server resides]) +subst_required_var([PREVMAJORVERSION], [PG major version to upgrade _from_]) +subst_required_var([PREVPGENGINE], [directory where old PG server resides]) +subst_required_var([README_DIST], [README file for distribution]) +subst_required_var([INITDB_LOG], [log file for initdb]) +subst_required_var([UPGRADE_LOG], [log file for pg_upgrade]) +subst_required_var([SYSCONFIG_DIR], [log file for pg_upgrade]) + +AC_OUTPUT diff --git a/postgresql-setup b/postgresql-setup.in index 2a682e2..65f540a 100644 --- a/postgresql-setup +++ b/postgresql-setup.in @@ -6,39 +6,33 @@ test -z "$PATH" && export PATH="/sbin:/usr/sbin:/bin:/usr/bin" test x"$PGSETUP_DEBUG" != x && set -x && PS4='${LINENO}: ' -# PGVERSION is the full package version, e.g., 9.0.2 -# Note: the specfile inserts the correct value during package build -PGVERSION=xxxx +# Full PostgreSQL version, e.g. 9.0.2 +PGVERSION=@PGVERSION@ -# PGMAJORVERSION is the major version, e.g. 9.0 -PGMAJORVERSION=xxxx +# Major version of PostgreSQL, e.g. 9.0 +PGMAJORVERSION=@PGMAJORVERSION@ -# PGENGINE is the directory containing the postmaster executable -PGENGINE=xxxx +# Directory containing the postmaster executable +PGENGINE=@PGENGINE@ -# PREVMAJORVERSION is the previous major version, e.g., 8.4, for upgrades -PREVMAJORVERSION=xxxx +# Previous major version, e.g., 8.4, for upgrades +PREVMAJORVERSION=@PREVMAJORVERSION@ -# PREVPGENGINE is the directory containing the previous postmaster executable -PREVPGENGINE=xxxx +# Directory containing the previous postmaster executable +PREVPGENGINE=@PREVPGENGINE@ -# Pathname of the RPM distribution README -README_RPM_DIST=xxxx +# Distribution README file +README_DIST=@README_DIST@ # Log file for initdb -PGLOG=/var/lib/pgsql/initdb.log +PGLOG=@INITDB_LOG@ # Log file for pg_upgrade -PGUPLOG=/var/lib/pgsql/pgupgrade.log +PGUPLOG=@UPGRADE_LOG@ -SYSCONFIG_DIR=/etc/sysconfig +SYSCONFIG_DIR=@SYSCONFIG_DIR@ -# For SELinux we need to use 'runuser' not 'su' -if [ -x /sbin/runuser ]; then - SU=runuser -else - SU=su -fi +SU=@SU@ USAGE_STRING=$" Usage: $0 {initdb|upgrade} [--name SERVICE_NAME] @@ -47,7 +41,7 @@ Script is aimed to help sysadmin with basic database cluster administration. The SERVICE_NAME is used for selection of proper unit configuration file; For more info and howto/when use this script please look at the docu file -$README_RPM_DIST. The 'postgresql' +$README_DIST. The 'postgresql' string is used when no SERVICE_NAME is explicitly passed. Available operation mode: |