diff --git a/README.md b/README.md deleted file mode 100644 index 61d3cfe..0000000 --- a/README.md +++ /dev/null @@ -1,79 +0,0 @@ - - -# Zap for YunoHost - -[![Integration level](https://dash.yunohost.org/integration/zap.svg)](https://dash.yunohost.org/appci/app/zap) ![Working status](https://ci-apps.yunohost.org/ci/badges/zap.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/zap.maintain.svg) - -[![Install Zap with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=zap) - -*[Lire ce readme en français.](./README_fr.md)* - -> *This package allows you to install Zap 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 - -[Zap](https://zotlabs.com/zap/) is an an ethical alternative to Fediverse that provides powerful features for creating interconnected websites featuring a decentralized identity, communications, and permissions framework built using common webserver technology. - -Compatible with **Mastodon**, **Pleroma**, **Pixelfed**, **Friendica**, **Hubzilla**, **Funkwhale**, **Peertube**, **Plume**, **WriteFreely** and many, many more. - -## Unique Features of ZAP - -- **Groups** : public, private, and moderated. -- **Events** : Calendar and attendance; automatic birthday notifications for friends using this feature. -- **Cloud**storage : Built-in network file storage integrated with social networking access. -- **Editor** : Supports both markdown and bbcode. Use either or both - if you want. -- **Share**: Drag-and-drop a number of different things such as files, photos, webpages, maps, phone numbers to share- them. -- **Lists**: Sometimes referred to as circles or aspects, this lets you define your own groups of related friends and- communicate with them as a private group. -- **Extend** : Change or upgrade your software functionality as desired by installing additional features from addons and- the free app collection. - - -**Shipped version:** 21.11.28~ynh1 -## Disclaimers / important information - -## Installation - -Before installing, read the [Zap installation instructions](https://codeberg.org/zot/zap/src/branch/release/install/INSTALL.txt) for important information about: - -### Register a new domain and add it to YunoHost - -- Zap requires a dedicated domain, so obtain one and add it using the YunoHost admin panel. **Domains -> Add domain**. As Zap uses the full domain and is installed on the root, you can create a subdomain such as Zap.domain.tld. Don't forget to update your DNS if you manage them manually. - -## LDAP Admin user rights, logs and failed database updates - -- **For admin rights**: When installation is complete, you will need to visit your new hub's page and login with the **admin account username** which was entered at the time of installation process. You should then be able to create your first channel and have the **admin rights** for the hub. - -- **For normal YunoHost users :** Normal LDAP users can login through Ldap authentication and create there channels. - -- **Failing to get admin rights :** If the admin cannot access the admin settings at `https://zap.example.com/admin` or you want to grant admin rights to any other user(s) on the hub, then you have to **manually add 4096** to the **account_roles** under **accounts** for that user in the **database through phpMYAdmin**. - -- **For logs:** Go to **admin->logs** and enter the file name **php.log**. - -- **Failed Database after Upgrade:** Some times databse upgrade fails after version upgrade. You can go to hub eg. `https://zap.example.com/admin/dbsync/` and check the numbers of failled update. These updates will have to be ran manually by **phpMYAdmin**. - -## :red_circle: Antifeatures - -- **Upstream not maintained**: This software is not maintained anymore. Expect it to break down over time, be exposed to unfixed security breaches, etc. - -## Documentation and resources - -* 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/zap_ynh/tree/testing). - -To try the testing branch, please proceed like that. - -``` bash -sudo yunohost app install https://github.com/YunoHost-Apps/zap_ynh/tree/testing --debug -or -sudo yunohost app upgrade zap -u https://github.com/YunoHost-Apps/zap_ynh/tree/testing --debug -``` - -**More info regarding app packaging:** diff --git a/README_fr.md b/README_fr.md deleted file mode 100644 index bd83268..0000000 --- a/README_fr.md +++ /dev/null @@ -1,79 +0,0 @@ - - -# Zap pour YunoHost - -[![Niveau d’intégration](https://dash.yunohost.org/integration/zap.svg)](https://dash.yunohost.org/appci/app/zap) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/zap.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/zap.maintain.svg) - -[![Installer Zap avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=zap) - -*[Read this readme in english.](./README.md)* - -> *Ce package vous permet d’installer Zap 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 - -[Zap](https://zotlabs.com/zap/) is an an ethical alternative to Fediverse that provides powerful features for creating interconnected websites featuring a decentralized identity, communications, and permissions framework built using common webserver technology. - -Compatible with **Mastodon**, **Pleroma**, **Pixelfed**, **Friendica**, **Hubzilla**, **Funkwhale**, **Peertube**, **Plume**, **WriteFreely** and many, many more. - -## Unique Features of ZAP - -- **Groups** : public, private, and moderated. -- **Events** : Calendar and attendance; automatic birthday notifications for friends using this feature. -- **Cloud**storage : Built-in network file storage integrated with social networking access. -- **Editor** : Supports both markdown and bbcode. Use either or both - if you want. -- **Share**: Drag-and-drop a number of different things such as files, photos, webpages, maps, phone numbers to share- them. -- **Lists**: Sometimes referred to as circles or aspects, this lets you define your own groups of related friends and- communicate with them as a private group. -- **Extend** : Change or upgrade your software functionality as desired by installing additional features from addons and- the free app collection. - - -**Version incluse :** 21.11.28~ynh1 -## Avertissements / informations importantes - -## Installation - -Before installing, read the [Zap installation instructions](https://codeberg.org/zot/zap/src/branch/release/install/INSTALL.txt) for important information about: - -### Register a new domain and add it to YunoHost - -- Zap requires a dedicated domain, so obtain one and add it using the YunoHost admin panel. **Domains -> Add domain**. As Zap uses the full domain and is installed on the root, you can create a subdomain such as Zap.domain.tld. Don't forget to update your DNS if you manage them manually. - -## LDAP Admin user rights, logs and failed database updates - -- **For admin rights**: When installation is complete, you will need to visit your new hub's page and login with the **admin account username** which was entered at the time of installation process. You should then be able to create your first channel and have the **admin rights** for the hub. - -- **For normal YunoHost users :** Normal LDAP users can login through Ldap authentication and create there channels. - -- **Failing to get admin rights :** If the admin cannot access the admin settings at `https://zap.example.com/admin` or you want to grant admin rights to any other user(s) on the hub, then you have to **manually add 4096** to the **account_roles** under **accounts** for that user in the **database through phpMYAdmin**. - -- **For logs:** Go to **admin->logs** and enter the file name **php.log**. - -- **Failed Database after Upgrade:** Some times databse upgrade fails after version upgrade. You can go to hub eg. `https://zap.example.com/admin/dbsync/` and check the numbers of failled update. These updates will have to be ran manually by **phpMYAdmin**. - -## :red_circle: Fonctions indésirables - -- **Upstream not maintained**: This software is not maintained anymore. Expect it to break down over time, be exposed to unfixed security breaches, etc. - -## Documentations et ressources - -* 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/zap_ynh/tree/testing). - -Pour essayer la branche testing, procédez comme suit. - -``` bash -sudo yunohost app install https://github.com/YunoHost-Apps/zap_ynh/tree/testing --debug -ou -sudo yunohost app upgrade zap -u https://github.com/YunoHost-Apps/zap_ynh/tree/testing --debug -``` - -**Plus d’infos sur le packaging d’applications :** \ No newline at end of file diff --git a/check_process b/check_process deleted file mode 100644 index b89514a..0000000 --- a/check_process +++ /dev/null @@ -1,20 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - admin="john" - upload="256M" - database="1" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=1 - upgrade=1 - backup_restore=1 - multi_instance=1 - change_url=0 -;;; Options -Email= -Notification= diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index 1274f88..0000000 --- a/conf/app.src +++ /dev/null @@ -1,3 +0,0 @@ -SOURCE_URL=https://codeberg.org/streams/streams/archive/c6cfd33c0e1b88e30399a4f9efd557512bb9ec86.tar.gz -SOURCE_SUM=a336c9f70109459bc167736aaa9211fba05a009110d8d0e9586af126337c8ec8 -SOURCE_FORMAT=tar.gz diff --git a/conf/app_addons.src b/conf/app_addons.src deleted file mode 100644 index 8e7f08f..0000000 --- a/conf/app_addons.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://codeberg.org/streams/streams-addons/archive/0ff7cafbb205611c9f5fbbb8d8294c0b9dba0d70.tar.gz -SOURCE_SUM=2118bb796e1113a50b72c525708484563656edfe4b03c50b01ef973d839f3bce -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR= -SOURCE_FILENAME= - diff --git a/conf/php-fpm.conf b/conf/extra_php-fpm.conf similarity index 99% rename from conf/php-fpm.conf rename to conf/extra_php-fpm.conf index ab1a471..13a53b0 100644 --- a/conf/php-fpm.conf +++ b/conf/extra_php-fpm.conf @@ -358,7 +358,7 @@ request_terminate_timeout = 1d ; Chdir to this directory at the start. ; Note: relative path can be used. ; Default Value: current directory or / when chroot -chdir = __FINALPATH__ +chdir = __INSTALL_DIR__ ; Redirect worker stdout and stderr into main error log. If not set, stdout and ; stderr will be redirected to /dev/null according to FastCGI specs. diff --git a/conf/htconfig.sample.php b/conf/htconfig.sample.php new file mode 100644 index 0000000..af51076 --- /dev/null +++ b/conf/htconfig.sample.php @@ -0,0 +1,94 @@ + /dev/null 2>&1 +*/10 * * * * __APP__ /usr/bin/php__PHPVERSION__ -f __INSTALL_DIR__/Code/Daemon/Run.php Cron > /dev/null 2>&1 diff --git a/conf/streams.php b/conf/streams.php deleted file mode 100644 index df2ff61..0000000 --- a/conf/streams.php +++ /dev/null @@ -1 +0,0 @@ -define('NOMADIC',1); diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 0000000..a05a734 --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,30 @@ +version = "1.0" + +[main] +name = "Hubzilla configuration" + + [main.php_fpm_config] + name = "PHP-FPM configuration" + + [main.php_fpm_config.fpm_footprint] + ask = "Memory footprint" + type = "select" + choices.low = "Low, <= 20Mb per pool" + choices.medium = "Medium, between 20Mb and 40Mb per pool" + choices.high = "High, > 40Mb per pool" + choices.specific = "Use specific value" + default = "low" + + [main.php_fpm_config.fpm_free_footprint] + visible = "fpm_footprint == 'specific'" + ask = "Memory footprint of the service?" + type = "number" + default = "0" + help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values." + + [main.php_fpm_config.fpm_usage] + ask = "Expected usage" + type = "select" + choices = ["low", "medium", "high"] + default = "low" + help = "low: Personal usage, behind the SSO. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." diff --git a/doc/DISCLAIMER.md b/doc/ADMIN.md similarity index 100% rename from doc/DISCLAIMER.md rename to doc/ADMIN.md diff --git a/doc/ADMIN_fr.md b/doc/ADMIN_fr.md new file mode 100644 index 0000000..46914bd --- /dev/null +++ b/doc/ADMIN_fr.md @@ -0,0 +1,15 @@ +### Enregistrez un nouveau domaine et ajoutez-le à YunoHost + +- Votre site basé sur Streams nécessite un domaine dédié, alors obtenez-en un et ajoutez-le à l'aide du panneau d'administration YunoHost. **Domaines -> Ajouter un domaine**. Votre site utilise un domaine complet et est installé à la racine, vous pouvez donc créer un sous-domaine tel que monsite.domaine.tld. N'oubliez pas de mettre à jour vos DNS si vous les gérez manuellement. + +## Droits d'utilisateur de l'administrateur LDAP, journaux et échec des mises à jour de la base de données + +- **Pour les droits d'administrateur** : lorsque l'installation est terminée, vous devrez visiter la page d'accueil de votre nouveau site et vous connecter avec le **nom d'utilisateur du compte administrateur** qui a été saisi au moment du processus d'installation. Vous devriez alors pouvoir créer votre premier canal et disposer des **droits d'administrateur** pour le site. + +- **Pour les utilisateurs YunoHost normaux** : les utilisateurs LDAP normaux peuvent se connecter via l'authentification LDAP et y créer des canaux. + +- **Échec de l'obtention des droits d'administrateur** : si l'administrateur ne peut pas accéder aux paramètres d'administration sur `https://monsite.domaine.tld/admin`, vous devez **ajouter manuellement 4096** aux **account_roles* * sous **comptes** pour cet utilisateur dans la **base de données via phpMyAdmin**. + +- **Pour les logs** : Allez dans **admin->logs** et saisissez le nom du fichier **php.log**. + +- **Échec de la base de données après la mise à niveau :** Parfois, la mise à niveau de la base de données échoue après la mise à niveau de la version. Vous pouvez aller au hub, par exemple. `https://monsite.domaine.tld/admin/dbsync/` et vérifiez le nombre de mises à jour défaillantes. Ces mises à jour devront être exécutées manuellement par **phpMyAdmin**. diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..535b82b --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1,24 @@ +[Streams](https://codeberg.org/streams/streams/) est un serveur fediverse open source qui a une longue histoire d'innovation. Voir [FEATURES](https://codeberg.org/streams/streams/src/branch/dev/FEATURES.md). + +Ce logiciel appartient au domaine public dans les limites autorisées par la loi et n'est pas associé à une marque ou à un produit. + +Compatible avec **Mastodon**, **Pleroma**, **Pixelfed**, **Friendica**, **Hubzilla**, **Funkwhale**, **Peertube**, **Plume**, **WriteFreely** et bien d'autres encore. + +## Caractéristiques uniques de Streams + +- **Signature unique fédérée** : Rend les ressources privées/protégées sur des sites externes aussi accessibles que sur des sites locaux. +- **Contrôle d'accès fédéré** : Permet l'authentification unique fédérée pour fournir des ressources multimédias et web privées/protégées à n'importe qui, y compris à ceux qui visitent le site depuis d'autres sites. +- **Groupes** : Publics, privés et modérés. Ils fonctionnent sur presque toutes les plateformes fediverse. +- **Événements** : Calendrier et présence ; notifications automatiques d'anniversaire ajustées au fuseau horaire pour les amis utilisant cette fonctionnalité. +- **Permissions** : Parce que tout le monde ne souhaite pas converser et partager des aspects intimes de sa vie avec des inconnus. +- **Stockage en ligne** : Stockage en ligne de fichiers intégré au logiciel, avec contrôle d'accès fédéré et accès/permissions aux réseaux sociaux. Accessible via le protocole WebDAV. +- **Éditeur** : Supporte le markdown, le html et le bbcode. Utilisez l'un ou l'autre de ces éléments dans un message y intégrer des médias. L'édition et la prévisualisation des messages sont disponibles. Il est peu probable que, dans le cadre d'une utilisation normale, vous dépassiez les limites de longueur des messages fédérés (environ 100 pages imprimées de texte). Il n'y a pas de limites arbitraires imposées au nombre de photos, de fichiers ou de réponses à des sondages joints à vos publications. +- **Partager** : Glissez-déposez un certain nombre de choses différentes telles que des fichiers, des photos, des vidéos, des pages web, des cartes, des articles de fediverse et des numéros de téléphone pour les partager. +- **Listes** : Parfois appelées cercles ou aspects, elles vous permettent de définir vos propres groupes d'amis et de communiquer avec eux en tant que groupe privé. +- **Extension** : Modifiez ou mettez à niveau les fonctionnalités de votre logiciel en installant des fonctions supplémentaires à partir de modules complémentaires et de la collection d'applications gratuites. +- **Guest Pass** : Fournissez à des invités un accès unique à des ressources et à des médias privés - vous fixez les conditions. +- **Zoom sur les amis** : Définissez votre degré de proximité avec n'importe quelle connexion, puis effectuez un zoom avant interactif pour filtrer votre flux vers vos amis proches, ou un zoom arrière pour voir les messages de vos simples connaissances. +- **Services de localisation** : Activation et désactivation, départ et recherche en fonction de la distance. +- **Rapports de distribution** : Dans un monde de plateforme multiples et décentralisées, il y a des imprévus. Les sites et les réseaux tombent parfois en panne. Les développeurs de projets introduisent parfois des bogues et des incompatibilités. Cette fonction vous permet de savoir ce qu'il est advenu de votre message ou de votre commentaire et où il est réellement passé une fois que vous l'avez publié. +- **Sécurité des données** : Parce que le meilleur moment pour faire une sauvegarde à jour de vos données, c'était il y a 10 secondes. Clonez votre identité et votre contenu en ligne sur plusieurs sites à l'aide du protocole Nomad et reproduisez tout changement en temps quasi réel. Ainsi, si le site qui héberge votre compte tombe en panne (temporairement ou définitivement) ou si vous en êtes expulsé pour une raison quelconque, votre vie en ligne n'est pas perdue et vous n'êtes pas obligé de la reprendre à zéro. Tous vos amis et tout votre contenu sont disponibles sur n'importe laquelle de vos instances clonées - à tout moment. +- **ActivityPub** : Fournit l'API ActivityPub "Client to Server" pour une utilisation avec des applications externes. diff --git a/manifest.toml b/manifest.toml index 210064e..8936e76 100644 --- a/manifest.toml +++ b/manifest.toml @@ -57,12 +57,12 @@ ram.runtime = "50M" main.url = "/" [resources.apt] - packages = "php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-ldap php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-gd" + packages = "php8.2-mbstring php8.2-cli php8.2-imagick php8.2-xml php8.2-zip php8.2-curl php8.2-ldap php8.2-json php8.2-gd" packages_from_raw_bash = """ if [[ "$database" == "mysql" ]]; then - echo "mariadb-server" + echo "mariadb-server php8.2-mysql" elif [[ "$database" == "postgresql" ]]; then - echo "postgresql postgresql-contrib" + echo "postgresql postgresql-contrib php8.2-pgsql" fi """ diff --git a/scripts/_common.sh b/scripts/_common.sh index ad33116..3b59e88 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -3,43 +3,19 @@ #================================================= # COMMON VARIABLES #================================================= +# PHP APP SPECIFIC +#================================================= -# dependencies used by the app -YNH_PHP_VERSION="8.2" YNH_COMPOSER_VERSION="2.5.8" -pkg_dependencies_main="php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-ldap php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-gd" -pkg_dependencies_psql="postgresql postgresql-contrib php${YNH_PHP_VERSION}-pgsql" +#================================================= +# PERSONAL HELPERS +#================================================= #================================================= # EXPERIMENTAL HELPERS #================================================= -ynh_smart_mktemp () { - local min_size="${1:-300}" - # Transform the minimum size from megabytes to kilobytes - min_size=$(( $min_size * 1024 )) - - # Check if there's enough free space in a directory - is_there_enough_space () { - local free_space=$(df --output=avail "$1" | sed 1d) - test $free_space -ge $min_size - } - - if is_there_enough_space /tmp; then - local tmpdir=/tmp - elif is_there_enough_space /var; then - local tmpdir=/var - elif is_there_enough_space /; then - local tmpdir=/ - elif is_there_enough_space /home; then - local tmpdir=/home - else - ynh_die "Insufficient free space to continue..." - fi - - echo "$(mktemp --directory --tmpdir="$tmpdir")" -} #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup old mode 100755 new mode 100644 index d39ad02..7b28f27 --- a/scripts/backup +++ b/scripts/backup @@ -6,32 +6,10 @@ # 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_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -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) -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -database=$(ynh_app_setting_get --app=$app --key=database) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -41,7 +19,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION @@ -55,31 +33,6 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" -#================================================= -# BACKUP OF THE DATABASE -#================================================= - -if [ $database -eq 1 ]; then - ynh_print_info --message="Backup of the MySQL database..." - ynh_mysql_dump_db --database="$db_name" > db.sql -elif [ $database -eq 2 ]; then - # Removing postgresSQL database - ynh_print_info --message="Backup of the postgreSQL database..." - ynh_psql_dump_db --database="$db_name" > db.sql -fi - -#================================================= -# BACKUP LOGROTATE -#================================================= - -ynh_backup --src_path="/etc/logrotate.d/$app" - -#================================================= -# BACKUP A CRON FILE -#================================================= - -ynh_backup --src_path="/etc/cron.d/$app" - #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= @@ -87,6 +40,34 @@ ynh_backup --src_path="/etc/cron.d/$app" ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + +#================================================= +# BACKUP VARIOUS FILES +#================================================= + +ynh_backup --src_path="/etc/cron.d/$app" + +#================================================= +# BACKUP THE DATABASE +#================================================= + +if [ $database = "mysql" ]; then + # Backup MySQL database + ynh_print_info --message="Backup of the MySQL database..." + ynh_mysql_dump_db --database="$db_name" > db.sql +elif [ $database = "postgresql" ]; then + # Backup PostgreSQL database + ynh_print_info --message="Backup of the PostgreSQL database..." + ynh_psql_dump_db --database="$db_name" > db.sql +fi + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..91c2de7 --- /dev/null +++ b/scripts/config @@ -0,0 +1,95 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) + +#================================================= +# SPECIFIC GETTERS FOR TOML SHORT KEY +#================================================= + +get__fpm_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null + then + echo "specific" + else + echo "$current_fpm_footprint" + fi +} + +get__free_footprint() { + # Free footprint value for php-fpm + # Check if current_fpm_footprint is an integer + if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null + then + # If current_fpm_footprint is an integer, that's a numeric value for the footprint + echo "$current_fpm_footprint" + else + echo "0" + fi +} + +#================================================= +# SPECIFIC SETTERS FOR TOML SHORT KEYS +#================================================= + +set__fpm_footprint() { + if [ "$fpm_footprint" != "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" + fi +} + +set__fpm_free_footprint() { + if [ "$fpm_footprint" = "specific" ] + then + ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_free_footprint" + fi +} + +#================================================= +# GENERIC FINALIZATION +#================================================= + +ynh_app_config_validate() { + _ynh_app_config_validate + + if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[fpm_free_footprint]}" == "true" ]; then + # If fpm_footprint is set to 'specific', use $fpm_free_footprint value. + if [ "$fpm_footprint" = "specific" ] + then + fpm_footprint=$fpm_free_footprint + fi + + if [ "$fpm_footprint" == "0" ] + then + ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." + + exit 0 + fi + fi +} + +ynh_app_config_apply() { + _ynh_app_config_apply + + ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint +} + +ynh_app_config_run $1 diff --git a/scripts/install b/scripts/install index c746424..6762a26 100755 --- a/scripts/install +++ b/scripts/install @@ -9,259 +9,153 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -domain=$YNH_APP_ARG_DOMAIN -path_url="/" -admin=$YNH_APP_ARG_ADMIN email=$(ynh_user_get_info --username=$admin --key=mail) upload="256M" -database="1" -random_string=$(ynh_string_random --length=48) -database=`expr $YNH_APP_ARG_DATABASE` - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." - -final_path=/var/www/$app -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 +random_string="$(ynh_string_random --length=48)" +fpm_footprint="low" +fpm_free_footprint=0 +fpm_usage="low" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_print_info "Storing installation settings..." +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=admin --value=$admin +ynh_app_setting_set --app=$app --key=database --value=$database ynh_app_setting_set --app=$app --key=email --value=$email ynh_app_setting_set --app=$app --key=upload --value=$upload -ynh_app_setting_set --app=$app --key=database --value=$database ynh_app_setting_set --app=$app --key=random_string --value=$random_string +ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint +ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint +ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage #================================================= -# STANDARD MODIFICATIONS +# CREATE A DATABASE #================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_print_info "Installing dependencies..." -ynh_install_app_dependencies $pkg_dependencies_main -if [ $database == "postgresql" ]; then - ynh_install_app_dependencies $pkg_dependencies_psql +ynh_script_progression --message="Creating a database..." --weight=2 + +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +db_pwd=$(ynh_string_random --length=30) +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_app_setting_set --app=$app --key=db_user --value=$db_user +ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd + +if [ $database == "mysql" ]; then + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ + <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" + db_type=0 +elif [ $database == "postgresql" ]; then + ynh_psql_test_if_first_run + ynh_psql_setup_db --db_user=$db_user --db_name=$db_name + db_type=1 fi -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." --weight=1 -# 1 - Streams -ynh_script_progression --message="Setting up Streams source files..." - -ynh_app_setting_set --app=$app --key=final_path --value=$final_path -# Download -# Uncomment the line below to use latest available release version -# git clone https://codeberg.org/streams/streams.git "$final_path" --quiet -# git checkout release - -# Secure install - Comment the two lines below to use the git repository as the source +# Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir/addon" --source_id="addons" -# 2 - Composer -ynh_script_progression --message="Pulling in external libraries with Composer..." +touch "$install_dir/php.log" +mkdir -p "$install_dir/store" +mkdir -p "$install_dir/cache/smarty3" -ynh_install_composer - -# 3 - Streams Addons - -# Make addon Directory and unpack the addons to this directory -ynh_script_progression --message="Setting up Streams addons source files..." - -pushd "$final_path" - mkdir -p extend/addon/zaddons - mkdir addon - git clone https://codeberg.org/streams/streams-addons.git $final_path/extend/addon/zaddons --quiet - filelist=(`ls extend/addon/zaddons`) - cd addon - for a in "${filelist[@]}" ; do - base=`basename $a` - if [ $base = '.git' ]; then - #echo 'ignoring git' - continue; - fi - if [ ! -d ../extend/addon/zaddons/$base ]; then - #echo $a 'not a directory' - continue; - fi - if [ -x $base ]; then - #echo $base 'file exists' - continue; - fi - - echo linking $base - - ln -s ../extend/addon/zaddons/$base $base - done - -popd - - - -# 3 - Some extra folders -ynh_script_progression --message="Creating smarty3 folder for personal data..." - -mkdir -p "${final_path}/store" -mkdir -p "${final_path}/cache/smarty3" -chmod -R 775 $final_path/store $final_path/cache - -# Copy the template install/htconfig.sample.php to .htconfig.php -config="$final_path/.htconfig.php" -ynh_script_progression --message="Moving .htconfig.php to root of Zap ..." -cp $final_path/install/htconfig.sample.php $config -config="$final_path/.htconfig.php" -# Create php.log inside for logs -ynh_print_info "Create php.log for the debuging..." -touch "$final_path/php.log" - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" - -#================================================= -# CREATE A DATABASE -#================================================= - -if [ $database == "mysql" ]; then - ynh_script_progression --message="Creating a MySQL database..." - 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 - ynh_script_progression --message="Importing database..." - ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $final_path/install/schema_mysql.sql -elif [ $database == "postgresql" ]; then - # Create postgresql database - ynh_script_progression --message="Creating a postgresql database..." - ynh_replace_string --match_string="db_type = 0;" --replace_string="db_type = 1;" --target_file="$config" - db_name=$(ynh_sanitize_dbid --db_name=$app) - db_user=$app - ynh_psql_test_if_first_run - ynh_psql_setup_db --db_user=$db_user --db_name=$db_name - ynh_app_setting_set --app=$app --key=db_name --value=$db_name - ynh_script_progression --message="Importing database..." - ynh_psql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $final_path/install/schema_postgres.sql -else - ynh_die --message="Some problem occured in creating the database, contact maintainer" -fi - -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$config" -ynh_replace_string --match_string= "mysqlpassword" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string= "mysqldatabasename" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string= "mysite.example" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string= "if the auto install failed, put a unique random string here" --replace_string="$random_string" --target_file="$config" -sed -i "s/\['admin_email'\] = '';/\['admin_email'\] = '$email';/g" "$config" -ynh_replace_string --match_string= "//error_reporting(E_ERROR | E_WARNING | E_PARSE );" --replace_string="error_reporting(E_ERROR | E_WARNING | E_PARSE );" --target_file="$config" -ynh_replace_string --match_string= "//ini_set('error_log','php.out');" --replace_string="ini_set('error_log','php.log');" --target_file="$config" -ynh_replace_string --match_string= "//ini_set('log_errors','1');" --replace_string="ini_set('log_errors','1');" --target_file="$config" -ynh_replace_string --match_string= "//ini_set('display_errors', '0');" --replace_string="ini_set('display_errors', '0');" --target_file="$config" -sed -i "s/\['php_path'\] = 'php';/\['php_path'\] = 'php$phpversion';/g" "$config" - -# addon LDAP config -ynh_script_progression --message="Push Ldap configuration to .htconfig.php..." - -cat ../conf/ldap_conf.php >> $final_path/.htconfig.php - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." - -# Create a dedicated nginx config -ynh_add_nginx_config +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod -R 775 $install_dir/store $install_dir/cache #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring PHP-FPM..." +ynh_script_progression --message="Configuring PHP-FPM..." --weight=1 -# Create a dedicated php-fpm config -ynh_add_fpm_config +# Create a dedicated PHP-FPM config +ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint + +# Create a dedicated NGINX config +ynh_add_nginx_config #================================================= -# CRON JOB CONFIGURATION +# COMPOSER #================================================= -ynh_script_progression --message="Setting up cron job..." +ynh_script_progression --message="Pulling in external libraries with Composer..." + +ynh_install_composer + +#================================================= +# SPECIFIC SETUP +#================================================= +# PROVISION DATABASE +#================================================= +ynh_script_progression --message="Provisionning database..." --weight=1 + +if [ $database = "mysql" ]; then + ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $install_dir/install/schema_mysql.sql +elif [ $database = "postgresql" ]; then + ynh_psql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $install_dir/install/schema_postgres.sql +fi + +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +ynh_add_config --template="../conf/htconfig.sample.php" --destination="$install_dir/.htconfig.php" + +# addon ldap config +ynh_script_progression --message="Push LDAP configuration to .htconfig.php..." + +cat ../conf/ldap_conf.php >> $install_dir/.htconfig.php +ynh_store_file_checksum --file=$install_dir/.htconfig.php + +chmod 600 "$install_dir/.htconfig.php" +chown $app:$app "$install_dir/.htconfig.php" + +#================================================= +# SET CRON JOB +#================================================= +ynh_script_progression --message="Setuping cron job..." --weight=1 + +# Set up cron job ynh_add_config --template="../conf/poller-cron" --destination="/etc/cron.d/$app" chown root: "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app" +#================================================= +# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." +ynh_script_progression --message="Configuring log rotation..." --weight=1 # Use logrotate to manage application logfile(s) -ynh_use_logrotate "$final_path/php.log" +ynh_use_logrotate "$install_dir/php.log" #================================================= # SETUP FAIL2BAN #================================================= -ynh_script_progression --message="Add Fail2Ban..." +ynh_script_progression --message="Configuring Fail2Ban..." --weight=1 -ynh_add_fail2ban_config --logpath="$final_path/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." - -ynh_permission_update --permission="main" --add="visitors" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" #================================================= # LDAP ADDON ACTIVATION #================================================= ynh_script_progression --message="Enabling ldapauth addon..." -pushd "$final_path" +pushd "$install_dir" /usr/bin/php${YNH_PHP_VERSION} util/addons install ldapauth popd @@ -269,4 +163,4 @@ popd # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 8655412..406d546 100755 --- a/scripts/remove +++ b/scripts/remove @@ -9,98 +9,40 @@ 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) -database=$(ynh_app_setting_get --app=$app --key=database) - #================================================= # REMOVE THE DATABASE #================================================= -if [ $database -eq 1 ]; then - ynh_script_progression --message="Removing MySQL database..." +if [ $database = "mysql" ]; then + ynh_script_progression --message="Removing MySQL database..." --weight=1 ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name -elif [ $database -eq 2 ]; then - # Removing postgresql database - ynh_script_progression --message="Removing postgreSQL database..." - ynh_psql_remove_db --db_user=$db_user --db_name=$db_name +elif [ $database = "postgresql" ]; then + ynh_script_progression --message="Removing PostgreSQL database..." --weight=1 + ynh_psql_remove_db --db_user=$db_user --db_name=$db_name fi -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies" - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# 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..." +ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Removing PHP-FPM configuration..." - -# Remove the dedicated php-fpm config +# Remove the dedicated PHP-FPM config ynh_remove_fpm_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# REMOVE THE CRON FILE -#================================================= +# Remove the dedicated Fail2Ban config +ynh_remove_fail2ban_config # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" -#================================================= -# REMOVE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Removing Fail2Ban configuration..." - -ynh_remove_fail2ban_config - -#================================================= -# 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" +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore old mode 100755 new mode 100644 index 315f8af..0dfb0c2 --- a/scripts/restore +++ b/scripts/restore @@ -6,85 +6,31 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# 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 -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -database=$(ynh_app_setting_get --app=$app --key=database) -db_user=$db_name -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." - -test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_print_info "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_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" #================================================= -# RESTORE THE MYSQL DATABASE +# RESTORE THE DATABASE #================================================= -ynh_script_progression --message="Restoring the database..." -ynh_install_app_dependencies $pkg_dependencies_main - -if [ $database -eq 1 ]; then - ynh_script_progression --message="Restoring MySQL database..." +if [ $database = "mysql" ]; then + ynh_script_progression --message="Restoring MySQL database..." --weight=1 db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) - ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd - ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql -elif [ $database -eq 2 ]; then - # Reinstalling postgresql database - ynh_script_progression --message="Reinstalling dependencies..." - # Define and install dependencies - ynh_install_app_dependencies $pkg_dependencies_psql - ynh_script_progression --message="Restoring the PostgreSQL database..." + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd + ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +elif [ $database = "postgresql" ]; then + ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd @@ -92,39 +38,28 @@ elif [ $database -eq 2 ]; then fi #================================================= -# RESTORE THE PHP-FPM CONFIGURATION +# RESTORE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Restoring PHP-FPM configuration..." +ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" +ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" +ynh_systemd_action --action=restart --service_name=fail2ban ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" -#================================================= -# RESTORE THE CRON FILE -#================================================= +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/cron.d/$app" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - ynh_restore_file --origin_path="/etc/logrotate.d/$app" -#================================================= -# RESTORE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the Fail2Ban configuration..." - -ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" -ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" -ynh_systemd_action --action=restart --service_name=fail2ban - #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." +ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload @@ -133,4 +68,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index f15212e..0d6242e 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,209 +12,138 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_script_progression --message="Loading settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +email=$(ynh_user_get_info --username=$admin --key=mail) -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -upload=$(ynh_app_setting_get --app=$app --key=upload) -version=$(grep STD_VERSION $final_path/boot.php | cut -c 38- | rev | cut -c 5- | rev) -last_update=$(grep update_time: /etc/yunohost/apps/$app/settings.yml | cut -c 14-) -database=$(ynh_app_setting_get --app=$app --key=database) -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +#================================================= +# CHECK VERSION +#================================================= +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# STANDARD UPGRADE STEPS #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# If db_name doesn't exist, create it -if [ -z "$db_name" ]; then - db_name=$(ynh_sanitize_dbid --db_name=$app) - ynh_app_setting_set --app=$app --key=db_name --value=$db_name + +# If fpm_footprint doesn't exist, create it +if [ -z "$fpm_footprint" ]; then + fpm_footprint=low + ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint fi -#================================================= -# 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 - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# Migrate legacy permissions to new system -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." - -# If final_path doesn't exist, create it -if [ -z "$final_path" ]; then - final_path=/var/www/$app - ynh_app_setting_set --app=$app --key=final_path --value=$final_path +# If fpm_free_footprint doesn't exist, create it +if [ -z "$fpm_free_footprint" ]; then + fpm_free_footprint=0 + ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint fi -if ynh_legacy_permissions_exists -then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public +# If fpm_usage doesn't exist, create it +if [ -z "$fpm_usage" ]; then + fpm_usage=low + ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage 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" +# Switch $database to "mysql" or "postgresql" +if [[ $database == "1" ]] 2>/dev/null; then + database="mysql" + ynh_app_setting_set --app=$app --key=database --value=$database +elif [[ $database == "2" ]] 2>/dev/null; then + database="postgresql" + ynh_app_setting_set --app=$app --key=database --value=$database +fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." -# Download, check integrity, uncompress and patch the source from app.src -# ynh_setup_source --dest_dir="$final_path" - -if [ `cd $final_path && git rev-parse --is-inside-work-tree` ]; then - pushd "$final_path" - git pull --quiet - ynh_install_composer - cd extend/addon/zaddons - git pull --quiet - cd ../../.. - filelist=(`ls extend/addon/zaddons`) - cd addon - for a in "${filelist[@]}" ; do - base=`basename $a` - if [ $base = '.git' ]; then - #echo 'ignoring git' - continue; - fi - if [ ! -d ../extend/addon/zaddons/$base ]; then - #echo $a 'not a directory' - continue; - fi - if [ -x $base ]; then - #echo $base 'file exists' - continue; - fi - - echo linking $base - - ln -s ../extend/addon/zaddons/$base $base - done - for x in `ls` ; do - if [ -L "$x" ] && ! [ -e "$x" ]; then - echo "removing dead symlink $x" ; - rm -- "$x"; - fi; - done - popd - chmod -R 775 $final_path/store -else - - # Create a temporary directory - tmpdir="$(ynh_smart_mktemp 6000)" - # Backup the config file in the temp dir - cp -a "$final_path/.htconfig.php" "$tmpdir/.htconfig.php" - cp -a "$final_path/store" "$tmpdir/store" - cp -a "$final_path/php.log" "$tmpdir/php.log" - cp -a "$final_path/cache" "$tmpdir/cache" - - # Remove the app directory securely - ynh_secure_remove "$final_path" +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" - - cp -a "$tmpdir/cache" "${final_path}" - cp -a "$tmpdir/store" "${final_path}" - cp -a "$tmpdir/.htconfig.php" "${final_path}" - cp -a "$tmpdir/php.log" "${final_path}" - ynh_secure_remove --file="$tmpdir" - chmod -R 775 $final_path/store - mkdir $final_path/addon - ynh_setup_source --dest_dir="$final_path/addon" --source_id="app_addons" + ynh_setup_source --dest_dir="$install_dir" --keep="store/ .htconfig.php php.log" + ynh_setup_source --dest_dir="$install_dir/addon" --source_id="addons" fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +mkdir -p "$install_dir/store" +mkdir -p "$install_dir/cache/smarty3" -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." - -# Create a dedicated nginx config -ynh_add_nginx_config +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod -R 775 $install_dir/store $install_dir/cache #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." +ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 -# Create a dedicated php-fpm config -ynh_add_fpm_config +# Create a dedicated PHP-FPM config +ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. -### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different --file="$final_path/.htconfig.php" -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/.htconfig.php" +# Create a dedicated NGINX config +ynh_add_nginx_config #================================================= -# SETUP LOGROTATE +# SPECIFIC UPGRADE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append +if [ $database = "mysql" ]; then + db_type=0 + db_name=$(ynh_sanitize_dbid --db_name=$app) + db_user=$db_name + db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) + # Change your databases character set and collation + ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ + <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" +elif [ $database = "postgresql" ]; then + db_type=1 + db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +fi + +ynh_add_config --template="../conf/htconfig.sample.php" --destination="$install_dir/.htconfig.php" + +# addon ldap config +ynh_script_progression --message="Push LDAP configuration to .htconfig.php..." + +cat ../conf/ldap_conf.php >> $install_dir/.htconfig.php +ynh_store_file_checksum --file=$install_dir/.htconfig.php + +chmod 600 "$install_dir/.htconfig.php" +chown $app:$app "$install_dir/.htconfig.php" #================================================= -# UPGRADE FAIL2BAN +# UPGRADE CRON JOB #================================================= -ynh_script_progression --message="Re-configure Fail2Ban..." - -ynh_add_fail2ban_config --logpath="$final_path/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" - -#================================================= -# UPGRADE CRON -#================================================= -ynh_script_progression --message="Setting up cron job..." +ynh_script_progression --message="Upgrading cron job..." --weight=1 +# Set up cron job ynh_add_config --template="../conf/poller-cron" --destination="/etc/cron.d/$app" chown root: "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app" #================================================= -# UPGRADE DEPENDENCIES +# GENERIC FINALIZATION #================================================= -ynh_script_progression --message="Upgrading dependencies..." - -ynh_install_app_dependencies $pkg_dependencies_main - -if [ $database -eq 2 ]; then - ynh_install_app_dependencies $pkg_dependencies_psql -fi - +# SETUP LOGROTATE #================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..d5d13bb --- /dev/null +++ b/tests.toml @@ -0,0 +1,29 @@ +test_format = 1.0 + +[default] + + + # ------------ + # Tests to run + # ------------ + + exclude = ["change_url"] + + # ------------------------------- + # Default args to use for install + # ------------------------------- + + args.database="mysql" + + # ------------------------------- + # Commits to test upgrade from + # ------------------------------- + + test_upgrade_from.7c4bcff615c9ea9e87b2d5bad110dc10b1921efc.name = "Upgrade from 8.4.1" + + +[with_postgresql] + + only = ["install.subdir"] + + args.database="postgresql" \ No newline at end of file