1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lutim_ynh.git synced 2024-09-03 19:36:24 +02:00
lutim_ynh/scripts/actions/public_private

84 lines
2.6 KiB
Text
Raw Normal View History

2018-09-30 11:52:12 +02:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-01-13 19:10:28 +01:00
source scripts/_common.sh
2018-09-30 11:52:12 +02:00
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
# Get is_public
is_public=${YNH_ACTION_IS_PUBLIC}
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
2020-01-02 18:40:15 +01:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
2018-09-30 11:52:12 +02:00
#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
#=================================================
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
2020-01-02 18:40:15 +01:00
is_public_old=$(ynh_app_setting_get --app=$app --key=is_public)
2018-09-30 11:52:12 +02:00
if [ $is_public -eq $is_public_old ]
then
2020-01-02 18:40:15 +01:00
ynh_die --message="is_public is already set as $is_public." --ret_code=0
2018-09-30 11:52:12 +02:00
fi
#=================================================
# SPECIFIC ACTION
#=================================================
# MOVE TO PUBLIC OR PRIVATE
#=================================================
2020-01-02 18:40:15 +01:00
2019-01-30 16:19:40 +01:00
if [ $is_public -eq 0 ]; then
public_private="private"
else
public_private="public"
fi
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Moving the application to $public_private..." --weight=3
2018-09-30 11:52:12 +02:00
if [ $is_public -eq 0 ]
then
2019-01-18 19:56:43 +01:00
# If the app is private, viewing images stays publicly accessible.
2018-09-30 11:52:12 +02:00
if [ "$path_url" == "/" ]; then
2019-01-18 19:56:43 +01:00
# If the path is /, clear it to prevent any error with the regex.
path_url=""
2018-09-30 11:52:12 +02:00
fi
2019-01-18 19:56:43 +01:00
# Modify the domain to be used in a regex
2018-09-30 11:52:12 +02:00
domain_regex=$(echo "$domain" | sed 's@-@.@g')
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
2018-09-30 11:52:12 +02:00
else
2020-01-02 18:40:15 +01:00
ynh_app_setting_delete --app=$app --key=protected_regex
2018-09-30 11:52:12 +02:00
fi
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Upgrading SSOwat configuration..."
2018-09-30 11:52:12 +02:00
# Regen ssowat configuration
yunohost app ssowatconf
# Update the config of the app
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
2018-09-30 11:52:12 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Reloading nginx web server..."
2018-09-30 11:52:12 +02:00
2020-01-02 18:40:15 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2019-01-30 16:19:40 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last