Helper - improve ynh_add_nginx_config

Add 2 new features :
- Permit to replace some others variables in the template
- Manage automatically the redirection (alias_transversal issue fix)
This commit is contained in:
Josue-T 2018-05-10 00:05:46 +02:00 committed by GitHub
parent 9570832f42
commit 0f8cef9cf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -117,7 +117,10 @@ ynh_remove_systemd_config () {
# Create a dedicated nginx config
#
# usage: ynh_add_nginx_config
# usage: ynh_add_nginx_config "list of others variables to replace"
#
# | arg: list of others variables to replace separeted by a space
# | for example : 'path_2 port_2 ...'
#
# This will use a template in ../conf/nginx.conf
# __PATH__ by $path_url
@ -126,8 +129,13 @@ ynh_remove_systemd_config () {
# __NAME__ by $app
# __FINALPATH__ by $final_path
#
# And dynamic variables (from the last example) :
# __PATH_2__ by $path_2
# __PORT_2__ by $port_2
#
ynh_add_nginx_config () {
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
local finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
local others_var=${1:-}
ynh_backup_if_checksum_is_different "$finalnginxconf"
sudo cp ../conf/nginx.conf "$finalnginxconf"
@ -151,6 +159,18 @@ ynh_add_nginx_config () {
if test -n "${final_path:-}"; then
ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf"
fi
# Replace all other variable given as arguments
for v in $others_var
do
ynh_replace_string "__${v^^}__" "${!v}" "$finalnginxconf"
done
if [ "${path_url:-}" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "$finalnginxconf"
fi
ynh_store_file_checksum "$finalnginxconf"
sudo systemctl reload nginx