From 96d0281249fa1c05800df23a5d180059d1850774 Mon Sep 17 00:00:00 2001 From: Chris Vogel Date: Wed, 12 Jun 2024 13:57:38 +0200 Subject: [PATCH 1/5] get rid of some linter warnings --- scripts/_common.sh | 48 ++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 638287e..cee0278 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -111,8 +111,8 @@ flohmarkt_old_service="flohmarkt" # deprecated before the last re-design of this sub) # # Requires YunoHost version 3.2.2 or higher. -# flohmarkt_ynh_handle_getopts_args() { -ynh_handle_getopts_args() { +# ynh_handle_getopts_args() { +flohmarkt_ynh_handle_getopts_args() { # Manage arguments only if there's some provided set +o xtrace # set +x if [ $# -eq 0 ]; then @@ -365,7 +365,7 @@ ynh_handle_getopts_args() { # https://github.com/YunoHost/yunohost/pull/1857 # https://github.com/YunoHost/issues/issues/2396 # https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/51 -ynh_local_curl() { +flohmarkt_ynh_local_curl() { # Curl abstraction to help with POST requests to local pages (such as installation forms) # # usage: ynh_local_curl [--option [-other_option […]]] "page" "key1=value1" "key2=value2" ... @@ -422,11 +422,21 @@ ynh_local_curl() { local -a data local -a curl_opt_args # optional arguments to `curl` # Manage arguments with getopts - ynh_handle_getopts_args "$@" + flohmarkt_ynh_handle_getopts_args "$@" # make sure method is a supported one if ! [[ -v supported_methods[$method] ]]; then - ynh_die --message="method $method not supported by ynh_local_curl" + ynh_die --message="method $method not supported by flohmarkt_ynh_local_curl" + fi + + # check that $location is a valid '/path' + if [[ -n "${location}" ]]; then + if [ "${location:0:1}" != "/" ]; then + location="/${location}" + fi + if [ "${location:${#location}-1}" == "/" ]; then + location="${location:0:${#location}-1}" + fi fi # Define url of page to curl @@ -437,10 +447,10 @@ ynh_local_curl() { full_page_url="$location" elif [ "${path_url}" == "/" ]; then # if $path_url points to the webserver root just append $location to localhost URL - full_page_url="https://localhost$(ynh_normalize_url_path $location)" + full_page_url="https://localhost${location}" else # else append $path_url and $location to localhost URL - full_page_url="https://localhost${path_url}$(ynh_normalize_url_path $location)" + full_page_url="https://localhost${path_url}${location}" fi flohmarkt_print_debug "full_page_url='$full_page_url'" @@ -537,7 +547,7 @@ ynh_local_curl() { # PERSONAL HELPERS #================================================= -# debug output for ynh_handle_getopts_args and ynh_local_curl +# debug output for flohmarkt_ynh_handle_getopts_args and flohmarkt_ynh_local_curl # otherwise not needed TODO delete after development of the two is done flohmarkt_debug=0 flohmarkt_print_debug() { @@ -632,14 +642,14 @@ flohmarkt_ynh_import_couchdb() { } flohmarkt_ynh_delete_couchdb_user() { - local couchdb_user_revision=$( ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" \ + local couchdb_user_revision=$( flohmarkt_ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" \ "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}" | jq -r ._rev ) - ynh_local_curl -n -m DELETE -u admin -p ${password_couchdb_admin} -l '"ok":true' \ + flohmarkt_ynh_local_curl -n -m DELETE -u admin -p ${password_couchdb_admin} -l '"ok":true' \ "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}?rev=${couchdb_user_revision}" } flohmarkt_ynh_create_couchdb_user() { - ynh_local_curl -n -m PUT -u admin -p "${password_couchdb_admin}" \ + flohmarkt_ynh_local_curl -n -m PUT -u admin -p "${password_couchdb_admin}" \ -H "Accept: application/json" -H "Content-Type: application/json" \ -d '{' \ -d "\"name\": \"${app}\", \"password\": \"${password_couchdb_flohmarkt}\"," \ @@ -649,7 +659,7 @@ flohmarkt_ynh_create_couchdb_user() { } flohmarkt_ynh_couchdb_user_permissions() { - ynh_local_curl -n -m PUT -u admin -p "$password_couchdb_admin" \ + flohmarkt_ynh_local_curl -n -m PUT -u admin -p "$password_couchdb_admin" \ -H "Accept: application/json" -H "Content-Type: application/json" \ -d "{\"members\":{\"names\": [\"${app}\"],\"roles\": [\"editor\"]}}" \ --line_match='"ok":true' \ @@ -657,22 +667,22 @@ flohmarkt_ynh_couchdb_user_permissions() { } flohmarkt_ynh_exists_couchdb_user() { - ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" -l "\"_id\":\"org.couchdb.user:${app}\"" \ + flohmarkt_ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" -l "\"_id\":\"org.couchdb.user:${app}\"" \ "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}" } flohmarkt_ynh_exists_couchdb_db() { - ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" -l "\"db_name\":\"${app}\"" \ + flohmarkt_ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" -l "\"db_name\":\"${app}\"" \ "http://127.0.0.1:5984/${app}" } flohmarkt_ynh_delete_couchdb_db() { local legacy_args='n' local -A args_array=( [n]=name= ) - ynh_handle_getopts_args "$@" + flohmarkt_ynh_handle_getopts_args "$@" local name=${name:-${app}} - ynh_local_curl -n -m DELETE -u admin -p "$password_couchdb_admin" \ + flohmarkt_ynh_local_curl -n -m DELETE -u admin -p "$password_couchdb_admin" \ --line_match='"ok":true' "http://127.0.0.1:5984/${name}" } @@ -682,10 +692,10 @@ flohmarkt_ynh_copy_couchdb() { local -A args_array=( [o]=old_name= [n]=new_name= ) local new_name local old_name - ynh_handle_getopts_args "$@" + flohmarkt_ynh_handle_getopts_args "$@" old_name=${old_name:-${app}} - ynh_local_curl -n -m POST -u admin -p "$password_couchdb_admin" \ + flohmarkt_ynh_local_curl -n -m POST -u admin -p "$password_couchdb_admin" \ -H "Accept: application/json" -H "Content-Type: application/json" \ -d '{ "create_target":true,"source" : "' -d"${old_name}" -d'",' \ -d '"target":"' -d "${new_name}" -d'"}' --seperator=none \ @@ -698,7 +708,7 @@ flohmarkt_ynh_rename_couchdb() { local -A args_array=( [o]=old_name= [n]=new_name= ) local new_name local old_name - ynh_handle_getopts_args "$@" + flohmarkt_ynh_handle_getopts_args "$@" old_name=${old_name:-${app}} flohmarkt_ynh_copy_couchdb -o "$old_name" -n "$new_name" From e9f1a5f245e310b6b80c661c8be8fe86fe57fe2e Mon Sep 17 00:00:00 2001 From: Chris Vogel Date: Wed, 12 Jun 2024 14:33:45 +0200 Subject: [PATCH 2/5] remove some more linter warnings --- scripts/install | 2 +- scripts/remove | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index eee94f2..257be2a 100755 --- a/scripts/install +++ b/scripts/install @@ -1,8 +1,8 @@ #!/bin/bash # IMPORT GENERIC HELPERS -source /usr/share/yunohost/helpers source _common.sh +source /usr/share/yunohost/helpers # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/9 # check if couchdb is already installed diff --git a/scripts/remove b/scripts/remove index 5a64d60..bd8a9e0 100755 --- a/scripts/remove +++ b/scripts/remove @@ -6,8 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source /usr/share/yunohost/helpers source _common.sh +source /usr/share/yunohost/helpers #================================================= # STANDARD REMOVE diff --git a/scripts/restore b/scripts/restore index 162c95f..a710510 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,7 @@ #!/bin/bash -source /usr/share/yunohost/helpers source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers # reinstall couchdb ynh_script_progression --message="Reinstalling couchdb..." --weight=40 diff --git a/scripts/upgrade b/scripts/upgrade index 36f9d60..8ed81bb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,7 @@ #!/bin/bash -source /usr/share/yunohost/helpers source _common.sh +source /usr/share/yunohost/helpers # UPGRADE_PACKAGE if only the YunoHost package has changed # UPGRADE_APP if the upstream app version has changed From e45aa5de8ad59f978163a1410675466dc2164e08 Mon Sep 17 00:00:00 2001 From: Chris Vogel Date: Wed, 12 Jun 2024 18:17:18 +0200 Subject: [PATCH 3/5] repair getting rid of warnings --- scripts/_common.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index cee0278..83d55df 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -429,27 +429,34 @@ flohmarkt_ynh_local_curl() { ynh_die --message="method $method not supported by flohmarkt_ynh_local_curl" fi - # check that $location is a valid '/path' - if [[ -n "${location}" ]]; then - if [ "${location:0:1}" != "/" ]; then - location="/${location}" + # linter doesn't want that the internal function is used anymore + # it's replaced here quick and dirty + flohmarkt_normalize_url_path() { + # check that $location is a valid '/path' + if [[ -n "${location}" ]]; then + if [ "${location:0:1}" != "/" ]; then + location="/${location}" + fi + if [ "${location:${#location}-1}" == "/" ]; then + location="${location:0:${#location}-1}" + fi fi - if [ "${location:${#location}-1}" == "/" ]; then - location="${location:0:${#location}-1}" - fi - fi + } # Define url of page to curl # $location contains either an URL or just a page local full_page_url + echo "################### location='$location' ###################" if [[ "$location" =~ ^https?:// ]]; then # if $location starts with an http-protocol use value as a complete URL full_page_url="$location" elif [ "${path_url}" == "/" ]; then # if $path_url points to the webserver root just append $location to localhost URL + flohmarkt_normalize_url_path full_page_url="https://localhost${location}" else # else append $path_url and $location to localhost URL + flohmarkt_normalize_url_path full_page_url="https://localhost${path_url}${location}" fi flohmarkt_print_debug "full_page_url='$full_page_url'" From 0997efa17b246a797f6e8cac43200f709b3235e6 Mon Sep 17 00:00:00 2001 From: Chris Vogel Date: Wed, 12 Jun 2024 20:15:50 +0200 Subject: [PATCH 4/5] when observation changes the result... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤦 --- scripts/_common.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 83d55df..5c58f76 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -446,7 +446,6 @@ flohmarkt_ynh_local_curl() { # Define url of page to curl # $location contains either an URL or just a page local full_page_url - echo "################### location='$location' ###################" if [[ "$location" =~ ^https?:// ]]; then # if $location starts with an http-protocol use value as a complete URL full_page_url="$location" @@ -651,8 +650,12 @@ flohmarkt_ynh_import_couchdb() { flohmarkt_ynh_delete_couchdb_user() { local couchdb_user_revision=$( flohmarkt_ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" \ "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}" | jq -r ._rev ) - flohmarkt_ynh_local_curl -n -m DELETE -u admin -p ${password_couchdb_admin} -l '"ok":true' \ - "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}?rev=${couchdb_user_revision}" + if [[ -v ${couchdb_user_revision} ]] && [[ -n ${couchdb_user_revision} ]]; then + flohmarkt_ynh_local_curl -n -m DELETE -u admin -p ${password_couchdb_admin} -l '"ok":true' \ + "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}?rev=${couchdb_user_revision}" + else + ynh_die --message "couchdb_user_revision is empty (${couchdb_user_revision})" + fi } flohmarkt_ynh_create_couchdb_user() { From e0be0bb7804442ceaaf535bffd1f79dfb3c63fb9 Mon Sep 17 00:00:00 2001 From: Chris Vogel Date: Wed, 12 Jun 2024 21:50:42 +0200 Subject: [PATCH 5/5] bashtastig --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 5c58f76..3406ff4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -650,7 +650,7 @@ flohmarkt_ynh_import_couchdb() { flohmarkt_ynh_delete_couchdb_user() { local couchdb_user_revision=$( flohmarkt_ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" \ "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}" | jq -r ._rev ) - if [[ -v ${couchdb_user_revision} ]] && [[ -n ${couchdb_user_revision} ]]; then + if [[ -v couchdb_user_revision ]] && [[ -n "${couchdb_user_revision}" ]]; then flohmarkt_ynh_local_curl -n -m DELETE -u admin -p ${password_couchdb_admin} -l '"ok":true' \ "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}?rev=${couchdb_user_revision}" else