summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac8
-rw-r--r--postgresql-check-db-dir.in46
-rw-r--r--postgresql-setup.in99
-rw-r--r--share/postgresql-setup/.gitignore1
-rw-r--r--share/postgresql-setup/Makefile.inc21
-rw-r--r--share/postgresql-setup/library.sh.in99
7 files changed, 165 insertions, 113 deletions
diff --git a/Makefile.am b/Makefile.am
index 21d448a..6371bb7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -78,6 +78,8 @@ EXTRA_DIST += \
$(srcdir)/*.in \
$(srcdir)/etc/postgresql-setup/upgrade/postgresql.conf
+include $(srcdir)/share/postgresql-setup/Makefile.inc
+
GENERATED_FILES += \
$(bin_SCRIPTS) \
$(libexec_SCRIPTS) \
@@ -85,7 +87,7 @@ GENERATED_FILES += \
$(pkgsysconf_DATA) \
$(systemdunits_DATA) \
$(initscripts_DATA) \
- $(systemdlegacyscripts_SCRIPTS)
+ $(legacyscripts_SCRIPTS)
CLEANFILES += $(GENERATED_FILES) $(TEST_GEN_FILES_LIST)
diff --git a/configure.ac b/configure.ac
index 022c22a..e25b6a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,6 +71,7 @@ conf_dir([systemdunitsdir], ['${prefix}/lib/systemd/system'])
conf_dir([systemduserunitsdir], ['${prefix}/etc/systemd/system'])
conf_dir([systemdlegacyscriptsdir], ['${libexecdir}/initscripts/legacy-actions'])
conf_dir([initscriptsdir], ['${sysconfdir}/rc.d/init.d'])
+conf_dir([rawpkgdatadir], ['${datadir}/postgresql-setup'])
INSTANTIATE_CONV="\$(AM_V_GEN)rm -rf \$@; \$(MKDIR_P) \$(@D)"
INSTANTIATE="\$(INSTANTIATE_CONV) && \$(SED_CALL) \$< > \$@ && chmod -w \$@"
@@ -133,7 +134,12 @@ if test -z "$POSTGRES_HOMEDIR" -a "$pgsetup_cv_os_family" = redhat; then
fi
if test -z "$PGDATADIR" -a "$pgsetup_cv_os_family" = redhat; then
- PGDATADIR="\${prefix}/var/lib/pgsql/data"
+ if test x"$prefix" = x/usr
+ then
+ PGDATADIR=/var/lib/pgsql/data
+ else
+ PGDATADIR="\${prefix}/var/lib/pgsql/data"
+ fi
fi
pgdocdir="\${datarootdir}/doc/\${pkgname}"
diff --git a/postgresql-check-db-dir.in b/postgresql-check-db-dir.in
index fec7891..0d9854d 100644
--- a/postgresql-check-db-dir.in
+++ b/postgresql-check-db-dir.in
@@ -42,35 +42,53 @@ PGVERSION=@PGVERSION@
# Major version of PostgreSQL, e.g. 9.0
PGMAJORVERSION=@PGMAJORVERSION@
-# Previous major version, e.g., 8.4, for upgrades
-PREVMAJORVERSION=@PREVMAJORVERSION@
-
# Distribution README file
README_DIST=@README_DIST@
+bad_version()
+{
+ local real_version="$1"
+
+ . "@rawpkgdatadir@/library.sh"
+
+ while read id version; do
+ test "$version" = "$real_version" || continue
+
+ local cmd="postgresql-setup --upgrade"
+
+ test "@NAME_DEFAULT_PREV_SERVICE@" = "$id" \
+ || cmd="$cmd --upgrade-from $id"
+
+ echo $"An old version of the database format was found."
+ echo $"Use '$cmd' to upgrade to version '$PGMAJORVERSION'"
+ echo $"See $README_DIST for more information."
+
+ return
+ done < <(parse_upgrade_setup list)
+
+ echo $"An old version '$real_version' of the database format was found."
+ echo $"You need to dump and reload before using PostgreSQL $PGVERSION."
+ echo $"See $README_DIST for more information."
+
+ return
+}
+
# Check for the PGDATA structure
if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
then
+ real_version=`cat "$PGDATA/PG_VERSION"`
# Check version of existing PGDATA
- if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
+ if [ x"$real_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 $README_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 $README_DIST for more information."
+ bad_version "$real_version"
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 $"Use \"@NAME_BINARYBASE@-setup --initdb\" to initialize the database cluster."
echo $"See $README_DIST for more information."
exit 1
fi
diff --git a/postgresql-setup.in b/postgresql-setup.in
index 33021f5..5c1f08a 100644
--- a/postgresql-setup.in
+++ b/postgresql-setup.in
@@ -21,6 +21,8 @@ SU_POSTGRES="@SU_POSTGRES@"
# The where PostgreSQL server listens by default
PGPORT_DEF=5432
+. "@rawpkgdatadir@/library.sh"
+
# We upgrade by default from system's default PostgreSQL installation
option_upgradefrom="@NAME_DEFAULT_PREV_SERVICE@"
@@ -105,103 +107,6 @@ root_prereq()
}
-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
-
- local upgrade_confdir="@sysconfdir@/@NAME_BINARYBASE@-setup/upgrade"
-
- debug "using 'upgrade' confdir $upgrade_confdir"
- test -d "$upgrade_confdir" || die "can't read confdir $upgrade_confdir"
-
- local my_vars="id comment data_default engine description major scls \
- redhat_sockets_hack"
- while read conffile
- do
- read_config_file "$conffile" "$my_vars"
-
- 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"
-
- local cm="config file '$conffile'"
- # 'scls' and 'redhat_sockets_hack' are used to adjust
- # environment and could be bash-injected.
- case "$i" in
- scls)
- test -z "$upgrade_from_scls" \
- || [[ $upgrade_from_scls =~ ^[-a-zA-Z0-9_\ ]+$ ]] \
- || die "$cm: bad '$i' value '$upgrade_from_scls'"
- ;;
- redhat_sockets_hack)
- case "$upgradefrom_redhat_sockets_hack" in
- yes|no|'')
- ;;
- *)
- die "$cm: bad '$i' value"
- ;;
- esac
- ;;
- esac
- done
- return 0
- fi
- done < <(find "$upgrade_confdir" -maxdepth 1 -type f -name '*.conf')
-
- case "$action" in
- help)
- return 0
- ;;
- esac
- return 1
-}
-
-
print_version()
{
echo "@NAME_BINARYBASE@-setup @VERSION@"
diff --git a/share/postgresql-setup/.gitignore b/share/postgresql-setup/.gitignore
index d9c09a5..64c0145 100644
--- a/share/postgresql-setup/.gitignore
+++ b/share/postgresql-setup/.gitignore
@@ -1 +1,2 @@
upgrade.conf
+library.sh
diff --git a/share/postgresql-setup/Makefile.inc b/share/postgresql-setup/Makefile.inc
new file mode 100644
index 0000000..0f23e91
--- /dev/null
+++ b/share/postgresql-setup/Makefile.inc
@@ -0,0 +1,21 @@
+lib = %D%/library.sh
+lib_in = $(srcdir)/$(lib).in
+
+rawdata_generated_files = \
+ $(lib)
+
+rawdata_template_files = \
+ $(lib_in)
+
+rawdata_static_files =
+
+rawpkgdata_DATA = \
+ $(rawdata_generated_files)
+
+GENERATED_FILES += $(rawdata_generated_files)
+EXTRA_DIST += $(rawdata_static_files) $(rawdata_template_files)
+
+$(lib): $(lib_in) $(c_s)
+ $(INSTANTIATE_SCRIPT)
+
+# vim: ft=automake noet
diff --git a/share/postgresql-setup/library.sh.in b/share/postgresql-setup/library.sh.in
new file mode 100644
index 0000000..32c8036
--- /dev/null
+++ b/share/postgresql-setup/library.sh.in
@@ -0,0 +1,99 @@
+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
+
+ local upgrade_confdir="@sysconfdir@/@NAME_BINARYBASE@-setup/upgrade"
+
+ debug "using 'upgrade' confdir $upgrade_confdir"
+ test -d "$upgrade_confdir" || die "can't read confdir $upgrade_confdir"
+
+ local my_vars="id comment data_default engine description major scls \
+ redhat_sockets_hack"
+ while read conffile
+ do
+ read_config_file "$conffile" "$my_vars"
+
+ if test help = "$action"; then
+ echo "$__pg_conf_id - $__pg_conf_description"
+ elif test list = "$action"; then
+ echo "$__pg_conf_id $__pg_conf_major"
+ 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"
+
+ local cm="config file '$conffile'"
+ # 'scls' and 'redhat_sockets_hack' are used to adjust
+ # environment and could be bash-injected.
+ case "$i" in
+ scls)
+ test -z "$upgrade_from_scls" \
+ || [[ $upgrade_from_scls =~ ^[-a-zA-Z0-9_\ ]+$ ]] \
+ || die "$cm: bad '$i' value '$upgrade_from_scls'"
+ ;;
+ redhat_sockets_hack)
+ case "$upgradefrom_redhat_sockets_hack" in
+ yes|no|'')
+ ;;
+ *)
+ die "$cm: bad '$i' value"
+ ;;
+ esac
+ ;;
+ esac
+ done
+ return 0
+ fi
+ done < <(find "$upgrade_confdir" -maxdepth 1 -type f -name '*.conf')
+
+ case "$action" in
+ help|list)
+ return 0
+ ;;
+ esac
+ return 1
+}
+
+