From 8c79dba1d189e5ae9fda95309c0abf42ff29911c Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Fri, 30 Aug 2024 22:48:49 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- conf/nginx.conf | 4 +- conf/sidekiq.yml | 22 ++-- conf/systemd.service | 2 +- manifest.toml | 2 + scripts/_common.sh | 22 +--- scripts/backup | 19 ++- scripts/change_url | 33 +++--- scripts/install | 109 +++++++++--------- scripts/remove | 16 +-- scripts/restore | 48 ++++---- scripts/upgrade | 108 +++++++++-------- .../patches/main-1-use-latest_uglify-js.patch | 14 --- ...support-for-older-versions-of-brotli.patch | 29 ----- .../main-4-fix-missing-git-repository.patch | 22 ---- ...ain-5-fix-admin-watched-words-action.patch | 15 --- .../main-6-fix-download-calendar.patch | 13 --- sources/patches/main-7-fix-uppy-upload.patch | 13 --- 17 files changed, 182 insertions(+), 309 deletions(-) delete mode 100644 sources/patches/main-1-use-latest_uglify-js.patch delete mode 100644 sources/patches/main-3-Re-add-support-for-older-versions-of-brotli.patch delete mode 100644 sources/patches/main-4-fix-missing-git-repository.patch delete mode 100644 sources/patches/main-5-fix-admin-watched-words-action.patch delete mode 100644 sources/patches/main-6-fix-download-calendar.patch delete mode 100644 sources/patches/main-7-fix-uppy-upload.patch diff --git a/conf/nginx.conf b/conf/nginx.conf index 13682be..86c856d 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -194,7 +194,7 @@ } # this means every file in public is tried first - try_files $uri @__NAME__; + try_files $uri @__APP__; } location __PATH__/downloads/ { @@ -202,7 +202,7 @@ alias __INSTALL_DIR__/public/ ; } - location @__NAME__ { + location @__APP__ { more_set_headers "Referrer-Policy : no-referrer-when-downgrade"; proxy_set_header Host $host; proxy_set_header X-Request-Start "t=${msec}"; diff --git a/conf/sidekiq.yml b/conf/sidekiq.yml index 4c8ab29..5e77eae 100644 --- a/conf/sidekiq.yml +++ b/conf/sidekiq.yml @@ -1,11 +1,11 @@ ---- -:concurrency: 5 -:pidfile: tmp/pids/sidekiq.pid -staging: - :concurrency: 10 -production: - :concurrency: 20 -:queues: - - default - - critical - - low +--- +:concurrency: 5 +:pidfile: tmp/pids/sidekiq.pid +staging: + :concurrency: 10 +production: + :concurrency: 20 +:queues: + - default + - critical + - low diff --git a/conf/systemd.service b/conf/systemd.service index d233091..639ca04 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -14,7 +14,7 @@ Environment=RAILS_ENV=production Environment=UNICORN_SIDEKIQS=1 Environment=LD_PRELOAD=__LIBJEMALLOC__ Environment=UNICORN_LISTENER=__INSTALL_DIR__/tmp/sockets/unicorn.sock -Environment="__YNH_RUBY_LOAD_PATH__" +Environment="PATH=__PATH_WITH_RUBY__" ExecStart=__INSTALL_DIR__/bin/bundle exec unicorn --config config/unicorn.conf.rb -E production Restart=always RestartSec=10 diff --git a/manifest.toml b/manifest.toml index d65d87c..a1f878a 100644 --- a/manifest.toml +++ b/manifest.toml @@ -20,6 +20,7 @@ cpe = "cpe:2.3:a:discourse:discourse" [integration] yunohost = ">=11.2.20" +helpers_version = "2.1" architectures = "all" multi_instance = true ldap = true @@ -62,6 +63,7 @@ ram.runtime = "1G" [resources.system_user] [resources.install_dir] + group = "www-data:r-x" [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index 06ebbfb..d4cede6 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,7 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= ruby_version="3.0.0" @@ -10,10 +10,6 @@ nodejs_version="18" libjemalloc="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')" -#================================================= -# PERSONAL HELPERS -#================================================= - # Returns true if a swap partition is enabled, false otherwise # usage: is_swap_present is_swap_present() { @@ -39,11 +35,11 @@ is_memory_available() { # terminates installation if requirements not met check_memory_requirements() { if ! is_swap_present ; then - ynh_print_warn --message="You must have a swap partition in order to install and use this application" + ynh_print_warn "You must have a swap partition in order to install and use this application" elif ! is_swappiness_sufficient ; then - ynh_print_warn --message="Your swappiness must be higher than 10; please see https://en.wikipedia.org/wiki/Swappiness" + ynh_print_warn "Your swappiness must be higher than 10; please see https://en.wikipedia.org/wiki/Swappiness" elif ! is_memory_available 1000000 ; then - ynh_print_warn --message="You must have a minimum of 1Gb available memory (RAM+swap) for the installation" + ynh_print_warn "You must have a minimum of 1Gb available memory (RAM+swap) for the installation" fi } # Checks discourse upgrade memory requirements @@ -51,7 +47,7 @@ check_memory_requirements() { # terminates upgrade if requirements not met check_memory_requirements_upgrade() { if ! is_memory_available 400000 ; then - ynh_die --message="You must have a minimum of 400Mb available memory (RAM+swap) for the upgrade" + ynh_die "You must have a minimum of 400Mb available memory (RAM+swap) for the upgrade" fi } @@ -115,11 +111,3 @@ ynh_maintenance_mode_OFF () { systemctl reload nginx } - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index d744b14..b289835 100644 --- a/scripts/backup +++ b/scripts/backup @@ -8,36 +8,33 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the PostgreSQL database..." +ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index f693d23..6830182 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -10,21 +10,21 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping $app's systemd service..." +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action="stop" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a config file..." +ynh_script_progression "Updating a config file..." discourse_config_file="$install_dir/config/discourse.conf" @@ -32,39 +32,38 @@ old_relative_url_root="${old_path%/}" new_relative_url_root="${new_path%/}" # Configure hostname -ynh_replace_string --match_string="hostname = .*" --replace_string="hostname = \"$new_domain\"" --target_file="$discourse_config_file" -ynh_replace_string --match_string="relative_url_root = .*" --replace_string="relative_url_root = ${new_path%/}" --target_file="$discourse_config_file" -ynh_replace_string --match_string="smtp_domain = .*" --replace_string="smtp_domain = $new_domain" --target_file="$discourse_config_file" +ynh_replace --match="hostname = .*" --replace="hostname = \"$new_domain\"" --file="$discourse_config_file" +ynh_replace --match="relative_url_root = .*" --replace="relative_url_root = ${new_path%/}" --file="$discourse_config_file" +ynh_replace --match="smtp_domain = .*" --replace="smtp_domain = $new_domain" --file="$discourse_config_file" # Calculate and store the config file checksum -ynh_store_file_checksum --file="$discourse_config_file" +ynh_store_file_checksum "$discourse_config_file" # Change URL setting -ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" \ +ynh_psql_db_shell \ <<< "UPDATE site_settings SET value = replace(value, '$old_relative_url_root/images/', '$new_relative_url_root/images/'); UPDATE site_settings SET value = '${new_path}' WHERE name='long_polling_base_url';" -ynh_use_ruby # Remap URLs in forum posts -ynh_exec_as "$app" --login RAILS_ENV=production bin/bundle exec script/discourse remap "$old_relative_url_root/uploads" "$new_relative_url_root/uploads" <<< "YES +ynh_exec_as_app --login RAILS_ENV=production bin/bundle exec script/discourse remap "$old_relative_url_root/uploads" "$new_relative_url_root/uploads" <<< "YES # " # Regenerate assets -ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production bin/rake assets:precompile +ynh_hide_warnings ynh_exec_as_app --login RAILS_ENV=production bin/rake assets:precompile # Regenerate all forum posts -ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production bin/rake posts:rebake +ynh_hide_warnings ynh_exec_as_app --login RAILS_ENV=production bin/rake posts:rebake #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready" +ynh_systemctl --service="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --wait_until="INFO -- : worker=$((unicorn_workers-1)) ready" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 941613f..c485f57 100644 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,7 @@ source _common.sh source /usr/share/yunohost/helpers -if [ "${PACKAGE_CHECK_EXEC:-0}" -ne 1 ]; then +if ! ynh_in_ci_tests; then # Check memory requirements check_memory_requirements fi @@ -23,7 +23,7 @@ admin_pwd=$(ynh_string_random) admin_mail=$(ynh_user_get_info --username=$admin --key=mail) redis_db=$(ynh_redis_get_free_db) -ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" +ynh_app_setting_set --key=redis_db --value="$redis_db" # Set a secret value secret="$(ynh_string_random)" @@ -35,33 +35,32 @@ if dpkg --print-architecture | grep -q "arm"; then else unicorn_workers=3 fi -ynh_app_setting_set --app="$app" --key=unicorn_workers --value=$unicorn_workers +ynh_app_setting_set --key=unicorn_workers --value=$unicorn_workers #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing Ruby..." +ynh_script_progression "Installing Ruby..." -ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version" -ynh_use_ruby +ynh_ruby_install -ynh_script_progression --message="Installing NodeJS..." +ynh_script_progression "Installing NodeJS..." -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install #================================================= # CONFIGURE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Configuring $app's PostgreSQL database..." +ynh_script_progression "Configuring $app's PostgreSQL database..." # Set extensions -ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS hstore;" -ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS hstore;" +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." # Specific actions on ARM architecture if dpkg --print-architecture | grep -q "arm"; then @@ -69,7 +68,7 @@ if dpkg --print-architecture | grep -q "arm"; then # compatibility by pointing to a recent libv8 version # This is due to this libv8 issue (https://github.com/cowboyd/libv8/issues/261) # that prevents it from being compiled on ARM hence no binary gem is available yet - cp ../sources/patches_arm/* ../sources/patches + cp ../patches_arm/* ../patches fi # Download, check integrity, uncompress and patch the source from app.src @@ -88,44 +87,43 @@ mkdir -p "$install_dir/public/forum" ln -s "$install_dir/public/uploads" "$install_dir/public/forum/uploads" ln -s "$install_dir/public/backups" "$install_dir/public/forum/backups" -chmod -R o-rwx "$install_dir" -chown -R "$app:www-data" "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding $app's configuration file..." +ynh_script_progression "Adding $app's configuration file..." -ynh_add_config --template="discourse_defaults.conf" --destination="$install_dir/config/discourse.conf" -ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml" -ynh_add_config --template="settings.yml" --destination="$install_dir/plugins/discourse-ldap-auth/config/settings.yml" +ynh_config_add --template="discourse_defaults.conf" --destination="$install_dir/config/discourse.conf" +ynh_config_add --template="secrets.yml" --destination="$install_dir/config/secrets.yml" +ynh_config_add --template="settings.yml" --destination="$install_dir/plugins/discourse-ldap-auth/config/settings.yml" # Disable svgo worker -echo "svgo: false" | ynh_exec_as "$app" tee "$install_dir/.image_optim.yml" >/dev/null +echo "svgo: false" | ynh_exec_as_app tee "$install_dir/.image_optim.yml" >/dev/null #================================================= # SETUP UNICORN, A RUBY SERVER #================================================= -ynh_script_progression --message="Setting up Unicorn..." +ynh_script_progression "Setting up Unicorn..." pushd "$install_dir" # Install bundler, a gems installer - ynh_gem install bundler + gem install bundler # Install without documentation - echo "gem: --no-ri --no-rdoc" | ynh_exec_as "$app" tee "$install_dir/.gemrc" >/dev/null + echo "gem: --no-ri --no-rdoc" | ynh_exec_as_app tee "$install_dir/.gemrc" >/dev/null popd # Specific actions on ARM architecture if dpkg --print-architecture | grep -q "arm"; then # Define the platform specifically to retrieve binaries # for libv8 because it currently doesn't compile on ARM devices - ynh_exec_as "$app" --login bin/bundle config specific_platform arm-linux + ynh_exec_as_app --login bin/bundle config specific_platform arm-linux fi # Install dependencies -ynh_exec_as "$app" --login bin/bundle config set path 'vendor/bundle' -ynh_exec_as "$app" --login bin/bundle config set with 'development' -ynh_exec_as "$app" --login MAKEFLAGS=-j2 bin/bundle install --jobs 2 +ynh_exec_as_app --login bin/bundle config set path 'vendor/bundle' +ynh_exec_as_app --login bin/bundle config set with 'development' +ynh_exec_as_app --login MAKEFLAGS=-j2 bin/bundle install --jobs 2 # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible @@ -138,32 +136,32 @@ if dpkg --print-architecture | grep -q "arm"; then fi pushd "$install_dir" - ynh_use_nodejs - ynh_npm install --location=global terser - ynh_npm install --location=global uglify-js - ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" yarn install --production --frozen-lockfile - ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" yarn cache clean + + npm install --location=global terser + npm install --location=global uglify-js + ynh_hide_warnings ynh_exec_as_app node_load_PATH" yarn install --production --frozen-lockfile + ynh_hide_warnings ynh_exec_as_app node_load_PATH" yarn cache clean popd #================================================= # PREPARE THE DATABASE #================================================= -ynh_script_progression --message="Preparing the database..." +ynh_script_progression "Preparing the database..." -ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production bin/bundle exec rake db:migrate -ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production bin/bundle exec rake themes:update assets:precompile +ynh_hide_warnings ynh_exec_as_app --login RAILS_ENV=production bin/bundle exec rake db:migrate +ynh_hide_warnings ynh_exec_as_app --login RAILS_ENV=production bin/bundle exec rake themes:update assets:precompile # Set default data (especially to have correct image URLs for subfolder install) -ynh_add_config --template="provisioning.sql" --destination="$install_dir/provisioning.sql" -ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < "$install_dir/provisioning.sql" -ynh_secure_remove --file="$install_dir/provisioning.sql" +ynh_config_add --template="provisioning.sql" --destination="$install_dir/provisioning.sql" +ynh_psql_db_shell < "$install_dir/provisioning.sql" +ynh_safe_rm "$install_dir/provisioning.sql" #================================================= # CREATE DISCOURSE ADMIN USER #================================================= -ynh_script_progression --message="Creating Discourse admin user..." +ynh_script_progression "Creating Discourse admin user..." -ynh_exec_as "$app" --login RAILS_ENV=production bin/rake admin:create <<< "$admin_mail +ynh_exec_as_app --login RAILS_ENV=production bin/rake admin:create <<< "$admin_mail $admin_pwd $admin_pwd y @@ -172,7 +170,7 @@ y #================================================= # CONFIGURE PLUGINS #================================================= -ynh_script_progression --message="Configuring plugins..." +ynh_script_progression "Configuring plugins..." # Patch ldap-auth plugin dependency (omniauth-ldap) to fix it when using domain subfolder # (Can only do that now because we are patching dependencies which have just been downloaded) @@ -183,38 +181,37 @@ patch -p1 -d "$install_dir/plugins/discourse-ldap-auth/gems/$ruby_version/gems/o #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +ynh_script_progression "Adding system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191 if [ "$path" != "/" ] ; then - ynh_replace_string --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" \ - --match_string='$proxy_add_x_forwarded_for' \ - --replace_string='$http_your_original_ip_header' + ynh_replace --file="/etc/nginx/conf.d/$domain.d/$app.conf" \ + --match='$proxy_add_x_forwarded_for' \ + --replace='$http_your_original_ip_header' fi -ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" additional_env="UNICORN_WORKERS=$unicorn_workers" -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --log "$install_dir/log/unicorn.stderr.log" "$install_dir/log/unicorn.stdout.log" "$install_dir/log/production.log" - # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile="$install_dir/log/unicorn.stderr.log" -ynh_use_logrotate --logfile="$install_dir/log/unicorn.stdout.log" -ynh_use_logrotate --logfile="$install_dir/log/production.log" +ynh_config_add_logrotate "$install_dir/log/unicorn.stderr.log" +ynh_config_add_logrotate "$install_dir/log/unicorn.stdout.log" +ynh_config_add_logrotate "$install_dir/log/production.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready" +ynh_systemctl --service="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --wait_until="INFO -- : worker=$((unicorn_workers-1)) ready" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index ad7764d..5cc3e08 100644 --- a/scripts/remove +++ b/scripts/remove @@ -10,30 +10,30 @@ source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +ynh_script_progression "Removing system configurations related to $app..." # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then +if ynh_hide_warnings yunohost service status "$app" >/dev/null; then yunohost service remove "$app" fi # Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_config_remove_systemd # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx ynh_redis_remove_db "$redis_db" -ynh_remove_nodejs +ynh_nodejs_remove -ynh_remove_ruby +ynh_ruby_remove #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index aa3ffee..94d412a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,7 +8,7 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -if [ "${PACKAGE_CHECK_EXEC:-0}" -ne 1 ]; then +if ! ynh_in_ci_tests; then # Check memory requirements check_memory_requirements fi @@ -16,66 +16,64 @@ fi #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling Ruby..." -ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version" -ynh_use_ruby +ynh_script_progression "Reinstalling Ruby..." +ynh_ruby_install -ynh_script_progression --message="Reinstalling NodeJS..." -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_script_progression "Reinstalling NodeJS..." +ynh_nodejs_install #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod -R o-rwx "$install_dir" -chown -R "$app:www-data" "$install_dir" +ynh_restore "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS hstore;" -ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS hstore;" +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;" -ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql +ynh_psql_db_shell < ./db.sql #================================================= # REINSTALL BUNDLE GEM #================================================= -ynh_script_progression --message="Reinstall Bundle Gem..." +ynh_script_progression "Reinstall Bundle Gem..." pushd "$install_dir" - ynh_gem install bundler + gem install bundler popd #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable "$app.service" --quiet yunohost service add "$app" --log "$install_dir/log/unicorn.stderr.log" "$install_dir/log/unicorn.stdout.log" "$install_dir/log/production.log" -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 +ynh_script_progression "Reloading NGINX web server and $app's service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready" +ynh_systemctl --service="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --wait_until="INFO -- : worker=$((unicorn_workers-1)) ready" -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 0cb4d02..e38a50a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,7 @@ source _common.sh source /usr/share/yunohost/helpers -if [ "${PACKAGE_CHECK_EXEC:-0}" -ne 1 ]; then +if ! ynh_in_ci_tests; then # Check memory requirements check_memory_requirements fi @@ -23,21 +23,21 @@ secret="$(ynh_string_random)" #================================================= # ENABLE MAINTENANCE MODE #================================================= -ynh_script_progression --message="Enabling maintenance mode..." +ynh_script_progression "Enabling maintenance mode..." ynh_maintenance_mode_ON #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="stop" --log_path="$install_dir/log/unicorn.stderr.log" +ynh_systemctl --service="$app" --action="stop" --log_path="$install_dir/log/unicorn.stderr.log" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." +ynh_script_progression "Ensuring downward compatibility..." # If unicorn_workers doesn't exist, create it if [ -z "$unicorn_workers" ]; then @@ -48,22 +48,22 @@ if [ -z "$unicorn_workers" ]; then else unicorn_workers=3 fi - ynh_app_setting_set --app="$app" --key="unicorn_workers" --value="$unicorn_workers" + ynh_app_setting_set --key="unicorn_workers" --value="$unicorn_workers" fi #================================================= # UPGRADING DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading Ruby..." -ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version" +ynh_script_progression "Upgrading Ruby..." +ynh_ruby_install -ynh_script_progression --message="Upgrading NodeJS..." -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_script_progression "Upgrading NodeJS..." +ynh_nodejs_install #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." +ynh_script_progression "Upgrading source files..." # Specific actions on ARM architecture if dpkg --print-architecture | grep -q "arm"; then @@ -71,14 +71,14 @@ if dpkg --print-architecture | grep -q "arm"; then # compatibility by pointing to a recent libv8 version # This is due to this libv8 issue (https://github.com/cowboyd/libv8/issues/261) # that prevents it from being compiled on ARM hence no binary gem is available yet - cp ../sources/patches_arm/* ../sources/patches + cp ../patches_arm/* ../patches fi # Small trick to backup non-core plugins mv "$install_dir/plugins" "$install_dir/plugins_old" # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$install_dir" --full_replace=1 \ +ynh_setup_source --dest_dir="$install_dir" --full_replace \ --keep="config/discourse.conf plugins_old public/uploads public/backups log" # Restore all non-core plugins @@ -89,10 +89,10 @@ for plugin_dir in "$install_dir/plugins_old"/*; do fi done -ynh_secure_remove --file="$install_dir/plugins_old" +ynh_safe_rm "$install_dir/plugins_old" # Install LDAP plugin -ynh_setup_source --source_id=ldap-auth --dest_dir="$install_dir/plugins/discourse-ldap-auth" --full_replace=1 \ +ynh_setup_source --source_id=ldap-auth --dest_dir="$install_dir/plugins/discourse-ldap-auth" --full_replace \ --keep="config/settings.yml" # Add a pids and socket directory for the systemd script. @@ -106,52 +106,50 @@ ln -s "$install_dir/public/uploads" "$install_dir/public/forum/uploads" ln -s "$install_dir/public/backups" "$install_dir/public/forum/backups" # Set permissions to app files -chmod -R o-rwx "$install_dir" -chown -R "$app:www-data" "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir" #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating $app's config file..." +ynh_script_progression "Updating $app's config file..." -ynh_add_config --template="discourse_defaults.conf" --destination="$install_dir/config/discourse.conf" -ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml" -ynh_add_config --template="settings.yml" --destination="$install_dir/plugins/discourse-ldap-auth/config/settings.yml" +ynh_config_add --template="discourse_defaults.conf" --destination="$install_dir/config/discourse.conf" +ynh_config_add --template="secrets.yml" --destination="$install_dir/config/secrets.yml" +ynh_config_add --template="settings.yml" --destination="$install_dir/plugins/discourse-ldap-auth/config/settings.yml" # Disable svgo worker -echo "svgo: false" | ynh_exec_as "$app" tee "$install_dir/.image_optim.yml" >/dev/null +echo "svgo: false" | ynh_exec_as_app tee "$install_dir/.image_optim.yml" >/dev/null #================================================= # SETUP UNICORN, A RUBY SERVER #================================================= -ynh_script_progression --message="Setting up Unicorn..." +ynh_script_progression "Setting up Unicorn..." # Do it after setup_source because .ruby-version is stored in cwd -ynh_use_ruby # Make a backup of the original config file if modified unicorn_config_file="$install_dir/config/unicorn.conf.rb" ynh_backup_if_checksum_is_different "$unicorn_config_file" -ynh_store_file_checksum --file="$unicorn_config_file" +ynh_store_file_checksum "$unicorn_config_file" pushd "$install_dir" # Install bundler, a gems installer - ynh_gem install bundler + gem install bundler # Install without documentation - echo "gem: --no-ri --no-rdoc" | ynh_exec_as "$app" tee "$install_dir/.gemrc" >/dev/null + echo "gem: --no-ri --no-rdoc" | ynh_exec_as_app tee "$install_dir/.gemrc" >/dev/null popd # Specific actions on ARM architecture if dpkg --print-architecture | grep -q "arm"; then # Define the platform specifically to retrieve binaries # for libv8 because it currently doesn't compile on ARM devices - ynh_exec_as "$app" --login bin/bundle config specific_platform arm-linux + ynh_exec_as_app --login bin/bundle config specific_platform arm-linux fi # Install dependencies -ynh_exec_as "$app" --login bin/bundle config set path 'vendor/bundle' -ynh_exec_as "$app" --login bin/bundle config set with 'development' -ynh_exec_as "$app" --login MAKEFLAGS=-j2 bin/bundle install --jobs 2 +ynh_exec_as_app --login bin/bundle config set path 'vendor/bundle' +ynh_exec_as_app --login bin/bundle config set with 'development' +ynh_exec_as_app --login MAKEFLAGS=-j2 bin/bundle install --jobs 2 # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible @@ -164,26 +162,26 @@ if dpkg --print-architecture | grep -q "arm"; then fi pushd "$install_dir" - ynh_use_nodejs - ynh_npm install --location=global terser - ynh_npm install --location=global uglify-js - ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" yarn install --production --frozen-lockfile - ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" yarn cache clean + + npm install --location=global terser + npm install --location=global uglify-js + ynh_hide_warnings ynh_exec_as_app node_load_PATH" yarn install --production --frozen-lockfile + ynh_hide_warnings ynh_exec_as_app node_load_PATH" yarn cache clean popd #================================================= # PREPARE THE DATABASE #================================================= -ynh_script_progression --message="Preparing the database..." +ynh_script_progression "Preparing the database..." -ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production bin/bundle exec rake db:migrate -ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production bin/bundle exec rake themes:update assets:precompile +ynh_hide_warnings ynh_exec_as_app --login RAILS_ENV=production bin/bundle exec rake db:migrate +ynh_hide_warnings ynh_exec_as_app --login RAILS_ENV=production bin/bundle exec rake themes:update assets:precompile #================================================= # CONFIGURE PLUGINS #================================================= -ynh_script_progression --message="Configuring plugins..." +ynh_script_progression "Configuring plugins..." # Patch ldap-auth plugin dependency (omniauth-ldap) to fix it when using domain subfolder # (Can only do that now because we are patching dependencies which have just been downloaded) @@ -194,38 +192,38 @@ patch -p1 -d "$install_dir/plugins/discourse-ldap-auth/gems/$ruby_version/gems/o #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191 if [ "$path" != "/" ] ; then - ynh_replace_string --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" \ - --match_string='$proxy_add_x_forwarded_for' \ - --replace_string='$http_your_original_ip_header' + ynh_replace --file="/etc/nginx/conf.d/$domain.d/$app.conf" \ + --match='$proxy_add_x_forwarded_for' \ + --replace='$http_your_original_ip_header' fi -ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" additional_env="UNICORN_WORKERS=$unicorn_workers" -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --log "$install_dir/log/unicorn.stderr.log" "$install_dir/log/unicorn.stdout.log" "$install_dir/log/production.log" # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --logfile="$install_dir/log/unicorn.stderr.log" -ynh_use_logrotate --logfile="$install_dir/log/unicorn.stdout.log" -ynh_use_logrotate --logfile="$install_dir/log/production.log" +ynh_config_add_logrotate "$install_dir/log/unicorn.stderr.log" +ynh_config_add_logrotate "$install_dir/log/unicorn.stdout.log" +ynh_config_add_logrotate "$install_dir/log/production.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready" +ynh_systemctl --service="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --wait_until="INFO -- : worker=$((unicorn_workers-1)) ready" #================================================= # DISABLE MAINTENANCE MODE #================================================= -ynh_script_progression --message="Disabling maintenance mode..." +ynh_script_progression "Disabling maintenance mode..." ynh_maintenance_mode_OFF @@ -233,4 +231,4 @@ ynh_maintenance_mode_OFF # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression "Upgrade of $app completed" diff --git a/sources/patches/main-1-use-latest_uglify-js.patch b/sources/patches/main-1-use-latest_uglify-js.patch deleted file mode 100644 index 415ec9e..0000000 --- a/sources/patches/main-1-use-latest_uglify-js.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake -index 4a02d5f1b1..7b47f21658 100644 ---- a/lib/tasks/assets.rake -+++ b/lib/tasks/assets.rake -@@ -126,6 +126,9 @@ - data = File.read("#{assets_path}/#{from}") - - uglified, map = Uglifier.new(comments: :none, -+ harmony: true, -+ mangle: false, -+ compress: false, - source_map: { - filename: File.basename(from), - output_filename: File.basename(to) diff --git a/sources/patches/main-3-Re-add-support-for-older-versions-of-brotli.patch b/sources/patches/main-3-Re-add-support-for-older-versions-of-brotli.patch deleted file mode 100644 index 728758a..0000000 --- a/sources/patches/main-3-Re-add-support-for-older-versions-of-brotli.patch +++ /dev/null @@ -1,29 +0,0 @@ -diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake -index 7b47f21658..ea6d0da2c4 100644 ---- a/lib/tasks/assets.rake -+++ b/lib/tasks/assets.rake -@@ -116,9 +116,21 @@ def gzip(path) - end - - # different brotli versions use different parameters --def brotli_command(path, max_compress) -- compression_quality = max_compress ? "11" : "6" -- "brotli -f --quality=#{compression_quality} #{path} --output=#{path}.br" -+ver_out, _ver_err, ver_status = Open3.capture3('brotli --version') -+if !ver_status.success? -+ # old versions of brotli don't respond to --version -+ def brotli_command(path, max_compress) -+ compression_quality = max_compress ? "11" : "6" -+ "brotli --quality 11 --input #{path} --output #{path}.br" -+ end -+elsif ver_out >= "brotli 1.0.0" -+ def brotli_command(path, max_compress) -+ compression_quality = max_compress ? "11" : "6" -+ "brotli -f --quality=11 #{path} --output=#{path}.br" -+ end -+else -+ # not sure what to do here, not expecting this -+ raise "cannot determine brotli version" - end - - def brotli(path, max_compress) diff --git a/sources/patches/main-4-fix-missing-git-repository.patch b/sources/patches/main-4-fix-missing-git-repository.patch deleted file mode 100644 index a98afb6..0000000 --- a/sources/patches/main-4-fix-missing-git-repository.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff --git a/lib/discourse.rb b/lib/discourse.rb -index 2b53a91eb3..eec55647d5 100644 ---- a/lib/discourse.rb -+++ b/lib/discourse.rb -@@ -439,7 +439,7 @@ module Discourse - def self.full_version - @full_version ||= begin - git_cmd = 'git describe --dirty --match "v[0-9]*" 2> /dev/null' -- self.try_git(git_cmd, 'unknown') -+ self.try_git(git_cmd, Discourse::VERSION::STRING) - end - end - -@@ -448,7 +448,7 @@ module Discourse - def self.last_commit_date - @last_commit_date ||= begin - git_cmd = 'git log -1 --format="%ct"' -- seconds = self.try_git(git_cmd, nil) -+ seconds = '1563199245' # Note(decentral1se): Output from actual command in the v2.3.2 branch - seconds.nil? ? nil : DateTime.strptime(seconds, '%s') - end - end diff --git a/sources/patches/main-5-fix-admin-watched-words-action.patch b/sources/patches/main-5-fix-admin-watched-words-action.patch deleted file mode 100644 index a431d71..0000000 --- a/sources/patches/main-5-fix-admin-watched-words-action.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/app/assets/javascripts/admin/addon/controllers/admin-watched-words-action.js b/app/assets/javascripts/admin/addon/controllers/admin-watched-words-action.js -index 2b53a91eb3..eec55647d5 100644 ---- a/app/assets/javascripts/admin/addon/controllers/admin-watched-words-action.js -+++ b/app/assets/javascripts/admin/addon/controllers/admin-watched-words-action.js -@@ -32,9 +32,9 @@ - for (const { regexp, word } of words) { - try { - RegExp(regexp); -- } catch { -+ } catch (err) { - return I18n.t("admin.watched_words.invalid_regex", { word }); - } - } - }, - diff --git a/sources/patches/main-6-fix-download-calendar.patch b/sources/patches/main-6-fix-download-calendar.patch deleted file mode 100644 index 580e10d..0000000 --- a/sources/patches/main-6-fix-download-calendar.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/app/assets/javascripts/discourse/app/lib/download-calendar.js b/app/assets/javascripts/discourse/app/lib/download-calendar.js -index 2b53a91eb3..eec55647d5 100644 ---- a/app/assets/javascripts/discourse/app/lib/download-calendar.js -+++ b/app/assets/javascripts/discourse/app/lib/download-calendar.js -@@ -22,7 +22,7 @@ - } - - export function downloadIcs(title, dates) { -- const REMOVE_FILE_AFTER = 20_000; -+ const REMOVE_FILE_AFTER = 20000; - const file = new File([generateIcsData(title, dates)], { - type: "text/plain", - }); diff --git a/sources/patches/main-7-fix-uppy-upload.patch b/sources/patches/main-7-fix-uppy-upload.patch deleted file mode 100644 index 6af3580..0000000 --- a/sources/patches/main-7-fix-uppy-upload.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/app/assets/javascripts/discourse/app/mixins/uppy-upload.js b/app/assets/javascripts/discourse/app/mixins/uppy-upload.js -index 2b53a91eb3..eec55647d5 100644 ---- a/app/assets/javascripts/discourse/app/mixins/uppy-upload.js -+++ b/app/assets/javascripts/discourse/app/mixins/uppy-upload.js -@@ -21,7 +21,7 @@ - import { warn } from "@ember/debug"; - import bootbox from "bootbox"; - --export const HUGE_FILE_THRESHOLD_BYTES = 104_857_600; // 100MB -+export const HUGE_FILE_THRESHOLD_BYTES = "104_857_600"; // 100MB - - export default Mixin.create(UppyS3Multipart, { - uploading: false,