[type/__postgres_database] Proper quoting in state explorer
This commit is contained in:
parent
8296051653
commit
0d33407b18
1 changed files with 7 additions and 2 deletions
|
@ -21,9 +21,14 @@
|
|||
|
||||
postgres_user=$("${__type_explorer:?}/postgres_user")
|
||||
|
||||
name=${__object_id:?}
|
||||
dbname=${__object_id:?}
|
||||
|
||||
if test -n "$(su - "${postgres_user}" -c "psql postgres -twAc \"SELECT 1 FROM pg_database WHERE datname='${name}'\"")"
|
||||
quote() { printf '%s\n' "$*" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"; }
|
||||
psql_exec() {
|
||||
su - "${postgres_user}" -c "psql $(quote "$1") -twAc $(quote "$2")"
|
||||
}
|
||||
|
||||
if psql_exec postgres "SELECT datname FROM pg_database" | grep -qFx "${dbname}"
|
||||
then
|
||||
echo 'present'
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue