1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/flohmarkt_ynh.git synced 2024-09-03 18:36:30 +02:00

paths and filenames - part II

adjusted paths after trying, thinking and talking to people in the matrix room again.
This commit is contained in:
Chris Vogel 2024-05-07 12:18:36 +02:00
parent b6d9fac30f
commit b943dfa6f1
6 changed files with 41 additions and 51 deletions

View file

@ -2,4 +2,4 @@
; prevent non admin users to be able to access the list of all databases ; prevent non admin users to be able to access the list of all databases
admin_only_all_dbs = true admin_only_all_dbs = true
port = __PORT_COUCHDB__ ; port = __##PORT_COUCHDB__

View file

@ -10,7 +10,8 @@ UseHttps = 0
Host = 127.0.0.1 Host = 127.0.0.1
User = __APP__ User = __APP__
Password = __PASSWORD_COUCHDB_FLOHMARKT__ Password = __PASSWORD_COUCHDB_FLOHMARKT__
Port = __PORT_COUCHDB__ # Port = __##PORT_COUCHDB__
Port = 5984
Database = __APP__ Database = __APP__
[SMTP] [SMTP]

View file

@ -28,8 +28,7 @@ code = "https://codeberg.org/flohmarkt/flohmarkt"
yunohost = ">= 11.2.11" yunohost = ">= 11.2.11"
architectures = "all" architectures = "all"
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/11 # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/11
# multi_instance = true multi_instance = true
multi_instance = false
# the "ldap" key corresponds to wether or not a user *can* login on the app using # the "ldap" key corresponds to wether or not a user *can* login on the app using
# its YunoHost credentials. # its YunoHost credentials.
@ -108,8 +107,8 @@ ram.runtime = "100M"
# This will pre-fetch the asset which can then be deployed during the install/upgrade scripts with : # This will pre-fetch the asset which can then be deployed during the install/upgrade scripts with :
# ynh_setup_source --dest_dir="$install_dir" # ynh_setup_source --dest_dir="$install_dir"
# You can also define other assets than "main" and add --source_id="foobar" in the previous command # You can also define other assets than "main" and add --source_id="foobar" in the previous command
url = "https://codeberg.org/flohmarkt/flohmarkt/archive/2c5ea313d9b04dad25649335f415af5ca484f262.tar.gz" url = "https://codeberg.org/flohmarkt/flohmarkt/archive/78b2cc137d7c88d961e12dcb5017b17257bc4a71.tar.gz"
sha256 = "ce08228e2e9e650925c53094bf9c02bac8cdcb03a931f262034802ce6541e1f7" sha256 = "4acbfe20372583fdf75f4eea7b9c29d9ae20d04283559578f5e33f8347570c33"
# These infos are used by https://github.com/YunoHost/apps/blob/master/tools/autoupdate_app_sources/autoupdate_app_sources.py # These infos are used by https://github.com/YunoHost/apps/blob/master/tools/autoupdate_app_sources/autoupdate_app_sources.py
# to auto-update the previous asset urls and sha256sum + manifest version # to auto-update the previous asset urls and sha256sum + manifest version
@ -132,10 +131,8 @@ ram.runtime = "100M"
# @@ how to create a couchdb user if needed? in install-script manually? # @@ how to create a couchdb user if needed? in install-script manually?
[resources.install_dir] [resources.install_dir]
dir = "/opt/flohmarkt"
# [resources.data_dir] [resources.data_dir]
# we'll take care of this inside the install script and save it to the settings
[resources.permissions] [resources.permissions]
# This will configure SSOwat permission for $domain/$path/ # This will configure SSOwat permission for $domain/$path/
@ -149,13 +146,16 @@ ram.runtime = "100M"
# uvicorn running the flohmarkt app will be started listening to this port # uvicorn running the flohmarkt app will be started listening to this port
# if 'main.default' is already in use another random port will be used # if 'main.default' is already in use another random port will be used
main.default = 8000 main.default = 8000
couchdb.default = 5984 # we'll rely on couchdb choosing the default port to listen to
# otherwise I'll set a new port for each flohmarkt that will be installed until the
# installation of couchdb is reworked by making it possible to do as a pure dependency
# couchdb.default = 5984
[resources.apt] [resources.apt]
# python dependencies shall be installed in a venv using pip. # python dependencies shall be installed in a venv using pip.
# moreutils is needed for `ts` used in systemd.service # moreutils is needed for `ts` used in systemd.service
packages = "python3-pip python3-full curl apt-transport-https gnupg moreutils" packages = "python3-pip python3-full curl apt-transport-https gnupg moreutils curl"
# repo for couchdb - doesn't work, yet # repo for couchdb - doesn't work, yet
# extras.couchdb.repo = "deb https://apache.jfrog.io/artifactory/couchdb-deb/ __YNH_DEBIAN_VERSION__ main" # extras.couchdb.repo = "deb https://apache.jfrog.io/artifactory/couchdb-deb/ __YNH_DEBIAN_VERSION__ main"
# extras.couchdb.key = "https://couchdb.apache.org/repo/keys.asc" # extras.couchdb.key = "https://couchdb.apache.org/repo/keys.asc"

View file

@ -14,24 +14,24 @@ if [[ "__${url_path}__" == '____' ]]; then
else else
flohmarkt_filename="$domain-${url_path}" flohmarkt_filename="$domain-${url_path}"
fi fi
# just in case we append $app to make it really unique
# this filename is used for logfile name and systemd.service name # this filename is used for logfile name and systemd.service name
flohmarkt_filename="${flohmarkt_filename//[^A-Za-z0-9._-]/_}_${app}" # and for symlinking install_dir and data_dir
# flohmarkt_filename="${YNH_APP_ID}_${flohmarkt_filename//[^A-Za-z0-9._-]/_}"
# directory flohmarkts software is installed to # directory flohmarkts software is installed to
# contains ./venv and ./src as sub-directories # contains ./venv and ./src as sub-directories
flohmarkt_install="/opt/${id}/${domain}/${url_path}" flohmarkt_install="$install_dir"
flohmarkt_sym_install="$( dirname $flohmarkt_install )/$flohmarkt_filename"
flohmarkt_venv_dir="${flohmarkt_install}/venv" flohmarkt_venv_dir="${flohmarkt_install}/venv"
flohmarkt_app_dir="${flohmarkt_install}/app" flohmarkt_app_dir="${flohmarkt_install}/app"
# directory containing logfiles # directory containing logfiles
flohmarkt_log_dir="/var/log/${id}/${flohmarkt_filename}" flohmarkt_log_dir="/var/log/${YNH_APP_ID}/${flohmarkt_filename}"
# filename for logfiles - ¡ojo! if not ends with .log will be interpreted # filename for logfiles - ¡ojo! if not ends with .log will be interpreted
# as a directory by ynh_use_logrotate # as a directory by ynh_use_logrotate
# https://github.com/YunoHost/issues/issues/2383 # https://github.com/YunoHost/issues/issues/2383
flohmarkt_logfile="${flohmarkt_log_dir}/${app}.log" flohmarkt_logfile="${flohmarkt_log_dir}/${app}.log"
# flohmarkt data_dir follows the naming convention above # flohmarkt data_dir
# its saved to settings during install flohmarkt_data_dir="$data_dir"
flohmarkt_data_dir="/home/yunohost.app/${flohmarkt_filename}" flohmarkt_sym_data_dir="$( dirname $flohmarkt_data_dir )/$flohmarkt_filename"
## old filenames before 0.00~ynh5 - for reference and needed to ## old filenames before 0.00~ynh5 - for reference and needed to
# migrate (see below) # migrate (see below)
@ -59,15 +59,6 @@ flohmarkt_ynh_upgrade_path_ynh5() {
# there's still some work open - see above # there's still some work open - see above
} }
# to follow the naming convention including information about domain
# and path we do create the data_dir here and save it during install
# to the settings of this flohmarkt instance
flohmarkt_ynh_create_data_dir() {
mkdir -p $data_dir
chown $app: $data_dir
chmod 750 $data_dir
}
#================================================= #=================================================
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS
#================================================= #=================================================

View file

@ -16,12 +16,6 @@ then
exit 1 exit 1
fi fi
# create and setup $data_dir
data_dir="${flohmarkt_data_dir}"
ynh_script_progression --message="Creating data_dir '$data_dir'..." --weight=2
ynh_app_setting_set --app=$app --key=data_dir --value="$data_dir"
flohmarkt_ynh_create_data_dir
# INITIALIZE AND STORE SETTINGS # INITIALIZE AND STORE SETTINGS
# todo: do we need to store the password un-encrypted somewhere on the system? # todo: do we need to store the password un-encrypted somewhere on the system?
# → there's no way to get the admin password later if sometimes in the future deleting # → there's no way to get the admin password later if sometimes in the future deleting
@ -68,10 +62,12 @@ systemctl restart couchdb
systemctl status couchdb systemctl status couchdb
# get flohmarkt # get flohmarkt
# suspecting that this deletes all other sources for YNH_APP_ID
ynh_setup_source --dest_dir="$flohmarkt_app_dir" ynh_setup_source --dest_dir="$flohmarkt_app_dir"
# setup python environment for flohmarkt # setup python environment for flohmarkt
ynh_secure_remove "$flohmarkt_venv_dir" ynh_secure_remove "$flohmarkt_venv_dir"
python3 -m venv --without-pip "$flohmarkt_venv_dir" python3 -m venv --without-pip "$flohmarkt_venv_dir"
# install python dependencies # install python dependencies
@ -129,7 +125,7 @@ mkdir -m755 -p "$flohmarkt_log_dir"
touch "$flohmarkt_logfile" touch "$flohmarkt_logfile"
chmod 640 "$flohmarkt_logfile" chmod 640 "$flohmarkt_logfile"
# start service # start service
ynh_systemd_action --service_name=$flohmarkt_filename --action="start" ynh_systemd_action --service_name=$flohmarkt_filename --action="start" --line_match='INFO: *Application startup complete.' --log_path="$flohmarkt_logfile" --timeout=30
# https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/44 # https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/44
# --line_match="INFO: Application startup complete." # --line_match="INFO: Application startup complete."
@ -137,4 +133,12 @@ ynh_systemd_action --service_name=$flohmarkt_filename --action="start"
ynh_script_progression --message="Configuring Fail2Ban..." --weight=3 ynh_script_progression --message="Configuring Fail2Ban..." --weight=3
ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden' --max_retry=5 ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden' --max_retry=5
# symlink data_dir and install_dir to make it easier to find the
# files for a certain domain/path
ln -s "$flohmarkt_install" "$flohmarkt_sym_install"
ln -s "$flohmarkt_data_dir" "$flohmarkt_sym_data_dir"
# debug
env
ynh_script_progression --message="Installation of $id completed" --last ynh_script_progression --message="Installation of $id completed" --last

View file

@ -27,23 +27,13 @@ then
yunohost service remove $flohmarkt_filename yunohost service remove $flohmarkt_filename
fi fi
## This needs to be rewritten: Only delete the database of the instance being removed
# https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/12 # https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/12
# ynh_script_progression --message="Stopping couchdb..." --weight=2 ynh_script_progression --message="Removing database and database user..." --weight=2
# systemctl stop couchdb # remove DB
# curl -s -X DELETE 'http://127.0.0.1:5984/flohmarkt' --user "admin:${password_couchdb_admin}"
# ynh_script_progression --message="Removing databases..." --weight=2 # remove DB user for this instance:
# # remove flohmarkt database and database user # get rev for the user and then delete user/rev
# # ynh_script_progression --message="removing flohmarkt couchdb user and database" --weight=2 curl -s -X DELETE "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}?rev=$( curl -sX GET "http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}" --user "admin:${password_couchdb_admin}" | jq -r ._rev)" --user "admin:${password_couchdb_admin}"
# # @@ wie komme ich hier an das admin-password, falls ich es brauche?
# # * brauche ich es? → ja
# # db:
# # curl -X DELETE 'http://127.0.0.1:5984/flohmarkt' --user '<admin-user>:<admin-password>'
# # user:
# # curl -X DELETE "http://127.0.0.1:5984/_users/org.couchdb.user%3Aflohmarkt?rev=`curl -sX GET 'http://127.0.0.1:5984/_users/org.couchdb.user%3Aflohmarkt' --user 'admin:bla42fasel' | jq -r ._rev`" --user '<admin-user>:<admin-password>'
# # @@ todo improve this like above
# # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/12
# ynh_secure_remove --file=/var/lib/couchdb
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_remove_logrotate
@ -68,6 +58,10 @@ ynh_secure_remove --file=$data_dir
ynh_script_progression --message="Removing data directory..." --weight=2 ynh_script_progression --message="Removing data directory..." --weight=2
ynh_remove_systemd_config ynh_remove_systemd_config
# remove symlinks
ynh_secure_remove "$flohmarkt_sym_install"
ynh_secure_remove "$flohmarkt_sym_data_dir"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================