1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hubzilla_ynh.git synced 2024-09-03 19:26:21 +02:00

Merge branch 'psqlinstallonly' into php-fpm-settings

This commit is contained in:
Papa Dragon 2024-02-03 21:47:37 +01:00 committed by GitHub
commit 55ab9db7cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 21 additions and 94 deletions

View file

@ -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

View file

@ -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"

View file

@ -10,6 +10,14 @@ YNH_PHP_VERSION="8.2"
# 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
#=================================================

View file

@ -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

View file

@ -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

View file

@ -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
#=================================================

View file

@ -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

View file

@ -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
#=================================================