qr_ynh/scripts/change_url

53 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
source /usr/share/yunohost/helpers
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
ynh_script_progression --message="Loading installation settings..."
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..."
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
ynh_restore_upgradebackup
}
ynh_abort_if_errors
ynh_script_progression --message="Updating NGINX web server configuration..."
# Change the path if needed
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
if [ $change_path -eq 1 ]
then
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
domain="$old_domain"
path_url="$new_path"
ynh_add_nginx_config
fi
# Change the domain if needed
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
if [ $change_domain -eq 1 ]
then
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
ynh_script_progression --message="Change of URL completed for $app" --last