mirror of
https://github.com/YunoHost-Apps/reverseproxy_ynh.git
synced 2024-09-03 20:16:23 +02:00
73 lines
2.7 KiB
Bash
73 lines
2.7 KiB
Bash
#!/bin/bash
|
|
|
|
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
|
set -e
|
|
|
|
# This is a multi-instance app, meaning it can be installed several times independently
|
|
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
|
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
|
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
|
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
|
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
|
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
|
# The app instance name is probably what you are interested the most, since this is
|
|
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
|
# db names, ...
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Source app helpers
|
|
. /usr/share/yunohost/helpers
|
|
|
|
# Retrieve arguments
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
path=$(ynh_app_setting_get "$app" path)
|
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
|
redirect_type=$(ynh_app_setting_get "$app" redirect_type)
|
|
redirect_path=$(ynh_app_setting_get "$app" redirect_path)
|
|
|
|
# Default value for redirect_type if upgrading from https://github.com/scith/redirect_ynh
|
|
if [ -z "$redirect_type" ];
|
|
then
|
|
redirect_type="proxy"
|
|
ynh_app_setting_set $app 'redirect_type' $redirect_type
|
|
fi
|
|
|
|
# Remove trailing slash to path
|
|
path=${path%/}
|
|
#force location to be / or /foo
|
|
location=${path:-/}
|
|
|
|
# Check domain/path availability
|
|
yunohost app checkurl $domain$path -a $app \
|
|
|| (echo "Path not available: $domain$path" && exit 1)
|
|
|
|
# Validate redirect path
|
|
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
|
[[ ! $redirect_path =~ $url_regex ]] && ynh_die \
|
|
"Invalid destination: $redirect_path" 1
|
|
|
|
# Nginx configuration
|
|
sed -i "s@YNH_LOCATION@$location@g" ../conf/nginx-*.conf
|
|
if [ "$redirect_type" = "visible_302" ];
|
|
then
|
|
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-302.conf
|
|
cp ../conf/nginx-visible-302.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
elif [ "$redirect_type" = "visible_301" ];
|
|
then
|
|
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-301.conf
|
|
cp ../conf/nginx-visible-301.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
elif [ "$redirect_type" = "proxy" ];
|
|
then
|
|
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-proxy.conf
|
|
cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
fi
|
|
|
|
# Make app public if necessary
|
|
if [[ "$is_public" -ne 0 ]];
|
|
then
|
|
yunohost app setting $app unprotected_uris -v "/"
|
|
fi
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
service nginx reload
|
|
yunohost app ssowatconf
|