2018-06-03 17:56:14 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2020-04-27 13:41:00 +02:00
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Stopping $app's systemd service..."
|
2020-04-27 13:41:00 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY URL IN NGINX CONF
|
2018-06-03 17:56:14 +02:00
|
|
|
#=================================================
|
2021-03-07 01:39:02 +01:00
|
|
|
ynh_script_progression --message="Updating NGINX web server configuration..."
|
2018-06-03 17:56:14 +02:00
|
|
|
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_change_url_nginx_config
|
2018-06-03 17:56:14 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-06-03 01:27:11 +02:00
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Updating a config file..."
|
2018-06-03 17:56:14 +02:00
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
discourse_config_file="$install_dir/discourse/config/discourse.conf"
|
2024-01-26 22:16:29 +01:00
|
|
|
|
|
|
|
old_relative_url_root="${old_path%/}"
|
|
|
|
new_relative_url_root="${new_path%/}"
|
|
|
|
|
2018-06-03 17:56:14 +02:00
|
|
|
# Configure hostname
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_replace_string --match_string="hostname = .*" --replace_string="hostname = \"$new_domain\"" --target_file="$discourse_config_file"
|
2020-05-12 17:24:36 +02:00
|
|
|
ynh_replace_string --match_string="relative_url_root = .*" --replace_string="relative_url_root = ${new_path%/}" --target_file="$discourse_config_file"
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_replace_string --match_string="smtp_domain = .*" --replace_string="smtp_domain = $new_domain" --target_file="$discourse_config_file"
|
2018-06-03 17:56:14 +02:00
|
|
|
|
|
|
|
# Calculate and store the config file checksum
|
2020-04-27 13:41:00 +02:00
|
|
|
ynh_store_file_checksum --file="$discourse_config_file"
|
2018-06-03 17:56:14 +02:00
|
|
|
|
|
|
|
# Change URL setting
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" \
|
|
|
|
<<< "UPDATE site_settings SET value = replace(value, '$old_relative_url_root/images/', '$new_relative_url_root/images/');
|
2018-06-03 17:56:14 +02:00
|
|
|
UPDATE site_settings SET value = '${new_path}' WHERE name='long_polling_base_url';"
|
|
|
|
|
2021-03-08 21:38:47 +01:00
|
|
|
ynh_use_ruby
|
2020-04-27 13:41:00 +02:00
|
|
|
# Remap URLs in forum posts
|
2024-08-30 11:22:21 +02:00
|
|
|
_exec_as_app_with_ruby_node RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec script/discourse remap "$old_relative_url_root/uploads" "$new_relative_url_root/uploads" <<< "YES
|
2018-06-03 17:56:14 +02:00
|
|
|
# "
|
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
pushd "$install_dir/discourse"
|
|
|
|
# Regenerate assets
|
2024-08-30 11:22:21 +02:00
|
|
|
ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production bin/rake assets:precompile
|
2018-06-03 17:56:14 +02:00
|
|
|
|
2024-08-29 12:47:51 +02:00
|
|
|
# Regenerate all forum posts
|
2024-08-30 11:22:21 +02:00
|
|
|
ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production bin/rake posts:rebake
|
2024-08-29 12:47:51 +02:00
|
|
|
popd
|
2018-06-03 17:56:14 +02:00
|
|
|
|
2020-04-27 13:41:00 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-01-26 22:16:29 +01:00
|
|
|
ynh_script_progression --message="Starting $app's systemd service..."
|
2020-04-27 13:41:00 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
2024-08-30 15:00:35 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="$install_dir/discourse/log/unicorn.stdout.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready"
|
2020-04-27 13:41:00 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2018-06-03 17:56:14 +02:00
|
|
|
|
2020-05-30 17:05:03 +02:00
|
|
|
ynh_script_progression --message="Change of URL completed for $app"
|