1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/discourse_ynh.git synced 2024-09-03 18:26:18 +02:00
discourse_ynh/scripts/change_url

73 lines
3 KiB
Text
Raw Normal View History

2018-06-03 17:56:14 +02:00
#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2024-01-26 22:16:29 +01:00
ynh_script_progression --message="Stopping $app's systemd service..."
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
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
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"
2018-06-03 17:56:14 +02:00
# Calculate and store the config file checksum
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
# Remap URLs in forum posts
_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
# "
pushd "$install_dir/discourse"
# Regenerate assets
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
# Regenerate all forum posts
ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production bin/rake posts:rebake
popd
2018-06-03 17:56:14 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-01-26 22:16:29 +01:00
ynh_script_progression --message="Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --log_path="$install_dir/discourse/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready"
#=================================================
# 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"