diff --git a/manifest.toml b/manifest.toml index f8a7c75..46c0262 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 = [] @@ -48,6 +48,24 @@ ram.runtime = "50M" [install.password] 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" + 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.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 = "n'est utile que dans des cas très particuliers" + type = "string" + default = "galette_" + [resources] [resources.sources.main] @@ -66,7 +84,12 @@ 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" - - [resources.database] - type = "postgresql" + + 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" + elif [[ "$db_type" == "postgresql" ]]; then + echo "postgresql, php8.3-pgsql" + fi + """ 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..537cb84 100644 --- a/scripts/install +++ b/scripts/install @@ -26,6 +26,24 @@ ynh_setup_source --dest_dir="$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" +#================================================= +# 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) + 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 #================================================= @@ -40,31 +58,28 @@ ynh_add_nginx_config # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# SPECIFIC SETUP -#================================================= -# ADD A CONFIGURATION -#================================================= -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 #================================================= 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" +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/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 374a644..a724400 100644 --- a/scripts/restore +++ b/scripts/restore @@ -27,11 +27,22 @@ 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 -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 #================================================= # RESTORE SYSTEM CONFIGURATIONS 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"