From e2e2e547232582e8c32812f83615d84134c6698a Mon Sep 17 00:00:00 2001 From: AlainCas Date: Tue, 16 Jul 2024 13:28:23 +0200 Subject: [PATCH 01/11] =?UTF-8?q?1=C3=A8re=20tentative=20pour=20donner=20l?= =?UTF-8?q?e=20choix=20du=20moteur=20de=20base=20de=20donn=C3=A9es.=20=20-?= =?UTF-8?q?=20ajout=C3=A9=20le=20choix=20dans=20manifest.toml,=20variable?= =?UTF-8?q?=20db=5Ftype=20=20-=20initialisation=20de=20la=20base=20de=20do?= =?UTF-8?q?nn=C3=A9es=20dans=20install,=20car=20je=20ne=20sais=20pas=20si?= =?UTF-8?q?=20on=20peut=20mettre=20des=20tests=20n'importe=20o=C3=B9=20dan?= =?UTF-8?q?s=20manifest=20(si=20oui,=20ce=20serait=20plus=20simple=20de=20?= =?UTF-8?q?le=20faire=20l=C3=A0=20=20-=20modifications=20en=20cons=C3=A9qu?= =?UTF-8?q?ence=20des=20appels=20yunohost-XXXX-sql=20dans=20install,=20bac?= =?UTF-8?q?kup=20et=20restore.=20=20-=20modifi=C3=A9=20install=20pour=20ne?= =?UTF-8?q?=20pas=20faire=20la=20copie=20du=20fichier=20de=20confog=20gale?= =?UTF-8?q?tte=20et=20laisser=20galette=20s'en=20charger.=20=20-=20modifie?= =?UTF-8?q?r=20els=20instructions=20"curl"=20de=20install=20pour=20indique?= =?UTF-8?q?r=20la=20bonne=20base=20de=20donn=C3=A9es=20et=20le=20bon=20por?= =?UTF-8?q?t=20=C3=A0=20galette.=20Utilisation=20d'une=20nouvelle=20variab?= =?UTF-8?q?le=20locale=20db=5Fport.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.toml | 36 ++++++++++++++++++++++++++++++++---- scripts/backup | 6 +++++- scripts/install | 35 ++++++++++++++++++++++++++++++----- scripts/restore | 6 +++++- 4 files changed, 72 insertions(+), 11 deletions(-) diff --git a/manifest.toml b/manifest.toml index f8a7c75..255cbc4 100644 --- a/manifest.toml +++ b/manifest.toml @@ -7,7 +7,7 @@ name = "Galette" description.en = "Membership management web application for non profit organizations" description.fr = "Outil de gestion d'adhérents et de cotisation en ligne pour associations" -version = "1.1.3~ynh1" +version = "1.1.3~ynh2" maintainers = [] @@ -49,6 +49,22 @@ ram.runtime = "50M" [install.password] type = "password" + [install.db_type] + ask.fr = "quel moteur de base de données souhaitez-vous" + ask.en = "which data base engine do you prefer" + help.fr : "Si vous ne savez pas quoi chosir, c'est que ça n'a aucune importance;" + help.en = "If you don't know what to choose ... don't choose ;-) " + type = "select" + choices = ["mysql","postgresql"] + default = "postgresql" + + [install.tb_prefix] + ask.fr = "voulez-vous utiliser un préfixe de table différent du défaut (galette_)?" + ask.help = "si oui, veillez à le terminer par un _ ("souligné", "tiret du 8",...) + type = "string" + default = "galette_" + + [resources] [resources.sources.main] url = "https://www.galette.eu/download/galette-1.1.3.tar.bz2" @@ -66,7 +82,19 @@ ram.runtime = "50M" main.url = "/" [resources.apt] - packages = "postgresql, php8.3-tidy, php8.3-intl, php8.3-mbstring, php8.3-xml, php8.3-gd, php8.3-curl, php8.3-pgsql" + + packages = "php8.3-tidy, php8.3-intl, php8.3-mbstring, php8.3-xml, php8.3-gd, php8.3-curl" + packages_from_raw_bash = """ + if [[ "$db_type" == "mysql" ]]; then + echo "mariadb-server, php8.3-mysql" + fi + elif [[ "$db_type" == "postgresql" ]]; then + echo "postgresql, php8.3-pgsql" + fi + """ - [resources.database] - type = "postgresql" + +# seulement une de ces lignes est possible. Peut-on faire ça par un test ? ou suffit-il d'initialiser la base dans le scriot d'install ? +# [resources.database] +# type = "mysql" +# type = "postgresql" diff --git a/scripts/backup b/scripts/backup index 91e34e0..c2b7b1f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -36,7 +36,11 @@ ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= ynh_print_info --message="Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +if [ $db_type == "mysql" ]; then + ynh_mysql_dump_db --database="$db_name" > db.sql +elif [ $db_type == "postgresql" ]; then + ynh_psql_dump_db --database="$db_name" > db.sql +fi #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 5825bed..1afbc49 100644 --- a/scripts/install +++ b/scripts/install @@ -26,6 +26,23 @@ ynh_setup_source --dest_dir="$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" +#================================================= +# DATA BASE CREATION (not done via ressources_database +#================================================= +ynh_script_progression --message="icréating data base for $app..." --weight=1 + db_name=$(ynh_sanitize_dbid --db_name=$app) + db_user=$db_name + db_pwd=$(ynh_string_random --length=30) + 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 + + if [ $db_type == "mysql" ]; then + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd + elif [ $db_type == "postgresql" ]; then + ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd + fi + #================================================= # SYSTEM CONFIGURATION #================================================= @@ -44,24 +61,32 @@ ynh_use_logrotate # SPECIFIC SETUP #================================================= # ADD A CONFIGURATION +# suppress to let galette create it it's proper way #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +#ynh_script_progression --message="Adding a configuration file..." --weight=1 -ynh_add_config --template="config.inc.php" --destination="$install_dir/galette/config/config.inc.php" +#ynh_add_config --template="config.inc.php" --destination="$install_dir/galette/config/config.inc.php" -chmod 400 "$install_dir/galette/config/config.inc.php" -chown $app:$app "$install_dir/galette/config/config.inc.php" +#chmod 400 "$install_dir/galette/config/config.inc.php" +#chown $app:$app "$install_dir/galette/config/config.inc.php" #================================================= # SETUP APPLICATION WITH CURL #================================================= ynh_script_progression --message="Setuping application with CURL..." + if [ $db_type == "mysql" ]; then + db_port="3306" + elif [ $db_type == "postgresql" ]; then + db_port="5432" + fi + + # Installation with curl ynh_script_progression --message="Finalizing installation..." ynh_local_curl "/installer.php" "install_permsok=1" ynh_local_curl "/installer.php" "install_type=i" -ynh_local_curl "/installer.php" "install_dbtype=pgsql" "install_dbhost=localhost" "install_dbport=5432" "install_dbuser=$db_user" "install_dbpass=$db_pwd" "install_dbname=$db_name" "install_dbprefix=galette_" +ynh_local_curl "/installer.php" "install_dbtype=$db_type" "install_dbhost=localhost" "install_dbport=$db_port" "install_dbuser=$db_user" "install_dbpass=$db_pwd" "install_dbname=$db_name" "install_dbprefix=$tb_prefix" ynh_local_curl "/installer.php" "install_dbperms_ok=1" ynh_local_curl "/installer.php" "install_dbwrite_ok=1" ynh_local_curl "/installer.php" "install_adminlogin=$admin" "install_adminpass=$password" "install_adminpass_verif=$password" diff --git a/scripts/restore b/scripts/restore index 374a644..2fd3a41 100644 --- a/scripts/restore +++ b/scripts/restore @@ -31,7 +31,11 @@ chown -R $app:www-data "$install_dir" #================================================= ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 -ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +if [ $db_type == "mysql" ]; then + ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +elif [ $db_type == "postgresql" ]; then + ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +fi #================================================= # RESTORE SYSTEM CONFIGURATIONS From c7bedc2ae8882121e70e68872df4e7e042384584 Mon Sep 17 00:00:00 2001 From: AlainCas <48677308+AlainCas@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:58:33 +0200 Subject: [PATCH 02/11] Update manifest.toml --- manifest.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.toml b/manifest.toml index 255cbc4..26f2967 100644 --- a/manifest.toml +++ b/manifest.toml @@ -52,7 +52,7 @@ ram.runtime = "50M" [install.db_type] ask.fr = "quel moteur de base de données souhaitez-vous" ask.en = "which data base engine do you prefer" - help.fr : "Si vous ne savez pas quoi chosir, c'est que ça n'a aucune importance;" + help.fr : "Si vous ne savez pas quoi choisir, c'est que ça n'a aucune importance;" help.en = "If you don't know what to choose ... don't choose ;-) " type = "select" choices = ["mysql","postgresql"] @@ -60,7 +60,7 @@ ram.runtime = "50M" [install.tb_prefix] ask.fr = "voulez-vous utiliser un préfixe de table différent du défaut (galette_)?" - ask.help = "si oui, veillez à le terminer par un _ ("souligné", "tiret du 8",...) + ask.help = "si oui, veillez à le terminer par un _ ('souligné', 'tiret du 8',...) type = "string" default = "galette_" From b02cf991bd3ab026d837ac881dc53ae72efb41ec Mon Sep 17 00:00:00 2001 From: AlainCas <48677308+AlainCas@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:15:42 +0200 Subject: [PATCH 03/11] Update manifest.toml --- manifest.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.toml b/manifest.toml index 26f2967..e88a6a8 100644 --- a/manifest.toml +++ b/manifest.toml @@ -52,7 +52,7 @@ ram.runtime = "50M" [install.db_type] ask.fr = "quel moteur de base de données souhaitez-vous" ask.en = "which data base engine do you prefer" - help.fr : "Si vous ne savez pas quoi choisir, c'est que ça n'a aucune importance;" + help.fr = "Si vous ne savez pas quoi choisir, c'est que ça n'a aucune importance;" help.en = "If you don't know what to choose ... don't choose ;-) " type = "select" choices = ["mysql","postgresql"] @@ -60,7 +60,7 @@ ram.runtime = "50M" [install.tb_prefix] ask.fr = "voulez-vous utiliser un préfixe de table différent du défaut (galette_)?" - ask.help = "si oui, veillez à le terminer par un _ ('souligné', 'tiret du 8',...) + ask.help = "si oui, veillez à le terminer par un _ ('souligné', 'tiret du 8',...)" type = "string" default = "galette_" From 1e49895eb7f17060e8df5ed134b81735905c8ce9 Mon Sep 17 00:00:00 2001 From: AlainCas <48677308+AlainCas@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:11:04 +0200 Subject: [PATCH 04/11] Update manifest.toml A small bub (an extra "fi" in manifest), oups! --- manifest.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/manifest.toml b/manifest.toml index e88a6a8..fb742b0 100644 --- a/manifest.toml +++ b/manifest.toml @@ -86,10 +86,9 @@ ram.runtime = "50M" packages = "php8.3-tidy, php8.3-intl, php8.3-mbstring, php8.3-xml, php8.3-gd, php8.3-curl" packages_from_raw_bash = """ if [[ "$db_type" == "mysql" ]]; then - echo "mariadb-server, php8.3-mysql" - fi + echo "mariadb-server, php8.3-mysql" elif [[ "$db_type" == "postgresql" ]]; then - echo "postgresql, php8.3-pgsql" + echo "postgresql, php8.3-pgsql" fi """ From 070397f8e24fd83f0797f8d2aae3cec11982ba38 Mon Sep 17 00:00:00 2001 From: AlainCas <48677308+AlainCas@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:12:59 +0200 Subject: [PATCH 05/11] Update manifest.toml --- manifest.toml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/manifest.toml b/manifest.toml index fb742b0..e8f0665 100644 --- a/manifest.toml +++ b/manifest.toml @@ -91,9 +91,3 @@ ram.runtime = "50M" echo "postgresql, php8.3-pgsql" fi """ - - -# seulement une de ces lignes est possible. Peut-on faire ça par un test ? ou suffit-il d'initialiser la base dans le scriot d'install ? -# [resources.database] -# type = "mysql" -# type = "postgresql" From 436faea15d8e99448d423d574395b5d6aa439169 Mon Sep 17 00:00:00 2001 From: AlainCas <48677308+AlainCas@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:46:42 +0200 Subject: [PATCH 06/11] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 1afbc49..e0a0539 100644 --- a/scripts/install +++ b/scripts/install @@ -29,7 +29,7 @@ chown -R $app:www-data "$install_dir" #================================================= # DATA BASE CREATION (not done via ressources_database #================================================= -ynh_script_progression --message="icréating data base for $app..." --weight=1 +ynh_script_progression --message="créating data base for $app..." --weight=1 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name db_pwd=$(ynh_string_random --length=30) From c3c6ac47c884eb777e62c54b7cf4933bcb98bae0 Mon Sep 17 00:00:00 2001 From: AlainCas <48677308+AlainCas@users.noreply.github.com> Date: Tue, 16 Jul 2024 21:43:01 +0200 Subject: [PATCH 07/11] Update install Added cirl dialog for telemetry to elt galette create the config file by itself --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index e0a0539..b9552bf 100644 --- a/scripts/install +++ b/scripts/install @@ -90,6 +90,7 @@ ynh_local_curl "/installer.php" "install_dbtype=$db_type" "install_dbhost=local ynh_local_curl "/installer.php" "install_dbperms_ok=1" ynh_local_curl "/installer.php" "install_dbwrite_ok=1" ynh_local_curl "/installer.php" "install_adminlogin=$admin" "install_adminpass=$password" "install_adminpass_verif=$password" +ynh_local_curl "/installer.php" "install_telemetry_ok=1" ynh_local_curl "/installer.php" "install_prefs_ok=1" #================================================= From 1c1f6e7b9bca807fa1518f6a6554572449eb9e43 Mon Sep 17 00:00:00 2001 From: AlainCas <48677308+AlainCas@users.noreply.github.com> Date: Wed, 17 Jul 2024 22:28:07 +0200 Subject: [PATCH 08/11] Update manifest.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed superadmin password input from type "password" to type "string"; otherwise, something différent (hashed value ?) is stored as superadmi password and it is impossible to get into for the first time --- manifest.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.toml b/manifest.toml index e8f0665..8e9067c 100644 --- a/manifest.toml +++ b/manifest.toml @@ -47,7 +47,7 @@ ram.runtime = "50M" type = "user" [install.password] - type = "password" + type = "string" [install.db_type] ask.fr = "quel moteur de base de données souhaitez-vous" @@ -60,7 +60,7 @@ ram.runtime = "50M" [install.tb_prefix] ask.fr = "voulez-vous utiliser un préfixe de table différent du défaut (galette_)?" - ask.help = "si oui, veillez à le terminer par un _ ('souligné', 'tiret du 8',...)" + ask.help = "n'est utile que dans des cas très particuliers" type = "string" default = "galette_" From 7cd0c5df328f896746bcd02e4ac7d7118e81ee84 Mon Sep 17 00:00:00 2001 From: AlainCas Date: Thu, 18 Jul 2024 13:18:53 +0200 Subject: [PATCH 09/11] database type management added database management in restore and remove --- scripts/remove | 14 ++++++++++++++ scripts/restore | 19 +++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/scripts/remove b/scripts/remove index 7a8278f..60b992e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,6 +9,20 @@ source _common.sh source /usr/share/yunohost/helpers +#================================================= +#Remove the data base +#================================================= +ynh_script_progression --message="Removing the database..." --weight=2 + +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name + +if [ $db_type == "mysql" ]; then + ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +elif [ $db_type == "postgresql" ]; then + ynh_psql_remove_db --db_user=$db_user --db_name=$db_name +fi + #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= diff --git a/scripts/restore b/scripts/restore index 2fd3a41..a724400 100644 --- a/scripts/restore +++ b/scripts/restore @@ -27,14 +27,21 @@ chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= -# RESTORE THE POSTGRESQL DATABASE +# RESTORE THE DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 +ynh_script_progression --message="Restoring the database..." --weight=1 -if [ $db_type == "mysql" ]; then - ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql -elif [ $db_type == "postgresql" ]; then - ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + 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) + + if [ $db_type == "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 [ $db_type == "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 #================================================= From 36a646172c41d106957528c4a2715c00089d244c Mon Sep 17 00:00:00 2001 From: AlainCas Date: Thu, 18 Jul 2024 23:17:54 +0200 Subject: [PATCH 10/11] =?UTF-8?q?Presque=20Bon=20Il=20ne=20reste=20qu'un?= =?UTF-8?q?=20probl=C3=A8me,=20c'est=20si=20il=20y=20a=20des=20caract?= =?UTF-8?q?=C3=A8res=20sp=C3=A9ciaux=20dans=20le=20passord=20saisi=20?= =?UTF-8?q?=C3=A0=20l'install=20(superadmin).=20Mais=20c'est=20d=C3=A9j?= =?UTF-8?q?=C3=A0=20le=20cas=20dans=20le=20package=20d'origine.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index 8e9067c..46c0262 100644 --- a/manifest.toml +++ b/manifest.toml @@ -47,7 +47,9 @@ ram.runtime = "50M" type = "user" [install.password] - type = "string" + type = "password" + help.fr = "pas besoin que ce soit le même que pour yunohost. ATTENTION : pas de caractères spéciaux dans le mot de passe, ça ne marche pas (encore); " + help.en = "it's not necessary to use the samme pw as for yunohost. WARNING : nos special char in this passord, there is (still) a bug with" [install.db_type] ask.fr = "quel moteur de base de données souhaitez-vous" From 9fdf008dbcf5fdddfeff3934e4283b5145583a1f Mon Sep 17 00:00:00 2001 From: AlainCas Date: Fri, 19 Jul 2024 22:22:37 +0200 Subject: [PATCH 11/11] First release Added choice for data base engine Protected password special chars before calling curl. Should it be extended to any parameter ? Keeping all files in config across upgrade, as there may be extra personnal files (exports for example). Is it the proper way ? --- scripts/install | 17 +++-------------- scripts/upgrade | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/scripts/install b/scripts/install index b9552bf..537cb84 100644 --- a/scripts/install +++ b/scripts/install @@ -27,7 +27,8 @@ chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= -# DATA BASE CREATION (not done via ressources_database +# DATA BASE CREATION +# as we want to choose the database engine, we cannot rely on manifest to do this #================================================= ynh_script_progression --message="créating data base for $app..." --weight=1 db_name=$(ynh_sanitize_dbid --db_name=$app) @@ -57,19 +58,6 @@ ynh_add_nginx_config # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# SPECIFIC SETUP -#================================================= -# ADD A CONFIGURATION -# suppress to let galette create it it's proper way -#================================================= -#ynh_script_progression --message="Adding a configuration file..." --weight=1 - -#ynh_add_config --template="config.inc.php" --destination="$install_dir/galette/config/config.inc.php" - -#chmod 400 "$install_dir/galette/config/config.inc.php" -#chown $app:$app "$install_dir/galette/config/config.inc.php" - #================================================= # SETUP APPLICATION WITH CURL #================================================= @@ -89,6 +77,7 @@ ynh_local_curl "/installer.php" "install_type=i" ynh_local_curl "/installer.php" "install_dbtype=$db_type" "install_dbhost=localhost" "install_dbport=$db_port" "install_dbuser=$db_user" "install_dbpass=$db_pwd" "install_dbname=$db_name" "install_dbprefix=$tb_prefix" ynh_local_curl "/installer.php" "install_dbperms_ok=1" ynh_local_curl "/installer.php" "install_dbwrite_ok=1" +password=`jq -Rj @uri <<<$password` #to escape special characters that may appear in a password ynh_local_curl "/installer.php" "install_adminlogin=$admin" "install_adminpass=$password" "install_adminpass_verif=$password" ynh_local_curl "/installer.php" "install_telemetry_ok=1" ynh_local_curl "/installer.php" "install_prefs_ok=1" diff --git a/scripts/upgrade b/scripts/upgrade index 87581b4..250e048 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,7 +20,7 @@ timezone="$(cat /etc/timezone)" #================================================= ynh_script_progression --message="Upgrading source files..." -ynh_setup_source --dest_dir="$install_dir" --keep="galette/config/config.inc.php galette/data galette/plugins" +ynh_setup_source --dest_dir="$install_dir" --keep="galette/config galette/data galette/plugins" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir"