Merge pull request #998 from YunoHost/psql-ynh_psql_setup_db-password

Do not create a new password if the user already exists
This commit is contained in:
Alexandre Aubin 2020-05-22 17:43:05 +02:00 committed by GitHub
commit 33667d7b1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -229,12 +229,14 @@ ynh_psql_setup_db() {
# Manage arguments with getopts # Manage arguments with getopts
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
if ! ynh_psql_user_exists --user=$db_user; then
local new_db_pwd=$(ynh_string_random) # Generate a random password local new_db_pwd=$(ynh_string_random) # Generate a random password
# If $db_pwd is not given, use new_db_pwd instead for db_pwd # If $db_pwd is not given, use new_db_pwd instead for db_pwd
db_pwd="${db_pwd:-$new_db_pwd}" db_pwd="${db_pwd:-$new_db_pwd}"
if ! ynh_psql_user_exists --user=$db_user; then
ynh_psql_create_user "$db_user" "$db_pwd" ynh_psql_create_user "$db_user" "$db_pwd"
elif [ -z $db_pwd ]; then
ynh_die --message="The user $db_user exists, please provide his password"
fi fi
ynh_psql_create_db "$db_name" "$db_user" # Create the database ynh_psql_create_db "$db_name" "$db_user" # Create the database