#!/bin/bash

#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# STANDARD MODIFICATIONS
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..."

ynh_change_url_nginx_config

#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
#REMOVEME? 
domain=$new_domain
path=$new_path

ynh_add_config --template="../conf/development.ini.sample" --destination="$install_dir/backend/development.ini"
chmod 400 "$install_dir/backend/development.ini"
chown $app:$app "$install_dir/backend/development.ini"

ynh_add_config --template="../conf/configEnv.json.sample" --destination="$install_dir/frontend/configEnv.json"
chmod 400 "$install_dir/frontend/configEnv.json"
chown $app:$app "$install_dir/frontend/configEnv.json"

#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."

# Start a systemd service
ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app-web.log" --line_match="spawned uWSGI"

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Change of URL completed for $app"