Follow recommendations to use more helpers

This commit is contained in:
selfhoster1312 2023-01-08 15:49:37 +01:00
parent bc55b0d0ff
commit ee7c5e9443
7 changed files with 30 additions and 52 deletions

View file

@ -1,5 +1,5 @@
location @YNH_APPNAME__proxy { location @__NAME____proxy {
proxy_pass YNH_PROXY_PATH; proxy_pass __PROXY_PATH__;
proxy_redirect off; proxy_redirect off;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
@ -18,11 +18,11 @@ location @YNH_APPNAME__proxy {
} }
# Support relative URLs # Support relative URLs
location = YNH_LOCATION { location = __PATH_URL__ {
return 302 YNH_LOCATION/; return 302 __PATH_URL__/;
} }
location YNH_LOCATION/ { location __PATH_URL__/ {
alias YNH_ASSETS_PATH; alias __ASSETS_PATH__;
try_files $uri @YNH_APPNAME__proxy; try_files $uri @__NAME____proxy;
} }

View file

@ -24,30 +24,3 @@ rp_validate_proxy_path() {
fi fi
fi fi
} }
# Make reverse proxy public if $1 is 1
# Yunohost boolean params are 1 if true
rp_make_permissions() {
ynh_script_progression --message="Configuring permissions..." --weight=2
if [ $1 = 1 ]; then
ynh_permission_update --permission="main" --add="visitors"
fi
}
# (re)generate nginx config
rp_make_webconfig() {
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Nginx configuration
ynh_replace_string "YNH_LOCATION" "$path_url" ../conf/nginx.conf
ynh_replace_string "YNH_PROXY_PATH" "$proxy_path" ../conf/nginx.conf
ynh_replace_string "YNH_APPNAME" "$app" ../conf/nginx.conf
ynh_replace_string "YNH_ASSETS_PATH" "$assets_path" ../conf/nginx.conf
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
}
rp_reload_web() {
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
}

View file

@ -33,15 +33,17 @@ new_path=$YNH_APP_NEW_PATH
#================================================= #=================================================
# Nginx configuration # Nginx configuration
ynh_replace_string "$old_path {" "$new_path {" /etc/nginx/conf.d/$old_domain.d/$app.conf ynh_script_progression --message="Configuring NGINX web server..." --weight=1
ynh_replace_string "${old_path}/ {" "${new_path}/ {" /etc/nginx/conf.d/$old_domain.d/$app.conf final_path=$(ynh_app_setting_get --app=$app --key=final_path)
ynh_replace_string "302 ${old_path}/" "302 ${new_path}/" /etc/nginx/conf.d/$old_domain.d/$app.conf 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)"
ynh_add_nginx_config
# Maybe only path part has changed... only move file if domain has changed # 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 [[ "$old_domain" != "$new_domain" ]] && mv /etc/nginx/conf.d/$old_domain.d/$app.conf /etc/nginx/conf.d/$new_domain.d/$app.conf
# Reload nginx
rp_reload_web
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -44,13 +44,15 @@ ynh_app_setting_set --app=$app --key=proxy_path --value=$proxy_path
ynh_app_setting_set --app=$app --key=assets_path --value=$assets_path ynh_app_setting_set --app=$app --key=assets_path --value=$assets_path
# Configure nginx # Configure nginx
rp_make_webconfig ynh_script_progression --message="Configuring NGINX web server..." --weight=1
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
ynh_add_nginx_config
# Make app public if necessary # Make app public if necessary (yunohost setting boolean is 1 when true)
rp_make_permissions $is_public ynh_script_progression --message="Configuring permissions..." --weight=2
if [ $is_public -eq 1 ]; then
# Reload nginx ynh_permission_update --permission="main" --add="visitors"
rp_reload_web fi
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -26,7 +26,8 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf
# Reload nginx # Reload nginx
rp_reload_web ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -42,7 +42,8 @@ NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf"
ynh_restore_file "$NGINX_CONF" ynh_restore_file "$NGINX_CONF"
# Reload nginx # Reload nginx
rp_reload_web ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -42,10 +42,9 @@ ynh_abort_if_errors
rp_validate_proxy_path "$proxy_path" rp_validate_proxy_path "$proxy_path"
# Configure nginx # Configure nginx
rp_make_webconfig ynh_script_progression --message="Configuring NGINX web server..." --weight=1
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Reload nginx ynh_add_nginx_config
rp_reload_web
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT