From 04392c7e40e61630f48149959694e60632a4bf8f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 13 Feb 2022 20:09:37 +0100 Subject: [PATCH 01/10] Apply last example_ynh --- .gitattributes | 17 ---- .github/ISSUE_TEMPLATE.md | 55 +++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 16 ++++ .gitignore | 43 --------- doc/.gitkeep | 0 doc/DESCRIPTION.md | 5 + doc/DISCLAIMER.md | 16 ++++ doc/screenshots/.gitkeep | 0 manifest.json | 156 ++++++++++++++++--------------- 9 files changed, 175 insertions(+), 133 deletions(-) delete mode 100644 .gitattributes create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .gitignore create mode 100644 doc/.gitkeep create mode 100644 doc/DESCRIPTION.md create mode 100644 doc/DISCLAIMER.md create mode 100644 doc/screenshots/.gitkeep diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index bdb0cab..0000000 --- a/.gitattributes +++ /dev/null @@ -1,17 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..2729a6b --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,55 @@ +--- +name: Bug report +about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. + +--- + +**How to post a meaningful bug report** +1. *Read this whole template first.* +2. *Determine if you are on the right place:* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* + - *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.* + - *When in doubt, post here and we will figure it out together.* +3. *Delete the italic comments as you write over them below, and remove this guide.* +--- + +### Describe the bug + +*A clear and concise description of what the bug is.* + +### Context + +- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* +- YunoHost version: x.x.x +- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes* + - If yes, please explain: +- Using, or trying to install package version/branch: +- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* + +### Steps to reproduce + +- *If you performed a command from the CLI, the command itself is enough. For example:* + ```sh + sudo yunohost app install the_app + ``` +- *If you used the webadmin, please perform the equivalent command from the CLI first.* +- *If the error occurs in your browser, explain what you did:* + 1. *Go to '...'* + 2. *Click on '...'* + 3. *Scroll down to '...'* + 4. *See error* + +### Expected behavior + +*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* + +### Logs + +*When an operation fails, YunoHost provides a simple way to share the logs.* +- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.* +- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.* + +*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)* + +*If applicable and useful, add screenshots to help explain your problem.* diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ef70e18 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ +## Problem + +- *Description of why you made this PR* + +## Solution + +- *And how do you fix that problem* + +## PR Status + +- [ ] Code finished and ready to be reviewed/tested +- [ ] The fix/enhancement were manually tested (if applicable) + +## Automatic tests + +Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 96374c4..0000000 --- a/.gitignore +++ /dev/null @@ -1,43 +0,0 @@ -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# ========================= -# Operating System Files -# ========================= - -# OSX -# ========================= - -.DS_Store -.AppleDouble -.LSOverride - -# Thumbnails -._* - -# Files that might appear on external disk -.Spotlight-V100 -.Trashes - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..2444842 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1,5 @@ +LibreERP is a suite of web based open source business apps. LibreERP is a fork of Odoo Community Edition. + +The main LibreERP Apps include an Open Source CRM, Website Builder, eCommerce, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, Purchase Management, ... + +LibreERP Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..07bdb0a --- /dev/null +++ b/doc/DISCLAIMER.md @@ -0,0 +1,16 @@ +**WARNING**: LibreERP is a complex app. **DO NOT USE THIS PACKAGE** to run your business unless you know what you are doing!!! If you don't, you should consider to ask for help from a professionnal! + +**IMPORTANT:** This app MUST be installed on a domain's root! +https://erp.example.com/ will work +https://example.com/erp/ will NOT work + +To connect on your LibreERP +----------- +- Go on https://YOURDOMAIN/web +- Use your master password + +About licences +----------- +LibreERP 8.0 is under AGPL-3.0 +Next version are under LGPL-3.0 +LibreERP is forked from Odoo Community Edition. The name is change due to Odoo trademark policy. diff --git a/doc/screenshots/.gitkeep b/doc/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json index 3f2e54e..8581034 100644 --- a/manifest.json +++ b/manifest.json @@ -1,75 +1,85 @@ { - "name": "LibreERP", - "id": "libreerp", - "packaging_format": 1, - "description": { - "en": "LibreERP is a suite of business apps (ERP: CRM, Accounting, Point of Sale, HR, Purchases...).", - "fr": "LibreERP est une collection d'apps de gestion d'entreprise (ERP : CRM, Comptabilité, Point de Vente, RH, Achats, ...)." - }, - "maintainer": { - "name": "ljf", - "email": "ljf+libreerp_ynh@reflexlibre.net" - }, - "previous_maintainers": { - "name": "scith" - }, - "version": "12.0-6", - "url": "https://github.com/YunoHost-Apps/libreerp_ynh", - "license": "LGPL-3.0,AGPL-3.0", - "requirements": { - "yunohost": ">= 3.4.2.3" - }, - "multi_instance": true, - "services": [ - "nginx" - ], - "arguments": { - "install": [{ - "name": "domain", - "type": "domain", - "ask": { - "en": "Choose a domain for LibreERP (LibreERP will be installed on its root!)", - "fr": "Choisissez un domaine pour LibreERP (LibreERP sera installé dans sa racine !)" - }, - "example": "erp.domain.org" - }, { - "name": "version", - "choices": ["11", "12", "14"], - "default": "14", - "ask": { - "en": "Choose the version you want", - "fr": "Choisissez la version désirée" - } - }, { - "name": "oca", - "type": "boolean", - "default": false, - "ask": { - "en": "Do you want to setup OCA instead of LibreERP ? (not yet implemented)", - "fr": "Désirez vous installer OCA à la place des sources de LibreERP (pas encore implémenté)" - } - }, { - "name": "admin_password", - "type": "password", - "ask": { - "en": "Choose a strong master admin password", - "fr": "Choisissez un mot de passe maître fort pour l'administration" - } - }, { - "name": "lang", - "ask": { - "en": "Choose a language", - "fr": "Choisissez une langue" - }, - "choices": ["sq_AL", "am_ET", "ar_SY", "eu_ES", "bs_BA", "bg_BG", "my_MM", "ca_ES", "zh_CN", "zh_HK", "zh_TW", "hr_HR", "cs_CZ", "da_DK", "nl_BE", "nl_NL", "en_AU", "en_GB", "en_US", "et_EE", "fi_FI", "fr_BE", "fr_CA", "fr_CH", "fr_FR", "gl_ES", "ka_GE", "de_CH", "de_DE", "el_GR", "gu_IN", "he_IL", "hi_IN", "hu_HU", "id_ID", "it_IT", "ja_JP", "kab_DZ", "ko_KP", "ko_KR", "lo_LA", "lv_LV", "lt_LT", "mk_MK", "mn_MN", "nb_NO", "fa_IR", "pl_PL", "pt_BR", "pt_PT", "ro_RO", "ru_RU", "sr_RS", "sr@latin", "sk_SK", "sl_SI", "es_AR", "es_BO", "es_CL", "es_CO", "es_CR", "es_DO", "es_EC", "es_GT", "es_MX", "es_PA", "es_PE", "es_PY", "es_UY", "es_VE", "es_ES", "sv_SE", "te_IN", "th_TH", "tr_TR", "uk_UA", "vi_VN"], - "default": "en_US" - }, { - "name": "tz", - "ask": { - "en": "Choose a timezone", - "fr": "Choisissez un fuseau horaire" - }, - "default": "Etc/UTC" - }] - } + "name": "LibreERP", + "id": "libreerp", + "packaging_format": 1, + "description": { + "en": "LibreERP is a suite of business apps (ERP: CRM, Accounting, Point of Sale, HR, Purchases...).", + "fr": "LibreERP est une collection d'apps de gestion d'entreprise (ERP : CRM, Comptabilité, Point de Vente, RH, Achats, ...)." + }, + "version": "12.0-6", + "url": "https://github.com/YunoHost-Apps/libreerp_ynh", + "upstream": { + "license": "LGPL-3.0-only", + "website": "https://odoo.com", + "demo": "https://www.odoo.com/trial", + "admindoc": "https://www.odoo.com/documentation/15.0/administration.html", + "userdoc": "https://www.odoo.com/documentation/15.0/applications.html", + "code": "https://github.com/odoo/odoo" + }, + "license": "LGPL-3.0,AGPL-3.0", + "maintainer": { + "name": "ljf", + "email": "ljf+libreerp_ynh@reflexlibre.net" + }, + "previous_maintainers": { + "name": "scith" + }, + "requirements": { + "yunohost": ">= 4.3.0" + }, + "multi_instance": true, + "services": [ + "nginx" + ], + "arguments": { + "install": [ + { + "name": "domain", + "type": "domain" + }, + { + "name": "version", + "choices": ["11", "12", "14"], + "default": "14", + "ask": { + "en": "Choose the version you want", + "fr": "Choisissez la version désirée" + } + }, + { + "name": "oca", + "type": "boolean", + "default": false, + "ask": { + "en": "Do you want to setup OCA instead of LibreERP ? (not yet implemented)", + "fr": "Désirez vous installer OCA à la place des sources de LibreERP (pas encore implémenté)" + } + }, + { + "name": "admin_password", + "type": "password", + "ask": { + "en": "Choose a strong master admin password", + "fr": "Choisissez un mot de passe maître fort pour l'administration" + } + }, + { + "name": "lang", + "ask": { + "en": "Choose the application language", + "fr": "Choisissez la langue de l'application" + }, + "choices": ["sq_AL", "am_ET", "ar_SY", "eu_ES", "bs_BA", "bg_BG", "my_MM", "ca_ES", "zh_CN", "zh_HK", "zh_TW", "hr_HR", "cs_CZ", "da_DK", "nl_BE", "nl_NL", "en_AU", "en_GB", "en_US", "et_EE", "fi_FI", "fr_BE", "fr_CA", "fr_CH", "fr_FR", "gl_ES", "ka_GE", "de_CH", "de_DE", "el_GR", "gu_IN", "he_IL", "hi_IN", "hu_HU", "id_ID", "it_IT", "ja_JP", "kab_DZ", "ko_KP", "ko_KR", "lo_LA", "lv_LV", "lt_LT", "mk_MK", "mn_MN", "nb_NO", "fa_IR", "pl_PL", "pt_BR", "pt_PT", "ro_RO", "ru_RU", "sr_RS", "sr@latin", "sk_SK", "sl_SI", "es_AR", "es_BO", "es_CL", "es_CO", "es_CR", "es_DO", "es_EC", "es_GT", "es_MX", "es_PA", "es_PE", "es_PY", "es_UY", "es_VE", "es_ES", "sv_SE", "te_IN", "th_TH", "tr_TR", "uk_UA", "vi_VN"], + "default": "en_US" + }, + { + "name": "tz", + "ask": { + "en": "Choose a timezone", + "fr": "Choisissez un fuseau horaire" + }, + "default": "Etc/UTC" + } + ] + } } From cf06ff63e63196cfdc96ed6a016a23a3633a143b Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sun, 13 Feb 2022 19:09:42 +0000 Subject: [PATCH 02/10] Auto-update README --- README.md | 57 +++++++++++++++++++++++++++++++++++++--------- README_fr.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 README_fr.md diff --git a/README.md b/README.md index 99d944b..11563bf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,19 @@ -LibreERP ----- -[![Integration level](https://dash.yunohost.org/integration/libreerp.svg)](https://dash.yunohost.org/appci/app/libreerp) -[![Install libreerp with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=libreerp) + + +# LibreERP for YunoHost + +[![Integration level](https://dash.yunohost.org/integration/libreerp.svg)](https://dash.yunohost.org/appci/app/libreerp) ![](https://ci-apps.yunohost.org/ci/badges/libreerp.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/libreerp.maintain.svg) +[![Install LibreERP with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=libreerp) + +*[Lire ce readme en français.](./README_fr.md)* + +> *This package allows you to install LibreERP quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* + +## Overview LibreERP is a suite of web based open source business apps. LibreERP is a fork of Odoo Community Edition. @@ -9,8 +21,13 @@ The main LibreERP Apps include an Open Source CRM, Website Builder, eCommerce, P LibreERP Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps. -LibreERP for YunoHost ----------------------------- + +**Shipped version:** 12.0-6 + +**Demo:** https://www.odoo.com/trial + +## Disclaimers / important information + **WARNING**: LibreERP is a complex app. **DO NOT USE THIS PACKAGE** to run your business unless you know what you are doing!!! If you don't, you should consider to ask for help from a professionnal! **IMPORTANT:** This app MUST be installed on a domain's root! @@ -20,14 +37,32 @@ https://example.com/erp/ will NOT work To connect on your LibreERP ----------- - Go on https://YOURDOMAIN/web -- Use your master password OR admin/admin if you use LibreERP 8.0 - -Contribute ------------ -See the project here : https://github.com/YunoHost-Apps/libreerp_ynh/projects/1 +- Use your master password About licences ----------- LibreERP 8.0 is under AGPL-3.0 Next version are under LGPL-3.0 LibreERP is forked from Odoo Community Edition. The name is change due to Odoo trademark policy. + +## Documentation and resources + +* Official app website: https://odoo.com +* Official user documentation: https://www.odoo.com/documentation/15.0/applications.html +* Official admin documentation: https://www.odoo.com/documentation/15.0/administration.html +* Upstream app code repository: https://github.com/odoo/odoo +* YunoHost documentation for this app: https://yunohost.org/app_libreerp +* Report a bug: https://github.com/YunoHost-Apps/libreerp_ynh/issues + +## Developer info + +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/libreerp_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/libreerp_ynh/tree/testing --debug +or +sudo yunohost app upgrade libreerp -u https://github.com/YunoHost-Apps/libreerp_ynh/tree/testing --debug +``` + +**More info regarding app packaging:** https://yunohost.org/packaging_apps \ No newline at end of file diff --git a/README_fr.md b/README_fr.md new file mode 100644 index 0000000..89be0e5 --- /dev/null +++ b/README_fr.md @@ -0,0 +1,64 @@ +# LibreERP pour YunoHost + +[![Niveau d'intégration](https://dash.yunohost.org/integration/libreerp.svg)](https://dash.yunohost.org/appci/app/libreerp) ![](https://ci-apps.yunohost.org/ci/badges/libreerp.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/libreerp.maintain.svg) +[![Installer LibreERP avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=libreerp) + +*[Read this readme in english.](./README.md)* +*[Lire ce readme en français.](./README_fr.md)* + +> *Ce package vous permet d'installer LibreERP 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 + +LibreERP is a suite of web based open source business apps. LibreERP is a fork of Odoo Community Edition. + +The main LibreERP Apps include an Open Source CRM, Website Builder, eCommerce, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, Purchase Management, ... + +LibreERP Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps. + + +**Version incluse :** 12.0-6 + +**Démo :** https://www.odoo.com/trial + +## Avertissements / informations importantes + +**WARNING**: LibreERP is a complex app. **DO NOT USE THIS PACKAGE** to run your business unless you know what you are doing!!! If you don't, you should consider to ask for help from a professionnal! + +**IMPORTANT:** This app MUST be installed on a domain's root! +https://erp.example.com/ will work +https://example.com/erp/ will NOT work + +To connect on your LibreERP +----------- +- Go on https://YOURDOMAIN/web +- Use your master password + +About licences +----------- +LibreERP 8.0 is under AGPL-3.0 +Next version are under LGPL-3.0 +LibreERP is forked from Odoo Community Edition. The name is change due to Odoo trademark policy. + +## Documentations et ressources + +* Site officiel de l'app : https://odoo.com +* Documentation officielle utilisateur : https://www.odoo.com/documentation/15.0/applications.html +* Documentation officielle de l'admin : https://www.odoo.com/documentation/15.0/administration.html +* Dépôt de code officiel de l'app : https://github.com/odoo/odoo +* Documentation YunoHost pour cette app : https://yunohost.org/app_libreerp +* Signaler un bug : https://github.com/YunoHost-Apps/libreerp_ynh/issues + +## Informations pour les développeurs + +Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/libreerp_ynh/tree/testing). + +Pour essayer la branche testing, procédez comme suit. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/libreerp_ynh/tree/testing --debug +ou +sudo yunohost app upgrade libreerp -u https://github.com/YunoHost-Apps/libreerp_ynh/tree/testing --debug +``` + +**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps \ No newline at end of file From 8af8c9e0963596a8e26fe707e0acb338ef7eb7b1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 13 Feb 2022 20:11:00 +0100 Subject: [PATCH 03/10] fix version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 8581034..484d54c 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "LibreERP is a suite of business apps (ERP: CRM, Accounting, Point of Sale, HR, Purchases...).", "fr": "LibreERP est une collection d'apps de gestion d'entreprise (ERP : CRM, Comptabilité, Point de Vente, RH, Achats, ...)." }, - "version": "12.0-6", + "version": "12.0~ynh6", "url": "https://github.com/YunoHost-Apps/libreerp_ynh", "upstream": { "license": "LGPL-3.0-only", From d854c545f7f2ec3c75cd00b5fd8811f390bb7908 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 13 Feb 2022 22:09:18 +0100 Subject: [PATCH 04/10] Apply last example_ynh --- conf/{nginx.conf.j2 => nginx.conf} | 0 conf/{server.conf.j2 => server.conf} | 0 conf/{app.service.j2 => systemd.service} | 0 scripts/_common.sh | 205 +++++++++++++----- scripts/_future.sh | 199 ----------------- scripts/backup | 86 ++++++-- scripts/install | 261 ++++++++++++++++------- scripts/remove | 94 ++++++-- scripts/restore | 188 +++++++++++++--- scripts/upgrade | 140 ++++++++++-- 10 files changed, 764 insertions(+), 409 deletions(-) rename conf/{nginx.conf.j2 => nginx.conf} (100%) rename conf/{server.conf.j2 => server.conf} (100%) rename conf/{app.service.j2 => systemd.service} (100%) delete mode 100644 scripts/_future.sh diff --git a/conf/nginx.conf.j2 b/conf/nginx.conf similarity index 100% rename from conf/nginx.conf.j2 rename to conf/nginx.conf diff --git a/conf/server.conf.j2 b/conf/server.conf similarity index 100% rename from conf/server.conf.j2 rename to conf/server.conf diff --git a/conf/app.service.j2 b/conf/systemd.service similarity index 100% rename from conf/app.service.j2 rename to conf/systemd.service diff --git a/scripts/_common.sh b/scripts/_common.sh index b6b83b4..0aef747 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,10 +1,18 @@ -# -# Common variables -# +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= export appname="libreerp" export FORKNAME="odoo" -DEPENDENCIES="curl postgresql xfonts-75dpi xfonts-base wkhtmltopdf node-less python3-dev gcc libldap2-dev libssl-dev libsasl2-dev python3-pip python3-dev python3-venv python3-wheel libxslt-dev libzip-dev python3-setuptools python-virtualenv python-wheel python-setuptools libjpeg-dev zlib1g-dev virtualenv libfreetype6-dev" + +# dependencies used by the app +pkg_dependencies="curl postgresql xfonts-75dpi xfonts-base wkhtmltopdf node-less python3-dev gcc libldap2-dev libssl-dev libsasl2-dev python3-pip python3-dev python3-venv python3-wheel libxslt-dev libzip-dev python3-setuptools python-virtualenv python-wheel python-setuptools libjpeg-dev zlib1g-dev virtualenv libfreetype6-dev" + +#================================================= +# PERSONAL HELPERS +#================================================= function debranding() { # Remove Odoo references to avoid trademark issue @@ -24,6 +32,7 @@ function debranding() { cp ../conf/favicon.ico $final_path/$appname/addons/web/static/src/img/favicon.ico } + function setup_files() { if [[ $oca -eq 0 ]]; then @@ -43,64 +52,162 @@ function setup_files() { # Autoinstall the LDAP auth module if ls $final_path/$appname/$FORKNAME-bin > /dev/null ; then - ynh_replace_string "^{$" "{'auto_install': True," ${final_path}/$appname/addons/auth_ldap/__manifest__.py + ynh_replace_string "^{$" "{'auto_install': True," $final_path/$appname/addons/auth_ldap/__manifest__.py else - ynh_replace_string "'auto_install': False" "'auto_install': True" ${final_path}/$appname/addons/auth_ldap/__openerp__.py + ynh_replace_string "'auto_install': False" "'auto_install': True" $final_path/$appname/addons/auth_ldap/__openerp__.py fi fi } -# Install dependencies -function install_dependencies() { - ynh_add_swap 1024 - ynh_install_app_dependencies $DEPENDENCIES - if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then - # The debian package has a bug so we deploy a more recent version - if [ -f '../manifest.json' ] ; then - ynh_setup_source /usr/ - else - OLD_YNH_CWD=$YNH_CWD - YNH_CWD=$YNH_CWD/../settings/conf - ynh_setup_source /usr/ - YNH_CWD=$OLD_YNH_CWD - fi +function setup_database() { + export preinstall=1 + ynh_configure server.conf $conf_file + chown $app:$app $conf_file + # Load translation + #param=" --without-demo True --addons-path $final_path/$appname/addons --db_user $app --db_password $db_pass --db_host 127.0.0.1 --db_port 5432 --db-filter '^$app\$' -d $app " + param=" -c $conf_file -d $app " + sudo -u $app $bin_file -c $conf_file --stop-after-init -i base -d $app + sudo -u $app $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $app + sudo -u $app $bin_file -c $conf_file --stop-after-init --load-language $lang -d $app + # Configure language, timezone and ldap + sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ +" +self.env['res.users'].search([['login', '=', 'admin']])[0].write({'password': '$admin_password'}) +self.env.cr.commit() +" + sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ +" +self.write({'tz':'$tz','lang':'$lang'}) +self.env.cr.commit() +" + sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ +" +template=env['res.users'].create({ + 'login':'template', + 'password':'', + 'name':'template', + 'email':'template', + 'sel_groups_9_10':9, + 'tz':'$tz', + 'lang':'$lang' +}) +self.env.cr.commit() +self.company_id.ldaps.create({ + 'ldap_server':'localhost', + 'ldap_server_port':389, + 'ldap_base':'ou=users, dc=yunohost,dc=org', + 'ldap_filter':'uid=%s', + 'user':template.id, + 'company':self.company_id.id +}) +self.env.cr.commit() +" + export preinstall=0 + ynh_configure server.conf $conf_file + chown $app:$app $conf_file +} + +ynh_sso_access () { + ynh_app_setting_set $app unprotected_uris "/" + + if [[ $is_public -eq 0 ]]; then + ynh_app_setting_set $app protected_uris "$1" fi - pushd $final_path - if grep "python3" $final_path/$appname/$FORKNAME-bin ; then - python3 -m venv venv - venv/bin/pip3 install wheel - venv/bin/pip3 install -r $appname/requirements.txt + sudo yunohost app ssowatconf +} + +ynh_configure () { + local TEMPLATE=$1 + local DEST=$2 + content="" + content2="" + content3="" + if [[ $preinstall == '1' ]] + then + content="dbfilter = $db_name" + else + content="db_name = $db_name" + if [[ $app_version > 9 ]] + then + content2="dbfilter = False" + fi + content3="list_db = False" + fi + + mkdir -p "$(dirname $DEST)" + if [ -f '../manifest.json' ] ; then + ynh_add_config "${YNH_CWD}/../conf/$TEMPLATE" "$DEST" else - virtualenv venv - venv/bin/pip install wheel - venv/bin/pip install -r $appname/requirements.txt + ynh_add_config "${YNH_CWD}/../settings/conf/$TEMPLATE" "$DEST" fi - popd } +# Argument $1 is the size of the swap in MiB +ynh_add_swap () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=size= ) + local size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" -# Add services -function add_services() { - if ! grep "^postgresql:$" /etc/yunohost/services.yml; then - yunohost service add postgresql - fi - ynh_configure app.service /etc/systemd/system/$app.service - systemctl daemon-reload + local swap_max_size=$(( $size * 1024 )) - yunohost service add $app --log /var/log/$app.log - yunohost service stop $app - yunohost service start $app - yunohost service enable $app + local free_space=$(df --output=avail / | sed 1d) + # Because we don't want to fill the disk with a swap file, divide by 2 the available space. + local usable_space=$(( $free_space / 2 )) + + # Compare the available space with the size of the swap. + # And set a acceptable size from the request + if [ $usable_space -ge $swap_max_size ] + then + local swap_size=$swap_max_size + elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] + then + local swap_size=$(( $swap_max_size / 2 )) + elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] + then + local swap_size=$(( $swap_max_size / 3 )) + elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] + then + local swap_size=$(( $swap_max_size / 4 )) + else + echo "Not enough space left for a swap file" >&2 + local swap_size=0 + fi + + # If there's enough space for a swap, and no existing swap here + if [ $swap_size -ne 0 ] && [ ! -e /swap ] + then + # Preallocate space for the swap file + fallocate -l ${swap_size}K /swap + chmod 0600 /swap + # Create the swap + mkswap /swap + # And activate it + swapon /swap + # Then add an entry in fstab to load this swap at each boot. + echo -e "/swap swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab + fi } -function ssowat_and_restart() { - # Restart odoo service - service $app restart - - # Configure SSOWat - ynh_sso_access "/web/database/manager" - - # Reload services - service nginx reload +ynh_del_swap () { + # If there a swap at this place + if [ -e /swap ] + then + # Clean the fstab + sed -i "/#Swap added by $app/d" /etc/fstab + # Desactive the swap file + swapoff /swap + # And remove it + rm /swap + fi } + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/_future.sh b/scripts/_future.sh deleted file mode 100644 index 7695cee..0000000 --- a/scripts/_future.sh +++ /dev/null @@ -1,199 +0,0 @@ -ynh_check_var () { - test -n "$1" || ynh_die "$2" -} - -ynh_export () { - local ynh_arg="" - for var in $@; - do - ynh_arg=$(echo $var | awk '{print toupper($0)}') - ynh_arg="YNH_APP_ARG_$ynh_arg" - export $var=${!ynh_arg} - done -} - -# Save listed var in YunoHost app settings -# usage: ynh_save_args VARNAME1 [VARNAME2 [...]] -ynh_save_args () { - for var in $@; - do - ynh_app_setting_set $app $var ${!var} - done -} - -ynh_sso_access () { - ynh_app_setting_set $app unprotected_uris "/" - - if [[ $is_public -eq 0 ]]; then - ynh_app_setting_set $app protected_uris "$1" - fi - sudo yunohost app ssowatconf -} -ynh_configure () { - local TEMPLATE=$1 - local DEST=$2 - content="" - content2="" - content3="" - if [[ $preinstall == '1' ]] - then - content="dbfilter = $db_name" - else - content="db_name = $db_name" - if [[ $app_version > 9 ]] - then - content2="dbfilter = False" - fi - content3="list_db = False" - fi - - mkdir -p "$(dirname $DEST)" - if [ -f '../manifest.json' ] ; then - ynh_add_config "${YNH_CWD}/../conf/$TEMPLATE.j2" "$DEST" - else - ynh_add_config "${YNH_CWD}/../settings/conf/$TEMPLATE.j2" "$DEST" - fi -} - -ynh_configure_nginx () { - ynh_configure nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - sudo service nginx reload -} - -# Upgrade -ynh_read_json () { - python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" -} - -ynh_read_manifest () { - if [ -f '../manifest.json' ] ; then - ynh_read_json '../manifest.json' "$1" - else - ynh_read_json '../settings/manifest.json' "$1" - fi -} - - -is_stretch () { - if [ "$(ynh_get_debian_release)" == "stretch" ] - then - return 0 - else - return 1 - fi -} - -is_jessie () { - if [ "$(ynh_get_debian_release)" == "jessie" ] - then - return 0 - else - return 1 - fi -} - -# Argument $1 is the size of the swap in MiB -ynh_add_swap () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [s]=size= ) - local size - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - local swap_max_size=$(( $size * 1024 )) - - local free_space=$(df --output=avail / | sed 1d) - # Because we don't want to fill the disk with a swap file, divide by 2 the available space. - local usable_space=$(( $free_space / 2 )) - - # Compare the available space with the size of the swap. - # And set a acceptable size from the request - if [ $usable_space -ge $swap_max_size ] - then - local swap_size=$swap_max_size - elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] - then - local swap_size=$(( $swap_max_size / 2 )) - elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] - then - local swap_size=$(( $swap_max_size / 3 )) - elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] - then - local swap_size=$(( $swap_max_size / 4 )) - else - echo "Not enough space left for a swap file" >&2 - local swap_size=0 - fi - - # If there's enough space for a swap, and no existing swap here - if [ $swap_size -ne 0 ] && [ ! -e /swap ] - then - # Preallocate space for the swap file - fallocate -l ${swap_size}K /swap - chmod 0600 /swap - # Create the swap - mkswap /swap - # And activate it - swapon /swap - # Then add an entry in fstab to load this swap at each boot. - echo -e "/swap swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab - fi -} - -ynh_del_swap () { - # If there a swap at this place - if [ -e /swap ] - then - # Clean the fstab - sed -i "/#Swap added by $app/d" /etc/fstab - # Desactive the swap file - swapoff /swap - # And remove it - rm /swap - fi -} - -# Checks the app version to upgrade with the existing app version and returns: -# - UPGRADE_APP if the upstream app version has changed -# - UPGRADE_PACKAGE if only the YunoHost package has changed -# -## It stops the current script without error if the package is up-to-date -# -# This helper should be used to avoid an upgrade of an app, or the upstream part -# of it, when it's not needed -# -# To force an upgrade, even if the package is up to date, -# you have to set the variable YNH_FORCE_UPGRADE before. -# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp - -# usage: ynh_check_app_version_changed -ynh_check_app_version_changed () { - local force_upgrade=${YNH_FORCE_UPGRADE:-0} - local package_check=${PACKAGE_CHECK_EXEC:-0} - - # By default, upstream app version has changed - local return_value="UPGRADE_APP" - - local current_version=$(ynh_read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) - local current_upstream_version="${current_version/~ynh*/}" - local update_version=$(ynh_read_manifest "version" || echo 1.0) - local update_upstream_version="${update_version/~ynh*/}" - - if [ "$current_version" == "$update_version" ] ; then - # Complete versions are the same - if [ "$force_upgrade" != "0" ] - then - echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 - unset YNH_FORCE_UPGRADE - elif [ "$package_check" != "0" ] - then - echo "Upgrade forced for package check." >&2 - else - ynh_die "Up-to-date, nothing to do" 0 - fi - elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then - # Upstream versions are the same, only YunoHost package versions differ - return_value="UPGRADE_PACKAGE" - fi - echo $return_value -} diff --git a/scripts/backup b/scripts/backup index 6ddf741..142e0d0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,31 +1,79 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -source /usr/share/yunohost/helpers -#source _future.sh +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_clean_setup () { + true +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# LOAD SETTINGS +#================================================= +ynh_print_info --message="Loading installation settings..." + app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get "$app" domain) -final_path=$(ynh_app_setting_get "$app" final_path) -conf_file=$(ynh_app_setting_get "$app" conf_file) -# Backup sources & data -ynh_backup "${final_path}/$appname" -ynh_backup "${final_path}/custom-addons" -ynh_backup "${final_path}/.local" +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +conf_file=$(ynh_app_setting_get --app=$app --key=conf_file) -# Backup configuration -ynh_backup "$conf_file" +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." -# Copy NGINX configuration -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= -# Backup services -ynh_backup "/etc/systemd/system/${app}.service" +ynh_backup --src_path="$final_path/$appname" +ynh_backup --src_path="$final_path/custom-addons" +ynh_backup --src_path="$final_path/.local" -# Copy database -sudo su -c "pg_dump $app" postgres > ./dump.sql +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" + +#================================================= +# BACKUP VARIOUS FILES +#================================================= + +ynh_backup --src_path="$conf_file" + +#================================================= +# BACKUP THE POSTGRESQL DATABASE +#================================================= +ynh_print_info --message="Backing up the PostgreSQL database..." + +ynh_psql_dump_db --database="$db_name" > db.sql + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index eb13e98..ef6a4f1 100644 --- a/scripts/install +++ b/scripts/install @@ -1,20 +1,41 @@ #!/bin/bash -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -source /usr/share/yunohost/helpers -source _future.sh source _common.sh +source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_clean_setup () { + true +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Arguments from manifest -export app=$YNH_APP_INSTANCE_NAME -ynh_export domain oca admin_password lang tz -export app_version=$YNH_APP_ARG_VERSION +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +domain=$YNH_APP_ARG_DOMAIN +path_url="/" export is_public=0 -export final_path="/var/www/$app" +export app_version=$YNH_APP_ARG_VERSION +oca=$YNH_APP_ARG_OCA +admin_password=$YNH_APP_ARG_ADMIN_PASSWORD +lang=$YNH_APP_ARG_LANG +tz=$YNH_APP_ARG_TZ + +export app=$YNH_APP_INSTANCE_NAME + export conf_file=/etc/$app/main.conf +export final_path=/var/www/$app export bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME-bin" if [ "$app_version" = "9" ]; then bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py" @@ -22,79 +43,173 @@ fi if [ "$app_version" = "8" ]; then bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py" fi -export db_name=$(ynh_sanitize_dbid $app) -export port=$(ynh_find_port 8069) -export port_chat=$(ynh_find_port 8072) export preinstall=0 #================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -test ! -e "$final_path" || ynh_die "This path already contains a folder" -ynh_webpath_register $app $domain "/" +ynh_script_progression --message="Validating installation parameters..." +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" + +# Register (book) web path +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= -# SETUP THE APP BY MODIFYING THE SYSTEM +# STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." -function setup_database() { - export preinstall=1 - ynh_configure server.conf $conf_file - chown $app:$app $conf_file - # Load translation - #param=" --without-demo True --addons-path $final_path/$appname/addons --db_user $app --db_password $db_pass --db_host 127.0.0.1 --db_port 5432 --db-filter '^$app\$' -d $app " - param=" -c $conf_file -d $app " - sudo -u $app $bin_file -c $conf_file --stop-after-init -i base -d $app - sudo -u $app $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $app - sudo -u $app $bin_file -c $conf_file --stop-after-init --load-language $lang -d $app - # Configure language, timezone and ldap - sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ -" -self.env['res.users'].search([['login', '=', 'admin']])[0].write({'password': '$admin_password'}) -self.env.cr.commit() -" - sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ -" -self.write({'tz':'$tz','lang':'$lang'}) -self.env.cr.commit() -" - sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ -" -template=env['res.users'].create({ - 'login':'template', - 'password':'', - 'name':'template', - 'email':'template', - 'sel_groups_9_10':9, - 'tz':'$tz', - 'lang':'$lang' -}) -self.env.cr.commit() -self.company_id.ldaps.create({ - 'ldap_server':'localhost', - 'ldap_server_port':389, - 'ldap_base':'ou=users, dc=yunohost,dc=org', - 'ldap_filter':'uid=%s', - 'user':template.id, - 'company':self.company_id.id -}) -self.env.cr.commit() -" - export preinstall=0 - ynh_configure server.conf $conf_file - chown $app:$app $conf_file -} -ynh_save_args domain app_version oca lang tz final_path conf_file db_name port port_chat -ynh_system_user_create -u $app -h $final_path +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=app_version --value=$app_version +ynh_app_setting_set --app=$app --key=oca --value=$oca +ynh_app_setting_set --app=$app --key=lang --value=$lang +ynh_app_setting_set --app=$app --key=tz --value=$tz +ynh_app_setting_set --app=$app --key=conf_file --value=$conf_file + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# FIND AND OPEN A PORT +#================================================= +ynh_script_progression --message="Finding an available port..." + +# Find an available port +port=$(ynh_find_port --port=8069) +ynh_app_setting_set --app=$app --key=port --value=$port + +# Find an available port +port_chat=$(ynh_find_port --port=8072) +ynh_app_setting_set --app=$app --key=port_chat --value=$port_chat + +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." + +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + +#================================================= +# CREATE A POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Creating a PostgreSQL database..." + +export db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name export db_pass=$(ynh_string_random) -setup_files -install_dependencies -ynh_psql_test_if_first_run -ynh_psql_setup_db $db_name $db_name $db_pass -export db_pass=$(ynh_app_setting_get $app psqlpwd) -ynh_configure_nginx -add_services -setup_database -ssowat_and_restart +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +# Make sure that postgresql is installed and running +ynh_psql_test_if_first_run + +# Create the database +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pass +export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd) + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Setting up source files..." + +ynh_app_setting_set --app=$app --key=final_path --value=$final_path +# Download, check integrity, uncompress and patch the source from app.src +setup_files + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring NGINX web server..." + +# Create a dedicated NGINX config +ynh_add_nginx_config + +#================================================= +# SPECIFIC SETUP +#================================================= +# BUILD APP +#================================================= +ynh_script_progression --message="Building $app..." + +ynh_add_swap 1024 +if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then + # The debian package has a bug so we deploy a more recent version + if [ -f '../manifest.json' ] ; then + ynh_setup_source /usr/ + else + OLD_YNH_CWD=$YNH_CWD + YNH_CWD=$YNH_CWD/../settings/conf + ynh_setup_source /usr/ + YNH_CWD=$OLD_YNH_CWD + fi +fi +pushd $final_path + if grep "python3" $final_path/$appname/$FORKNAME-bin ; then + python3 -m venv venv + venv/bin/pip3 install wheel + venv/bin/pip3 install -r $appname/requirements.txt + else + virtualenv venv + venv/bin/pip install wheel + venv/bin/pip install -r $appname/requirements.txt + fi +popd + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# SETUP DATABASE +#================================================= +ynh_script_progression --message="Setuping the database..." + +setup_database + +#================================================= +# GENERIC FINALIZATION +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --log="/var/log/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log" + +#================================================= +# SETUP SSOWAT +#================================================= +ynh_script_progression --message="Configuring permissions..." + +ynh_sso_access "/web/database/manager" + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 92462ab..c3c7a44 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,29 +1,95 @@ #!/bin/bash -set -u -source /usr/share/yunohost/helpers -source _future.sh +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +conf_file=$(ynh_app_setting_get --app=$app --key=conf_file) -# Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) -final_path=$(ynh_app_setting_get "$app" final_path) -conf_file=$(ynh_app_setting_get "$app" conf_file) +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE SERVICE INTEGRATION IN YUNOHOST +#================================================= -yunohost service stop $app -yunohost service remove $app -ynh_psql_remove_db $app $app +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null +then + ynh_script_progression --message="Removing $app service integration..." + yunohost service remove $app +fi -ynh_secure_remove "$final_path" -ynh_secure_remove "$conf_file" +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Removing the MySQL database..." -ynh_remove_app_dependencies +# Remove a database if it exists, along with the associated user +ynh_psql_remove_db --db_user=$db_user --db_name=$db_name -ynh_system_user_delete $app +#================================================= +# REMOVE APP MAIN DIR +#================================================= +ynh_script_progression --message="Removing app main directory..." +# Remove the app directory securely +ynh_secure_remove --file="$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Removing NGINX web server configuration..." + +# Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_script_progression --message="Removing dependencies..." + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." + +ynh_secure_remove --file="$conf_file" + ynh_del_swap + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= +ynh_script_progression --message="Removing the dedicated system user..." + +# Delete a system user +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 5c9eaa1..c280184 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,23 +1,43 @@ #!/bin/bash -set -eu -# Import helpers -source /usr/share/yunohost/helpers -source ../settings/scripts/_future.sh +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_clean_setup () { + true +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." + export app=$YNH_APP_INSTANCE_NAME -export domain=$(ynh_app_setting_get $app domain) -export app_version=$(ynh_app_setting_get $app app_version) -export oca=$(ynh_app_setting_get $app oca) -export port=$(ynh_app_setting_get $app port) -export port_chat=$(ynh_app_setting_get $app port_chat) -export db_name=$(ynh_app_setting_get $app db_name) -export db_pass=$(ynh_app_setting_get $app psqlpwd) -export final_path=$(ynh_app_setting_get $app final_path) -export conf_file=$(ynh_app_setting_get $app conf_file) + +export domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +export app_version=$(ynh_app_setting_get --app=$app --key=app_version) +export oca=$(ynh_app_setting_get --app=$app --key=oca) +export port=$(ynh_app_setting_get --app=$app --key=port) +export port_chat=$(ynh_app_setting_get --app=$app --key=port_chat) +export db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd) +export final_path=$(ynh_app_setting_get --app=$app --key=final_path) +export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file) export is_public=0 export bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME-bin" if [ "$app_version" = "9" ]; then @@ -30,33 +50,133 @@ fi #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_webpath_available "$domain" "/" +ynh_script_progression --message="Validating restoration parameters..." + +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= -# RESTORE THE APP BY MODIFYING THE SYSTEM +# STANDARD RESTORATION STEPS #================================================= -# Restore files -function restore_files () { - ynh_restore - chown -R $app:$app $final_path - chown $app:$app $conf_file - touch /var/log/$app.log - chown $app:$app /var/log/$app.log -} +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." -# Restore database -function restore_database () { - su -c "psql $app" postgres < ./dump.sql -} +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_system_user_create $app $final_path -restore_files -install_dependencies +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring the app main directory..." + +ynh_restore_file --origin_path="$final_path/$appname" +ynh_restore_file --origin_path="$final_path/custom-addons" +ynh_restore_file --origin_path="$final_path/.local" + +chown -R $app:$app "$final_path" + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling dependencies..." + +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# BUILD APP +#================================================= +ynh_script_progression --message="Building $app..." + +ynh_add_swap 1024 +if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then + # The debian package has a bug so we deploy a more recent version + if [ -f '../manifest.json' ] ; then + ynh_setup_source /usr/ + else + OLD_YNH_CWD=$YNH_CWD + YNH_CWD=$YNH_CWD/../settings/conf + ynh_setup_source /usr/ + YNH_CWD=$OLD_YNH_CWD + fi +fi +pushd $final_path + if grep "python3" $final_path/$appname/$FORKNAME-bin ; then + python3 -m venv venv + venv/bin/pip3 install wheel + venv/bin/pip3 install -r $appname/requirements.txt + else + virtualenv venv + venv/bin/pip install wheel + venv/bin/pip install -r $appname/requirements.txt + fi +popd + +#================================================= +# RESTORE THE POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the PostgreSQL database..." + +# Make sure that postgresql is installed and running ynh_psql_test_if_first_run -ynh_psql_setup_db $db_name $db_name $db_pass -add_services -restore_database -ssowat_and_restart +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pass +ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +#================================================= +# RESTORE VARIOUS FILES +#================================================= +ynh_script_progression --message="Restoring various files..." +ynh_restore_file --origin_path="$conf_file" +chown $app:$app $conf_file + +touch /var/log/$app.log +chown $app:$app /var/log/$app.log + +#================================================= +# RESTORE SYSTEMD +#================================================= +ynh_script_progression --message="Restoring the systemd configuration..." + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service --quiet + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --log="/var/log/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index f6bc1d5..0be75b9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,58 +1,156 @@ #!/bin/bash #================================================= -# GENERIC STARTING +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= -# Source YunoHost helpers -source /usr/share/yunohost/helpers -source _future.sh source _common.sh +source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." -# Retrieve arguments export app=$YNH_APP_INSTANCE_NAME -export domain=$(ynh_app_setting_get "$app" domain) -export app_version=$(ynh_app_setting_get "$app" app_version) -export oca=$(ynh_app_setting_get "$app" oca) -export port=$(ynh_app_setting_get $app port) -export port_chat=$(ynh_app_setting_get $app port_chat) + +export domain=$(ynh_app_setting_get --app=$app --key=domain) +export app_version=$(ynh_app_setting_get --app=$app --key=app_version) +export oca=$(ynh_app_setting_get --app=$app --key=oca) +export port=$(ynh_app_setting_get --app=$app --key=port) +export port_chat=$(ynh_app_setting_get --app=$app --key=port_chat) export is_public=0 -export final_path=$(ynh_app_setting_get $app final_path) -export conf_file=$(ynh_app_setting_get $app conf_file) +export final_path=$(ynh_app_setting_get --app=$app --key=final_path) +export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file) export preinstall=0 #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." -ynh_check_app_version_changed +upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# STANDARD UPGRADE STEPS #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app.log" #================================================= -# STEP Migrations +# ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_system_user_create $app -setup_files -install_dependencies -service $app restart +ynh_script_progression --message="Ensuring downward compatibility..." + +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all + + ynh_app_setting_delete --app=$app --key=is_public +fi + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." + + # Download, check integrity, uncompress and patch the source from app.src + setup_files +fi + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." + +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# BUILD APP +#================================================= +ynh_script_progression --message="Building $app..." + +ynh_add_swap 1024 +if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then + # The debian package has a bug so we deploy a more recent version + if [ -f '../manifest.json' ] ; then + ynh_setup_source /usr/ + else + OLD_YNH_CWD=$YNH_CWD + YNH_CWD=$YNH_CWD/../settings/conf + ynh_setup_source /usr/ + YNH_CWD=$OLD_YNH_CWD + fi +fi +pushd $final_path + if grep "python3" $final_path/$appname/$FORKNAME-bin ; then + python3 -m venv venv + venv/bin/pip3 install wheel + venv/bin/pip3 install -r $appname/requirements.txt + else + virtualenv venv + venv/bin/pip install wheel + venv/bin/pip install -r $appname/requirements.txt + fi +popd + +#================================================= +# GENERIC FINALIZATION +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --log="/var/log/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log" + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" From d612dcd88c9d079da5c01791c8d91f05a713001b Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sun, 13 Feb 2022 21:09:25 +0000 Subject: [PATCH 05/10] Auto-update README --- README.md | 2 +- README_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 11563bf..4c3e9fb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The main LibreERP Apps include an Open Source CRM, Website Builder, eCommerce, P LibreERP Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps. -**Shipped version:** 12.0-6 +**Shipped version:** 12.0~ynh6 **Demo:** https://www.odoo.com/trial diff --git a/README_fr.md b/README_fr.md index 89be0e5..d10ec20 100644 --- a/README_fr.md +++ b/README_fr.md @@ -18,7 +18,7 @@ The main LibreERP Apps include an Open Source CRM, Website Builder, eCommerce, P LibreERP Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps. -**Version incluse :** 12.0-6 +**Version incluse :** 12.0~ynh6 **Démo :** https://www.odoo.com/trial From 8ab34039ee95be5b38e51a76d16ae4e3cfcc5553 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 16 Feb 2022 20:12:36 +0100 Subject: [PATCH 06/10] Fix manifest --- manifest.json | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/manifest.json b/manifest.json index 484d54c..52c2559 100644 --- a/manifest.json +++ b/manifest.json @@ -3,11 +3,11 @@ "id": "libreerp", "packaging_format": 1, "description": { - "en": "LibreERP is a suite of business apps (ERP: CRM, Accounting, Point of Sale, HR, Purchases...).", - "fr": "LibreERP est une collection d'apps de gestion d'entreprise (ERP : CRM, Comptabilité, Point de Vente, RH, Achats, ...)." + "en": "Suite of business apps (ERP: CRM, Accounting, Point of Sale, HR, Purchases...).", + "fr": "Une collection d'apps de gestion d'entreprise (ERP : CRM, Comptabilité, Point de Vente, RH, Achats, ...)." }, "version": "12.0~ynh6", - "url": "https://github.com/YunoHost-Apps/libreerp_ynh", + "url": "https://odoo.com", "upstream": { "license": "LGPL-3.0-only", "website": "https://odoo.com", @@ -39,12 +39,13 @@ }, { "name": "version", - "choices": ["11", "12", "14"], - "default": "14", + "type": "string", "ask": { "en": "Choose the version you want", "fr": "Choisissez la version désirée" - } + }, + "choices": ["11", "12", "14"], + "default": "14" }, { "name": "oca", @@ -65,6 +66,7 @@ }, { "name": "lang", + "type": "string", "ask": { "en": "Choose the application language", "fr": "Choisissez la langue de l'application" @@ -74,6 +76,7 @@ }, { "name": "tz", + "type": "string", "ask": { "en": "Choose a timezone", "fr": "Choisissez un fuseau horaire" From 76a2219caff17060e6d6fc81cb61aae09d1488bf Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 16 Feb 2022 20:14:34 +0100 Subject: [PATCH 07/10] Fix sudo --- scripts/_common.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index ae54329..b49e33a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -67,21 +67,21 @@ function setup_database() { # Load translation #param=" --without-demo True --addons-path $final_path/$appname/addons --db_user $app --db_password $db_pass --db_host 127.0.0.1 --db_port 5432 --db-filter '^$app\$' -d $app " param=" -c $conf_file -d $app " - sudo -u $app $bin_file -c $conf_file --stop-after-init -i base -d $app - sudo -u $app $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $app - sudo -u $app $bin_file -c $conf_file --stop-after-init --load-language $lang -d $app + ynh_exec_as $app $bin_file -c $conf_file --stop-after-init -i base -d $app + ynh_exec_as $app $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $app + ynh_exec_as $app $bin_file -c $conf_file --stop-after-init --load-language $lang -d $app # Configure language, timezone and ldap - sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ + ynh_exec_as $app $bin_file shell -c $conf_file -d $app <<< \ " self.env['res.users'].search([['login', '=', 'admin']])[0].write({'password': '$admin_password'}) self.env.cr.commit() " - sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ + ynh_exec_as $app $bin_file shell -c $conf_file -d $app <<< \ " self.write({'tz':'$tz','lang':'$lang'}) self.env.cr.commit() " - sudo -u $app $bin_file shell -c $conf_file -d $app <<< \ + ynh_exec_as $app $bin_file shell -c $conf_file -d $app <<< \ " template=env['res.users'].create({ 'login':'template', From d242b3f7b2b2aea70365a2cb29c45bfb5a7cfc77 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 16 Feb 2022 20:17:10 +0100 Subject: [PATCH 08/10] Fix Is_public --- scripts/_common.sh | 9 --------- scripts/install | 7 ++++++- scripts/restore | 1 - scripts/upgrade | 1 - 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index b49e33a..907f4dc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -108,15 +108,6 @@ self.env.cr.commit() chown $app:$app $conf_file } -ynh_sso_access () { - ynh_app_setting_set $app unprotected_uris "/" - - if [[ $is_public -eq 0 ]]; then - ynh_app_setting_set $app protected_uris "$1" - fi - sudo yunohost app ssowatconf -} - ynh_configure () { local TEMPLATE=$1 local DEST=$2 diff --git a/scripts/install b/scripts/install index ef6a4f1..c4da338 100644 --- a/scripts/install +++ b/scripts/install @@ -199,7 +199,12 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap #================================================= ynh_script_progression --message="Configuring permissions..." -ynh_sso_access "/web/database/manager" +ynh_app_setting_set $app unprotected_uris "/" + +if [[ $is_public -eq 0 ]]; then + ynh_app_setting_set $app protected_uris "/web/database/manager" +fi +sudo yunohost app ssowatconf #================================================= # RELOAD NGINX diff --git a/scripts/restore b/scripts/restore index 0e179cf..0c38b08 100644 --- a/scripts/restore +++ b/scripts/restore @@ -38,7 +38,6 @@ db_user=$db_name export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd) export final_path=$(ynh_app_setting_get --app=$app --key=final_path) export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file) -export is_public=0 export bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME-bin" if [ "$app_version" = "9" ]; then bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME.py" diff --git a/scripts/upgrade b/scripts/upgrade index 0be75b9..ddd78f4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,7 +21,6 @@ export app_version=$(ynh_app_setting_get --app=$app --key=app_version) export oca=$(ynh_app_setting_get --app=$app --key=oca) export port=$(ynh_app_setting_get --app=$app --key=port) export port_chat=$(ynh_app_setting_get --app=$app --key=port_chat) -export is_public=0 export final_path=$(ynh_app_setting_get --app=$app --key=final_path) export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file) export preinstall=0 From 7c870560ac536c4033c4bbd678b488d6c63ba82e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 17 Feb 2022 01:23:35 +0100 Subject: [PATCH 09/10] Several fixes --- conf/server.conf | 2 +- manifest.json | 4 ++ scripts/_common.sh | 164 +++++++++++++++++++++++++++------------------ scripts/install | 47 +++++++------ scripts/remove | 23 ++++++- scripts/restore | 27 ++++++-- scripts/upgrade | 16 ++++- 7 files changed, 187 insertions(+), 96 deletions(-) diff --git a/conf/server.conf b/conf/server.conf index 4947406..29e201e 100644 --- a/conf/server.conf +++ b/conf/server.conf @@ -5,7 +5,7 @@ admin_passwd = __ADMIN_PASSWORD__ db_host = localhost db_port = 5432 db_user = __DB_NAME__ -db_password = __DB_PASS__ +db_password = __DB_PWD__ __CONTENT__ __CONTENT2__ __CONTENT3__ diff --git a/manifest.json b/manifest.json index 52c2559..38d53c0 100644 --- a/manifest.json +++ b/manifest.json @@ -37,6 +37,10 @@ "name": "domain", "type": "domain" }, + { + "name": "admin", + "type": "user" + }, { "name": "version", "type": "string", diff --git a/scripts/_common.sh b/scripts/_common.sh index 907f4dc..3497fe9 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,8 @@ export appname="libreerp" export FORKNAME="odoo" +swap_needed=1024 + # dependencies used by the app pkg_dependencies="curl postgresql xfonts-75dpi xfonts-base wkhtmltopdf node-less python3-dev gcc libldap2-dev libssl-dev libsasl2-dev python3-pip python3-dev python3-venv python3-wheel libxslt-dev libzip-dev python3-setuptools libjpeg-dev zlib1g-dev libfreetype6-dev libffi-dev libpq-dev" @@ -42,13 +44,16 @@ function setup_files() { fi debranding mkdir -p $final_path/custom-addons - chown -R $app:$app $final_path + chmod 750 "$final_path" + chmod -R o-rwx "$final_path" + chown -R $app:$app "$final_path" touch /var/log/$app.log chown $app:$app /var/log/$app.log if [ ! -f $conf_file ]; then ynh_configure server.conf $conf_file - chown $app:$app $conf_file + chmod 400 "$conf_file" + chown $app:$app "$conf_file" # Autoinstall the LDAP auth module if ls $final_path/$appname/$FORKNAME-bin > /dev/null ; then @@ -65,7 +70,7 @@ function setup_database() { ynh_configure server.conf $conf_file chown $app:$app $conf_file # Load translation - #param=" --without-demo True --addons-path $final_path/$appname/addons --db_user $app --db_password $db_pass --db_host 127.0.0.1 --db_port 5432 --db-filter '^$app\$' -d $app " + #param=" --without-demo True --addons-path $final_path/$appname/addons --db_user $app --db_password $db_pwd --db_host 127.0.0.1 --db_port 5432 --db-filter '^$app\$' -d $app " param=" -c $conf_file -d $app " ynh_exec_as $app $bin_file -c $conf_file --stop-after-init -i base -d $app ynh_exec_as $app $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $app @@ -134,71 +139,102 @@ ynh_configure () { fi } -# Argument $1 is the size of the swap in MiB -ynh_add_swap () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [s]=size= ) - local size - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - local swap_max_size=$(( $size * 1024 )) - - local free_space=$(df --output=avail / | sed 1d) - # Because we don't want to fill the disk with a swap file, divide by 2 the available space. - local usable_space=$(( $free_space / 2 )) - - # Compare the available space with the size of the swap. - # And set a acceptable size from the request - if [ $usable_space -ge $swap_max_size ] - then - local swap_size=$swap_max_size - elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] - then - local swap_size=$(( $swap_max_size / 2 )) - elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] - then - local swap_size=$(( $swap_max_size / 3 )) - elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] - then - local swap_size=$(( $swap_max_size / 4 )) - else - echo "Not enough space left for a swap file" >&2 - local swap_size=0 - fi - - # If there's enough space for a swap, and no existing swap here - if [ $swap_size -ne 0 ] && [ ! -e /swap ] - then - # Preallocate space for the swap file - fallocate -l ${swap_size}K /swap - chmod 0600 /swap - # Create the swap - mkswap /swap - # And activate it - swapon /swap - # Then add an entry in fstab to load this swap at each boot. - echo -e "/swap swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab - fi -} - -ynh_del_swap () { - # If there a swap at this place - if [ -e /swap ] - then - # Clean the fstab - sed -i "/#Swap added by $app/d" /etc/fstab - # Desactive the swap file - swapoff /swap - # And remove it - rm /swap - fi -} - #================================================= # EXPERIMENTAL HELPERS #================================================= +# Add swap +# +# usage: ynh_add_swap --size=SWAP in Mb +# | arg: -s, --size= - Amount of SWAP to add in Mb. +ynh_add_swap () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=size= ) + local size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local swap_max_size=$(( $size * 1024 )) + + local free_space=$(df --output=avail / | sed 1d) + # Because we don't want to fill the disk with a swap file, divide by 2 the available space. + local usable_space=$(( $free_space / 2 )) + + SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} + + # Swap on SD card only if it's is specified + if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] + then + ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" + return + fi + + # Compare the available space with the size of the swap. + # And set a acceptable size from the request + if [ $usable_space -ge $swap_max_size ] + then + local swap_size=$swap_max_size + elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] + then + local swap_size=$(( $swap_max_size / 2 )) + elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] + then + local swap_size=$(( $swap_max_size / 3 )) + elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] + then + local swap_size=$(( $swap_max_size / 4 )) + else + echo "Not enough space left for a swap file" >&2 + local swap_size=0 + fi + + # If there's enough space for a swap, and no existing swap here + if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] + then + # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case + if ! fallocate -l ${swap_size}K /swap_$app + then + dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} + fi + chmod 0600 /swap_$app + # Create the swap + mkswap /swap_$app + # And activate it + swapon /swap_$app + # Then add an entry in fstab to load this swap at each boot. + echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab + fi +} + +ynh_del_swap () { + # If there a swap at this place + if [ -e /swap_$app ] + then + # Clean the fstab + sed -i "/#Swap added by $app/d" /etc/fstab + # Desactive the swap file + swapoff /swap_$app + # And remove it + rm /swap_$app + fi +} + +# Check if the device of the main mountpoint "/" is an SD card +# +# [internal] +# +# return 0 if it's an SD card, else 1 +ynh_is_main_device_a_sd_card () { + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] + then + return 0 + else + return 1 + fi +} + #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index c4da338..5ea13b3 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -25,7 +25,7 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" -export is_public=0 +admin=$YNH_APP_ARG_ADMIN export app_version=$YNH_APP_ARG_VERSION oca=$YNH_APP_ARG_OCA admin_password=$YNH_APP_ARG_ADMIN_PASSWORD @@ -35,14 +35,6 @@ tz=$YNH_APP_ARG_TZ export app=$YNH_APP_INSTANCE_NAME export conf_file=/etc/$app/main.conf -export final_path=/var/www/$app -export bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME-bin" -if [ "$app_version" = "9" ]; then - bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py" -fi -if [ "$app_version" = "8" ]; then - bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py" -fi export preinstall=0 #================================================= @@ -50,8 +42,17 @@ export preinstall=0 #================================================= ynh_script_progression --message="Validating installation parameters..." +export final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" +export bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME-bin" +if [ "$app_version" = "9" ]; then + bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py" +fi +if [ "$app_version" = "8" ]; then + bin_file="$final_path/venv/bin/python3 $final_path/$appname/$FORKNAME.py" +fi + # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -87,7 +88,7 @@ ynh_app_setting_set --app=$app --key=port_chat --value=$port_chat #================================================= ynh_script_progression --message="Installing dependencies..." -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER @@ -104,15 +105,17 @@ ynh_script_progression --message="Creating a PostgreSQL database..." export db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name -export db_pass=$(ynh_string_random) ynh_app_setting_set --app=$app --key=db_name --value=$db_name # Make sure that postgresql is installed and running ynh_psql_test_if_first_run # Create the database -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pass -export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd) +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name +export db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) + +# Make sure that its encoding is UTF-8 +ynh_psql_execute_as_root --sql="update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name'" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -133,12 +136,18 @@ ynh_add_nginx_config #================================================= # SPECIFIC SETUP +#================================================= +# ADD SWAP +#================================================= +ynh_script_progression --message="Adding swap..." + +ynh_add_swap --size=$swap_needed + #================================================= # BUILD APP #================================================= ynh_script_progression --message="Building $app..." -ynh_add_swap 1024 if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then # The debian package has a bug so we deploy a more recent version if [ -f '../manifest.json' ] ; then @@ -199,12 +208,10 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap #================================================= ynh_script_progression --message="Configuring permissions..." -ynh_app_setting_set $app unprotected_uris "/" +ynh_permission_update --permission="main" --add="visitors" -if [[ $is_public -eq 0 ]]; then - ynh_app_setting_set $app protected_uris "/web/database/manager" -fi -sudo yunohost app ssowatconf +# Only the admin can access the admin panel of the app (if the app has an admin panel) +ynh_permission_create --permission="admin" --url="/web/database/manager" --allowed="all_users" #================================================= # RELOAD NGINX diff --git a/scripts/remove b/scripts/remove index c3c7a44..5cbf8c7 100644 --- a/scripts/remove +++ b/scripts/remove @@ -36,9 +36,17 @@ then fi #================================================= -# REMOVE THE MYSQL DATABASE +# STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Removing the MySQL database..." +ynh_script_progression --message="Stopping and removing the systemd service..." + +# Remove the dedicated systemd config +ynh_remove_systemd_config + +#================================================= +# REMOVE THE POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Removing the PostgreSQL database..." # Remove a database if it exists, along with the associated user ynh_psql_remove_db --db_user=$db_user --db_name=$db_name @@ -74,7 +82,16 @@ ynh_remove_app_dependencies #================================================= ynh_script_progression --message="Removing various files..." -ynh_secure_remove --file="$conf_file" +# Remove a directory securely +ynh_secure_remove --file="/etc/$app" + +# Remove the log files +ynh_secure_remove --file="/var/log/$app.log" + +#================================================= +# REMOVE SWAP +#================================================= +ynh_script_progression --message="Removing swap..." ynh_del_swap diff --git a/scripts/restore b/scripts/restore index 0c38b08..aa44a01 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -35,7 +35,7 @@ export port=$(ynh_app_setting_get --app=$app --key=port) export port_chat=$(ynh_app_setting_get --app=$app --key=port_chat) export db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name -export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd) +export db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) export final_path=$(ynh_app_setting_get --app=$app --key=final_path) export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file) export bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME-bin" @@ -81,6 +81,8 @@ ynh_restore_file --origin_path="$final_path/$appname" ynh_restore_file --origin_path="$final_path/custom-addons" ynh_restore_file --origin_path="$final_path/.local" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" #================================================= @@ -91,14 +93,20 @@ chown -R $app:$app "$final_path" ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# ADD SWAP +#================================================= +ynh_script_progression --message="Adding swap..." + +ynh_add_swap --size=$swap_needed #================================================= # BUILD APP #================================================= ynh_script_progression --message="Building $app..." -ynh_add_swap 1024 if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then # The debian package has a bug so we deploy a more recent version if [ -f '../manifest.json' ] ; then @@ -130,7 +138,13 @@ ynh_script_progression --message="Restoring the PostgreSQL database..." # Make sure that postgresql is installed and running ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pass +# Create the database +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd + +# Make sure that its encoding is UTF-8 +ynh_psql_execute_as_root --sql="update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name'" + +# Restore the database contents ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= @@ -139,7 +153,8 @@ ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./d ynh_script_progression --message="Restoring various files..." ynh_restore_file --origin_path="$conf_file" -chown $app:$app $conf_file +chmod 400 "$conf_file" +chown $app:$app "$conf_file" touch /var/log/$app.log chown $app:$app /var/log/$app.log diff --git a/scripts/upgrade b/scripts/upgrade index ddd78f4..63a586d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -40,6 +40,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + ynh_clean_check_starting # Restore it if the upgrade fails ynh_restore_upgradebackup } @@ -67,6 +68,11 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi +if ! ynh_permission_exists --permission="admin"; then + # Create the required permissions + ynh_permission_create --permission="admin" --url="/web/database/manager" --allowed="all_users" +fi + #================================================= # CREATE DEDICATED USER #================================================= @@ -92,16 +98,22 @@ fi #================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # SPECIFIC UPGRADE +#================================================= +# ADD SWAP +#================================================= +ynh_script_progression --message="Adding swap..." + +ynh_add_swap --size=$swap_needed + #================================================= # BUILD APP #================================================= ynh_script_progression --message="Building $app..." -ynh_add_swap 1024 if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then # The debian package has a bug so we deploy a more recent version if [ -f '../manifest.json' ] ; then From 665b01a79e9504d26c61d3e1a9b3dff71fed6fc6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 17 Feb 2022 20:37:19 +0100 Subject: [PATCH 10/10] Update check_process --- check_process | 2 ++ 1 file changed, 2 insertions(+) diff --git a/check_process b/check_process index ab58cea..ba1d0d3 100644 --- a/check_process +++ b/check_process @@ -15,6 +15,8 @@ setup_private=0 setup_public=1 upgrade=1 + # 12.0-6 + upgrade=1 from_commit=2cfdbc229faa8700873e681a01f823c32475cca8 backup_restore=1 multi_instance=1 port_already_use=0