1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/redirect_ynh.git synced 2024-09-03 20:16:10 +02:00
redirect_ynh/scripts/install

88 lines
3 KiB
Text
Raw Normal View History

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 /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
# Retrieve arguments
2019-05-15 18:42:44 +02:00
app=$YNH_APP_INSTANCE_NAME
2016-06-20 23:43:51 +02:00
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
2016-06-20 23:43:51 +02:00
redirect_type=$YNH_APP_ARG_REDIRECT_TYPE
redirect_path=$YNH_APP_ARG_REDIRECT_PATH
# Check domain/path availability
2021-01-23 15:21:17 +01:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$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\+&@#/%=~_|]'
[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1
2016-06-20 23:43:51 +02:00
# Save extra settings
2021-01-23 15:21:17 +01:00
ynh_app_setting_set --app=$app --key=redirect_type --value=$redirect_type
ynh_app_setting_set --app=$app --key=redirect_path --value=$redirect_path
2016-06-20 23:43:51 +02:00
2019-05-15 18:42:44 +02:00
#=================================================
# CONFIGURE NGINX
#=================================================
2021-01-23 15:21:17 +01:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
2019-05-15 18:42:44 +02:00
2016-06-20 23:43:51 +02:00
# Nginx configuration
for FILE in $(ls ../conf/nginx-*.conf)
do
2019-05-09 23:08:09 +02:00
ynh_replace_string "YNH_LOCATION" "$path_url" $FILE
done
if [ "$redirect_type" = "public_302" ];
2016-06-20 23:43:51 +02:00
then
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
elif [ "$redirect_type" = "public_301" ];
2016-06-20 23:43:51 +02:00
then
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
elif [ "$redirect_type" = "public_proxy" ] || [ "$redirect_type" = "private_proxy" ];
2016-06-20 23:43:51 +02:00
then
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
#=================================================
2019-05-15 18:42:44 +02:00
# CONFIGURE SSOWAT
2018-05-26 10:27:01 +02:00
#=================================================
2021-01-23 15:21:17 +01:00
ynh_script_progression --message="Configuring permissions..." --weight=2
2018-05-26 10:27:01 +02:00
2016-06-20 23:43:51 +02:00
# Make app public if necessary
if [ "$redirect_type" != "private_proxy" ]
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.
2021-01-23 15:21:17 +01:00
ynh_permission_update --permission="main" --add="visitors"
2016-06-20 23:43:51 +02:00
fi
2021-01-23 15:21:17 +01:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last