From a79d205387c1dc5e239a3e8c956c577791e806ff Mon Sep 17 00:00:00 2001 From: Augustin Trancart Date: Tue, 29 Nov 2022 18:51:33 +0100 Subject: [PATCH] Better error message when psql is not there for database_exists (#992) --- data/helpers.d/postgresql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data/helpers.d/postgresql b/data/helpers.d/postgresql index 284c02d3e..3995e9157 100644 --- a/data/helpers.d/postgresql +++ b/data/helpers.d/postgresql @@ -188,7 +188,13 @@ ynh_psql_database_exists() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - if ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT datname FROM pg_database WHERE datname='$database';" | grep --quiet "$database" + # if psql is not there, we cannot check the db + # though it could exists. + if ! command -v psql + then + ynh_print_err -m "PostgreSQL is not installed, impossible to check for db existence." + return 1 + elif ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT datname FROM pg_database WHERE datname='$database';" | grep --quiet "$database" then return 1 else