From e288f029a9fe42b4a02a46cb3c92b1307229a6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 12 Jan 2024 15:46:49 +0100 Subject: [PATCH] Manifest v2 --- check_process | 29 --- conf/amd64.src | 6 - conf/arm64.src | 6 - conf/armhf.src | 6 - conf/cache.conf | 1 - conf/ldap.exs | 2 +- conf/systemd.service | 8 +- doc/{yunohost.md => ADMIN.md} | 30 +++ doc/{yunohost_fr.md => ADMIN_fr.md} | 31 ++- doc/DISCLAIMER.md | 38 ---- doc/DISCLAIMER_fr.md | 37 ---- doc/PRE_INSTALL.md | 6 + doc/PRE_INSTALL_fr.md | 6 + manifest.json | 100 ---------- manifest.toml | 115 ++++++++++++ scripts/_common.sh | 8 +- scripts/backup | 45 +---- scripts/change_url | 92 +-------- scripts/install | 282 +++++++--------------------- scripts/remove | 105 +---------- scripts/restore | 136 +++----------- scripts/upgrade | 264 ++++++-------------------- scripts/ynh_package_version | 26 --- tests.toml | 8 + 24 files changed, 371 insertions(+), 1016 deletions(-) delete mode 100644 check_process delete mode 100644 conf/amd64.src delete mode 100644 conf/arm64.src delete mode 100644 conf/armhf.src rename doc/{yunohost.md => ADMIN.md} (58%) rename doc/{yunohost_fr.md => ADMIN_fr.md} (51%) delete mode 100644 doc/DISCLAIMER.md delete mode 100644 doc/DISCLAIMER_fr.md create mode 100644 doc/PRE_INSTALL.md create mode 100644 doc/PRE_INSTALL_fr.md delete mode 100644 manifest.json create mode 100644 manifest.toml delete mode 100644 scripts/ynh_package_version create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index 983c9bf..0000000 --- a/check_process +++ /dev/null @@ -1,29 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - is_public=1 - admin="john" - password="1Strong-Password" - name="My_Pleroma" - registration=0 - cache=1 - size="5g" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - # 2.4.1~ynh1 - upgrade=1 from_commit=e6d9935af254018baf326281662c55407170694d - # 2.4.3~ynh1 - upgrade=1 from_commit=ba16bc8bee7715c479a7ee575ec5f7d9970a84f8 - backup_restore=1 - multi_instance=0 - port_already_use=0 - change_url=1 -;;; Options -Email= -Notification=none diff --git a/conf/amd64.src b/conf/amd64.src deleted file mode 100644 index f8feb50..0000000 --- a/conf/amd64.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://git.pleroma.social/pleroma/pleroma/-/jobs/241073/artifacts/download?file_type=archive -SOURCE_SUM=ce5b861a19a756d3ea26b6e1708c1be954108823d644b1c19036e992c6a6267e -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=zip -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/arm64.src b/conf/arm64.src deleted file mode 100644 index d025175..0000000 --- a/conf/arm64.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://git.pleroma.social/pleroma/pleroma/-/jobs/241077/artifacts/download?file_type=archive -SOURCE_SUM=6841a8d258683a70ba8b4466e502022eda865ddfae1ded415a5d1317f29fae16 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=zip -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/armhf.src b/conf/armhf.src deleted file mode 100644 index f64e94c..0000000 --- a/conf/armhf.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://git.pleroma.social/pleroma/pleroma/-/jobs/241075/artifacts/download?file_type=archive -SOURCE_SUM=ff588d370b11939150bd46353274d4b8f879dcfdd87a43eca1bb6fc0a21eec0a -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=zip -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/cache.conf b/conf/cache.conf index c2da95d..c9471b4 100644 --- a/conf/cache.conf +++ b/conf/cache.conf @@ -1,2 +1 @@ proxy_cache_path /tmp/__APP__-media-cache levels=1:2 keys_zone=__APP___media_cache:10m max_size=__SIZE__ inactive=720m use_temp_path=off; - diff --git a/conf/ldap.exs b/conf/ldap.exs index b7e3272..542d8aa 100644 --- a/conf/ldap.exs +++ b/conf/ldap.exs @@ -8,4 +8,4 @@ config :pleroma, :ldap, tls: false, # tlsopts: [], base: "ou=users,dc=yunohost,dc=org", - uid: "uid" \ No newline at end of file + uid: "uid" diff --git a/conf/systemd.service b/conf/systemd.service index 587b174..7018530 100755 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -15,12 +15,12 @@ Environment="MIX_ENV=prod" ; Make sure that all paths fit your installation. ; Path to the home directory of the user running the Pleroma service. -Environment="HOME=__FINALPATH__/live/" +Environment="HOME=__INSTALL_DIR__/live/" ; Path to the folder containing the Pleroma installation. -WorkingDirectory=__FINALPATH__/live/ +WorkingDirectory=__INSTALL_DIR__/live/ ; Path to the Pleroma binary. -ExecStart=__FINALPATH__/live/bin/pleroma start -ExecStop=__FINALPATH__/live/bin/pleroma stop +ExecStart=__INSTALL_DIR__/live/bin/pleroma start +ExecStop=__INSTALL_DIR__/live/bin/pleroma stop ; Some security directives. ; Use private /tmp and /var/tmp folders inside a new file system namespace, which are discarded after the process stops. diff --git a/doc/yunohost.md b/doc/ADMIN.md similarity index 58% rename from doc/yunohost.md rename to doc/ADMIN.md index ca0aba7..1122344 100644 --- a/doc/yunohost.md +++ b/doc/ADMIN.md @@ -14,3 +14,33 @@ Some information, for all intents and purposes, on the differences between a dir - The installation of Pleroma with Yunohost is a so-called OTP installation (and not MIX, i.e. from the sources). Have this in mind, as the administration _commands_ are not the same in either case. - All commands must be run as the `pleroma` user, who is _not_ part of Yunohost `admin` group, it’s not possible to invoque these commands directly with `sudo`. + +Connect with SSH to your Yunohost server as YNH admin user. + +For the commands syntax, have in mind the specificities of [Yunohost Pleroma install](./doc/yunohost.md). + +## Administration tasks + +### Adding users + +```bash +sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user new " +``` + +### Password reset + +```bash +sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user reset_password " +``` + +This will generate a **password reset link** that you can then send to the user. + +### Moderators + +You can make users **moderators**. They will then be able to _delete any post_. + +```bash +sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user set --admin" +``` + +Note: `--admin` option will _make the user moderator_ and `--no-admin` will _take away_ the moderator privileges from the user. diff --git a/doc/yunohost_fr.md b/doc/ADMIN_fr.md similarity index 51% rename from doc/yunohost_fr.md rename to doc/ADMIN_fr.md index 8a99e74..a6198bf 100644 --- a/doc/yunohost_fr.md +++ b/doc/ADMIN_fr.md @@ -9,8 +9,37 @@ Quelques informations, à toutes fins utiles, sur les différences entre une ins | Fichier de configuration | `/etc/pleroma/config.exs` | `/etc/pleroma/config.exs` | | Ligne de commandes | `/bin/pleroma_ctl` | `/var/www/pleroma/live/bin/pleroma_ctl` | -## A noter +## À noter - L’installation de Pleroma avec Yunohost est une installation dite OTP (et non MIX, c’est à dire à partir des sources). Information à mémoriser, dans la mesure où les commandes d’administration ne sont pas les mêmes dans l’un ou l’autre cas. - Toutes les commandes doivent être exécutées en tant qu’utilisateur `pleroma`, qui n’est _pas_ membre du groupe `admin` de Yunohost, celle-ci ne peuvent donc être invoquées directement avec `sudo`. + +## Tâches d’administration + +Se connecter avec SSH à votre serveur Yunohost avec le compte admin (nous parlons ici de l’admin YNH pas de l’admin de Pleroma). +Pour la syntaxe des commandes, garder en tête les spécificités d’une installations de [Pleroma avec Yunohost](./doc/yunohost_fr.md). + +### Ajouter un utilisateur ou utilisatrice + +```bash +sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user new " +``` + +### Changer de mot de passe + +```bash +sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user reset_password " +``` + +Ceci générera un **lien de réinitialisation** (URL) du mot de passe, que vous pouvez envoyer à l’utilisateur ou utilisatrice. + +### Modérateurs + +Vous pouvez donner à des utilisateurs ou utilisatrices les droits de **modération**. Ils ou elles pourront alors _supprimer_ n’importe quel billet publié par n’importe quel autre compte. + +```bash +sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user set --admin" +``` + +Note : l’option `--admin` donne au compte _les droits de moderation_ et avec l’option `--no-admin` à l’inverse on _enlève_ les privilèges de modération de celui-ci. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index 0d497d0..0000000 --- a/doc/DISCLAIMER.md +++ /dev/null @@ -1,38 +0,0 @@ -## Limitations - -- **Pleroma** require a dedicated **root domain**, eg. pleroma.domain.tld -- **Pleroma** require a valid **certificate** installed on the domain. Yunohost can **install Letsencrypt certificate** on the domain from **admin web-interface** or through **command-line**. -- This package is currently set to **single-instance** that means you can run a **single Pleroma instance** on a **single server**. -- The admin **password** entered when installing must **not** contain **special characters**. (See [issue #132](https://github.com/YunoHost-Apps/pleroma_ynh/issues/132)) -- LDAP supported but HTTP auth not. - -## Admin Tasks - -Connect with SSH to your Yunohost server as YNH admin user. -For the commands syntax, have in mind the specificities of [Yunohost Pleroma install](./doc/yunohost.md). - - -### Adding users - -``` -sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user new " -``` - -### Password reset - -``` -sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user reset_password " -``` - -This will generate a **password reset link** that you can then send to the user. - -### Moderators - -You can make users **moderators**. They will then be able to _delete any post_. - - -``` -sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user set --admin" -``` - -Note: `--admin` option will _make the user moderator_ and `--no-admin` will _take away_ the moderator privileges from the user. diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md deleted file mode 100644 index 2876798..0000000 --- a/doc/DISCLAIMER_fr.md +++ /dev/null @@ -1,37 +0,0 @@ -## Limitations - -- Pleroma doit impérativement s’installer sur son propre **nom de domaine dédié** (ou sous-domaine), par ex. pleroma.domain.tld -- Pleroma nécessite par ailleurs un **certificat SSL** valide activé sur ce domaine. Yunohost peut installer et configurer un **certificat Letsencrypt** pour le domaine depuis l’interface d'administration de Yunohost ou avec la ligne de commande. -- Ce paquet est actuellement configuré pour une **instance unique**, c’est-à-dire que l’on ne peut installer _qu’une seule instance_ de Pleroma sur un même serveur Yunohost. -- Le **mot de passe** saisi durant l’installation ne doit _en aucun cas_ contenir de **caractères spéciaux**. (Voir [issue #132](https://github.com/YunoHost-Apps/pleroma_ynh/issues/132)) -- L’authentification LDAP fonctionne, mais pas `HTTP auth` en revanche. - -## Tâches d’administration - -Se connecter avec SSH à votre serveur Yunohost avec le compte admin (nous parlons ici de l’admin YNH pas de l’admin de Pleroma). -Pour la syntaxe des commandes, garder en tête les spécificités d’une installations de [Pleroma avec Yunohost](./doc/yunohost_fr.md). - - -### Ajouter un utilisateur ou utilisatrice - -``` -sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user new " -``` - -### Changer de mot de passe - -``` -sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user reset_password " -``` - -Ceci générera un **lien de réinitialisation** (URL) du mot de passe, que vous pouvez envoyer à l’utilisateur ou utilisatrice. - -### Modérateurs - -Vous pouvez donner à des utilisateurs ou utilisatrices les droits de **modération**. Ils ou elles pourront alors _supprimer_ n’importe quel billet publié par n’importe quel autre compte. - -``` -sudo su pleroma -s $SHELL -lc "/var/www/pleroma/live/bin/pleroma_ctl user set --admin" -``` - -Note : l’option `--admin` donne au compte _les droits de moderation_ et avec l’option `--no-admin` à l’inverse on _enlève_ les privilèges de modération de celui-ci. diff --git a/doc/PRE_INSTALL.md b/doc/PRE_INSTALL.md new file mode 100644 index 0000000..0395acc --- /dev/null +++ b/doc/PRE_INSTALL.md @@ -0,0 +1,6 @@ +## Limitations + +- **Pleroma** require a dedicated **root domain**, eg. pleroma.domain.tld +- **Pleroma** require a valid **certificate** installed on the domain. Yunohost can **install Letsencrypt certificate** on the domain from **admin web-interface** or through **command-line**. +- This package is currently set to **single-instance** that means you can run a **single Pleroma instance** on a **single server**. +- The admin **password** entered when installing must **not** contain **special characters**. (See [issue #132](https://github.com/YunoHost-Apps/pleroma_ynh/issues/132)) diff --git a/doc/PRE_INSTALL_fr.md b/doc/PRE_INSTALL_fr.md new file mode 100644 index 0000000..6efa954 --- /dev/null +++ b/doc/PRE_INSTALL_fr.md @@ -0,0 +1,6 @@ +## Limitations + +- Pleroma doit impérativement s’installer sur son propre **nom de domaine dédié** (ou sous-domaine), par ex. pleroma.domain.tld +- Pleroma nécessite par ailleurs un **certificat SSL** valide activé sur ce domaine. Yunohost peut installer et configurer un **certificat Letsencrypt** pour le domaine depuis l’interface d'administration de Yunohost ou avec la ligne de commande. +- Ce paquet est actuellement configuré pour une **instance unique**, c’est-à-dire que l’on ne peut installer _qu’une seule instance_ de Pleroma sur un même serveur Yunohost. +- Le **mot de passe** saisi durant l’installation ne doit _en aucun cas_ contenir de **caractères spéciaux**. (Voir [issue #132](https://github.com/YunoHost-Apps/pleroma_ynh/issues/132)) diff --git a/manifest.json b/manifest.json deleted file mode 100644 index de13ab8..0000000 --- a/manifest.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "name": "Pleroma", - "id": "pleroma", - "packaging_format": 1, - "description": { - "en": "Federated social networking server built on open protocols", - "fr": "Serveur de réseautage social fédéré basé sur des protocoles ouverts" - }, - "version": "2.5.5~ynh1", - "url": "https://pleroma.social/", - "upstream": { - "license": "AGPL-3.0-only", - "website": "https://pleroma.social/", - "admindoc": "https://docs.pleroma.social/", - "code": "https://git.pleroma.social/pleroma/pleroma/" - }, - "license": "AGPL-3.0-only", - "maintainer": [ - { - "name": "Anmol Sharma", - "email": "anmol@datamol.org" - }, - { - "name": "yalh76" - } - ], - "requirements": { - "yunohost": ">= 4.3.1.8" - }, - "multi_instance": false, - "services": [ - "nginx" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "is_public", - "type": "boolean", - "default": true - }, - { - "name": "admin", - "type": "user" - }, - { - "name": "password", - "type": "password" - }, - { - "name": "name", - "type": "string", - "ask": { - "en": "Choose a name for your Pleroma instance", - "fr": "Choisissez un nom pour votre instance Pleroma" - }, - "example": "My_Pleroma", - "default": "My_Pleroma" - }, - { - "name": "registration", - "type": "boolean", - "ask": { - "en": "Should registration be open to users who do not have a YunoHost account on the system?", - "fr": "L'inscription doit-elle être ouverte aux utilisateurs qui n'ont pas de compte YunoHost sur le système ?" - }, - "default": false - }, - { - "name": "cache", - "type": "boolean", - "ask": { - "en": "Enable media-cache for your instance", - "fr": "Activer le cache média pour votre instance" - }, - "default": true - }, - { - "name": "size", - "type": "string", - "ask": { - "en": "Select the cache size. If you did not enabled media-cache in above option then this option will have no effect", - "fr": "Sélectionner la taille du cache. Si vous n'avez pas activé le cache média ci-dessus, cette option n'aura aucun effet" - }, - "choices": [ - "2g", - "5g", - "10g", - "20g", - "40g", - "80g" - ], - "default": "5g" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..0cc9270 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,115 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "pleroma" +name = "Pleroma" +description.en = "Federated social networking server built on open protocols" +description.fr = "Serveur de réseautage social fédéré basé sur des protocoles ouverts" + +version = "2.5.5~ynh1" + +maintainers = ["Anmol Sharma", "yalh76"] + +[upstream] +license = "AGPL-3.0-only" +website = "https://pleroma.social/" +admindoc = "https://docs.pleroma.social/" +code = "https://git.pleroma.social/pleroma/pleroma/" +cpe = "cpe:2.3:a:kpherox:pleroma" +fund = "https://liberapay.com/Pleroma-euro/" + +[integration] +yunohost = ">=11.2" +architectures = ["amd64", "armhf", "arm64"] +multi_instance = false +ldap = true +sso = false +disk = "200M" +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.domain] + type = "domain" + + [install.init_main_permission] + type = "group" + default = "visitors" + + [install.admin] + type = "user" + + [install.password] + type = "password" + + [install.name] + ask.en = "Choose a name for your Pleroma instance" + ask.fr = "Choisissez un nom pour votre instance Pleroma" + type = "string" + example = "My_Pleroma" + default = "My_Pleroma" + + [install.registration] + ask.en = "Should registration be open to users who do not have a YunoHost account on the system?" + ask.fr = "L'inscription doit-elle être ouverte aux utilisateurs qui n'ont pas de compte YunoHost sur le système ?" + type = "boolean" + default = false + + [install.cache] + ask.en = "Enable media-cache for your instance" + ask.fr = "Activer le cache média pour votre instance" + type = "boolean" + default = true + + [install.size] + ask.en = "Select the cache size. If you did not enabled media-cache in above option then this option will have no effect" + ask.fr = "Sélectionner la taille du cache. Si vous n'avez pas activé le cache média ci-dessus, cette option n'aura aucun effet" + type = "select" + choices = ["2g", "5g", "10g", "20g", "40g", "80g"] + default = "5g" + +[resources] + [resources.sources.main] + amd64.url = "https://git.pleroma.social/pleroma/pleroma/-/jobs/241073/artifacts/download?file_type=archive" + amd64.sha256 = "ce5b861a19a756d3ea26b6e1708c1be954108823d644b1c19036e992c6a6267e" + + armhf.url = "https://git.pleroma.social/pleroma/pleroma/-/jobs/241075/artifacts/download?file_type=archive" + armhf.sha256 = "ff588d370b11939150bd46353274d4b8f879dcfdd87a43eca1bb6fc0a21eec0a" + + arm64.url = "https://git.pleroma.social/pleroma/pleroma/-/jobs/241077/artifacts/download?file_type=archive" + arm64.sha256 = "6841a8d258683a70ba8b4466e502022eda865ddfae1ded415a5d1317f29fae16" + + format = "zip" + extract = true + + [resources.system_user] + + [resources.install_dir] + + [resources.data_dir] + subdirs = [ + "uploads", "static", "static/emoji", + ] + + [resources.permissions] + main.url = "/" + + [resources.ports] + main.default = 8095 + + [resources.apt] + packages = [ + "curl", + "unzip", + "libncurses5", + "imagemagick", + "ffmpeg", + "exiftool", + "libimage-exiftool-perl", + "postgresql", + "postgresql-contrib", + ] + + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index e898399..53cb834 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,13 +4,15 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app (must be on a single line) -pkg_dependencies="curl unzip libncurses5 postgresql postgresql-contrib imagemagick ffmpeg exiftool libimage-exiftool-perl" - #================================================= # PERSONAL HELPERS #================================================= +boolstr() { + bool=("false" "true") + echo "${bool[$1]}" +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 9d07a3b..38ee835 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,29 +10,6 @@ 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 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) -cache=$(ynh_app_setting_get --app=$app --key=cache) -datadir=$(ynh_app_setting_get --app=$app --key=datadir) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -42,37 +19,23 @@ 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 DATA DIR #================================================= -ynh_backup --src_path="$datadir" --is_big +ynh_backup --src_path="$data_dir" --is_big #================================================= -# BACKUP THE NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -if [ $cache -eq 1 ] -then - ynh_backup --src_path="/etc/nginx/conf.d/$app-cache.conf" -fi - -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP SYSTEMD -#================================================= +ynh_backup --src_path="/etc/nginx/conf.d/$app-cache.conf" --not_mandatory ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# BACKUP VARIOUS FILES -#================================================= - ynh_backup --src_path="/etc/$app/" #================================================= diff --git a/scripts/change_url b/scripts/change_url index c5447ea..24cf2f6 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,62 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path="/" - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading settings..." --weight=1 - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -# Add settings here as needed by your application -port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -74,36 +18,14 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" -pkill -u $app || true +pkill -u "$app" || true #================================================= # MODIFY URL IN NGINX CONF #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - -# Change the path in the NGINX config file -if [ $change_path -eq 1 ] -then - # Make a backup of the original NGINX config file if modified - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper - domain="$old_domain" - path_url="$new_path" - # Create a dedicated NGINX config - ynh_add_nginx_config -fi - -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi +ynh_change_url_nginx_config #================================================= # SPECIFIC MODIFICATIONS @@ -124,15 +46,7 @@ ynh_store_file_checksum --file="$config" #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -# Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index e16ba54..09ac792 100755 --- a/scripts/install +++ b/scripts/install @@ -10,234 +10,117 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INITIALIZE AND STORE SETTINGS #================================================= -ynh_clean_setup () { - true -} -# 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="/" -is_public=$YNH_APP_ARG_IS_PUBLIC -admin=$YNH_APP_ARG_ADMIN -password=$YNH_APP_ARG_PASSWORD -name="${YNH_APP_ARG_NAME// /_}" -registration=$YNH_APP_ARG_REGISTRATION -cache=$YNH_APP_ARG_CACHE -size=$YNH_APP_ARG_SIZE +path="/" random_key=$(ynh_string_random --length=64) +ynh_app_setting_set --app="$app" --key=random_key --value="$random_key" signing_salt=$(ynh_string_random --length=8) -admin_email=$(ynh_user_get_info --username=$admin --key="mail") +ynh_app_setting_set --app="$app" --key=signing_salt --value="$signing_salt" +admin_email=$(ynh_user_get_info --username="$admin" --key="mail") +ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email" ## Bypass package_checker name not compatible with pleroma -if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then - admin="test" +if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then + admin="test" fi -app=$YNH_APP_INSTANCE_NAME - #================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 - -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 - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -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=name --value=$name -ynh_app_setting_set --app=$app --key=registration --value=$registration -ynh_app_setting_set --app=$app --key=cache --value=$cache -ynh_app_setting_set --app=$app --key=size --value=$size -ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email -ynh_app_setting_set --app=$app --key=random_key --value=$random_key -ynh_app_setting_set --app=$app --key=signing_salt --value=$signing_salt - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." --weight=1 - -# Find an available port -port=$(ynh_find_port --port=8095) -ynh_app_setting_set --app=$app --key=port --value=$port - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=1 - -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# 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..." --weight=1 - -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_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name - +# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 -ynh_app_setting_set --app=$app --key=final_path --value=$final_path -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$final_path/live" --source_id=$YNH_ARCH +# Download, check integrity, uncompress and patch the source from manifest.toml +ynh_setup_source --dest_dir="$install_dir/live" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" +chown -R "$app:www-data" "$install_dir" #================================================= -# NGINX CONFIGURATION +# UPDATE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=1 +ynh_script_progression --message="Configuring the PostgreSQL database..." --weight=1 -if [ $cache -eq 1 ] -then - ynh_add_config --template="../conf/cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf" +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database="$db_name" +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name" +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database="$db_name" +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database="$db_name" - cat ../conf/media.conf >> ../conf/nginx.conf +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +if [ "$cache" -eq 1 ]; then + ynh_add_config --template="../conf/cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf" + cat ../conf/media.conf >> ../conf/nginx.conf fi - # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# SPECIFIC SETUP -#================================================= -# CREATE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Creating a data directory..." --weight=1 - -datadir=/home/yunohost.app/$app -ynh_app_setting_set --app=$app --key=datadir --value=$datadir - -mkdir -p $datadir -mkdir -p "$datadir/uploads/" -mkdir -p "$datadir/static/" -mkdir -p "$datadir/static/emoji/" - -chmod 750 "$datadir" -chmod -R o-rwx "$datadir" -chown -R $app:$app "$datadir" - -#================================================= -# ADD A CONFIGURATION -#================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 - -config="/etc/$app/config.exs" - -mkdir -p /etc/$app -chown $app:$app /etc/$app - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 - # Create a dedicated systemd config ynh_add_systemd_config +yunohost service add "$app" --description="$app daemon for Pleroma" #================================================= # MAKE SETUP #================================================= ynh_script_progression --message="Making setup..." --weight=1 -pushd $final_path/live - #Generate instance - ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl instance gen --force \ - --output $config \ - --output-psql /tmp/setup_db.psql \ - --domain $domain \ - --instance-name \"$name\" \ - --admin-email $admin_email \ - --notify-email $admin_email \ - --dbhost localhost \ - --dbname $db_name \ - --dbuser $db_user \ - --dbpass $db_pwd \ - --rum N \ - --indexable Y \ - --db-configurable Y \ - --uploads-dir $datadir/uploads \ - --static-dir $datadir/static \ - --listen-ip 127.0.0.1 \ - --listen-port $port \ - --strip-uploads-location Y \ - --read-uploads-description Y \ - --anonymize-uploads Y \ - --dedupe-uploads Y" -popd +config="/etc/$app/config.exs" +mkdir -p "/etc/$app" +chown "$app:$app" "/etc/$app" + +# Generate instance +ynh_exec_warn_less ynh_exec_as "$app" -i \ +"$install_dir/live/bin/pleroma_ctl" instance gen \ + --force \ + --output "$config" \ + --output-psql /tmp/setup_db.psql \ + --domain "$domain" \ + --instance-name "$name" \ + --admin-email "$admin_email" \ + --notify-email "$admin_email" \ + --dbhost localhost \ + --dbname "$db_name" \ + --dbuser "$db_user" \ + --dbpass "$db_pwd" \ + --rum N \ + --indexable Y \ + --db-configurable Y \ + --uploads-dir "$data_dir/uploads" \ + --static-dir "$data_dir/static" \ + --listen-ip 127.0.0.1 \ + --listen-port "$port" \ + --strip-uploads-location Y \ + --read-uploads-description Y \ + --anonymize-uploads Y \ + --dedupe-uploads Y cat "../conf/ldap.exs" >> "$config" -ynh_replace_string --match_string="config :pleroma, configurable_from_database: false" --replace_string="config :pleroma, configurable_from_database: true" --target_file="$config" -registration_bool_value=`(($registration)) && echo "true" || echo "false"` -ynh_replace_string --match_string="registrations_open: true" --replace_string="registrations_open: $registration_bool_value" --target_file="$config" +ynh_replace_string --target_file="$config" \ + --match_string="config :pleroma, configurable_from_database: false" \ + --replace_string="config :pleroma, configurable_from_database: true" -pushd $final_path/live - ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl migrate" +ynh_replace_string --target_file="$config" \ + --match_string="registrations_open: true" \ + --replace_string="registrations_open: $(boolstr "$registration")" - ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" +ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" migrate +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" - # Add user - ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl user new $admin $admin_email --password $password --moderator --admin -y" - - ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd -popd +# Add user +ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" user new "$admin" "$admin_email" --password "$password" --moderator --admin -y +ynh_systemd_action --service_name="$app" --action="stop" --log_path=systemd # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config" chmod 400 "$config" -chown $app:$app "$config" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="$app daemon for Pleroma" +chown "$app:$app" "$config" #================================================= # START SYSTEMD SERVICE @@ -245,32 +128,7 @@ yunohost service add $app --description="$app daemon for Pleroma" ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. - ynh_permission_update --permission="main" --add="visitors" -fi - -# Everyone can access to the api part -# We don't want to display the tile in the sso so we put --show_tile="false" -# And we don't want that the YunoHost Admin can remove visitors group to this permission, so we put --protected="true" -ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" #================================================= # POST INSTALL @@ -278,7 +136,7 @@ ynh_systemd_action --service_name=nginx --action=reload # Correct path to 'static dir' in DB # This must be done when Pleroma is running (i.e. after install and start) -ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl config migrate_to_db" +ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" config migrate_to_db #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index bd52739..bff128e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,118 +10,27 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -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) -datadir=$(ynh_app_setting_get --app=$app --key=datadir) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # 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..." --weight=1 - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + ynh_script_progression --message="Removing $app service integration..." --weight=1 + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" - -pkill -u $app || true - # Remove the dedicated systemd config +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" +pkill -u "$app" || true ynh_remove_systemd_config -#================================================= -# REMOVE THE POSTGRESQL DATABASE -#================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1 - -# Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE DATA DIR -#================================================= - -# Remove the data directory if --purge option is used -if [ "${YNH_APP_PURGE:-0}" -eq 1 ] -then - ynh_script_progression --message="Removing app data directory..." --weight=1 - ynh_secure_remove --file="$datadir" -fi - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 - # Remove the dedicated NGINX config ynh_remove_nginx_config ynh_secure_remove --file="/etc/nginx/conf.d/$app-cache.conf" -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." --weight=1 - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." --weight=1 - -# Remove a directory securely ynh_secure_remove --file="/etc/$app" -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 - -# Delete a system user -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index c21c04e..d6c4a0c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,113 +10,47 @@ 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 settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -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) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -port=$(ynh_app_setting_get --app=$app --key=port) -cache=$(ynh_app_setting_get --app=$app --key=cache) -datadir=$(ynh_app_setting_get --app=$app --key=datadir) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# 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..." --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:$app "$final_path" +chown -R "$app:$app" "$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= ynh_script_progression --message="Restoring the data directory..." --weight=1 -ynh_restore_file --origin_path="$datadir" --not_mandatory +ynh_restore_file --origin_path="$data_dir" --not_mandatory -mkdir -p $datadir -mkdir -p "$datadir/uploads/" -mkdir -p "$datadir/static/" -mkdir -p "$datadir/static/emoji/" - -chmod 750 "$datadir" -chmod -R o-rwx "$datadir" -chown -R $app:$app "$datadir" - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=1 - -# Define and install dependencies -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -if [ $cache -eq 1 ] -then - ynh_restore_file --origin_path="/etc/nginx/conf.d/$app-cache.conf" -fi +chown -R "$app:$app" "$data_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= 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 -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database="$db_name" +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name" +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database="$db_name" +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database="$db_name" ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" +#================================================= +# RESTORE SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$app-cache.conf" --not_mandatory + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable "$app.service" --quiet +yunohost service add "$app" --description="$app daemon for Pleroma" + #================================================= # RESTORE VARIOUS FILES #================================================= @@ -124,36 +58,16 @@ ynh_script_progression --message="Restoring various files..." --weight=1 ynh_restore_file --origin_path="/etc/$app/" chmod 400 "/etc/$app/config.exs" -chown $app:$app "/etc/$app/config.exs" - -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 - -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..." --weight=1 - -yunohost service add $app --description="$app daemon for Pleroma" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" +chown "$app:$app" "/etc/$app/config.exs" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 + +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index d7c3df7..2226b70 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,64 +7,8 @@ #================================================= source _common.sh -source ynh_package_version source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading settings..." --weight=1 - -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) -db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -admin_email=$(ynh_app_setting_get --app=$app --key=admin_email) -random_key=$(ynh_app_setting_get --app=$app --key=random_key) -name=$(ynh_app_setting_get --app=$app --key=name) -port=$(ynh_app_setting_get --app=$app --key=port) -cache=$(ynh_app_setting_get --app=$app --key=cache) -size=$(ynh_app_setting_get --app=$app --key=size) -registration=$(ynh_app_setting_get --app=$app --key=registration) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." --weight=1 - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# CHECK VERSION NUMBER -#================================================= -ynh_script_progression --message="Checking version number..." --weight=1 - -if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then - sleep 60 -fi -abort_if_up_to_date -# previous function is what defines 'version', more precisely the 'previous version' -previous_version="${version}" - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# 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 - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -74,8 +18,8 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" -if ynh_version_gt "${previous_version}" "1.1.1~ynh1" ; then - pkill -u $app || true +if ynh_compare_current_package_version --comparison gt --version "1.1.1~ynh1"; then + pkill -u "$app" || true fi #================================================= @@ -83,158 +27,90 @@ fi #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# 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 a permission if needed -if ! ynh_permission_exists --permission="api"; then - ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true" -fi - -# 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 -fi - -# If db_user doesn't exist, create it -if [ -z "$db_user" ]; then - db_user=$db_name -fi - -# If db_pwd doesn't exist, create it -if [ -z "$db_pwd" ]; then - db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) - ynh_app_setting_set --app=$app --key=psqlpwd --value=$db_pwd -fi - -# Switch variables name -psql_db=$(ynh_app_setting_get --app=$app --key=psql_db) - -if [ -n "$psql_db" ] -then - db_name=$(ynh_app_setting_get --app=$app --key=psql_db) - ynh_app_setting_set --app=$app --key=db_name --value=$db_name - ynh_app_setting_delete --app=$app --key=psql_db +if [ -n "${psql_db:-}" ]; then + ynh_app_setting_delete --app="$app" --key=psql_db fi # Close a port -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port +if yunohost firewall list | grep -q "\- $port$"; then + ynh_script_progression --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP "$port" fi # Remove old repository ynh_secure_remove --file="/etc/apt/sources.list.d/erlang-solutions.list" apt-key del A14F4FCA -# Switch to $final_path/live -if [ ! -d "$final_path/live" ]; then - mv $final_path/$app $final_path/live +# Switch to $install_dir/live +if [ ! -d "$install_dir/live" ]; then + mv "$install_dir/$app" "$install_dir/live" fi -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" - -#================================================= -# UPGRADE TO OTP RELEASE -#================================================= - config="/etc/$app/config.exs" + +# if ynh_compare_current_package_version --comparison gt --version "1.1.1~ynh1"; then if ynh_version_gt "1.1.1~ynh1" "${previous_version}" ; then - ynh_script_progression --message="Upgrading to OTP release..." --weight=1 + ynh_script_progression --message="Upgrading to OTP release..." --weight=1 - # Define app's data directory - datadir="/home/yunohost.app/${app}" - ynh_app_setting_set --app=$app --key=datadir --value="$datadir" + # Give permission to the data_dir + chown -R "$app":"$app" "$data_dir" - # Create app folders - mkdir -p "$datadir/" - mkdir -p "$datadir/uploads/" - mkdir -p "$datadir/static/" - mkdir -p "$datadir/static/emoji/" + rsync -a "$install_dir/live/uploads/" "$data_dir/uploads/" + if [ -d "$install_dir/live/instance/static/" ]; then + rsync -a "$install_dir/live/instance/static/" "$data_dir/static/" + fi + rsync -a "$install_dir/live/priv/static/emoji/" "$data_dir/static/emoji/" - # Give permission to the datadir - chown -R "$app":"$app" "$datadir" + mkdir -p "/etc/$app" + chown -R "$app" "/etc/$app" + mv "$install_dir/live/config/prod.secret.exs" "$config" + ynh_replace_string --target_file="$config" \ + --match_string="use Mix.Config" \ + --replace_string="import Config" + echo "config :pleroma, :instance, static_dir: \"/home/yunohost.app/$app/static\"" >> "$config" + echo "config :pleroma, Pleroma.Uploaders.Local, uploads: \"/home/yunohost.app/$app/uploads\"" >> "$config" - rsync -a "$final_path/live/uploads/" "$datadir/uploads/" - if [ -d "$final_path/live/instance/static/" ]; then - rsync -a "$final_path/live/instance/static/" "$datadir/static/" - fi - - rsync -a "$final_path/live/priv/static/emoji/" "$datadir/static/emoji/" - - mkdir -p /etc/$app - chown -R $app /etc/$app - mv $final_path/live/config/prod.secret.exs $config - ynh_replace_string --match_string="use Mix.Config" --replace_string="import Config" --target_file="$config" - echo "config :pleroma, :instance, static_dir: \"/home/yunohost.app/$app/static\"" >> $config - echo "config :pleroma, Pleroma.Uploaders.Local, uploads: \"/home/yunohost.app/$app/uploads\"" >> $config - - ynh_backup_if_checksum_is_different --file="$config" - - ynh_secure_remove --file="$final_path/live" + ynh_backup_if_checksum_is_different --file="$config" fi +# if ynh_compare_current_package_version --comparison gt --version "2.0.5~ynh1"; then if ynh_version_gt "2.0.5~ynh1" "${previous_version}" ; then - cat "../conf/ldap.exs" >> "$config" - ynh_replace_string --match_string="config :pleroma, configurable_from_database: false" --replace_string="config :pleroma, configurable_from_database: true" --target_file="$config" + cat "../conf/ldap.exs" >> "$config" fi -if ynh_version_gt "2.4.4~ynh2" "${previous_version}"; then - registration_bool_value=`(($registration)) && echo "true" || echo "false"` - ynh_replace_string --match_string='registrations_open: true' --replace_string="registrations_open: $registration_bool_value" --target_file="$config" -fi +ynh_replace_string --target_file="$config" \ + --match_string="config :pleroma, configurable_from_database: false" \ + --replace_string="config :pleroma, configurable_from_database: true" + +ynh_replace_string --target_file="$config" \ + --match_string='registrations_open: true' \ + --replace_string="registrations_open: $(boolstr "$registration")" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=1 +ynh_setup_source --dest_dir="$install_dir/live" --full_replace - ynh_secure_remove --file="$final_path/live" - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path/live" --source_id=$YNH_ARCH +chown -R "$app:$app" "$install_dir" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +if [ "$cache" -eq 1 ]; then + ynh_add_config --template="../conf/cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf" + cat ../conf/media.conf >> ../conf/nginx.conf fi - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=1 - -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 - -if [ $cache -eq 1 ] -then - ynh_add_config --template="../conf/cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf" - - cat ../conf/media.conf >> ../conf/nginx.conf -fi - # Create a dedicated NGINX config ynh_add_nginx_config +# Create a dedicated systemd config +ynh_add_systemd_config +yunohost service add "$app" --description="$app daemon for Pleroma" + #================================================= # SPECIFIC UPGRADE #================================================= @@ -242,9 +118,7 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Making upgrade..." --weight=1 -pushd $final_path/live - ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl migrate" -popd +ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" migrate #================================================= # UPDATE A CONFIG FILE @@ -256,38 +130,14 @@ config="/etc/$app/config.exs" ynh_backup_if_checksum_is_different --file="$config" chmod 400 "$config" -chown $app:$app "$config" - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 - -# Create a dedicated systemd config -ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="$app daemon for Pleroma" +chown "$app:$app" "$config" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" #================================================= # END OF SCRIPT diff --git a/scripts/ynh_package_version b/scripts/ynh_package_version deleted file mode 100644 index 0887f5f..0000000 --- a/scripts/ynh_package_version +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -read_json () { - sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" -} - -read_manifest () { - if [ -f '../manifest.json' ] ; then - read_json '../manifest.json' "$1" - else - read_json '../settings/manifest.json' "$1" - fi -} -abort_if_up_to_date () { - version=$(read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" 'version' 2> /dev/null || echo '20160501-7') - last_version=$(read_manifest 'version') - if [ "${version}" = "${last_version}" ] && [ "$YNH_APP_UPGRADE_TYPE" != "UPGRADE_FORCED" ]; then - ynh_print_info "Up-to-date, nothing to do" - ynh_die "" 0 - fi -} - -ynh_version_gt () -{ - dpkg --compare-versions "$1" gt "$2" -} diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..6df4ead --- /dev/null +++ b/tests.toml @@ -0,0 +1,8 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + test_upgrade_from.e6d9935af254018baf326281662c55407170694d.name = "2.4.1" + test_upgrade_from.ba16bc8bee7715c479a7ee575ec5f7d9970a84f8.name = "2.4.3"