From 41384f3a0ba0e0ffaad92021975ae3a1029a729d Mon Sep 17 00:00:00 2001 From: dragondaddy Date: Sat, 3 Feb 2024 20:10:49 +0100 Subject: [PATCH] psql on 1st install + Keep mysql if already used --- conf/htconfig.sample.php | 2 +- manifest.toml | 20 ++++---------------- scripts/_common.sh | 8 ++++++++ scripts/backup | 6 +++--- scripts/install | 30 +----------------------------- scripts/remove | 8 ++------ scripts/restore | 11 +++-------- scripts/upgrade | 32 -------------------------------- 8 files changed, 22 insertions(+), 95 deletions(-) diff --git a/conf/htconfig.sample.php b/conf/htconfig.sample.php index bcbf4551..ee13b529 100644 --- a/conf/htconfig.sample.php +++ b/conf/htconfig.sample.php @@ -17,7 +17,7 @@ $db_port = 0; // leave 0 for default or set your port $db_user = '__DB_USER__'; $db_pass = '__DB_PWD__'; $db_data = '__DB_NAME__'; -$db_type = __DB_TYPE__; // use 1 for postgres, 0 for mysql +$db_type = 1; // use 1 for postgres, 0 for mysql /* * Notice: Many of the following settings will be available in the admin panel diff --git a/manifest.toml b/manifest.toml index c7150752..c40a2e9b 100644 --- a/manifest.toml +++ b/manifest.toml @@ -5,7 +5,7 @@ name = "Hubzilla" description.en = "Decentralized publication platform and social network" description.fr = "Plateforme de publication décentralisée et un réseau social" -version = "8.8.6~ynh1" +version = "8.8.6~ynh2" maintainers = [""] @@ -38,13 +38,6 @@ ram.runtime = "50M" [install.admin] type = "user" - [install.database] - ask.en = "Choose Hubzilla database" - ask.fr = "Choisissez la database de Hubzilla" - type = "select" - choices = ["mysql", "postgresql"] - default = "mysql" - [resources] [resources.sources] [resources.sources.main] @@ -63,12 +56,7 @@ ram.runtime = "50M" main.url = "/" [resources.apt] - packages = "php8.2-curl, php8.2-gd, php8.2-mysql, php8.2-pgsql, php8.2-mbstring, php8.2-xml, php8.2-zip, php8.2-cli, php8.2-imagick, php8.2-gmp" + packages = "postgresql, php8.2-curl, php8.2-gd, php8.2-pgsql, php8.2-mbstring, php8.2-xml, php8.2-zip, php8.2-cli, php8.2-imagick, php8.2-gmp" - packages_from_raw_bash = """ - if [[ "$database" == "mysql" ]]; then - echo "mariadb-server" - elif [[ "$database" == "postgresql" ]]; then - echo "postgresql postgresql-contrib" - fi - """ + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index 1e47ce72..6577b56e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,6 +10,14 @@ # PERSONAL HELPERS #================================================= +mysql_remove() { + ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +} + +mysql_restore() { + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 7b28f279..9e684bd9 100644 --- a/scripts/backup +++ b/scripts/backup @@ -58,11 +58,11 @@ ynh_backup --src_path="/etc/cron.d/$app" # BACKUP THE DATABASE #================================================= -if [ $database = "mysql" ]; then +if mysqlshow | grep -q "^| $db_name "; then # Backup MySQL database ynh_print_info --message="Backup of the MySQL database..." - ynh_mysql_dump_db --database="$db_name" > db.sql -elif [ $database = "postgresql" ]; then + ynh_mysql_dump_db --database="$db_name" > mydb.sql +else # Backup PostgreSQL database ynh_print_info --message="Backup of the PostgreSQL database..." ynh_psql_dump_db --database="$db_name" > db.sql diff --git a/scripts/install b/scripts/install index 6c1beb70..3719d4bf 100755 --- a/scripts/install +++ b/scripts/install @@ -25,7 +25,6 @@ fpm_usage="low" #================================================= ynh_script_progression --message="Storing installation settings..." --weight=1 -ynh_app_setting_set --app=$app --key=database --value=$database ynh_app_setting_set --app=$app --key=email --value=$email ynh_app_setting_set --app=$app --key=upload --value=$upload ynh_app_setting_set --app=$app --key=random_string --value=$random_string @@ -33,29 +32,6 @@ ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage -#================================================= -# CREATE A DATABASE -#================================================= -ynh_script_progression --message="Creating a database..." --weight=2 - -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 [ $database == "mysql" ]; then - ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name - ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ - <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" - db_type=0 -elif [ $database == "postgresql" ]; then - ynh_psql_test_if_first_run - ynh_psql_setup_db --db_user=$db_user --db_name=$db_name - db_type=1 -fi - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -101,11 +77,7 @@ chmod 644 "/etc/cron.d/$app" #================================================= ynh_script_progression --message="Provisionning database..." --weight=1 -if [ $database = "mysql" ]; then - ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $install_dir/install/schema_mysql.sql -elif [ $database = "postgresql" ]; then - ynh_psql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $install_dir/install/schema_postgres.sql -fi +ynh_psql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $install_dir/install/schema_postgres.sql #================================================= # ADD A CONFIGURATION diff --git a/scripts/remove b/scripts/remove index 0a5ec9eb..715da0e6 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,13 +12,9 @@ source /usr/share/yunohost/helpers #================================================= # REMOVE THE DATABASE #================================================= - -if [ $database = "mysql" ]; then +if mysqlshow | grep -q "^| $db_name "; then ynh_script_progression --message="Removing MySQL database..." --weight=1 - ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name -elif [ $database = "postgresql" ]; then - ynh_script_progression --message="Removing PostgreSQL database..." --weight=1 - ynh_psql_remove_db --db_user=$db_user --db_name=$db_name + mysql_remove fi #================================================= diff --git a/scripts/restore b/scripts/restore index 7f1bab2e..68b9d8ce 100644 --- a/scripts/restore +++ b/scripts/restore @@ -23,16 +23,11 @@ chown -R $app:www-data "$install_dir" # RESTORE THE DATABASE #================================================= -if [ $database = "mysql" ]; then +if [ -f mydb.sql ]; then ynh_script_progression --message="Restoring MySQL database..." --weight=1 - db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) - 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_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./mydb.sql +else ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 - db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) - ynh_psql_test_if_first_run - ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" fi diff --git a/scripts/upgrade b/scripts/upgrade index ce0f55a5..88297be0 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -53,15 +53,6 @@ if [ -z "${fpm_usage:-}" ]; then ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage fi -# Switch $database to "mysql" or "postgresql" -if [[ $database == "1" ]] 2>/dev/null; then - database="mysql" - ynh_app_setting_set --app=$app --key=database --value=$database -elif [[ $database == "2" ]] 2>/dev/null; then - database="postgresql" - ynh_app_setting_set --app=$app --key=database --value=$database -fi - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -97,29 +88,6 @@ ynh_add_nginx_config # SPECIFIC UPGRADE #================================================= # UPDATE A CONFIG FILE -#================================================= -# ynh_script_progression --message="Updating a configuration file..." --weight=1 - -# if [ $database = "mysql" ]; then -# db_type=0 -# db_name=$(ynh_sanitize_dbid --db_name=$app) -# db_user=$db_name -# db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -# # Change your databases character set and collation -# ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ -# <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" -# elif [ $database = "postgresql" ]; then -# db_type=1 -# db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -# fi - -# ynh_add_config --template="../conf/htconfig.sample.php" --destination="$install_dir/.htconfig.php" - -# ynh_store_file_checksum --file=$install_dir/.htconfig.php - -# chmod 600 "$install_dir/.htconfig.php" -# chown $app:$app "$install_dir/.htconfig.php" - #================================================= # UPGRADE CRON JOB #=================================================