From 6cfc25660327db69f8479eb89ce80b4af1ab9631 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 29 Apr 2019 20:49:40 +0200 Subject: [PATCH] Various fixes for linter warnings / deprecrated practices --- manifest.json | 7 ++++++- scripts/backup | 4 ++-- scripts/install | 24 ++++++++++++------------ scripts/remove | 5 ++--- scripts/restore | 11 +++-------- scripts/upgrade | 16 +++++----------- 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/manifest.json b/manifest.json index bb22c9d..0419d0f 100644 --- a/manifest.json +++ b/manifest.json @@ -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 }, { diff --git a/scripts/backup b/scripts/backup index ddb8155..73bca48 100644 --- a/scripts/backup +++ b/scripts/backup @@ -38,8 +38,8 @@ 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 -cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf \ No newline at end of file +cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf diff --git a/scripts/install b/scripts/install index dc53e28..b3583d9 100644 --- a/scripts/install +++ b/scripts/install @@ -45,32 +45,33 @@ path=${path%/} 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 # 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" "$location" $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 @@ -92,4 +93,3 @@ fi # Reload Nginx and regenerate SSOwat conf service nginx reload -yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index 32159db..0f596fd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -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 diff --git a/scripts/restore b/scripts/restore index 1a4b8e8..f7c05f6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -48,19 +48,15 @@ redirect_path=$(ynh_app_setting_get "$app" redirect_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." +ynh_webpath_register $app $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 # 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" @@ -82,4 +78,3 @@ fi # Reload Nginx and regenerate SSOwat conf service nginx reload -yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index 027b27c..0a53309 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -74,28 +74,23 @@ 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 +ynh_replace_string "YNH_LOCATION" "$location" ../conf/nginx-*.conf 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 @@ -116,4 +111,3 @@ fi # Reload Nginx and regenerate SSOwat conf service nginx reload -yunohost app ssowatconf