diff --git a/README.md b/README.md new file mode 100644 index 0000000..040bf1e --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ + + +# Bonfire for YunoHost + +[![Integration level](https://dash.yunohost.org/integration/bonfire.svg)](https://dash.yunohost.org/appci/app/bonfire) ![Working status](https://ci-apps.yunohost.org/ci/badges/bonfire.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/bonfire.maintain.svg) + +[![Install Bonfire with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=bonfire) + +*[Lire ce readme en français.](./README_fr.md)* + +> *This package allows you to install Bonfire 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 + +Federated social networking server built on ActivityPub open protocol + +**Shipped version:** 0.9.8-beta.26~ynh2 + +**Demo:** https://playground.bonfire.cafe/ +## Documentation and resources + +* Official app website: +* Official user documentation: +* Official admin documentation: +* Upstream app code repository: +* YunoHost Store: +* Report a bug: + +## Developer info + +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/bonfire_ynh/tree/testing). + +To try the testing branch, please proceed like that. + +``` bash +sudo yunohost app install https://github.com/YunoHost-Apps/bonfire_ynh/tree/testing --debug +or +sudo yunohost app upgrade bonfire -u https://github.com/YunoHost-Apps/bonfire_ynh/tree/testing --debug +``` + +**More info regarding app packaging:** diff --git a/README_fr.md b/README_fr.md new file mode 100644 index 0000000..32e4c56 --- /dev/null +++ b/README_fr.md @@ -0,0 +1,45 @@ + + +# Bonfire pour YunoHost + +[![Niveau d’intégration](https://dash.yunohost.org/integration/bonfire.svg)](https://dash.yunohost.org/appci/app/bonfire) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/bonfire.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/bonfire.maintain.svg) + +[![Installer Bonfire avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=bonfire) + +*[Read this readme in english.](./README.md)* + +> *Ce package vous permet d’installer Bonfire 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 + +Serveur de réseautage social fédéré basé sur le protocole ouvert ActivityPub + +**Version incluse :** 0.9.8-beta.26~ynh2 + +**Démo :** https://playground.bonfire.cafe/ +## Documentations et ressources + +* Site officiel de l’app : +* Documentation officielle utilisateur : +* Documentation officielle de l’admin : +* Dépôt de code officiel de l’app : +* YunoHost Store: +* Signaler un bug : + +## Informations pour les développeurs + +Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/bonfire_ynh/tree/testing). + +Pour essayer la branche testing, procédez comme suit. + +``` bash +sudo yunohost app install https://github.com/YunoHost-Apps/bonfire_ynh/tree/testing --debug +ou +sudo yunohost app upgrade bonfire -u https://github.com/YunoHost-Apps/bonfire_ynh/tree/testing --debug +``` + +**Plus d’infos sur le packaging d’applications :** \ No newline at end of file diff --git a/conf/.env b/conf/.env new file mode 100644 index 0000000..0c1fcbd --- /dev/null +++ b/conf/.env @@ -0,0 +1,84 @@ +MIX_ENV=prod +FLAVOUR=classic + +WITH_DOCKER=no + +## OTHER CONFIG ## +# server domain name: +HOSTNAME=__DOMAIN__ +# server port: +SERVER_PORT=__PORT__ +# port your visitors will access (typically 80 or 443, will be different than SERVER_PORT only if using a reverse proxy) +PUBLIC_PORT=443 +# hostname and port of meili search index +SEARCH_MEILI_INSTANCE=http://localhost:7700 +# require an email address to be invited before being able to sign up +INVITE_ONLY=true + +# uncomment in order to NOT automatically change the database schema when you upgrade the app +# DISABLE_DB_AUTOMIGRATION=true +# max file upload size (default is 20 meg) +UPLOAD_LIMIT=__MEDIA_UPLOAD_SIZE__ +# ==================================== +# You should not have to edit any of the following ones: +POSTGRES_HOST=localhost +LANG=en_US.UTF-8 +LANGUAGE=en_US.UTF-8 +REPLACE_OS_VARS=true +LIVEVIEW_ENABLED=true +POSTGRES_USER=__APP__ +POSTGRES_DB=__APP__ +ACME_AGREE=true +SHOW_DEBUG_IN_DEV=true +# PLUG_SERVER=bandit +## SECRETS ## +# make sure you change everything to your own secrets! +# and do not check this into git or any public host + +# for sessions/cookies, you can generate strings for these by running: just secrets +SECRET_KEY_BASE=__SECRET_KEY_BASE__ +SIGNING_SALT=__SIGNING_SALT__ +ENCRYPTION_SALT=__ENCRYPTION_SALT__ + +# database access +POSTGRES_PASSWORD=__DB_PWD__ + +# password for the search index +MEILI_MASTER_KEY=__MEILI_MASTER_KEY__ + +# what service to use for sending out emails (eg. smtp, mailgun, none) NOTE: you should also set the corresponding keys in secrets section +MAIL_BACKEND=smtp +MAIL_DOMAIN=__DOMAIN__ +MAIL_PASSWORD=__MAIL_PWD__ +MAIL_USER=__APP__ +MAIL_SERVER=__DOMAIN__ +MAIL_PORT=587 + +# TODO : Configure S3 - with proper Yunohost question during installation +# Uploads +# UPLOADS_S3_BUCKET= +# UPLOADS_S3_ACCESS_KEY_ID= +# UPLOADS_S3_SECRET_ACCESS_KEY= + +# telemetry API keys +# SENTRY_DSN= +OTEL_ENABLED=0 +# OTEL_HONEYCOMB_API_KEY= +# OTEL_LIGHTSEP_API_KEY= + +# default admin user if you generate seed data +SEEDS_USER=root + +# backend stuff +ERLANG_COOKIE=bonfire_cookie + +# Bonfire extensions configs +WEB_PUSH_SUBJECT=mailto:__APP__@__DOMAIN__ +WEB_PUSH_PUBLIC_KEY= +WEB_PUSH_PRIVATE_KEY= +GEOLOCATE_OPENCAGEDATA= +MAPBOX_API_KEY=pk.eyJ1IjoibWF5ZWwiLCJhIjoiY2tlMmxzNXF5MGFpaDJ0bzR2M29id2EzOCJ9.QsmjD-zypsE0_wonLGCYlA +GITHUB_TOKEN= +TX_TOKEN= + +## END OF SECRETS ## diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..2670423 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,27 @@ +location @app_upstream { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + proxy_pass http://127.0.0.1:__PORT__; + proxy_redirect off; + proxy_read_timeout 240s; +} + +location __PATH__/ { + + root /var/www/bonfire/_build/prod/rel/bonfire/lib/bonfire-0.9.8-classic-beta.26/priv/static; + + index index.html; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; + + + try_files $uri $uri.html $uri/index.html $uri/ @app_upstream; + +} diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..67de51f --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,52 @@ +[Unit] +Description=Bonfire daemon +After=network.target + +[Service] +Type=simple +User=__APP__ +Group=__APP__ +WorkingDirectory=__INSTALL_DIR__/ +Environment=NODE_ENV=production +Environment="__YNH_NODE_LOAD_PATH__" +ExecStart=just cmd __INSTALL_DIR__/_build/prod/rel/bonfire/bin/bonfire start daemon +StandardOutput=append:/var/log/__APP__/__APP__.log +StandardError=inherit + +# Sandboxing options to harden security +# Depending on specificities of your service/app, you may need to tweak these +# .. but this should be a good baseline +# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html +NoNewPrivileges=yes +PrivateTmp=yes +PrivateDevices=yes +RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK +RestrictNamespaces=yes +RestrictRealtime=yes +DevicePolicy=closed +ProtectClock=yes +ProtectHostname=yes +ProtectProc=invisible +ProtectSystem=full +ProtectControlGroups=yes +ProtectKernelModules=yes +ProtectKernelTunables=yes +LockPersonality=yes +SystemCallArchitectures=native +SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap @cpu-emulation @privileged + +# Denying access to capabilities that should not be relevant for webapps +# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html +CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD +CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE +CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT +CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK +CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM +CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG +CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE +CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW +CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG + +[Install] +WantedBy=multi-user.target + diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..e69de29 diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..f803f86 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,145 @@ +packaging_format = 2 + +id = "bonfire" +name = "Bonfire" + +version = "0.9.8-beta.26~ynh2" + +maintainers = ["Lapineige"] + +[description] +en = "Federated social networking server built on ActivityPub open protocol" +fr = "Serveur de réseautage social fédéré basé sur le protocole ouvert ActivityPub" + +[upstream] +license = "AGPL-3.0-only" +website = "https://bonfirenetworks.org/" +demo = "https://playground.bonfire.cafe/" +admindoc = "https://bonfirenetworks.org/docs/" +userdoc = "https://bonfirenetworks.org/docs/" +code = "https://github.com/bonfire-networks/bonfire-app" + +[integration] +yunohost = ">= 11.1.18" +multi_instance = false +architectures = "all" +ldap = false +sso = false +disk = "2000M" +ram.build = "1500M" +ram.runtime = "500M" + +[install] + [install.domain] + type = "domain" + help.en = "The domain name to use. Bonfire will be installed at its root path (/). This can't be changed." + help.fr = "Nom de domaine à utiliser. Bonfire sera installé à sa racine (/). Cela ne pourra pas être changé." + + [install.is_public] + type = "boolean" + default = true + help.en = "Should that instance be visible to the fediverse ? It is required for federation." + help.fr = "Cette instance doit elle être visible sur le fédiverse? C'est nécessaire pour la fédération." + + [install.init_main_permission] + type = "group" + default = "visitors" + + [install.language] + ask.en = "Choose the application language" + ask.fr = "Choisissez la langue de l'application" + type = "select" + choices = ["fr", "en"] + default = "fr" + + [install.admin] + type = "user" + + [install.password] + help.en = "Use the help field to add an information for the admin about this question." + help.fr = "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question." + type = "password" + + [install.media_upload_size] + ask.en = "Choose the maximum size of the media uploaded. Can be changed later." + ask.fr = "Choisissez la taille maximale des médias mis en ligne. Peut-être modifié ultérieurement." + type = "select" + choices = [ + "1MB", + "2MB", + "5MB", + "10MB", + "15MB", + "20MB", + "35MB", + "50MB", + "70MB", + "100MB", + "150MB" + ] + default = "35MB" + +[resources] + + #[resources.data_dir] + # This will create/remove the data dir as /home/yunohost.app/$app + # and store the corresponding setting $data_dir + #TODO + + [resources.sources] + + [resources.sources.main] + url = "https://github.com/bonfire-networks/bonfire-app/archive/289ad2d8b57a2ce9a7ce609f000b1ac5d887e7a0.tar.gz" + sha256 = "5b79032647f9fd95465692d1de48839359dfa532a72c727f76bf03a1b68e8cdd" + + [resources.ports] + + [resources.system_user] + allow_email = true + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + + [resources.apt] + packages = "erlang-dev erlang-parsetools erlang-os-mon erlang-tools erlang-xmerl postgresql npm node-postcss" + + ##### (this part is optional and corresponds to the legacy ynh_install_extra_app_dependencies helper) + + ### Yarn dependency (correct version) + extras.yarn.repo = "deb https://dl.yarnpkg.com/debian/ stable main" + extras.yarn.key = "https://dl.yarnpkg.com/debian/pubkey.gpg" + extras.yarn.packages = ["yarn"] + + + ### Elixir 13 dependency - instead of v15 for now + extras.elixir13.repo = "deb https://packages.erlang-solutions.com/debian bullseye contrib" + extras.elixir13.key = "https://packages.erlang-solutions.com/debian/erlang_solutions.asc" + extras.elixir13.packages = ["elixir"] + ### Elixir 15 dependency + # Bulleyes comes with v1.10 instead of v1.15 that is required + # ynh_install_extra_app_dependencies --repo="https://packages.erlang-solutions.com/debian bullseye contrib" --package="elixir-lang" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc' + # v15 is not available in default repo. RabbitMQ repo should be used (https://elixir-lang.org/install.html). No debian simple syntax. TODO later, using the simple syntax for now + # erlang 26, for elixir v1.15 + #extras.elixir15.repo = "deb https://ppa.launchpadcontent.net/rabbitmq/rabbitmq-erlang/ubuntu jammy main" + #extras.elixir15.key = "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xb279943d2a549531e144b875f77f1eda57ebb1cc" + #extras.elixir15.packages = ["elixir"] + # exlang-dev -> https://github.com/elixir-lang/ex_doc/pull/1442/files # Debian default package is newer (enough), don't use this custom repo + ### Elixir 15 with mise + #extras.mise.repo = "deb https://mise.jdx.dev/deb stable main" + #extras.mise.key = "https://mise.jdx.dev/gpg-key.pub" + #extras.mise.packages = ["mise"] + + ### just dependency + # TODO : this is unsafe and should be dealt with in a better way. + # There is currently no proper way to install it simply on Debian 11 https://github.com/casey/just#packages + # only works for x86, we need to switch to the other option with makedeb package ? + extras.just.repo = "deb https://proget.makedeb.org prebuilt-mpr bullseye" + extras.just.key = "https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub" + extras.just.packages = ["just"] + + + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..9195d57 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= + +nodejs_version=18 + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..69055c4 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,41 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup --src_path="$install_dir" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# BACKUP THE POSTGRESQL DATABASE +#================================================= +ynh_print_info --message="Backing up the PostgreSQL database..." + +ynh_psql_dump_db --database="$db_name" > db.sql + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..13d202b --- /dev/null +++ b/scripts/install @@ -0,0 +1,118 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing nodejs..." + +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_use_nodejs + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Setting up source files..." --weight=1 + +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" + +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring NGINX web server..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +#================================================= +# ADD A CONFIGURATION +#================================================= +## Generate secrets and other config values +secret_key_base=$(ynh_string_random --length=50) +signing_salt=$(ynh_string_random --length=50) +encryption_salt=$(ynh_string_random --length=50) +# search +meili_master_key=$(ynh_string_random --length=50) +# max file upload size +MEDIA_UPLOAD_SIZE="${media_upload_size//[!0-9]/}000000" + +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" +ynh_store_file_checksum --file="$install_dir/.env" + +chmod 400 "$install_dir/.env" +chown $app:$app "$install_dir/.env" + +#================================================= +# SPECIFIC SETUP +#================================================= + +source $install_dir/.env +export WITH_DOCKER=no # or source .env ? # Using this for now + +ynh_script_progression --message="Configuring Bonfire release..." --weight=1 +cd $install_dir +#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "mise plugin add erlang https://github.com/asdf-vm/asdf-erlang.git" # add erlang as source +#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "mise install" # install Elixir +ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no $ynh_node_load_PATH mix local.hex --force" # install Hex in non-interractive way +ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no $ynh_node_load_PATH just config-basic" +#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no $ynh_node_load_PATH just mix bonfire.deps .update" + +#================================================= +# Building the release +#================================================= +ynh_script_progression --message="Building Bonfire release... (This will take a long time)" --weight=1 +export TERM=linux # why is that not defined ? +export TERMINFO=/etc/terminfo +### DONT USE GLOBAL NPM INSTALL +ynh_replace_string --match_string="npm install --global" --replace_string="npm install" --target_file="$install_dir/justfile" +ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no $ynh_node_load_PATH just rel-build" + +#================================================= +# START SYSTEMD SERVICE - Run the release +#================================================= +release_folder="_build/prod/rel/bonfire" + +### Not running the migration, they are done on startup anyway +#ynh_script_progression --message="Running database migrations..." --weight=1 +## Database created before, let's run the migrations +#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no just cmd $release_folder/bin/bonfire eval 'EctoSparkles.Migrator.migrate()'" + +#ynh_script_progression --message="Starting Bonfire..." --weight=1 +#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no just cmd $release_folder/bin/bonfire start" + +mkdir -p "/var/log/$app" +chown -R $app:$app "/var/log/$app" + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate + +# Create a dedicated systemd config +ynh_add_systemd_config + +yunohost service add $app --description="Bonfire daemon" --log="/var/log/$app/$app.log" + +ynh_script_progression --message="Starting Bonfire daemon service..." --weight=1 + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="[info] Running Bonfire.Web.Endpoint" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --weight=1 +ynh_script_progression --message="Now you need to sign-up, the first account will automatically be admin." --last diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..35decdd --- /dev/null +++ b/scripts/remove @@ -0,0 +1,47 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# REMOVE DEDICATED USER +#================================================= +ynh_script_progression --message="Stoping Bonfire..." --weight=1 + +# stop bonfire daemon +"$release_folder/bin/bonfire stop" + + + +#================================================= +# REMOVE SYSTEM CONFIGURATIONS SERVICE +#================================================= +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 +fi + +ynh_remove_systemd_config +ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 + +# Remove the dedicated NGINX config +ynh_remove_nginx_config + +ynh_remove_logrotate +ynh_secure_remove --file="/var/log/$app" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..868ff95 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,67 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=1 + +ynh_restore_file --origin_path="$install_dir" + +chown -R $app:www-data "$install_dir" + +#================================================= +# RESTORE THE POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 + +ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + +#================================================= +# 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/systemd/system/$app.service" +systemctl enable $app.service --quiet + +mkdir -p "/var/log/$app" +chown -R $app:$app "/var/log/$app" +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + +yunohost service add $app --description="Bonfire daemon" --log="/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting Bonfire daemon service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="[info] Running Bonfire.Web.Endpoint" + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE +#================================================= +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..66c276c --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,90 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" + +#================================================= +# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +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="$install_dir" +fi + +chown -R $app:www-data "$install_dir" + +#================================================= +# Building the release +#================================================= +ynh_script_progression --message="Building Bonfire release... (This will take a long time)" --weight=1 +export TERM=linux # why is that not defined ? +export TERMINFO=/etc/terminfo +### DONT USE GLOBAL NPM INSTALL +ynh_replace_string --match_string="npm install --global" --replace_string="npm install" --target_file="$install_dir/justfile" +ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no $ynh_node_load_PATH just rel-build" + +#================================================= +# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file... (this will remove any manual change you could have made before)" --weight=1 + +ynh_add_config --template=".env" --destination="$install_dir/.env" + +chmod 400 "$install_dir/.env" +chown $app:$app "$install_dir/.env" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS + Run the service +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +# Create a dedicated systemd config +ynh_add_systemd_config + +mkdir -p "/var/log/$app" +chown -R $app:$app "/var/log/$app" + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +# Create a dedicated systemd config +ynh_add_systemd_config + +yunohost service add $app --description="Bonfire daemon" --log="/var/log/$app/$app.log" + +ynh_script_progression --message="Starting Bonfire daemon service..." --weight=1 + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="[info] Running Bonfire.Web.Endpoint" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..eb73b8d --- /dev/null +++ b/tests.toml @@ -0,0 +1,3 @@ +test_format = 1.0 + +[default] \ No newline at end of file