2016-06-20 23:43:51 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2018-05-26 10:27:01 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC START
|
|
|
|
|
#=================================================
|
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
|
#=================================================
|
2016-06-20 23:43:51 +02:00
|
|
|
|
|
2018-05-26 10:27:01 +02:00
|
|
|
|
# source _common.sh
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
|
#=================================================
|
2016-06-20 23:43:51 +02:00
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2019-05-09 19:57:27 +02:00
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2016-06-20 23:43:51 +02:00
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
redirect_type=$YNH_APP_ARG_REDIRECT_TYPE
|
|
|
|
|
redirect_path=$YNH_APP_ARG_REDIRECT_PATH
|
|
|
|
|
|
|
|
|
|
# Check domain/path availability
|
2019-05-09 19:57:27 +02:00
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
2016-06-20 23:43:51 +02:00
|
|
|
|
|
|
|
|
|
# Validate redirect path
|
|
|
|
|
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
2019-04-29 20:49:40 +02:00
|
|
|
|
[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1
|
2016-06-20 23:43:51 +02:00
|
|
|
|
|
|
|
|
|
# Save extra settings
|
2019-04-29 20:49:40 +02:00
|
|
|
|
ynh_app_setting_set $app is_public "$is_public"
|
|
|
|
|
ynh_app_setting_set $app redirect_type "$redirect_type"
|
|
|
|
|
ynh_app_setting_set $app redirect_path "$redirect_path"
|
2016-06-20 23:43:51 +02:00
|
|
|
|
|
|
|
|
|
# Nginx configuration
|
2019-04-29 20:49:40 +02:00
|
|
|
|
for FILE in $(ls ../conf/nginx-*.conf)
|
|
|
|
|
do
|
2019-05-09 23:08:09 +02:00
|
|
|
|
ynh_replace_string "YNH_LOCATION" "$path_url" $FILE
|
2019-04-29 20:49:40 +02:00
|
|
|
|
done
|
2016-06-20 23:43:51 +02:00
|
|
|
|
if [ "$redirect_type" = "visible_302" ];
|
|
|
|
|
then
|
2019-04-29 20:49:40 +02:00
|
|
|
|
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-visible-302.conf
|
2018-05-26 10:01:42 +02:00
|
|
|
|
cp ../conf/nginx-visible-302.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2016-06-20 23:43:51 +02:00
|
|
|
|
elif [ "$redirect_type" = "visible_301" ];
|
|
|
|
|
then
|
2019-04-29 20:49:40 +02:00
|
|
|
|
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-visible-301.conf
|
2018-05-26 10:01:42 +02:00
|
|
|
|
cp ../conf/nginx-visible-301.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2016-06-20 23:43:51 +02:00
|
|
|
|
elif [ "$redirect_type" = "proxy" ];
|
|
|
|
|
then
|
2019-04-29 20:49:40 +02:00
|
|
|
|
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-proxy.conf
|
2018-05-26 10:01:42 +02:00
|
|
|
|
cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2016-06-20 23:43:51 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2018-05-26 10:27:01 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SSOWAT
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2019-05-09 23:08:09 +02:00
|
|
|
|
if [ $is_public -eq 0 ]
|
2018-05-26 10:27:01 +02:00
|
|
|
|
then # Remove the public access
|
|
|
|
|
ynh_app_setting_delete "$app" skipped_uris
|
|
|
|
|
fi
|
2016-06-20 23:43:51 +02:00
|
|
|
|
# Make app public if necessary
|
2019-05-09 23:08:09 +02:00
|
|
|
|
if [ $is_public -eq 1 ]
|
2016-06-20 23:43:51 +02:00
|
|
|
|
then
|
2018-05-26 10:27:01 +02:00
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2016-06-20 23:43:51 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2018-05-26 10:27:01 +02:00
|
|
|
|
|
2016-06-20 23:43:51 +02:00
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
2018-05-26 10:01:42 +02:00
|
|
|
|
service nginx reload
|