diff --git a/README.md b/README.md index cceeb65..d54ad94 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ It shall NOT be edited by hand. # I Hate Money for YunoHost -[![Integration level](https://dash.yunohost.org/integration/ihatemoney.svg)](https://dash.yunohost.org/appci/app/ihatemoney) ![](https://ci-apps.yunohost.org/ci/badges/ihatemoney.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/ihatemoney.maintain.svg) +[![Integration level](https://dash.yunohost.org/integration/ihatemoney.svg)](https://dash.yunohost.org/appci/app/ihatemoney) ![Working status](https://ci-apps.yunohost.org/ci/badges/ihatemoney.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/ihatemoney.maintain.svg) [![Install I Hate Money with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=ihatemoney) *[Lire ce readme en français.](./README_fr.md)* @@ -18,14 +18,14 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in I hate money is a web application made to ease shared budget management. It keeps track of who bought what, when, and for whom; and helps to settle the bills. -**Shipped version:** 4.1.5~ynh3 +**Shipped version:** 5.2.0~ynh1 **Demo:** https://ihatemoney.org/demo/ ## Screenshots -![](./doc/screenshots/screenshot_1_global.webp) -![](./doc/screenshots/screenshot_2_new_operation.webp) +![Screenshot of I Hate Money](./doc/screenshots/screenshot_1_global.webp) +![Screenshot of I Hate Money](./doc/screenshots/screenshot_2_new_operation.webp) ## Disclaimers / important information @@ -40,23 +40,26 @@ I hate money is a web application made to ease shared budget management. It keep - per-project identifiers required - any visitor can create a new project. +* During upgrade from version 4.1.5~ynh3, a new admin password is generated and sent to the root + ## Documentation and resources -* Official app website: https://github.com/spiral-project/ihatemoney -* Official admin documentation: https://ihatemoney.readthedocs.org/ -* Upstream app code repository: https://github.com/spiral-project/ihatemoney -* YunoHost documentation for this app: https://yunohost.org/app_ihatemoney -* Report a bug: https://github.com/YunoHost-Apps/ihatemoney_ynh/issues +* Official app website: +* Official admin documentation: +* Upstream app code repository: +* YunoHost documentation for this app: +* Report a bug: ## Developer info Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/ihatemoney_ynh/tree/testing). To try the testing branch, please proceed like that. -``` + +``` bash sudo yunohost app install https://github.com/YunoHost-Apps/ihatemoney_ynh/tree/testing --debug or sudo yunohost app upgrade ihatemoney -u https://github.com/YunoHost-Apps/ihatemoney_ynh/tree/testing --debug ``` -**More info regarding app packaging:** https://yunohost.org/packaging_apps \ No newline at end of file +**More info regarding app packaging:** diff --git a/README_fr.md b/README_fr.md index 180ff89..a4e0b3b 100644 --- a/README_fr.md +++ b/README_fr.md @@ -1,27 +1,31 @@ + + # I Hate Money pour YunoHost -[![Niveau d'intégration](https://dash.yunohost.org/integration/ihatemoney.svg)](https://dash.yunohost.org/appci/app/ihatemoney) ![](https://ci-apps.yunohost.org/ci/badges/ihatemoney.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/ihatemoney.maintain.svg) +[![Niveau d'intégration](https://dash.yunohost.org/integration/ihatemoney.svg)](https://dash.yunohost.org/appci/app/ihatemoney) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/ihatemoney.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/ihatemoney.maintain.svg) [![Installer I Hate Money avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=ihatemoney) *[Read this readme in english.](./README.md)* -*[Lire ce readme en français.](./README_fr.md)* > *Ce package vous permet d'installer I Hate Money rapidement et simplement sur un serveur YunoHost. Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* ## Vue d'ensemble -I hate money is a web application made to ease shared budget management. It keeps track of who bought what, when, and for whom; and helps to settle the bills. +I hate money est une application web conçue pour faciliter la gestion partagée du budget. Elle permet de savoir qui a acheté quoi, quand et pour qui, et aide à régler les factures. -**Version incluse :** 4.1.5~ynh3 +**Version incluse :** 5.2.0~ynh1 **Démo :** https://ihatemoney.org/demo/ ## Captures d'écran -![](./doc/screenshots/screenshot_1_global.webp) -![](./doc/screenshots/screenshot_2_new_operation.webp) +![Capture d'écran de I Hate Money](./doc/screenshots/screenshot_1_global.webp) +![Capture d'écran de I Hate Money](./doc/screenshots/screenshot_2_new_operation.webp) ## Avertissements / informations importantes @@ -36,23 +40,26 @@ I hate money is a web application made to ease shared budget management. It keep - identifiants de projets requis - Tout visiteur peut créer un nouveau projet. +* Lors de la mise à jour de la version 4.1.5~ynh3, un nouveau mot de passe administrateur est généré et envoyé à root. + ## Documentations et ressources -* Site officiel de l'app : https://github.com/spiral-project/ihatemoney -* Documentation officielle de l'admin : https://ihatemoney.readthedocs.org/ -* Dépôt de code officiel de l'app : https://github.com/spiral-project/ihatemoney -* Documentation YunoHost pour cette app : https://yunohost.org/app_ihatemoney -* Signaler un bug : https://github.com/YunoHost-Apps/ihatemoney_ynh/issues +* Site officiel de l'app : +* Documentation officielle de l'admin : +* Dépôt de code officiel de l'app : +* Documentation YunoHost pour cette app : +* Signaler un bug : ## Informations pour les développeurs Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/ihatemoney_ynh/tree/testing). Pour essayer la branche testing, procédez comme suit. -``` + +``` bash sudo yunohost app install https://github.com/YunoHost-Apps/ihatemoney_ynh/tree/testing --debug ou sudo yunohost app upgrade ihatemoney -u https://github.com/YunoHost-Apps/ihatemoney_ynh/tree/testing --debug ``` -**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps \ No newline at end of file +**Plus d'infos sur le packaging d'applications :** diff --git a/check_process b/check_process index 461d489..97b4294 100644 --- a/check_process +++ b/check_process @@ -3,6 +3,7 @@ domain="domain.tld" path="/path" is_public=1 + password="1Strong-Password" ; Checks pkg_linter=1 setup_sub_dir=1 @@ -11,7 +12,10 @@ setup_private=1 setup_public=1 upgrade=1 - upgrade=1 from_commit=0f904d99367cfec27ec5fe303941fbf1124a7571 + # Before refactoring yunohost package + #upgrade=1 from_commit=0f904d99367cfec27ec5fe303941fbf1124a7571 + # 4.1.5~ynh3 + upgrade=1 from_commit=17bde85b095eddeeb279ef96f5697f92a59380db backup_restore=1 multi_instance=1 port_already_use=0 @@ -19,6 +23,3 @@ ;;; Options Email= Notification=none -;;; Upgrade options - ; commit=0f904d99367cfec27ec5fe303941fbf1124a7571 - name=Before refactoring yunohost package diff --git a/conf/hash_generator.py b/conf/hash_generator.py new file mode 100644 index 0000000..5b021b7 --- /dev/null +++ b/conf/hash_generator.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +import sys +from werkzeug.security import generate_password_hash + +print(generate_password_hash(sys.argv[1])) diff --git a/conf/ihatemoney.cfg b/conf/ihatemoney.cfg index 147c189..bfd5b90 100644 --- a/conf/ihatemoney.cfg +++ b/conf/ihatemoney.cfg @@ -1,9 +1,17 @@ -DEBUG = True +DEBUG = False SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://__DB_USER__:__DB_PWD__@localhost/__DB_NAME__' -SQLACHEMY_ECHO = DEBUG +SQLACHEMY_ECHO = False +SQLALCHEMY_TRACK_MODIFICATIONS = False SECRET_KEY = "__SECRET_KEY__" - -MAIL_DEFAULT_SENDER = ("Budget manager", "__MAILS_SENDER__") +MAIL_DEFAULT_SENDER = "Budget manager " +SHOW_ADMIN_EMAIL = False +ACTIVATE_DEMO_PROJECT = False +ADMIN_PASSWORD = "__HASHED_PASSWORD__" +ALLOW_PUBLIC_PROJECT_CREATION = True +ACTIVATE_ADMIN_DASHBOARD = True +SESSION_COOKIE_SECURE = True +ENABLE_CAPTCHA = False +LEGAL_LINK = "" __SUB_PATH_ONLY__APPLICATION_ROOT='__PATH__' try: diff --git a/conf/upgrade.msg b/conf/upgrade.msg new file mode 100644 index 0000000..e3edfed --- /dev/null +++ b/conf/upgrade.msg @@ -0,0 +1,4 @@ +I Hate Money was successfully upgraded :) +Please open https://__DOMAIN____PATH_URL__/admin +The admin password is: __PASSWORD__ +If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/ihatemoney_ynh \ No newline at end of file diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..4cf40df --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1 @@ +I hate money est une application web conçue pour faciliter la gestion partagée du budget. Elle permet de savoir qui a acheté quoi, quand et pour qui, et aide à régler les factures. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md index 37b4fcf..69c994f 100644 --- a/doc/DISCLAIMER.md +++ b/doc/DISCLAIMER.md @@ -8,3 +8,5 @@ - no yunohost login required - per-project identifiers required - any visitor can create a new project. + +* During upgrade from version 4.1.5~ynh3, a new admin password is generated and sent to the root diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md index 5403414..892196b 100644 --- a/doc/DISCLAIMER_fr.md +++ b/doc/DISCLAIMER_fr.md @@ -8,3 +8,5 @@ - authentification Yunohost non requise - identifiants de projets requis - Tout visiteur peut créer un nouveau projet. + +* Lors de la mise à jour de la version 4.1.5~ynh3, un nouveau mot de passe administrateur est généré et envoyé à root. diff --git a/manifest.json b/manifest.json index d171216..62ebc25 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Simple app to manage your collective expenses", "fr": "Gérez simplement vos dépenses collectives" }, - "version": "4.1.5~ynh3", + "version": "5.2.0~ynh1", "url": "http://ihatemoney.org/", "upstream": { "license": "MIT", @@ -26,12 +26,12 @@ }, "multi_instance": true, "services": [ - "nginx", - "postfix", - "mysql" + "nginx", + "postfix", + "mysql" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" @@ -50,6 +50,10 @@ "fr": "Les projets ihatemoney sont protégés par un mot de passe dans tous les cas" }, "default": true + }, + { + "name": "password", + "type": "password" } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index fad15ea..872b474 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -13,12 +13,9 @@ pkg_dependencies=( ) pip_dependencies=( - 'setuptools>=18.5' - 'gunicorn>=19.3.0' - 'PyMySQL>=0.9,<0.10' - 'SQLAlchemy<1.4' - 'ihatemoney==4.1.5' - 'markupsafe==2.0.1' + 'ihatemoney==5.2.0' + 'gunicorn>=20.0' + 'PyMySQL>=0.9,<1.1' ) ### Constants diff --git a/scripts/change_url b/scripts/change_url index 2ca3679..d908eee 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -23,6 +23,8 @@ app=$YNH_APP_INSTANCE_NAME db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +secret_key=$(ynh_app_setting_get --app=$app --key=secret_key) +hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password) #================================================= # LOAD SETTINGS @@ -115,18 +117,12 @@ fi path_url="$new_path" domain="$new_domain" -# Secret key for cookies encryption. -secret_key=$(ynh_string_random --length 32) -mails_sender="no-reply@$domain" # Allows to comment some config lines if not using sub path sub_path_only="$(if [[ "$path_url" == "/" ]]; then echo '# ' ; else echo ''; fi)" -ynh_backup_if_checksum_is_different --file="$final_path/ihatemoney.cfg" -ynh_add_config --template ../conf/ihatemoney.cfg --destination "$final_path/ihatemoney.cfg" - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$final_path/ihatemoney.cfg" +chmod 640 "$final_path/ihatemoney.cfg" +chown $app:$app "$final_path/ihatemoney.cfg" #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index 05db941..8aafc84 100755 --- a/scripts/install +++ b/scripts/install @@ -26,8 +26,13 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC +password=$YNH_APP_ARG_PASSWORD + app=$YNH_APP_INSTANCE_NAME +# Secret key for cookies encryption. +secret_key=$(ynh_string_random --length=32) + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -46,6 +51,7 @@ ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key #================================================= # STANDARD MODIFICATIONS @@ -73,21 +79,24 @@ db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name -# defines $db_pwd and setting mysqlpwd +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) #================================================= # SPECIFIC SETUP #================================================= -# Init venv +# BUILD VENV #================================================= - -ynh_script_progression --message="Configuring the app's installation..." --weight=6 +ynh_script_progression --message="Building venv..." --weight=6 ynh_app_setting_set --app=$app --key=final_path --value=$final_path __ynh_python_venv_setup --venv_dir="$final_path/venv" --packages "${pip_dependencies[*]}" python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$final_path/venv") +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -98,35 +107,32 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 ynh_add_nginx_config #================================================= -# Setup gunicorn +# ADD A CONFIGURATION #================================================= +ynh_script_progression --message="Adding a configuration file..." -ynh_add_config --template ../conf/gunicorn.conf.py --destination "$final_path/gunicorn.conf.py" -chmod 644 "$final_path/gunicorn.conf.py" +#run source in a 'sub shell' +( + set +o nounset + source "${final_path}/venv/bin/activate" + set -o nounset + python3 ../conf/hash_generator.py $password > ${final_path}/key.txt +) -#================================================= -# Setup ihatemoney -#================================================= +hashed_password=$(cat $final_path/key.txt) +ynh_secure_remove --file="$final_path/key.txt" +ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password + +ynh_add_config --template="../conf/gunicorn.conf.py" --destination="$final_path/gunicorn.conf.py" +chmod 640 "$final_path/gunicorn.conf.py" +chown $app:$app "$final_path/gunicorn.conf.py" -# Secret key for cookies encryption. -secret_key=$(ynh_string_random --length 32) -mails_sender="no-reply@$domain" # Allows to comment some config lines if not using sub path sub_path_only="$(if [[ "$path_url" == "/" ]]; then echo '# ' ; else echo ''; fi)" -ynh_add_config --template ../conf/ihatemoney.cfg --destination "$final_path/ihatemoney.cfg" +ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$final_path/ihatemoney.cfg" chmod 640 "$final_path/ihatemoney.cfg" - - -# FIXME: this should be managed by the core in the future -# Here, as a packager, you may have to tweak the ownerhsip/permissions -# such that the appropriate users (e.g. maybe www-data) can access -# files in some cases. -# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - -# this will be treated as a security issue. -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chown $app:$app "$final_path/ihatemoney.cfg" #================================================= # SETUP SYSTEMD @@ -151,7 +157,7 @@ yunohost service add $app --description="$app daemon for IHateMoney" --log=syste ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Booting worker" --timeout 30 +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening at" # line_match isn't enough because ihatemoney may stop if database upgrades for _ in {1..20}; do diff --git a/scripts/remove b/scripts/remove index 85a39fe..d86d733 100755 --- a/scripts/remove +++ b/scripts/remove @@ -79,7 +79,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing configuration files..." --weight=1 +ynh_script_progression --message="Removing various files..." --weight=1 # Remove the log files ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index d4911c1..e1beb8d 100755 --- a/scripts/restore +++ b/scripts/restore @@ -43,13 +43,6 @@ test ! -d $final_path \ #================================================= # STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -79,6 +72,13 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=4 # Define and install dependencies ynh_install_app_dependencies "${pkg_dependencies[@]}" +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # RESTORE THE MYSQL DATABASE #================================================= @@ -108,7 +108,7 @@ yunohost service add $app --description="$app daemon for IHateMoney" --log=syste #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Booting worker" --timeout 30 +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening at" # line_match isn't enough because ihatemoney may stop if database upgrades for _ in {1..20}; do diff --git a/scripts/upgrade b/scripts/upgrade index f09e760..0c0c71c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_send_readme_to_admin__2 source /usr/share/yunohost/helpers #================================================= @@ -22,6 +23,8 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +secret_key=$(ynh_app_setting_get --app=$app --key=secret_key) +hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password) #================================================= # CHECK VERSION @@ -104,6 +107,29 @@ if [[ "$upgrade_from_opt" == "true" ]]; then ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi +# If secret_key doesn't exist, create it +if [ -z "$secret_key" ]; then + secret_key=$(ynh_string_random --length=32) + ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key +fi + +# If hashed_password doesn't exist, create it +if [ -z "$hashed_password" ] && [ test -f "${final_path}/venv/bin/activate" ]; then + password=$(ynh_string_random --length=16) + #run source in a 'sub shell' + ( + set +o nounset + source "${final_path}/venv/bin/activate" + set -o nounset + python3 ../conf/hash_generator.py $password > ${final_path}/key.txt + ) + + hashed_password=$(cat $final_path/key.txt) + ynh_secure_remove --file="$final_path/key.txt" + ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password + ynh_send_readme_to_admin --app_message="../conf/upgrade.msg" --type="upgrade" +fi + #================================================= # CREATE DEDICATED USER #================================================= @@ -122,17 +148,18 @@ ynh_install_app_dependencies "${pkg_dependencies[@]}" #================================================= # SPECIFIC UPGRADE #================================================= -# Init venv +# BUILD VENV #================================================= -ynh_script_progression --message="Configuring the app's installation..." --weight=6 +ynh_script_progression --message="Building venv..." --weight=6 -ynh_app_setting_set --app=$app --key=final_path --value=$final_path - -# MIGRATION: Upgrade venv -python3 -m venv --upgrade "$final_path/venv" -"$final_path/venv/bin/python3" -m pip install --upgrade pip "${pip_dependencies[@]}" +ynh_secure_remove --file="$final_path/venv" +__ynh_python_venv_setup --venv_dir="$final_path/venv" --packages "${pip_dependencies[*]}" python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$final_path/venv") +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -140,31 +167,23 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated NGINX config ## Needs $python_venv_site_packages -ynh_add_nginx_config "PYTHON_VERSION" +ynh_add_nginx_config #================================================= -# Setup gunicorn +# UPDATE A CONFIG FILE #================================================= +ynh_script_progression --message="Updating a configuration file..." -ynh_add_config --template ../conf/gunicorn.conf.py --destination "$final_path/gunicorn.conf.py" -chmod 600 "$final_path/gunicorn.conf.py" +ynh_add_config --template="../conf/gunicorn.conf.py" --destination="$final_path/gunicorn.conf.py" +chmod 640 "$final_path/gunicorn.conf.py" +chown $app:$app "$final_path/gunicorn.conf.py" -#================================================= -# Setup ihatemoney -#================================================= - -# Secret key for cookies encryption. -secret_key=$(ynh_string_random --length 32) -mails_sender="no-reply@$domain" # Allows to comment some config lines if not using sub path sub_path_only="$(if [[ "$path_url" == "/" ]]; then echo '# ' ; else echo ''; fi)" ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$final_path/ihatemoney.cfg" -chmod 600 "$final_path/ihatemoney.cfg" - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chmod 640 "$final_path/ihatemoney.cfg" +chown $app:$app "$final_path/ihatemoney.cfg" #================================================= # SETUP SYSTEMD @@ -188,11 +207,13 @@ yunohost service add $app --description="$app daemon for IHateMoney" --log=syste #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Booting worker" --timeout 30 +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening at" # line_match isn't enough because ihatemoney may stop if database upgrades -# FIXME: We need to wait for the db to upgrade and gunicorn to restart! -sleep 3 +for _ in {1..20}; do + test -S /tmp/budget.gunicorn_$app.sock && break + sleep 1 +done #================================================= # RELOAD NGINX diff --git a/scripts/ynh_send_readme_to_admin__2 b/scripts/ynh_send_readme_to_admin__2 new file mode 100644 index 0000000..6a0ba70 --- /dev/null +++ b/scripts/ynh_send_readme_to_admin__2 @@ -0,0 +1,128 @@ +#!/bin/bash + +# Send an email to inform the administrator +# +# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] +# | arg: -m --app_message= - The file with the content to send to the administrator. +# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root +# example: "root admin@domain" +# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you +# example: "root admin@domain user1 user2" +# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade' +# +# Requires YunoHost version 4.1.0 or higher. +ynh_send_readme_to_admin() { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= ) + local app_message + local recipients + local type + # Manage arguments with getopts + + ynh_handle_getopts_args "$@" + app_message="${app_message:-}" + recipients="${recipients:-root}" + type="${type:-install}" + + # Get the value of admin_mail_html + admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) + admin_mail_html="${admin_mail_html:-0}" + + # Retrieve the email of users + find_mails () { + local list_mails="$1" + local mail + local recipients=" " + # Read each mail in argument + for mail in $list_mails + do + # Keep root or a real email address as it is + if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" + then + recipients="$recipients $mail" + else + # But replace an user name without a domain after by its email + if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) + then + recipients="$recipients $mail" + fi + fi + done + echo "$recipients" + } + recipients=$(find_mails "$recipients") + + # Subject base + local mail_subject="☁️🆈🅽🅷☁️: \`$app\`" + + # Adapt the subject according to the type of mail required. + if [ "$type" = "backup" ]; then + mail_subject="$mail_subject has just been backup." + elif [ "$type" = "change_url" ]; then + mail_subject="$mail_subject has just been moved to a new URL!" + elif [ "$type" = "remove" ]; then + mail_subject="$mail_subject has just been removed!" + elif [ "$type" = "restore" ]; then + mail_subject="$mail_subject has just been restored!" + elif [ "$type" = "upgrade" ]; then + mail_subject="$mail_subject has just been upgraded!" + else # install + mail_subject="$mail_subject has just been installed!" + fi + + ynh_add_config --template="$app_message" --destination="../conf/msg_to_send" + + ynh_delete_file_checksum --file="../conf/msg_to_send" + local mail_message="This is an automated message from your beloved YunoHost server. + +Specific information for the application $app. + +$(cat "../conf/msg_to_send")" + + # Store the message into a file for further modifications. + echo "$mail_message" > mail_to_send + + # If a html email is required. Apply html tags to the message. + if [ "$admin_mail_html" -eq 1 ] + then + # Insert 'br' tags at each ending of lines. + ynh_replace_string "$" "
" mail_to_send + + # Insert starting HTML tags + sed --in-place '1s@^@\n\n\n\n@' mail_to_send + + # Keep tabulations + ynh_replace_string " " "\ \ " mail_to_send + ynh_replace_string "\t" "\ \ " mail_to_send + + # Insert url links tags + ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send + + # Insert finishing HTML tags + echo -e "\n\n" >> mail_to_send + + # Otherwise, remove tags to keep a plain text. + else + # Remove URL tags + ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send + ynh_replace_string "__URL_TAG2__" ": " mail_to_send + fi + + # Define binary to use for mail command + if [ -e /usr/bin/bsd-mailx ] + then + local mail_bin=/usr/bin/bsd-mailx + else + local mail_bin=/usr/bin/mail.mailutils + fi + + if [ "$admin_mail_html" -eq 1 ] + then + content_type="text/html" + else + content_type="text/plain" + fi + + # Send the email to the recipients + cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients" +}