From e8625977a7f92896907a4d6fb22e4a38c3bee207 Mon Sep 17 00:00:00 2001 From: Chris Vogel Date: Sun, 19 May 2024 13:51:00 +0200 Subject: [PATCH] fixed small problems --- doc/PRE_INSTALL.md | 7 +++-- scripts/_common.sh | 71 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/backup | 4 --- scripts/install | 5 +--- scripts/remove | 5 ++-- scripts/restore | 3 ++ 6 files changed, 81 insertions(+), 14 deletions(-) diff --git a/doc/PRE_INSTALL.md b/doc/PRE_INSTALL.md index cf1d4e8..5f845b7 100644 --- a/doc/PRE_INSTALL.md +++ b/doc/PRE_INSTALL.md @@ -13,11 +13,12 @@ flohmarkt will send email and you'll be asked for an address used as the sender This [issue](https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/50) contains information about the problem. -## multiple flohmarkt on the same subdomain +## multiple flohmarkt on the same subdomain will not work -The installation will allow you to **test** this. The feature is not well tested, yet, and installing multiple productive flohmarkts in the same domain might not work on the fediverse. +flohmarkt **needs its own subdomain** to be installed on. Some of the discussion about this can be found here: -Feedback is more than welcome! +https://codeberg.org/flohmarkt/flohmarkt/issues/251 +https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/53 ## No integration in yunohost user database diff --git a/scripts/_common.sh b/scripts/_common.sh index 4a9880e..57fcaba 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -46,6 +46,77 @@ flohmarkt_old_service="flohmarkt" # PERSONAL HELPERS #================================================= +# local copy of ynh_local_curl() to test some improvement +# https://github.com/YunoHost/issues/issues/2396 +# https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/51 +flohmarkt_ynh_local_curl() { +# Curl abstraction to help with POST requests to local pages (such as installation forms) +# +# usage: ynh_local_curl "page_uri" "key1=value1" "key2=value2" ... +# | arg: page_uri - Path (relative to `$path_url`) of the page where POST data will be sent +# | arg: key1=value1 - (Optionnal) POST key and corresponding value +# | arg: key2=value2 - (Optionnal) Another POST key and corresponding value +# | arg: ... - (Optionnal) More POST keys and values +# +# example: ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2" +# +# For multiple calls, cookies are persisted between each call for the same app +# +# `$domain` and `$path_url` should be defined externally (and correspond to the domain.tld and the /path (of the app?)) +# +# Requires YunoHost version 2.6.4 or higher. + # Define url of page to curl + local local_page=$(ynh_normalize_url_path $1) + local full_path=$path_url$local_page + + if [ "${path_url}" == "/" ]; then + full_path=$local_page + fi + + local full_page_url=https://localhost$full_path + + # Concatenate all other arguments with '&' to prepare POST data + local POST_data="" + local arg="" + for arg in "${@:2}"; do + POST_data="${POST_data}${arg}&" + done + if [ -n "$POST_data" ]; then + # Add --data arg and remove the last character, which is an unecessary '&' + POST_data="--data ${POST_data::-1}" + fi + + # Wait untils nginx has fully reloaded (avoid curl fail with http2) + sleep 2 + + local cookiefile=/tmp/ynh-$app-cookie.txt + touch $cookiefile + chown root $cookiefile + chmod 700 $cookiefile + + # Temporarily enable visitors if needed... + local visitors_enabled=$(ynh_permission_has_user "main" "visitors" && echo yes || echo no) + if [[ $visitors_enabled == "no" ]]; then + ynh_permission_update --permission "main" --add "visitors" + fi + + # Curl the URL + curl --silent --show-error --insecure --location --header "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url" --cookie-jar $cookiefile --cookie $cookiefile + + if [[ $visitors_enabled == "no" ]]; then + ynh_permission_update --permission "main" --remove "visitors" + fi +} + +# create symlinks containing domain and path for install, data and log directories +flohmarkt_ynh_create_symlinks() { + ynh_script_progression --message="Creating symlinks..." --weight=1 + ln -s "$flohmarkt_install" "$flohmarkt_sym_install" + ln -s "$flohmarkt_data_dir" "$flohmarkt_sym_data_dir" + ln -s "$flohmarkt_log_dir" "$flohmarkt_sym_log_dir" + true +} + # set file permissions and owner for installation flohmarkt_ynh_set_permission() { # install dir - only root needs to write and $app reads diff --git a/scripts/backup b/scripts/backup index 2a84c68..337c00f 100755 --- a/scripts/backup +++ b/scripts/backup @@ -12,10 +12,6 @@ ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/opt/couchdb/etc/local.d/05-flohmarkt.ini" ynh_backup --src_path="/etc/systemd/system/$flohmarkt_filename.service" ynh_backup --src_path="${flohmarkt_log_dir}" -ynh_backup --src_path="$flohmarkt_sym_install" -ynh_backup --src_path="$flohmarkt_sym_data_dir" -ynh_backup --src_path="$flohmarkt_sym_log_dir" - # for the following backups we'll want to stop flohmarkt and couchdb # to guarentee a consistant state diff --git a/scripts/install b/scripts/install index 9b966fc..5845dc1 100755 --- a/scripts/install +++ b/scripts/install @@ -122,10 +122,7 @@ ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +