diff --git a/scripts/_common.sh b/scripts/_common.sh index 22ef669..f65b555 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -26,4 +26,17 @@ extract_application() { || ynh_die "Unable to extract application archive" rm "$archive" sudo rsync -a "$TMPDIR"/*/* "$DESTDIR" +} + +# Fix path if needed +# usage: fix_patch PATH_TO_FIX +fix_path() { + local path=$1 + if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then + path="/$path" + fi + if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then + path="${path:0:${#path}-1}" + fi + echo "$path" } \ No newline at end of file diff --git a/scripts/install b/scripts/install index 62ecfeb..1ea2e4c 100644 --- a/scripts/install +++ b/scripts/install @@ -32,12 +32,7 @@ ynh_app_setting_set "$app" is_public "$is_public" ynh_app_setting_set "$app" language "$language" # Fix path if needed -if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then - path="/$path" -fi -if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then - path="${path:0:${#path}-1}" -fi +path=$(fix_path $path) # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ diff --git a/scripts/upgrade b/scripts/upgrade index a54af26..e48e8a2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,9 @@ admin=$(ynh_app_setting_get "$app" admin) is_public=$(ynh_app_setting_get "$app" is_public) language=$(ynh_app_setting_get "$app" language) +# Fix path if needed +path=$(fix_path $path) + # Download and extract application extract_application .. @@ -39,7 +42,7 @@ sudo chmod 755 -R $src_path/galleries # Modify Nginx configuration file and copy it to Nginx conf directory nginx_conf=../conf/nginx.conf -sed -i "s@YNH_WWW_PATH@${path%/}@g" $nginx_conf +sed -i "s@YNH_WWW_PATH@${path}@g" $nginx_conf sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf