diff --git a/conf/config.json b/conf/config.json index 02d8572..a7fb25b 100644 --- a/conf/config.json +++ b/conf/config.json @@ -14,6 +14,7 @@ "hashing_default_password": true, "localstorage.allowsymlinks": true, "simpleSignUpLink.shown": false, + "default_phone_region": "", "maintenance_window_start": 1, "mail_smtpmode": "smtp", "mail_smtpport": "25", diff --git a/conf/nginx.conf b/conf/nginx.conf index aabd447..9aac4df 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -74,7 +74,7 @@ location ^~ __PATH__/ { # that file is correctly served; if it doesn't, then the request is passed to # the front-end controller. This consistent behaviour means that we don't need # to specify custom rules for certain paths (e.g. images and other assets, - # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus + # `/updater`, `/ocs-provider`), and thus # `try_files $uri $uri/ /nextcloud/index.php$request_uri` # always provides the desired behaviour. index index.php index.html __PATH__/index.php$request_uri; diff --git a/manifest.toml b/manifest.toml index 78d412b..0ab98a4 100644 --- a/manifest.toml +++ b/manifest.toml @@ -122,8 +122,8 @@ ram.runtime = "512M" api.allowed = ["visitors", "all_users"] [resources.apt] - packages = "mariadb-server, imagemagick, libmagickcore-6.q16-6-extra, acl, tar, smbclient, at, redis-server, php8.3-fpm, php8.3-bz2, php8.3-imap, php8.3-gmp, php8.3-gd, php8.3-intl, php8.3-curl, php8.3-apcu, php8.3-redis, php8.3-ldap, php8.3-imagick, php8.3-zip, php8.3-mbstring, php8.3-xml, php8.3-mysql, php8.3-igbinary, php8.3-bcmath" + packages = "postgresql, imagemagick, libmagickcore-6.q16-6-extra, acl, tar, smbclient, at, redis-server, php8.3-pgsql, php8.3-mysql, php8.3-fpm, php8.3-bz2, php8.3-imap, php8.3-gmp, php8.3-gd, php8.3-intl, php8.3-curl, php8.3-apcu, php8.3-redis, php8.3-ldap, php8.3-imagick, php8.3-zip, php8.3-mbstring, php8.3-xml, php8.3-igbinary, php8.3-bcmath" [resources.database] - type = "mysql" - + type = "postgresql" + \ No newline at end of file diff --git a/scripts/_ynh_mysql_connect_as.sh b/scripts/_ynh_mysql_connect_as.sh deleted file mode 100644 index a22963e..0000000 --- a/scripts/_ynh_mysql_connect_as.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# Open a connection as a user -# -# example: ynh_mysql_connect_as --user="user" --password="pass" <<< "UPDATE ...;" -# example: ynh_mysql_connect_as --user="user" --password="pass" --default_character_set="utf8mb4" < /path/to/file.sql -# -# usage: ynh_mysql_connect_as --user=user --password=password [--database=database] [--default_character_set=character-set] -# | arg: -u, --user= - the user name to connect as -# | arg: -p, --password= - the user password -# | arg: -d, --database= - the database to connect to -# | arg: -c, --default_character_set= - the charset to use -# -# Requires YunoHost version 2.2.4 or higher. -ynh_mysql_connect_as() { - # Declare an array to define the options of this helper. - local legacy_args=updc - local -A args_array=( [u]=user= [p]=password= [d]=database= [c]=default_character_set= ) - local user - local password - local database - local default_character_set - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - database="${database:-}" - default_character_set="${default_character_set:-}" - - if [ -n "$default_character_set" ] - then - default_character_set="--default-character-set=$default_character_set" - else - default_character_set="--default-character-set=latin1" - fi - - mysql --user="$user" --password="$password" "$default_character_set" --batch "$database" -} \ No newline at end of file diff --git a/scripts/_ynh_mysql_dump_db.sh b/scripts/_ynh_mysql_dump_db.sh deleted file mode 100644 index 3b922bb..0000000 --- a/scripts/_ynh_mysql_dump_db.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -# Dump a database -# -# example: ynh_mysql_dump_db --database=roundcube --default_character_set="utf8mb4" > ./dump.sql -# -# usage: ynh_mysql_dump_db --database=database -# | arg: -d, --database= - the database name to dump -# | arg: -c, --default_character_set= - the charset to use -# | ret: the mysqldump output -# -# Requires YunoHost version 2.2.4 or higher. -ynh_mysql_dump_db() { - # Declare an array to define the options of this helper. - local legacy_args=dc - local -A args_array=( [d]=database= [c]=default_character_set= ) - local database - local default_character_set - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - default_character_set="${default_character_set:-}" - MYSQL_ROOT_PWD_FILE=/etc/yunohost/mysql - - if [ -n "$default_character_set" ] - then - default_character_set="--default-character-set=$default_character_set" - else - # By default, default character set is "latin1" - default_character_set="--default-character-set=latin1" - fi - - if [ -f "$MYSQL_ROOT_PWD_FILE" ]; then - mysqldump --user="root" --password="$(cat $MYSQL_ROOT_PWD_FILE)" --single-transaction --skip-dump-date "$default_character_set" "$database" - else - mysqldump --single-transaction --skip-dump-date "$default_character_set" "$database" - fi -} \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index d9ecab9..733f4b1 100755 --- a/scripts/backup +++ b/scripts/backup @@ -8,7 +8,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -source ../settings/scripts/_ynh_mysql_dump_db.sh #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -60,11 +59,11 @@ ynh_backup --src_path="/etc/cron.d/$app" ynh_backup --src_path="/var/log/$app" #================================================= -# BACKUP THE MYSQL DATABASE +# BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the MySQL database..." +ynh_print_info --message="Backing up the PostgreSQL database..." -ynh_mysql_dump_db --database="$db_name" --default_character_set="utf8mb4" > db.sql +ynh_psql_dump_db --database="$db_name" > db.sql #================================================= # BACKUP THE NOTIFY_PUSH APP diff --git a/scripts/install b/scripts/install index a4ef70a..f1ef315 100755 --- a/scripts/install +++ b/scripts/install @@ -2,20 +2,11 @@ source _common.sh source /usr/share/yunohost/helpers -source _ynh_mysql_connect_as.sh phpflags="--define apc.enable_cli=1" ynh_app_setting_set --app=$app --key=phpflags --value="$phpflags" -#================================================= -# CREATE A MYSQL DATABASE -#================================================= -ynh_script_progression --message="Migrate MySQL database to utf8..." --weight=2 - -ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ - <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -82,7 +73,7 @@ admin_password="$(ynh_string_random --length=6)" # Install Nextcloud using a temporary admin user exec_occ maintenance:install \ - --database "mysql" --database-name $db_name \ + --database "pgsql" --database-name $db_name \ --database-user $db_user --database-pass "$db_pwd" \ --admin-user "admin" --admin-pass "$admin_password" \ --data-dir "$data_dir/data" \ @@ -185,8 +176,9 @@ exec_occ config:system:set overwrite.cli.url --value="https://${domain}${path}" #================================================= # Set the user as admin -ynh_mysql_connect_as --user=$db_name --password="$db_pwd" --database=$db_name --default_character_set="utf8mb4" \ +ynh_psql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ <<< "INSERT INTO oc_group_user VALUES ('admin','$admin');" + # And delete admin user exec_occ user:delete admin @@ -250,10 +242,12 @@ ynh_script_progression --message="Adding multimedia directories..." --weight=6 # Build YunoHost multimedia directories ynh_multimedia_build_main_dir + # Mount the user directory in Nextcloud exec_occ app:enable files_external create_external_storage "/home/yunohost.multimedia/\$user" "Multimedia" create_external_storage "/home/yunohost.multimedia/share" "Shared multimedia" + # Allow nextcloud to write into these directories ynh_multimedia_addaccess $app diff --git a/scripts/remove b/scripts/remove index 4bf6421..b4d1786 100755 --- a/scripts/remove +++ b/scripts/remove @@ -8,7 +8,7 @@ source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=5 +ynh_script_progression --message="Removing system configurations related to $app..." --weight=10 # Remove the dedicated NGINX config ynh_remove_nginx_config diff --git a/scripts/restore b/scripts/restore index d954430..ce14c42 100755 --- a/scripts/restore +++ b/scripts/restore @@ -2,7 +2,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -source ../settings/scripts/_ynh_mysql_connect_as.sh #================================================= # STANDARD RESTORATION STEPS @@ -14,16 +13,16 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$install_dir" #================================================= -# RESTORE THE MYSQL DATABASE +# RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=9 +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=9 -ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name --default_character_set="utf8mb4" < ./db.sql +ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Reconfiguring PHP-FPM..." --weight=50 +ynh_script_progression --message="Reconfiguring PHP-FPM..." --weight=5 # Restore the file first, so it can have a backup if different ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" diff --git a/scripts/upgrade b/scripts/upgrade index 5313109..4c19802 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -55,6 +55,12 @@ filter_boring_occ_warnings() { sed -E 's@\s*([0-9]+\/[0-9]+\s+\[(-|>|=)+\]\s+[0-9]+%|\s*Starting ...|Nextcloud or one of the apps require upgrade - only a limited number of commands are available|You may use your browser or the occ upgrade command to do the upgrade)@@g' } +current_version=$(grep OC_VersionString "$install_dir/version.php" | cut -d\' -f2) +current_major_version=${current_version%%.*} + +last_version=$(ynh_read_manifest --manifest_key="resources.sources.main.url" | grep -o '[0-9][0-9]\.[0-9]\.[0-9]') +last_major_version=${last_version%%.*} + # Define a function to execute commands with `occ` exec_occ() { # Backward compatibility to upgrade from older versions @@ -87,6 +93,35 @@ exec_occ() { php$NEXTCLOUD_PHP_VERSION --define apc.enable_cli=1 occ --no-interaction --no-ansi "$@") 2> >(filter_boring_occ_warnings >&2) } +#================================================= +# HANDLE DATABASE MIGRATION FROM MYSL TO PSQL +#================================================= + +# If we're moving through version 29.0.3~ynh1 (in which the switch to psql is made) +if ynh_compare_current_package_version --comparison lt --version 29.0.3~ynh1 +then + # Double-check the MySQL DB is here + if ! mysql -e "USE $db_name" 2>/dev/null + then + ynh_print_warn "Uhoh? The Nextcloud MySQL DB doesn't exist? We are supposed to move it to PostgreSQL... Maybe it was already migrated?" + # Double check the psql is not empty, otherwise big whoops? + if [[ "$(ynh_psql_execute_as_root --database=$db_name --sql="\dt" 2>/dev/null | wc -l)" == 0 ]] + then + ynh_die "Apparently the PostgreSQL DB is also empty, this is kind of worrying, what happened?!" + else + ynh_print_warn "Apparently the PostgreSQL DB is not empty, so this is probably OK?" + fi + else + ynh_print_info --message="Migrating to PostgreSQL database..." + ynh_exec_warn_less exec_occ db:convert-type --all-apps --clear-schema pgsql $db_name 127.0.0.1 $db_name --password=$db_pwd -n + ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name + fi +fi + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + # Define a function to add an external storage # Create the external storage for the given folders and enable sharing create_external_storage() { @@ -122,12 +157,11 @@ function list_installed_apps_not_compatible_with_future_version() comm -23 <(comm -23 $installed_apps $core_apps_in_current_version) $nextcloud_destination_appcatalog } +#current_version=$(grep OC_VersionString "$install_dir/version.php" | cut -d\' -f2) +#current_major_version=${current_version%%.*} -current_version=$(grep OC_VersionString "$install_dir/version.php" | cut -d\' -f2) -current_major_version=${current_version%%.*} - -last_version=$(ynh_read_manifest --manifest_key="resources.sources.main.url" | grep -o '[0-9][0-9]\.[0-9]\.[0-9]') -last_major_version=${last_version%%.*} +#last_version=$(ynh_read_manifest --manifest_key="resources.sources.main.url" | grep -o '[0-9][0-9]\.[0-9]\.[0-9]') +#last_major_version=${last_version%%.*} if [[ "$last_major_version" != "$current_major_version" ]] then @@ -148,15 +182,6 @@ then # Print the current version number of Nextcloud exec_occ -V - if [ "$(exec_occ config:system:get mysql.utf8mb4)" != "true" ]; then - db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) - # 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;" - # Set the mysql.utf8mb4 config to true in config.php - exec_occ config:system:set mysql.utf8mb4 --type boolean --value="true" - exec_occ maintenance:repair - fi # Upgrade may fail if this app is enabled # Take all apps enabled, and check if mail is one of them @@ -274,6 +299,11 @@ then # Then remove the config file ynh_secure_remove --file="$nc_conf" + # Occasionally new mimetypes are added to better handle certain file types. + # Migrating the mimetypes take a long time on larger instances + # so this is not done automatically during upgrades. + exec_occ maintenance:repair --include-expensive + #================================================= # ALLOW USERS TO DISCONNECT FROM NEXTCLOUD #=================================================