diff options
author | tcely <tcely@users.noreply.github.com> | 2019-08-03 15:36:24 -0400 |
---|---|---|
committer | Leo <thinkabit.ukim@gmail.com> | 2019-08-10 11:09:46 -0300 |
commit | 97f66ec899bf2ca4ea9ff11808fcde0c1e7296f7 (patch) | |
tree | 1999d2e32076fcc97f49328ea6a7c5bdd9042a33 /community/pdns/pdns-backend-pgsql.post-upgrade | |
parent | 2a8e2740dfd35a050de8f674bac24046eccf1544 (diff) | |
download | aports-97f66ec899bf2ca4ea9ff11808fcde0c1e7296f7.tar.bz2 aports-97f66ec899bf2ca4ea9ff11808fcde0c1e7296f7.tar.xz |
community/pdns: script schema change
Diffstat (limited to 'community/pdns/pdns-backend-pgsql.post-upgrade')
-rw-r--r-- | community/pdns/pdns-backend-pgsql.post-upgrade | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/community/pdns/pdns-backend-pgsql.post-upgrade b/community/pdns/pdns-backend-pgsql.post-upgrade new file mode 100644 index 0000000000..bd3dc67bdc --- /dev/null +++ b/community/pdns/pdns-backend-pgsql.post-upgrade @@ -0,0 +1,63 @@ +#!/bin/sh + +schema_file='/etc/pdns/4.1.10_to_4.1.11.schema.pgsql.sql' + +configs() { + find /etc/pdns -name pdns.conf -print -o -name 'pdns-*.conf' -print +} + +search_configs() { + local includedir + + includedir="$(grep '^include-dir=' "$1" | cut -d = -f 2- | tail -n 1)" + grep "^${2}=" "$1" ${includedir:+"$includedir"/*.conf} 2>/dev/null | tail -n 1 +} + +check_launch() { + search_configs "$1" launch | grep -q gpgsql +} + +psqlcmd() { + /usr/bin/psql -1 -w -f "$schema_file" "$@" +} + +pgsqlvars() { + local cfg extra passfile password tmp + cfg="$1" + extra="$(search_configs "$cfg" gpgsql-extra-connection-parameters | cut -d = -f 2-)" + tmp="$(mktemp -d -q)" + passfile="${tmp:-/tmp}/pgsql.passfile" + + PGDATABASE="$(search_configs "$cfg" gpgsql-dbname | cut -d = -f 2-)" + PGHOST="$(search_configs "$cfg" gpgsql-host | cut -d = -f 2-)" + PGPORT="$(search_configs "$cfg" gpgsql-port | cut -d = -f 2-)" + PGUSER="$(search_configs "$cfg" gpgsql-user | cut -d = -f 2-)" + + PGPASSFILE="$passfile" + touch "$passfile" + chmod 0600 "$passfile" + password="$(search_configs "$cfg" gpgsql-password | cut -d = -f 2- | sed -e 's,['\'':],\\&,g')" + printf > "$passfile" -- '*:*:*:*:%s\n' "$password" + unset -v password + + for ev in DATABASE HOST PORT USER PASSFILE; do + eval test -n \"\${PG${ev}}\" || continue + export "PG${ev}" + done + + psqlcmd ${extra:+"$extra"} + + for ev in DATABASE HOST PORT USER PASSFILE; do + unset -v "PG${ev}" + done + rm -f "$passfile" + rmdir "$tmp" 2>/dev/null +} + +for c in $(configs); do + check_launch "$c" || continue + + pgsqlvars "$c" +done; unset -v c + +exit 0 |