Merge pull request #16 from YunoHost-Apps/fix-deprecated-practices

Fix deprecated practices
This commit is contained in:
Alexandre Aubin 2019-05-15 17:33:02 +02:00 committed by GitHub
commit 09cf1c6b98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 61 deletions

View file

@ -10,8 +10,8 @@
"fr": "Créer une redirection ou un proxy vers un autre emplacement"
},
"version": "1.0.0~ynh2",
"url": "https://github.com/YunoHost-Apps/redirect_ynh",
"license": "AGPL-3.0-or-later",
"url": "https://github.com/YunoHost-Apps/redirect_ynh",
"maintainer": {
"name": "opi",
"email": "opi@zeropi.net"
@ -43,6 +43,7 @@
},
{
"name": "redirect_path",
"type": "string",
"ask": {
"en": "Redirect destination path",
"fr": "Emplacement de destination"
@ -57,6 +58,10 @@
"en": "Is it a public redirect?",
"fr": "Est-ce une redirection publique ?"
},
"help": {
"en": "A private redirection will only be effective for logged-in users.",
"fr": "Une redirection privée ne fonctionnera que pour les utilisateurs identifiés."
},
"default": false
},
{

View file

@ -38,7 +38,7 @@ ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(yunohost app setting $app domain)
domain=$(ynh_app_setting_get $app domain)
# Copy the conf files
mkdir -p ./conf

View file

@ -34,43 +34,39 @@ app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
redirect_type=$YNH_APP_ARG_REDIRECT_TYPE
redirect_path=$YNH_APP_ARG_REDIRECT_PATH
# 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 \
|| ynh_die "Path not available: $domain$path"
ynh_webpath_register $app $domain $path_url
# 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
[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1
# Save extra settings
yunohost app setting $app is_public -v "$is_public"
yunohost app setting $app redirect_type -v "$redirect_type"
yunohost app setting $app redirect_path -v "$redirect_path"
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"
# Nginx configuration
sed -i "s@YNH_LOCATION@$location@g" ../conf/nginx-*.conf
for FILE in $(ls ../conf/nginx-*.conf)
do
ynh_replace_string "YNH_LOCATION" "$path_url" $FILE
done
if [ "$redirect_type" = "visible_302" ];
then
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-302.conf
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../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
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../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
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-proxy.conf
cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
fi
@ -78,12 +74,12 @@ fi
# SETUP SSOWAT
#=================================================
if [[ "$is_public" -eq 0 ]]
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi
# Make app public if necessary
if [[ "$is_public" -eq 1 ]]
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
@ -92,4 +88,3 @@ fi
# Reload Nginx and regenerate SSOwat conf
service nginx reload
yunohost app ssowatconf

View file

@ -26,11 +26,10 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(yunohost app setting $app domain)
domain=$(ynh_app_setting_get $app domain)
# Remove configuration files
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf
# Restart services
service nginx reload
yunohost app ssowatconf

View file

@ -39,28 +39,18 @@ app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
path_url=$(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)
# Remove trailing slash to path
path=${path%/}
# Check domain/path availability
yunohost app checkurl $domain$path -a $app \
|| die "The path ${domain}${path} is not available for app installation."
# 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
[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1
# Check configuration files
NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf"
[[ -f $NGINX_CONF ]] && die \
"The NGINX configuration already exists at '${NGINX_CONF}'.
You should safely delete it before restoring this app."
[[ -f $NGINX_CONF ]] && ynh_die "The NGINX configuration already exists at '${NGINX_CONF}'. You should safely delete it before restoring this app."
# Restore configuration files
cp -a ./conf/nginx.conf "$NGINX_CONF"
@ -69,12 +59,12 @@ cp -a ./conf/nginx.conf "$NGINX_CONF"
# SETUP SSOWAT
#=================================================
if [[ "$is_public" -eq 0 ]]
if [ "$is_public" -eq 0 ]
then # Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi
# Make app public if necessary
if [[ "$is_public" -eq 1 ]]
if [ "$is_public" -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
@ -82,4 +72,3 @@ fi
# Reload Nginx and regenerate SSOwat conf
service nginx reload
yunohost app ssowatconf

View file

@ -31,7 +31,7 @@ app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
path_url=$(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)
@ -69,33 +69,26 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# 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 \
|| ynh_die "Path not available: $domain$path"
# 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
[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1
# Nginx configuration
sed -i "s@YNH_LOCATION@$location@g" ../conf/nginx-*.conf
for FILE in $(ls ../conf/nginx-*.conf)
do
ynh_replace_string "YNH_LOCATION" "$path_url" $FILE
done
if [ "$redirect_type" = "visible_302" ];
then
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-302.conf
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../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
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../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
ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-proxy.conf
cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
fi
@ -103,12 +96,12 @@ fi
# SETUP SSOWAT
#=================================================
if [[ "$is_public" -eq 0 ]]
if [ "$is_public" -eq 0 ]
then # Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi
# Make app public if necessary
if [[ "$is_public" -eq 1 ]]
if [ "$is_public" -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris -v "/"
@ -116,4 +109,3 @@ fi
# Reload Nginx and regenerate SSOwat conf
service nginx reload
yunohost app ssowatconf