From 7b1bb4fd5a05b9c35ae23734f12b2a92fe5f0a57 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Tue, 1 Jul 2014 13:41:43 +0200 Subject: postgresql-check-db-dir generated also Also generate files using sed as is suggested by autoconf manual (and the autoconf project does so internally). --- .gitignore | 3 ++- Makefile.am | 44 +++++++++++++++++++++++++++-------- TODO | 2 ++ configure.ac | 6 ++++- postgresql-check-db-dir | 57 ---------------------------------------------- postgresql-check-db-dir.in | 57 ++++++++++++++++++++++++++++++++++++++++++++++ postgresql.service.in | 2 +- 7 files changed, 102 insertions(+), 69 deletions(-) create mode 100644 TODO delete mode 100644 postgresql-check-db-dir create mode 100644 postgresql-check-db-dir.in diff --git a/.gitignore b/.gitignore index e7ec3c9..446e759 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,9 @@ install-sh missing *.log INSTALL -postgresql*-setup +postgresql*-check-db-dir postgresql*-ctl +postgresql*-setup postgresql*-setup.1 *.tar.gz conf/postgresql* diff --git a/Makefile.am b/Makefile.am index d09ee3d..ddd8b78 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,34 +2,60 @@ SUBDIRS = . doc bin_SCRIPTS = postgresql$(DISTSUFF)-setup -libexec_SCRIPTS = postgresql$(DISTSUFF)-ctl +libexec_SCRIPTS = postgresql$(DISTSUFF)-ctl \ + postgresql$(DISTSUFF)-check-db-dir pkgsysconfdir = $(PKGCONFIG_DIR) pkgsysconf_DATA = conf/postgresql$(DISTSUFF) systemdunitsdir = $(prefix)/lib/systemd/system -systemdunits_DATA = postgresql$(DISTSUFF).service +nodist_systemdunits_DATA = postgresql$(DISTSUFF).service nodist_pgdoc_DATA = README.rpm-dist -c_s_gen = $(AM_V_GEN)cmd="$(top_srcdir)/config.status --file=$@:$<" ; \ - if $(AM_V_P); then $$cmd; else $$cmd &>/dev/null; fi +# Encouraged by autoconf documentation itself. When we use config.status +# directly, e.g. libexecdir may result into '${exec_prefix}/libexec' -- but we +# need fully expanded strings there. +edit = $(SED) \ + -e 's|@DISTSUFF[@]|$(DISTSUFF)|g' \ + -e 's|@INITDB_LOG[@]|$(INITDB_LOG)|g' \ + -e 's|@libexecdir[@]|$(libexecdir)|g' \ + -e 's|@PGDATADIR[@]|$(PGDATADIR)|g' \ + -e 's|@pgdocdir[@]|$(pgdocdir)|g' \ + -e 's|@PGENGINE[@]|$(PGENGINE)|g' \ + -e 's|@PGMAJORVERSION[@]|$(PGMAJORVERSION)|g' \ + -e 's|@PGVERSION[@]|$(PGVERSION)|g' \ + -e 's|@PKGCONFIG_DIR[@]|$(PKGCONFIG_DIR)|g' \ + -e 's|@PREVMAJORVERSION[@]|$(PREVMAJORVERSION)|g' \ + -e 's|@PREVPGENGINE[@]|$(PREVPGENGINE)|g' \ + -e 's|@README_DIST[@]|$(README_DIST)|g' \ + -e 's|@SU[@]|$(SU)|g' \ + -e 's|@UPGRADE_LOG[@]|$(UPGRADE_LOG)|g' \ + -e 's|@VERSION[@]|$(VERSION)|g' \ + $< > $@ + +c_s = $(top_srcdir)/config.status + +c_s_gen = $(AM_V_GEN)$(edit) c_s_script_gen = $(c_s_gen) && chmod +x $@ -postgresql$(DISTSUFF)-ctl: postgresql-ctl.in +postgresql$(DISTSUFF)-ctl: postgresql-ctl.in $(c_s) + $(c_s_script_gen) + +postgresql$(DISTSUFF)-setup: postgresql-setup.in $(c_s) $(c_s_script_gen) -postgresql$(DISTSUFF)-setup: postgresql-setup.in +postgresql$(DISTSUFF)-check-db-dir: postgresql-check-db-dir.in $(c_s) $(c_s_script_gen) -conf/postgresql$(DISTSUFF): conf/postgresql.in +conf/postgresql$(DISTSUFF): conf/postgresql.in $(c_s) $(c_s_gen) -postgresql$(DISTSUFF).service: postgresql.service.in +postgresql$(DISTSUFF).service: postgresql.service.in $(c_s) $(c_s_gen) -README.rpm-dist: README.rpm-dist.in +README.rpm-dist: README.rpm-dist.in $(c_s) $(c_s_gen) EXTRA_DIST = *.in conf/*.in diff --git a/TODO b/TODO new file mode 100644 index 0000000..2f678e3 --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +* Testsuite + - check that none of @PATTERN@ is un-expanded in generated files diff --git a/configure.ac b/configure.ac index 285b01f..33bb4ef 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,10 @@ AM_SILENT_RULES([yes]) AC_ARG_VAR([DISTSUFF], [Append string suffix to all binaries]) AC_SUBST([DISTSUFF]) +AC_PATH_PROG([SED], [sed]) +test -z "$ac_cv_path_SED" && + AC_MSG_ERROR([Sed is needed but not found.]) + # For SELinux purposes use rather runuser AC_PATH_PROG([SU], [runuser]) test -z "$ac_cv_path_SU" && @@ -129,7 +133,7 @@ if test -z "$PGDATADIR" -a "$distro_family" = redhat; then fi # TODO -pgdocdir=/usr/share/postgresql/doc +pgdocdir=/usr/share/doc/postgresql AC_SUBST([pgdocdir]) # Deal with previous versions diff --git a/postgresql-check-db-dir b/postgresql-check-db-dir deleted file mode 100644 index 4266c7a..0000000 --- a/postgresql-check-db-dir +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh - -# This script verifies that the postgresql data directory has been correctly -# initialized. We do not want to automatically initdb it, because that has -# a risk of catastrophic failure (ie, overwriting a valuable database) in -# corner cases, such as a remotely mounted database on a volume that's a -# bit slow to mount. But we can at least emit a message advising newbies -# what to do. - -PGDATA="$1" - -if [ -z "$PGDATA" ] -then - echo "Usage: $0 database-path" - exit 1 -fi - -# PGVERSION is the full package version, e.g., 9.1.2 -# Note: the specfile inserts the correct value during package build -PGVERSION=xxxx -# PGMAJORVERSION is major version, e.g., 9.1 (this should match PG_VERSION) -PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'` -# PREVMAJORVERSION is the previous major version, e.g., 8.4, for upgrades -# Note: the specfile inserts the correct value during package build -PREVMAJORVERSION=xxxx -# PGDOCDIR is the directory containing the package's documentation -# Note: the specfile inserts the correct value during package build -PGDOCDIR=xxxx - -# Check for the PGDATA structure -if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ] -then - # Check version of existing PGDATA - if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ] - then - : A-OK - elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ] - then - echo $"An old version of the database format was found." - echo $"Use \"postgresql-setup upgrade\" to upgrade to version $PGMAJORVERSION." - echo $"See $PGDOCDIR/README.rpm-dist for more information." - exit 1 - else - echo $"An old version of the database format was found." - echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION." - echo $"See $PGDOCDIR/README.rpm-dist for more information." - exit 1 - fi -else - # No existing PGDATA! Warn the user to initdb it. - echo $"\"$PGDATA\" is missing or empty." - echo $"Use \"postgresql-setup initdb\" to initialize the database cluster." - echo $"See $PGDOCDIR/README.rpm-dist for more information." - exit 1 -fi - -exit 0 diff --git a/postgresql-check-db-dir.in b/postgresql-check-db-dir.in new file mode 100644 index 0000000..3514247 --- /dev/null +++ b/postgresql-check-db-dir.in @@ -0,0 +1,57 @@ +#!/bin/sh + +# This script verifies that the postgresql data directory has been correctly +# initialized. We do not want to automatically initdb it, because that has +# a risk of catastrophic failure (ie, overwriting a valuable database) in +# corner cases, such as a remotely mounted database on a volume that's a +# bit slow to mount. But we can at least emit a message advising newbies +# what to do. + +PGDATA="$1" + +if [ -z "$PGDATA" ] +then + echo "Usage: $0 database-path" + exit 1 +fi + +# Full PostgreSQL version, e.g. 9.0.2 +PGVERSION=@PGVERSION@ + +# Major version of PostgreSQL, e.g. 9.0 +PGMAJORVERSION=@PGMAJORVERSION@ + +# Previous major version, e.g., 8.4, for upgrades +PREVMAJORVERSION=@PREVMAJORVERSION@ + +# Directory containing the postgresql package's documentation +PGDOCDIR=@pgdocdir@ + +# Check for the PGDATA structure +if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ] +then + # Check version of existing PGDATA + if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ] + then + : A-OK + elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ] + then + echo $"An old version of the database format was found." + echo $"Use \"postgresql-setup upgrade\" to upgrade to version $PGMAJORVERSION." + echo $"See $PGDOCDIR/README.rpm-dist for more information." + exit 1 + else + echo $"An old version of the database format was found." + echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION." + echo $"See $PGDOCDIR/README.rpm-dist for more information." + exit 1 + fi +else + # No existing PGDATA! Warn the user to initdb it. + echo $"\"$PGDATA\" is missing or empty." + echo $"Use \"postgresql-setup initdb\" to initialize the database cluster." + echo $"See $PGDOCDIR/README.rpm-dist for more information." + exit 1 +fi + +exit 0 diff --git a/postgresql.service.in b/postgresql.service.in index c865bcc..b67488e 100644 --- a/postgresql.service.in +++ b/postgresql.service.in @@ -27,7 +27,7 @@ OOMScoreAdjust=-1000 Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj Environment=PG_OOM_ADJUST_VALUE=0 -ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} +ExecStartPre=@libexecdir@/postgresql-check-db-dir ${PGDATA} # Temporarily use postgresql-ctl wrapper around pg_ctl until there will # exist clients which set PGPORT in service file. -- cgit