summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2015-02-26 14:03:22 +0100
committerPavel Raiskup <praiskup@redhat.com>2015-02-26 16:52:25 +0100
commitf7f516372e2218daf18a79241d1fd271faa237cc (patch)
tree9f9653936f765241e606ed61b1c9eb1bb1720df3
parent1f35a8e32e9287d84b0d46f48a94eca85b59836f (diff)
downloadpostgresql-setup-f7f516372e2218daf18a79241d1fd271faa237cc.tar.gz
postgresql-setup-f7f516372e2218daf18a79241d1fd271faa237cc.tar.xz
postgresql-setup-f7f516372e2218daf18a79241d1fd271faa237cc.zip
configuration: define upgrade-config directory
Currently under /etc/postgresql-setup/upgrade. All '*.conf' files are going to be loaded run-time by postgresql-setup. * postgresql-setup.in (read_config_file): New helper to safely read configuration files. (set_var): Remove comment. (parse_upgrade_setup): Use new read_config_file(). (parse_configuration): Rename to service_configuration(). * Makefile.am: Don't include share/Makefile.inc. Indent fixes. Add install-data-hook helper to install config directory. * build-helpers/Makefile.inc: Removed. * build-helpers/build-config: Likewise. * upgrade_config.template: Removed. * etc/postgresql-setup/upgrade/postgresql.conf: New template. * configure.ac: Remove --with-upgrade-config. Package maintainers are supposed to provide those for now. * share/postgresql-setup/Makefile.inc: Removed.
-rw-r--r--Makefile.am26
-rw-r--r--build-helpers/Makefile.inc7
-rwxr-xr-xbuild-helpers/build-config11
-rw-r--r--configure.ac13
-rw-r--r--etc/postgresql-setup/upgrade/postgresql.conf18
-rw-r--r--postgresql-setup.in97
-rw-r--r--share/postgresql-setup/Makefile.inc16
-rw-r--r--upgrade_config.template16
8 files changed, 94 insertions, 110 deletions
diff --git a/Makefile.am b/Makefile.am
index 6dad8c7..b575702 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,8 +18,10 @@ initscript = $(NAME_SERVICE)
initscript_in = postgresql.init.in
EXTRA_DIST =
+GENERATED_FILES =
+CLEANFILES =
-include $(srcdir)/build-helpers/Makefile.inc
+# include $(srcdir)/build-helpers/Makefile.inc
SUBDIRS = . doc tests
@@ -77,19 +79,18 @@ $(README_DIST_BASENAME): $(README_DIST_BASENAME).in $(c_s)
EXTRA_DIST += \
$(srcdir)/*.in \
- upgrade_config.template
+ $(srcdir)/etc/postgresql-setup/upgrade/postgresql.conf
-GENERATED_FILES = $(bin_SCRIPTS) \
- $(libexec_SCRIPTS) \
- $(doc_DATA) \
- $(pkgsysconf_DATA) \
- $(systemdunits_DATA) \
- $(initscripts_DATA) \
- $(systemdlegacyscripts_SCRIPTS)
+GENERATED_FILES += \
+ $(bin_SCRIPTS) \
+ $(libexec_SCRIPTS) \
+ $(doc_DATA) \
+ $(pkgsysconf_DATA) \
+ $(systemdunits_DATA) \
+ $(initscripts_DATA) \
+ $(systemdlegacyscripts_SCRIPTS)
-CLEANFILES = $(GENERATED_FILES) $(TEST_GEN_FILES_LIST)
-
-include $(srcdir)/share/postgresql-setup/Makefile.inc
+CLEANFILES += $(GENERATED_FILES) $(TEST_GEN_FILES_LIST)
$(TEST_GEN_FILES_LIST): $(GENERATED_FILES)
$(AM_V_GEN)rm -rf $(TEST_GEN_FILES_LIST) && \
@@ -99,6 +100,7 @@ $(TEST_GEN_FILES_LIST): $(GENERATED_FILES)
install-data-hook:
test `id -u` -ne 0 || systemctl daemon-reload
+ $(MKDIR_P) $(DESTDIR)/$(sysconfdir)/$(NAME_BINARYBASE)-setup/upgrade
GL_GEN_BIN = gitlog-to-changelog
GL_GEN = if test -d .git; then \
diff --git a/build-helpers/Makefile.inc b/build-helpers/Makefile.inc
deleted file mode 100644
index d54d239..0000000
--- a/build-helpers/Makefile.inc
+++ /dev/null
@@ -1,7 +0,0 @@
-config_builder = $(top_srcdir)/%D%/build-config
-
-noinst_SCRIPT = $(config_builder)
-
-EXTRA_DIST += $(noinst_SCRIPT)
-
-# vim: ft=automake noet
diff --git a/build-helpers/build-config b/build-helpers/build-config
deleted file mode 100755
index 27841f2..0000000
--- a/build-helpers/build-config
+++ /dev/null
@@ -1,11 +0,0 @@
-#! /bin/sh
-
-# For easier parsing in postgresql-setup, we want to have each upgrade scenario
-# configured on separate line.
-
-eval set -- "$1"
-while test -n "$1"
-do
- echo $(cat "$1" | grep -v ^# )
- shift
-done
diff --git a/configure.ac b/configure.ac
index ce34c15..c419e0e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,15 +24,6 @@ AC_ARG_WITH([sysvinit],
[WANT_SYSVINIT=0]
)
-AC_ARG_WITH([upgrade-config],
- AS_HELP_STRING([--with-upgrade-config=/file/path,/path2],
- [List of files to be used as an upgrade configuration]),
- [UPGRADE_CONFIG_LIST="$withval"],
- [UPGRADE_CONFIG_LIST="upgrade_config.template"]
-)
-
-AC_SUBST([UPGRADE_CONFIG_LIST])
-
AM_CONDITIONAL([WANT_SYSVINIT], [test "$WANT_SYSVINIT" -eq 1])
# Instatiating generated files by sed instead of config.status.
@@ -62,11 +53,11 @@ sed_subst_var_pattern(PREVPGENGINE)
sed_subst_var_pattern(rawpkgdatadir)
sed_subst_var_pattern(README_DIST)
sed_subst_var_pattern(SU_POSTGRES)
+sed_subst_var_pattern(sysconfdir)
sed_subst_var_pattern(systemdunitsdir)
sed_subst_var_pattern(userunitsdir)
sed_subst_var_pattern(TEST_GEN_FILES_LIST)
-sed_subst_var_pattern(VERSION)
-sed_subst_var_pattern(UPGRADE_CONFIG_LIST)"
+sed_subst_var_pattern(VERSION)"
m4_define([add_sed_subst_var], [
SED_RULES="$SED_RULES
diff --git a/etc/postgresql-setup/upgrade/postgresql.conf b/etc/postgresql-setup/upgrade/postgresql.conf
new file mode 100644
index 0000000..db58470
--- /dev/null
+++ b/etc/postgresql-setup/upgrade/postgresql.conf
@@ -0,0 +1,18 @@
+# This is tempalte configuration for pg_upgrade via postgresql-setup. The
+# format of config-line 'key[[:space:]][[:space:]]*value'. Keys must be
+# valid shell identifiers and value should be either bare-word or string quoted
+# by double quotes (as in shell).
+
+id postgresql
+
+# Major version of the previous stack
+major 9.2
+
+# Location of default data
+data_default "/var/lib/pgsql/data"
+
+# Location of binaries
+engine /usr/bin
+
+# Just to feed ./postgresql-setup --upgrade-ids help output
+description "In-place upgrade from Fedora 19 (PostgreSQL 9.2)"
diff --git a/postgresql-setup.in b/postgresql-setup.in
index 6f32dc4..dadb615 100644
--- a/postgresql-setup.in
+++ b/postgresql-setup.in
@@ -92,7 +92,6 @@ debug() { test "$option_debug" = "1" && echo >&2 $"DEBUG: $@"; }
set_var()
{
- # TODO compare implementation with other tools.
eval "$1=\"$2\""
}
@@ -102,47 +101,71 @@ root_prereq()
test "$(id -u)" -eq 0 || die "$0 requires root access for this action"
}
+read_config_file()
+{
+ local key="" val=""
+
+ test -r "$1" || die "can't read file '$1'"
+
+ for i in $2; do
+ eval "unset __pg_conf_$i"
+ done
+
+ # No easy (and secure) way to read configuration files from bash script,
+ # sorry.
+ while read key val; do
+ [[ $key =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || return 1
+
+ case " $2 " in
+ *" $key "*)
+ ;;
+ *)
+ warn "config file '$1': unknown key '$key'"
+ continue
+ ;;
+ esac
+
+ # Strip double quotes
+ case "$val" in
+ \"*\")
+ val=${val##\"}
+ val=${val%%\"}
+ ;;
+ esac
+
+ # Make it reasonably safe. Keep dolar-sign escaped.
+ eval "__pg_conf_$key=\$val"
+
+ done < <(grep -v -e "^$" -e "^#" < "$1")
+}
+
+
parse_upgrade_setup()
{
local action="$1"
local expected_id="$2"
local id temp_major temp_engine temp_data_default temp_description
- while read line; do
- eval set -- "$line --"
+ local upgrade_confdir="@sysconfdir@/@NAME_BINARYBASE@-setup/upgrade"
- id="$1"
- shift
+ test -d "$upgrade_confdir" || die "can't read confdir $upgrade_confdir"
- while true; do
- case "$1" in
- --)
- break
- ;;
- major|engine|data_default|description)
- set_var "temp_$1" "$2"
- shift 2
- ;;
- *)
- die "unused upgrade config option '$1'"
- ;;
- esac
- done
+ local my_vars="id comment data_default engine description major"
+ while read conffile
+ do
+ read_config_file "$conffile" "$my_vars"
- case "$action" in
- help)
- echo "$id - $temp_description"
- ;;
- config)
- test "$id" = "$expected_id" || continue
- for i in major engine data_default description; do
- set_var "upgradefrom_$i" "\$temp_$i"
- done
- debug "used configuration '$id', $upgradefrom_engine"
- return 0
- ;;
- esac
- done < "@rawpkgdatadir@/upgrade.conf"
+ if test help = "$action"; then
+ echo "$__pg_conf_id - $__pg_conf_description"
+ elif test config = "$action"; then
+ test "$__pg_conf_id" = "$expected_id" || continue
+ debug "reading config $conffile"
+ for i in $my_vars; do
+ set_var "upgradefrom_$i" "\$__pg_conf_$i"
+ done
+ return 0
+ fi
+ done < <(find "$upgrade_confdir" -maxdepth 1 -type f -name '*.conf')
case "$action" in
help)
@@ -438,7 +461,7 @@ handle_pgconf()
}
-parse_configuration()
+service_configuration()
{
local data=
local port=
@@ -448,7 +471,7 @@ parse_configuration()
local envfile_pgdata=
local mode="$1" datavar="$2" portvar="$3" service="$4"
- debug "running parse_configuration() for $mode"
+ debug "running service_configuration() for $mode"
# Well, until the bug #1139148 is not resolved somehow, we need to stay ugly
# and parse Environment= and EnvironmentFile= statements.
@@ -641,7 +664,7 @@ debug "service name: $option_service"
root_prereq
# load service's pgdata
-parse_configuration initdb pgdata UNUSED "$option_service"
+service_configuration initdb pgdata UNUSED "$option_service"
# Check that nothing breaks --new-systemd-unit
if test "$option_systemd_config" = yes; then
@@ -677,7 +700,7 @@ test -n "$option_port" && pgport=$option_port
if test upgrade = "$option_mode"; then
upgradefrom_data="$upgradefrom_data_default"
- parse_configuration upgrade upgradefrom_data pgport "$option_upgradefrom"
+ service_configuration upgrade upgradefrom_data pgport "$option_upgradefrom"
test -n "$option_port" -a "$option_port" != "$pgport" \
&& warn "Old pgport $pgport has bigger priority than --pgport value."
fi
diff --git a/share/postgresql-setup/Makefile.inc b/share/postgresql-setup/Makefile.inc
deleted file mode 100644
index d202fc6..0000000
--- a/share/postgresql-setup/Makefile.inc
+++ /dev/null
@@ -1,16 +0,0 @@
-upgrade_config = %D%/upgrade.conf
-
-rawpkgdatadir = $(datadir)/postgresql-setup
-rawpkgdata_DATA = \
- $(upgrade_config)
-
-$(UPGRADE_CONFIG_LIST):
- @echo " error: config file '$@' does not exist" && false
-
-$(upgrade_config): $(UPGRADE_CONFIG_LIST) $(c_s)
- $(INSTANTIATE_CONV) \
- && $(config_builder) "$(UPGRADE_CONFIG_LIST)" > $@
-
-GENERATED_FILES += $(upgrade_config)
-
-# vim: ft=automake noet
diff --git a/upgrade_config.template b/upgrade_config.template
deleted file mode 100644
index 4ce2bd9..0000000
--- a/upgrade_config.template
+++ /dev/null
@@ -1,16 +0,0 @@
-# Consider those are to shell strings, so wrap those by quotes when needed
-
-# ID
-postgresql
-
-# Version of the previous stack
-major 9.2
-
-# Location of default data
-data_default "/var/lib/pgsql/data"
-
-# Location of binaries
-engine /usr/bin
-
-# Just to feed ./postgresql-setup --upgrade-ids help output
-description "In-place upgrade from Fedora 19 (PostgreSQL 9.2)"