1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/scrutiny_ynh.git synced 2024-09-03 20:16:24 +02:00
scrutiny_ynh/scripts/change_url
2023-04-03 11:59:03 +02:00

81 lines
3 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name="influxdb" --action="stop"
ynh_systemd_action --service_name="scrutiny-web-server.service" --action="stop" --log_path="/var/log/$app/web-server.log"
if [ $collector -eq 1 ]
then
ynh_systemd_action --service_name="scrutiny-collector.timer" --action="stop" --log_path="/var/log/$app/collector.log"
fi
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_change_url_nginx_config
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# in the change_url context, variables called new_domain, new_path, old_domain, old_path will be available, as well as change_domain and change_path equal to 0 (false) or 1 (true) depending if the domain / path changed
#=================================================
if [ "$old_path" != "$new_path" ]
then
# Update scrutiny.yaml
if [ "${new_path}" == "/" ]
then
new_base_path=""
else
new_base_path="\\${new_path}"
fi
key="basepath"
new_value="'$new_base_path'"
sed --regexp-extended "s/^(\s*${key}:\s*).*/\1${new_value}/" --in-place "$install_dir/config/scrutiny.yaml"
ynh_store_file_checksum --file="$install_dir/config/scrutiny.yaml"
# Update collector.yaml
port=$(ynh_app_setting_get --app=$app --key=port)
key="endpoint"
new_value="'http:\/\/127.0.0.1:${port}${new_base_path}\/'"
sed --regexp-extended "s/^(\s*${key}:\s*).*/\1${new_value}/" --in-place "$install_dir/config/collector.yaml"
ynh_store_file_checksum --file="$install_dir/config/collector.yaml"
fi
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
systemctl daemon-reload
ynh_systemd_action --service_name="influxdb" --action="start"
ynh_systemd_action --service_name="scrutiny-web-server.service" --action="start" --log_path="/var/log/$app/web-server.log"
if [ $collector -eq 1 ]
then
ynh_systemd_action --service_name="scrutiny-collector.timer" --action="start" --log_path="/var/log/$app/collector.log"
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last