summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2015-03-02 09:41:33 +0100
committerPavel Raiskup <praiskup@redhat.com>2015-03-02 10:10:53 +0100
commit7b1dbe74c98f5be41ad5605260f0edbf40a9fcd1 (patch)
tree12ce1599858a23ee9a0d9088543450b9e4617f62 /share
parent9094981751e776fa93537c91bc0e678f4d806b91 (diff)
downloadpostgresql-setup-7b1dbe74c98f5be41ad5605260f0edbf40a9fcd1.tar.gz
postgresql-setup-7b1dbe74c98f5be41ad5605260f0edbf40a9fcd1.tar.xz
postgresql-setup-7b1dbe74c98f5be41ad5605260f0edbf40a9fcd1.zip
postgresql-check-db-dir: match configuration approach
* configure.ac (PGDATADIR): Use /var/lib/pgsql/data when prefix is set to /usr. (rawpkgdatadir): New directory. Its different from pkgdatadir, because thats often set to /usr/share/postgresql. * Makefile.am: Include new rawpkgdatadir Makefile.inc. Fix distcheck by mentioning legacyscripts_SCRIPTS in GENERATED_FILES. * postgresql-check-db-dir.in: Use library.sh to give user better advice. Use @NAME_BINARYBASE@ prefix. (bad_version): New function. (PREVMAJORVERSION): Removed unused variable. * postgresql-setup.in: Cut out the config-parsing routines into library.sh. * share/postgresql-setup/library.sh.in: New library file. Added new option 'list' for parse_upgrade_setup. * share/postgresql-setup/Makefile.inc: New file. * share/postgresql-setup/.gitignore: Ignore library.sh.
Diffstat (limited to 'share')
-rw-r--r--share/postgresql-setup/.gitignore1
-rw-r--r--share/postgresql-setup/Makefile.inc21
-rw-r--r--share/postgresql-setup/library.sh.in99
3 files changed, 121 insertions, 0 deletions
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
+}
+
+