From 80f55d4febb7a3f6a210676946da6ec6f7d86cf1 Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Sun, 28 May 2023 18:43:16 +0200 Subject: [PATCH 1/8] Implement postgresql database choice --- manifest.toml | 16 +++++++++------- scripts/backup | 11 ++++++++--- scripts/install | 12 ++++++++---- scripts/remove | 10 +++++++--- scripts/restore | 14 ++++++++++---- scripts/upgrade | 12 ++++++++++++ tests.toml | 16 +++++++++++++++- 7 files changed, 69 insertions(+), 22 deletions(-) diff --git a/manifest.toml b/manifest.toml index e0085f2..22ccc6e 100644 --- a/manifest.toml +++ b/manifest.toml @@ -52,11 +52,12 @@ ram.runtime = "50M" choices = ["none", "7.4", "8.0", "8.1", "8.2"] default = "8.0" - [install.with_mysql] - ask.en = "Do you need a MySQL database?" - ask.fr = "Avez-vous besoin d'une base de données MySQL ?" - type = "boolean" - default = false + [install.database] + ask.en = "Do you need a database?" + ask.fr = "Avez-vous besoin d'une base de données ?" + type = "select" + choices = [ "none", "mysql, 'posrgresql" ] + default = "none" [resources] [resources.system_user] @@ -69,9 +70,10 @@ ram.runtime = "50M" [resources.apt] packages = "nginx" # Kind of "dummy" value to be sure to have a non-empty dep list packages_from_raw_bash = """ - if [[ "$with_mysql" = 1 ]] - then + if [[ "$database" == "mysql" ]]; then echo "mariadb-server" + elif [[ "$database" == "postgresql" ]]; then + echo "postgresql postgresql-contrib" fi if [[ "$phpversion" != none ]] diff --git a/scripts/backup b/scripts/backup index 17b1472..589c16b 100644 --- a/scripts/backup +++ b/scripts/backup @@ -40,10 +40,15 @@ fi # BACKUP THE MYSQL DATABASE #================================================= -if [ $with_mysql -eq 1 ] +if [ $database != "none" ] then - ynh_print_info --message="Backing up the MySQL database..." - ynh_mysql_dump_db --database="$db_name" > db.sql + ynh_print_info --message="Backing up the database..." + + if [ $database == "mysql" ]; then + ynh_mysql_dump_db --database="$db_name" > db.sql* + elif [ $database == "postgresql" ] + ynh_psql_dump_db --database="$db_name" > db.sql + fi fi #================================================= diff --git a/scripts/install b/scripts/install index a976713..f695b9d 100644 --- a/scripts/install +++ b/scripts/install @@ -35,9 +35,8 @@ ynh_app_setting_set --app=$app --key=password --value=$password # CREATE A MYSQL DATABASE #================================================= -if [ $with_mysql -eq 1 ] -then - ynh_script_progression --message="Creating a MySQL database..." --weight=2 +if [ $database != "none" ]; then + ynh_script_progression --message="Creating a database..." --weight=2 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name @@ -45,7 +44,12 @@ then ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_app_setting_set --app=$app --key=db_user --value=$db_user ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd - ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + + if [ $database == "mysql" ]; then + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + elif [ $database == "postgresql" ]; then + ynh_psql_setup_db --db_user=$db_user --db_name=$db_name + fi fi #================================================= diff --git a/scripts/remove b/scripts/remove index f86af18..f14eaee 100644 --- a/scripts/remove +++ b/scripts/remove @@ -15,14 +15,18 @@ source /usr/share/yunohost/helpers # REMOVE THE MYSQL DATABASE #================================================= -if [ $with_mysql -eq 1 ]; then - ynh_script_progression --message="Removing the MySQL database..." --weight=2 +if [ $database != "none" ]; then + ynh_script_progression --message="Removing the database..." --weight=2 db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name # Remove a database if it exists, along with the associated user - ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name + if [ $database == "mysql" ]; then + ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name + elif [ $database == "postgresql" ]; then + ynh_psql_remove_db --db_user=$db_user --db_name=$db_name + fi fi #================================================= diff --git a/scripts/restore b/scripts/restore index 8db3265..cd4f1af 100644 --- a/scripts/restore +++ b/scripts/restore @@ -20,14 +20,20 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.d/" # RESTORE THE MYSQL DATABASE #================================================= -if [ $with_mysql -eq 1 ]; then - ynh_script_progression --message="Restoring the MySQL database..." +if [ $database != "none" ]; then + ynh_script_progression --message="Restoring the database..." db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) - ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd - ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + + if [ $database == "mysql" ]; then + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd + ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + elif [ $database == "postgresql" ]; then + ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd + ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + fi fi #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 19a6549..49705ae 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,18 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Ensuring downward compatibility..." +# If database doesn't exist, create it and remove with_mysql setting +if [ -z "$(database:-)" ]; then + if [ $with_mysql -eq 1 ]; then + $database="mysql" + else + $database="none" + fi + + ynh_app_setting_set --app=$app --key=database --value=$database + ynh_app_setting_delete --app=$app --key=with_mysql +fi + # If admin_mail_html doesn't exist, create it if [ -z "${admin_mail_html:-}" ]; then admin_mail_html=1 diff --git a/tests.toml b/tests.toml index ce3886c..8cedce2 100644 --- a/tests.toml +++ b/tests.toml @@ -7,8 +7,10 @@ test_format = 1.0 # ------------------------------- args.with_sftp = "1" - args.with_mysql = "1" + args.database = "none" args.phpversion = "8.0" + test_upgrade_from.bf5d3ed.name = "Upgrade from 1.0~ynh14" + test_upgrade_from.bf5d3ed.args.with_mysql = "0" [80_test] @@ -19,3 +21,15 @@ test_format = 1.0 only = ["install.subdir", "backup_restore", "upgrade" ] args.phpversion = "none" + +[mysql_test] + + only = ["install.subdir", "backup_restore", "upgrade", "upgrade.bf5d3ed" ] + args.database = "mysql" + test_upgrade_from.bf5d3ed.name = "Upgrade from 1.0~ynh14" + test_upgrade_from.bf5d3ed.args.with_mysql = "1" + +[postgresql_test] + + only = ["install.subdir", "backup_restore", "upgrade" ] + args.database = "postgresql" From 0f78b7f4b19e9b656e1a769668815f9935cd0cd5 Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Sun, 28 May 2023 19:02:02 +0200 Subject: [PATCH 2/8] oops --- scripts/backup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup b/scripts/backup index 589c16b..4e0ff8c 100644 --- a/scripts/backup +++ b/scripts/backup @@ -46,7 +46,7 @@ then if [ $database == "mysql" ]; then ynh_mysql_dump_db --database="$db_name" > db.sql* - elif [ $database == "postgresql" ] + elif [ $database == "postgresql" ]; then ynh_psql_dump_db --database="$db_name" > db.sql fi fi From 8cff6952cbcb5660e044c51637de525eb376bcbd Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Sun, 28 May 2023 19:29:25 +0200 Subject: [PATCH 3/8] =?UTF-8?q?opps=C2=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 49705ae..5593d78 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,7 +21,7 @@ upgrade_type=$(ynh_check_app_version_changed) ynh_script_progression --message="Ensuring downward compatibility..." # If database doesn't exist, create it and remove with_mysql setting -if [ -z "$(database:-)" ]; then +if [ -z "${database:-}" ]; then if [ $with_mysql -eq 1 ]; then $database="mysql" else From 8657238c524cb5228d5e446b54a7266236f6a486 Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Sun, 28 May 2023 20:04:50 +0200 Subject: [PATCH 4/8] =?UTF-8?q?oops=C2=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.toml | 2 +- scripts/upgrade | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/manifest.toml b/manifest.toml index 22ccc6e..645df79 100644 --- a/manifest.toml +++ b/manifest.toml @@ -56,7 +56,7 @@ ram.runtime = "50M" ask.en = "Do you need a database?" ask.fr = "Avez-vous besoin d'une base de données ?" type = "select" - choices = [ "none", "mysql, 'posrgresql" ] + choices = [ "none", "mysql, 'postgresql" ] default = "none" [resources] diff --git a/scripts/upgrade b/scripts/upgrade index 5593d78..655f49e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,11 +21,11 @@ upgrade_type=$(ynh_check_app_version_changed) ynh_script_progression --message="Ensuring downward compatibility..." # If database doesn't exist, create it and remove with_mysql setting -if [ -z "${database:-}" ]; then +if [ -z "$database" ]; then if [ $with_mysql -eq 1 ]; then - $database="mysql" + database="mysql" else - $database="none" + database="none" fi ynh_app_setting_set --app=$app --key=database --value=$database From 810c3facfa3c9a2c7d3f2a1425d117d9e00fdbf3 Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Sun, 28 May 2023 21:01:51 +0200 Subject: [PATCH 5/8] i really can't type /o\ --- manifest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index 645df79..d422410 100644 --- a/manifest.toml +++ b/manifest.toml @@ -56,7 +56,7 @@ ram.runtime = "50M" ask.en = "Do you need a database?" ask.fr = "Avez-vous besoin d'une base de données ?" type = "select" - choices = [ "none", "mysql, 'postgresql" ] + choices = [ "none", "mysql", "postgresql" ] default = "none" [resources] From b5f4e50ff98934cd9f0628fdc0b6a704a529f52e Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Sun, 28 May 2023 22:16:28 +0200 Subject: [PATCH 6/8] fix database: unbound variable --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 655f49e..ef64b1e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,7 +21,7 @@ upgrade_type=$(ynh_check_app_version_changed) ynh_script_progression --message="Ensuring downward compatibility..." # If database doesn't exist, create it and remove with_mysql setting -if [ -z "$database" ]; then +if [ -z "${database:-}" ]; then if [ $with_mysql -eq 1 ]; then database="mysql" else From 1d83be3e56aba29087fe04de391183f7be7c6b8b Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Sat, 10 Jun 2023 22:38:37 +0200 Subject: [PATCH 7/8] Update manifest.toml --- manifest.toml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/manifest.toml b/manifest.toml index d422410..d29dbf6 100644 --- a/manifest.toml +++ b/manifest.toml @@ -72,12 +72,19 @@ ram.runtime = "50M" packages_from_raw_bash = """ if [[ "$database" == "mysql" ]]; then echo "mariadb-server" - elif [[ "$database" == "postgresql" ]]; then + + if [[ "$phpversion" != none ]]; then + echo "php${phpversion}-mysql" + fi + elif [[ "$database" == "postgresql" ]]; then echo "postgresql postgresql-contrib" + + if [[ "$phpversion" != none ]]; then + echo "php${phpversion}-pgsql" + fi fi - if [[ "$phpversion" != none ]] - then - echo "php${phpversion}-fpm php${phpversion}-mysql" + if [[ "$phpversion" != none ]]; then + echo "php${phpversion}-fpm" fi """ From e3599fe60c2ae982f8cc9539bb9063ed45e73770 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Wed, 16 Aug 2023 17:37:36 +0200 Subject: [PATCH 8/8] Improve POST_INSTALL documentation for databases --- doc/POST_INSTALL.md | 3 ++- doc/POST_INSTALL_fr.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/POST_INSTALL.md b/doc/POST_INSTALL.md index c463db3..a961614 100644 --- a/doc/POST_INSTALL.md +++ b/doc/POST_INSTALL.md @@ -1,5 +1,6 @@ -If you have requested a MYSQL database, please find information about this SQL database: +If you have requested a database, here are information to log into it: +- Type: __DATABASE__ - Database user: __DB_USER__ - Database name: __DB_NAME__ - Password: __DB_PWD__ diff --git a/doc/POST_INSTALL_fr.md b/doc/POST_INSTALL_fr.md index 87467a7..bb975e7 100644 --- a/doc/POST_INSTALL_fr.md +++ b/doc/POST_INSTALL_fr.md @@ -1,5 +1,6 @@ -Si vous avez demandé une base de données MYSQL, voici les informations de cette base de données SQL : +Si vous avez demandé une base de données, voici les informations pour s'y connecter : +- Type : __DATABASE__ - Utilisateur de la base de données : __DB_USER__ - Nom de la base de données : __DB_NAME__ - Mot de passe : __DB_PWD__