reverseproxy_ynh/scripts/change_url
selfhoster1312 c7b5b3dbee Handle edgecases gracefully
Yunohost templating doesn't like @__NAME____proxy because `reverseproxy__2__proxy` will evaluate __2__ to $2
or @__NAME__@proxy because ynh_replace_vars uses @ as sed delimiter
and ynh_replace_vars really hates multiline blocks... Using actual newlines in string produces a sed unclosed delimiter error,
while using \n gets them double escaped to some weird output that crashed nginx.
2023-01-10 13:12:50 +01:00

62 lines
1.8 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
source _common.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
old_domain=$YNH_APP_OLD_DOMAIN
new_domain=$YNH_APP_NEW_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_path=$YNH_APP_NEW_PATH
# Path availability is already checked for
#=================================================
# REVERSEPROXY_YNH
#=================================================
# Nginx configuration
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
path_url="$new_path"
domain="$old_domain"
proxy_path="$(ynh_app_setting_get --app=$app --key=proxy_path)"
assets_path="$(ynh_app_setting_get --app=$app --key=assets_path)"
# Validate reverse proxy destination
rp_validate_proxy_path
# Validate assets_path
rp_validate_assets_path
# Special case for "/" path_url
rp_handle_webroot
ynh_add_nginx_config
# Move file to new domain if domain has changed
[[ "$old_domain" != "$new_domain" ]] && mv /etc/nginx/conf.d/$old_domain.d/$app.conf /etc/nginx/conf.d/$new_domain.d/$app.conf
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Changing URL of $app completed" --last