From e2e2e547232582e8c32812f83615d84134c6698a Mon Sep 17 00:00:00 2001 From: AlainCas Date: Tue, 16 Jul 2024 13:28:23 +0200 Subject: [PATCH] =?UTF-8?q?1=C3=A8re=20tentative=20pour=20donner=20le=20ch?= =?UTF-8?q?oix=20du=20moteur=20de=20base=20de=20donn=C3=A9es.=20=20-=20ajo?= =?UTF-8?q?ut=C3=A9=20le=20choix=20dans=20manifest.toml,=20variable=20db?= =?UTF-8?q?=5Ftype=20=20-=20initialisation=20de=20la=20base=20de=20donn?= =?UTF-8?q?=C3=A9es=20dans=20install,=20car=20je=20ne=20sais=20pas=20si=20?= =?UTF-8?q?on=20peut=20mettre=20des=20tests=20n'importe=20o=C3=B9=20dans?= =?UTF-8?q?=20manifest=20(si=20oui,=20ce=20serait=20plus=20simple=20de=20l?= =?UTF-8?q?e=20faire=20l=C3=A0=20=20-=20modifications=20en=20cons=C3=A9que?= =?UTF-8?q?nce=20des=20appels=20yunohost-XXXX-sql=20dans=20install,=20back?= =?UTF-8?q?up=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