Chris Vogel 1 год назад
Родитель
Сommit
e8625977a7
6 измененных файлов с 81 добавлено и 14 удалено
  1. 4 3
      doc/PRE_INSTALL.md
  2. 71 0
      scripts/_common.sh
  3. 0 4
      scripts/backup
  4. 1 4
      scripts/install
  5. 2 3
      scripts/remove
  6. 3 0
      scripts/restore

+ 4 - 3
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
 

+ 71 - 0
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

+ 0 - 4
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

+ 1 - 4
scripts/install

@@ -122,10 +122,7 @@ ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST
 
 # symlink data_dir and install_dir to make it easier to find the
 # files for a certain domain/path
-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"
+flohmarkt_ynh_create_symlinks
 
 # start service
 ynh_script_progression --message="Debug before starting flohmarkt..." --weight=1

+ 2 - 3
scripts/remove

@@ -64,11 +64,10 @@ ynh_remove_systemd_config
 
 # remove symlinks
 ynh_script_progression --message="Removing symlinks..." --weight=2
-ynh_secure_remove --file="$flohmarkt_sym_install"
+# no ynh_secure_remove: 
+# https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/52
 rm "$flohmarkt_sym_install" || true
-ynh_secure_remove --file="$flohmarkt_sym_data_dir"
 rm "$flohmarkt_sym_data_dir" || true
-ynh_secure_remove --file="$flohmarkt_sym_log_dir"
 rm "$flohmarkt_sym_log_dir" || true
 
 #=================================================

+ 3 - 0
scripts/restore

@@ -74,4 +74,7 @@ flohmarkt_ynh_start_service
 ynh_script_progression --message="Reloading NGINX web server..." --weight=1
 ynh_systemd_action --service_name=nginx --action=reload
 
+# create symlinks
+flohmarkt_ynh_create_symlinks
+
 ynh_script_progression --message="Restoration completed for $app" --last