From db2dc428637b5139b7dc76a41a52246e1f20d283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Collin?= Date: Mon, 1 Apr 2024 14:28:27 +0200 Subject: [PATCH] db_password issue --- scripts/install | 10 +++++----- scripts/upgrade | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/install b/scripts/install index fe62ed1..040cc90 100755 --- a/scripts/install +++ b/scripts/install @@ -46,6 +46,11 @@ chown -R $app:www-data "$data_dir" #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 +# Let's create all databases needed, and assign them to the user +local new_db_pwd=$(ynh_string_random) # Generate a random password + # If $db_pwd is not provided, use new_db_pwd instead for db_pwd +db_pwd="${db_pwd:-$new_db_pwd}" + ynh_add_config --template=".env" --destination="$install_dir/.env" chmod 400 "$install_dir/.env" @@ -85,11 +90,6 @@ ynh_script_progression --message="Creating the Mongo databases..." --weight=1 db_user=$(ynh_sanitize_dbid --db_name="${app}") ynh_app_setting_set --app="$app" --key=db_user --value="$db_user" -# Let's create all databases needed, and assign them to the user -local new_db_pwd=$(ynh_string_random) # Generate a random password - # If $db_pwd is not provided, use new_db_pwd instead for db_pwd -db_pwd="${db_pwd:-$new_db_pwd}" - for db_name in "${MONGO_DB_LIST[@]}"; do ynh_mongo_setup_db --db_user="$db_user" --db_pwd="$db_pwd" --db_name="dontCode$tenant${db_name}" done diff --git a/scripts/upgrade b/scripts/upgrade index 24557f9..b53201e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -40,6 +40,10 @@ if [ -z "${tenant+x}" ]; then ynh_app_setting_set --app="$app" --key=tenant --value="$tenant" fi +local new_db_pwd=$(ynh_string_random) # Generate a random password + # If $db_pwd is not provided, use new_db_pwd instead for db_pwd +db_pwd="${db_pwd:-$new_db_pwd}" + if [[ -n "${document_path:-}" ]]; then # Renamed setting key document_dir="$document_path" @@ -133,10 +137,6 @@ ynh_script_progression --message="Upgrading MongoDB..." --weight=1 # Install the required version of Mongo ynh_install_mongo --mongo_version=$mongo_version -local new_db_pwd=$(ynh_string_random) # Generate a random password - # If $db_pwd is not provided, use new_db_pwd instead for db_pwd -db_pwd="${db_pwd:-$new_db_pwd}" - # We are now assigning the user to the database, so update the user's rights for db_name in "${MONGO_DB_LIST[@]}"; do ynh_mongo_setup_db --db_user="$db_user" --db_pwd="$db_pwd" --db_name="dontCode$tenant${db_name}"