From c3feeb37a50a708af7c2710da7dd131ca6d36d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 22 Jun 2023 09:23:53 +0200 Subject: [PATCH] v2 --- conf/bitwarden_migration | 15 -- conf/bitwarden_post_migration.sh | 38 ---- conf/nginx.conf | 6 +- conf/systemd.service | 2 +- conf/vaultwarden.env | 4 +- doc/{DISCLAIMER.md => ADMIN.md} | 0 doc/POST_INSTALL.md | 3 + manifest.json | 52 ------ manifest.toml | 36 ++-- scripts/_common.sh | 3 - scripts/backup | 21 --- scripts/change_url | 91 ---------- scripts/install | 115 +----------- scripts/remove | 48 ----- scripts/restore | 55 ------ scripts/upgrade | 145 +-------------- scripts/ynh_handle_app_migration | 265 ---------------------------- scripts/ynh_send_readme_to_admin__2 | 129 -------------- tests.toml | 0 19 files changed, 38 insertions(+), 990 deletions(-) delete mode 100644 conf/bitwarden_migration delete mode 100644 conf/bitwarden_post_migration.sh rename doc/{DISCLAIMER.md => ADMIN.md} (100%) create mode 100644 doc/POST_INSTALL.md delete mode 100644 manifest.json delete mode 100644 scripts/ynh_handle_app_migration delete mode 100644 scripts/ynh_send_readme_to_admin__2 create mode 100644 tests.toml diff --git a/conf/bitwarden_migration b/conf/bitwarden_migration deleted file mode 100644 index f5f4468..0000000 --- a/conf/bitwarden_migration +++ /dev/null @@ -1,15 +0,0 @@ -# App main directory -/var/www/$app - -# NGINX web server configuration -/etc/nginx/conf.d/$domain.d/$app.conf - -# App logs -/var/log/$app/ - -# Service configuration -/etc/systemd/system/$app.service - -# Fail2Ban configuration -/etc/fail2ban/jail.d/$app.conf -/etc/fail2ban/filter.d/$app.conf diff --git a/conf/bitwarden_post_migration.sh b/conf/bitwarden_post_migration.sh deleted file mode 100644 index 15c8f53..0000000 --- a/conf/bitwarden_post_migration.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -# Ending the migration process from Bitwarden to Vaultwarden - -set -u - -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source /usr/share/yunohost/helpers - -#================================================= -# SET VARIABLES -#================================================= - -old_app="__OLD_APP__" -new_app="__NEW_APP__" -script_name="$0" - -#================================================= -# DELETE OLD APP'S SETTINGS -#================================================= - -ynh_secure_remove --file="/etc/yunohost/apps/$old_app" -yunohost app ssowatconf - -#================================================= -# REMOVE THE OLD USER -#================================================= - -ynh_system_user_delete --username="$old_app" - -#================================================= -# DELETE THIS SCRIPT -#================================================= - -echo "rm $script_name" | at now + 1 minutes \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index f1961f5..4c1afff 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -11,7 +11,7 @@ location __PATH__/ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass http://127.0.0.1:__ROCKET_PORT__; + proxy_pass http://127.0.0.1:__PORT_ROCKET__; # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; @@ -23,9 +23,9 @@ location __INSTALL_DIR__/notifications/hub { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; - proxy_pass http://127.0.0.1:__WEBSOCKET_PORT__; + proxy_pass http://127.0.0.1:__PORT_WEBSOCKET__; } location __INSTALL_DIR__/notifications/hub/negotiate { - proxy_pass http://127.0.0.1:__ROCKET_PORT__; + proxy_pass http://127.0.0.1:__PORT_ROCKET__; } \ No newline at end of file diff --git a/conf/systemd.service b/conf/systemd.service index 6d063e0..78f5103 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,5 +1,5 @@ [Unit] -Description=vaultwarden Server (Rust Edition) +Description=Vaultwarden Server (Rust Edition) Documentation=https://github.com/dani-garcia/vaultwarden After=network.target diff --git a/conf/vaultwarden.env b/conf/vaultwarden.env index 53cda3b..b2158c2 100644 --- a/conf/vaultwarden.env +++ b/conf/vaultwarden.env @@ -69,7 +69,7 @@ WEBSOCKET_ENABLED=true ## Controls the WebSocket server address and port WEBSOCKET_ADDRESS=127.0.0.1 -WEBSOCKET_PORT=__WEBSOCKET_PORT__ +WEBSOCKET_PORT=__PORT_WEBSOCKET__ ## Controls whether users are allowed to create Bitwarden Sends. ## This setting applies globally to all users. @@ -337,7 +337,7 @@ DOMAIN=https://__DOMAIN____PATH__ ## Rocket specific settings ## See https://rocket.rs/v0.4/guide/configuration/ for more details. ROCKET_ADDRESS=127.0.0.1 -ROCKET_PORT=__ROCKET_PORT__ +ROCKET_PORT=__PORT_ROCKET__ ROCKET_WORKERS=1 # ROCKET_TLS={certs="/path/to/certs.pem",key="/path/to/key.pem"} diff --git a/doc/DISCLAIMER.md b/doc/ADMIN.md similarity index 100% rename from doc/DISCLAIMER.md rename to doc/ADMIN.md diff --git a/doc/POST_INSTALL.md b/doc/POST_INSTALL.md new file mode 100644 index 0000000..7398bbb --- /dev/null +++ b/doc/POST_INSTALL.md @@ -0,0 +1,3 @@ +Please open https://__DOMAIN____PATH__/admin +The admin token is: __ADMIN_TOKEN__ +You will be able to invite users to your vaultwarden instance. diff --git a/manifest.json b/manifest.json deleted file mode 100644 index cc749eb..0000000 --- a/manifest.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "name": "Vaultwarden", - "id": "vaultwarden", - "packaging_format": 1, - "description": { - "en": "Manage passwords and other sensitive informations", - "fr": "Gérez les mots de passe et autres informations sensibles" - }, - "version": "1.28.1~ynh1", - "url": "https://github.com/dani-garcia/vaultwarden", - "upstream": { - "license": "GPL-3.0-or-later", - "demo": "https://vault.bitwarden.com/#/register", - "admindoc": "https://github.com/dani-garcia/vaultwarden/wiki", - "userdoc": "https://help.bitwarden.com/", - "code": "https://github.com/dani-garcia/vaultwarden" - }, - "license": "GPL-3.0-or-later", - "maintainer": { - "name": "yalh76" - }, - "requirements": { - "yunohost": ">= 11.0.0" - }, - "multi_instance": true, - "services": [ - "nginx" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "path", - "type": "path", - "example": "/vaultwarden", - "default": "/vaultwarden" - }, - { - "name": "is_public", - "type": "boolean", - "default": true - }, - { - "name": "admin", - "type": "user" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml index d9e2ded..a93a965 100644 --- a/manifest.toml +++ b/manifest.toml @@ -16,26 +16,22 @@ admindoc = "https://github.com/dani-garcia/vaultwarden/wiki" userdoc = "https://help.bitwarden.com/" code = "https://github.com/dani-garcia/vaultwarden" website = "https://github.com/dani-garcia/vaultwarden" -cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number) -fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin. [integration] -yunohost = ">= 11.0.0" -architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +yunohost = ">= 11.1.21" +architectures = "all" multi_instance = true -ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials. -sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal. -disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... -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, ... +ldap = false +sso = false +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" [install] [install.domain] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "domain" [install.path] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "path" default = "/vaultwarden" @@ -44,10 +40,14 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen default = "visitors" [install.admin] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "user" [resources] + + [resources.ports] + websocket.default = 3012 + rocket.default = 8095 + [resources.system_user] [resources.install_dir] @@ -56,3 +56,15 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen [resources.permissions] main.url = "/" + api.url = "/api" + api.additional_urls = "/identity/connect/token" + api.allowed = "visitors" + api.auth_header = false + api.show_tile = false + api.protected = true + admin.url = "/admin" + admin.allowed = "admins" + admin.show_tile = false + + [resources.apt] + packages = "libpq5" diff --git a/scripts/_common.sh b/scripts/_common.sh index e11b899..ce03ddd 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,6 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -#REMOVEME? pkg_dependencies="libpq5" - pkg_image="vaultwarden/server" #================================================= diff --git a/scripts/backup b/scripts/backup index 6d02ff2..56012c0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -10,27 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_print_info --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= diff --git a/scripts/change_url b/scripts/change_url index e5e2fe2..828f8de 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,66 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN -#REMOVEME? old_path=$YNH_APP_OLD_PATH - -#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN -#REMOVEME? new_path=$YNH_APP_NEW_PATH - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? # Needed for helper "ynh_add_nginx_config" -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) - -# Add settings here as needed by your application -#REMOVEME? #db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#db_user=$db_name -#REMOVEME? #db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) -#REMOVEME? rocket_port=$(ynh_app_setting_get --app=$app --key=rocket_port) -#REMOVEME? websocket_port=$(ynh_app_setting_get --app=$app --key=websocket_port) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. -#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -#REMOVEME? change_domain=0 -#REMOVEME? if [ "$old_domain" != "$new_domain" ] -then - #REMOVEME? change_domain=1 -fi - -#REMOVEME? change_path=0 -#REMOVEME? if [ "$old_path" != "$new_path" ] -then - #REMOVEME? change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -85,30 +25,6 @@ ynh_script_progression --message="Updating NGINX web server configuration..." ynh_change_url_nginx_config -#REMOVEME? 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 -#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper -#REMOVEME? domain="$old_domain" -#REMOVEME? path="$new_path" - # Create a dedicated NGINX config -#REMOVEME? 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 -#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path" -#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location -#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi - #================================================= # SPECIFIC MODIFICATIONS #================================================= @@ -135,13 +51,6 @@ ynh_script_progression --message="Starting a systemd service..." # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Rocket has launched from" --length=100 -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." - -#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index ba96d81..b7c4f4f 100644 --- a/scripts/install +++ b/scripts/install @@ -8,90 +8,27 @@ source _common.sh source ynh_docker_image_extract -source ynh_send_readme_to_admin__2 source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -#REMOVEME? domain=$YNH_APP_ARG_DOMAIN -#REMOVEME? path=$YNH_APP_ARG_PATH -#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC -#REMOVEME? admin=$YNH_APP_ARG_ADMIN - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - admin_mail=$(ynh_user_get_info --username=$admin --key=mail) admin_token=$(ynh_string_random --length=48 | base64) -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -#REMOVEME? ynh_script_progression --message="Validating installation parameters..." - -#REMOVEME? install_dir=/var/www/$app -#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path - #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -#REMOVEME? ynh_script_progression --message="Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." -#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain -#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path -#REMOVEME? ynh_app_setting_set --app=$app --key=admin --value=$admin -#REMOVEME? ynh_app_setting_set --app=$app --key=admin_token --value=$admin_token - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -#REMOVEME? ynh_script_progression --message="Finding an available port..." - -# Find an available port -#REMOVEME? websocket_port=$(ynh_find_port --port=3012) -#REMOVEME? ynh_app_setting_set --app=$app --key=websocket_port --value="$websocket_port" - -# Find an available port -#REMOVEME? rocket_port=$(ynh_find_port --port=8095) -#REMOVEME? ynh_app_setting_set --app=$app --key=rocket_port --value="$rocket_port" - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Installing dependencies..." - -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Configuring system user..." - -# Create a system user -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" +ynh_app_setting_set --app=$app --key=admin_token --value=$admin_token #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." -#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir # Download, check integrity, uncompress and patch the source from app.src docker_arg="" if [ $YNH_ARCH == "armhf" ] @@ -113,22 +50,6 @@ ynh_script_progression --message="Configuring NGINX web server..." # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# SPECIFIC SETUP -#================================================= -# CREATE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Creating a data directory..." - -#REMOVEME? data_dir=/home/yunohost.app/$app -#REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir - -mkdir -p $data_dir - -chmod 750 "$data_dir" -chmod -R o-rwx "$data_dir" -chown -R $app:$app "$data_dir" - #================================================= # MAKE INSTALL #================================================= @@ -136,7 +57,7 @@ ynh_script_progression --message="Making install..." mv -f "$install_dir/build/vaultwarden" "$install_dir/live/vaultwarden" rsync -a "$install_dir/build/web-vault/" "$install_dir/live/web-vault/" -#REMOVEME? ynh_secure_remove --file="$install_dir/build" +ynh_secure_remove --file="$install_dir/build" chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" @@ -198,36 +119,6 @@ touch "/var/log/$app/$app.log" chown -R $app:$app "/var/log/$app" ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex="^.*Username or password is incorrect\. Try again\. IP: \. Username:.*$" -#================================================= -# SETUP SSOWAT -#================================================= -#REMOVEME? ynh_script_progression --message="Configuring permissions..." - -# Make app public if necessary -#REMOVEME? if [ $is_public -eq 1 ] -then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. -#REMOVEME? ynh_permission_update --permission="main" --add="visitors" -fi - -#REMOVEME? ynh_permission_create --permission="api" --url="/api" --additional_urls="/identity/connect/token" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true" -#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --allowed="$admin" --show_tile="false" - -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." - -#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - -#================================================= -# SEND A README FOR THE ADMIN -#================================================= -ynh_script_progression --message="Sending a readme for the admin..." - -ynh_send_readme_to_admin --app_message="../conf/msg_install" --recipients="$admin_mail" --type='install' - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index 5b04b54..0d6e071 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,17 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir) - #================================================= # STANDARD REMOVE #================================================= @@ -41,25 +30,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE APP MAIN DIR -#================================================= -#REMOVEME? ynh_script_progression --message="Removing app main directory..." - -# Remove the app directory securely -#REMOVEME? ynh_secure_remove --file="$install_dir" - -#================================================= -# 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..." -#REMOVEME? ynh_secure_remove --file="$data_dir" -fi - #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -68,14 +38,6 @@ ynh_script_progression --message="Removing NGINX web server configuration..." # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Removing dependencies..." - -# Remove metapackage and its dependencies -#REMOVEME? ynh_remove_app_dependencies - #================================================= # REMOVE FAIL2BAN CONFIGURATION #================================================= @@ -94,16 +56,6 @@ ynh_script_progression --message="Removing various files..." # Remove the log files ynh_secure_remove --file="/var/log/$app" -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -#REMOVEME? ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 01f271b..5ec75a6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,46 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." - -#REMOVEME? test ! -d $install_dir \ - || ynh_die --message="There is already a directory: $install_dir " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir=$install_dir - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -57,7 +17,6 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$install_dir" -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:$app "$install_dir" @@ -68,10 +27,6 @@ ynh_script_progression --message="Restoring the data directory..." ynh_restore_file --origin_path="$data_dir" --not_mandatory -mkdir -p $data_dir - -chmod 750 "$data_dir" -chmod -R o-rwx "$data_dir" chown -R $app:$app "$data_dir" #================================================= @@ -88,16 +43,6 @@ ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" ynh_systemd_action --action=restart --service_name=fail2ban -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." - -# Define and install dependencies -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies - #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 03b0d08..82a31be 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -11,45 +11,12 @@ source ynh_docker_image_extract source ynh_handle_app_migration source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir) - -#REMOVEME? admin_token=$(ynh_app_setting_get --app=$app --key=admin_token) -#REMOVEME? rocket_port=$(ynh_app_setting_get --app=$app --key=rocket_port) -#REMOVEME? websocket_port=$(ynh_app_setting_get --app=$app --key=websocket_port) - #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -59,81 +26,6 @@ ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped" -#================================================= -# HANDLE MIGRATION FROM BITWARDEN -#================================================= - -ynh_handle_app_migration --migration_id="bitwarden" --migration_list="bitwarden_migration" - -if [ $migration_process -eq 1 ] -then - # If a migration has been perform - # Reload some values changed by the migration process -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) - - # Move config file - mv $install_dir/live/bitwarden_rs.env $install_dir/live/.env - ynh_delete_file_checksum --file="/var/www/$old_app/live/bitwarden_rs.env" - ynh_store_file_checksum --file="$install_dir/live/.env" -#REMOVEME? ynh_secure_remove --file="$install_dir/live/bitwarden_rs" - - # Manage permissions -#REMOVEME? ynh_permission_update --permission="main" --add="all_users" -#REMOVEME? ynh_permission_update --permission="main" --add="visitors" - - # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) - if ynh_exec_warn_less yunohost service status $old_app >/dev/null - then - ynh_script_progression --message="Removing $old_app service integration..." - yunohost service remove $old_app - fi -fi - -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." - -# Cleaning legacy permissions -#REMOVEME? if ynh_legacy_permissions_exists; then -#REMOVEME? ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi - -#REMOVEME? if ! ynh_permission_exists --permission="admin"; then - # Create the required permissions -#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --show_tile="false" -fi - -# Create a permission if needed -#REMOVEME? if ! ynh_permission_exists --permission="api"; then -#REMOVEME? ynh_permission_create --permission="api" --url="/api" --additional_urls="/identity/connect/token" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true" -fi - -# If data_dir doesn't exist, create it -if [ -z $data_dir ]; then - ynh_script_progression --message="Making sure data directory exists..." - data_dir=/home/yunohost.app/$app -#REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir - mkdir -p $data_dir - rsync -arz "$install_dir/live/data/" "$data_dir/" --delete-after --remove-source-files -#REMOVEME? ynh_secure_remove --file="$install_dir/live/data" -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - chmod 750 "$data_dir" - chmod -R o-rwx "$data_dir" - chown -R $app:$app "$data_dir" -fi - -#================================================= -# CREATE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -152,17 +44,9 @@ then mkdir -p "$install_dir/live/" fi -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:$app "$install_dir" -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." - -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies - #================================================= # NGINX CONFIGURATION #================================================= @@ -181,9 +65,9 @@ ynh_script_progression --message="Making upgrade..." if [ "$upgrade_type" == "UPGRADE_APP" ] then mv -f "$install_dir/build/vaultwarden" "$install_dir/live/vaultwarden" -#REMOVEME? ynh_secure_remove --file="$install_dir/live/web-vault/" + ynh_secure_remove --file="$install_dir/live/web-vault/" rsync -a "$install_dir/build/web-vault/" "$install_dir/live/web-vault/" -#REMOVEME? ynh_secure_remove --file="$install_dir/build" + ynh_secure_remove --file="$install_dir/build" fi chmod 750 "$install_dir" @@ -245,31 +129,6 @@ chown -R $app:$app "/var/log/$app" # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex="^.*Username or password is incorrect\. Try again\. IP: \. Username:.*$" -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." - -#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - -#================================================= -# FINISH MIGRATION PROCESS -#================================================= - -if [ $migration_process -eq 1 ] -then - ynh_script_progression --message="Bitwarden has been successfully migrated to Vaultwarden! \ -A last scheduled operation will run in a couple of minutes to finish the \ -migration in YunoHost side. Do not proceed any application operation while \ -you don't see Vaultwarden as installed." - script_post_migration=bitwarden_post_migration.sh - cp ../conf/$script_post_migration /tmp - ynh_replace_string --match_string="__OLD_APP__" --replace_string="$old_app" --target_file=/tmp/$script_post_migration - ynh_replace_string --match_string="__NEW_APP__" --replace_string="$app" --target_file=/tmp/$script_post_migration - chmod +x /tmp/$script_post_migration - (cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes) -fi - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/ynh_handle_app_migration b/scripts/ynh_handle_app_migration deleted file mode 100644 index 409cdf6..0000000 --- a/scripts/ynh_handle_app_migration +++ /dev/null @@ -1,265 +0,0 @@ -#!/bin/bash - -# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args - -# Make the main steps to migrate an app to its fork. -# -# This helper has to be used for an app which needs to migrate to a new name or a new fork -# (like owncloud to nextcloud or zerobin to privatebin). -# -# This helper will move the files of an app to its new name -# or recreate the things it can't move. -# -# To specify which files it has to move, you have to create a "migration file", stored in ../conf -# This file is a simple list of each file it has to move, -# except that file names must reference the $app variable instead of the real name of the app, -# and every instance-specific variables (like $domain). -# $app is especially important because it's this variable which will be used to identify the old place and the new one for each file. -# -# If a database exists for this app, it will be dumped and then imported in a newly created database, with a new name and new user. -# Don't forget you have to then apply these changes to application-specific settings (depends on the packaged application) -# -# Same things for an existing user, a new one will be created. -# But the old one can't be removed unless it's not used. See below. -# -# If you have some dependencies for your app, it's possible to change the fake debian package which manages them. -# You have to fill the $pkg_dependencies variable, and then a new fake package will be created and installed, -# and the old one will be removed. -# If you don't have a $pkg_dependencies variable, the helper can't know what the app dependencies are. -# -# The app settings.yml will be modified as follows: -# - finalpath will be changed according to the new name (but only if the existing $final_path contains the old app name) -# - The checksums of php-fpm and nginx config files will be updated too. -# - If there is a $db_name value, it will be changed. -# - And, of course, the ID will be changed to the new name too. -# -# Finally, the $app variable will take the value of the new name. -# The helper will set the $migration_process variable to 1 if a migration has been successfully handled. -# -# You have to handle by yourself all the migrations not done by this helper, like configuration or special values in settings.yml -# Also, at the end of the upgrade script, you have to add a post_migration script to handle all the things the helper can't do during YunoHost upgrade (mostly for permission reasons), -# especially remove the old user, move some hooks and remove the old configuration directory -# To launch this script, you have to move it elsewhere and start it after the upgrade script. -# `cp ../conf/$script_post_migration /tmp` -# `(cd /tmp; echo "/tmp/$script_post_migration" | at now + 2 minutes)` -# -# usage: ynh_handle_app_migration migration_id migration_list -# | arg: -i, --migration_id= - ID from which to migrate -# | arg: -l, --migration_list= - File specifying every file to move (one file per line) -ynh_handle_app_migration () { - # Need for end of install - ynh_package_install at - - #================================================= - # LOAD SETTINGS - #================================================= - - old_app=$YNH_APP_INSTANCE_NAME - local old_app_id=$YNH_APP_ID - local old_app_number=$YNH_APP_INSTANCE_NUMBER - - # Declare an array to define the options of this helper. - declare -Ar args_array=( [i]=migration_id= [l]=migration_list= ) - # Get the id from which to migrate - local migration_id - # And the file with the paths to move - local migration_list - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - # Get the new app id in the manifest - local new_app_id=$(grep \"id\": ../manifest.json | cut -d\" -f4) - if [ $old_app_number -eq 1 ]; then - local new_app=$new_app_id - else - local new_app=${new_app_id}__${old_app_number} - fi - - #================================================= - # CHECK IF IT HAS TO MIGRATE - #================================================= - - migration_process=0 - - if [ "$old_app_id" == "$new_app_id" ] - then - # If the 2 id are the same - # No migration to do. - echo 0 - return 0 - else - if [ "$old_app_id" != "$migration_id" ] - then - # If the new app is not the authorized id, fail. - ynh_die --message="Incompatible application for migration from $old_app_id to $new_app_id" - fi - - ynh_print_info --message="Migrate from $old_app_id to $new_app_id" >&2 - - #================================================= - # CHECK IF THE MIGRATION CAN BE DONE - #================================================= - - # TODO Handle multi instance apps... - # Check that there is not already an app installed for this id. - (yunohost app list | grep -q -w "id: $new_app") \ - && ynh_die --message="$new_app is already installed" - - #================================================= - # CHECK THE LIST OF FILES TO MOVE - #================================================= - - local temp_migration_list="$(tempfile)" - - # Build the list by removing blank lines and comment lines - sed '/^#.*\|^$/d' "../conf/$migration_list" > "$temp_migration_list" - - # Check if there is no file in the destination - local file_to_move="" - while read file_to_move - do - # Replace all occurences of $app by $new_app in each file to move. - local move_to_destination="${file_to_move//\$app/$new_app}" - test -e "$move_to_destination" && ynh_die --message="A file named $move_to_destination already exists." - done < "$temp_migration_list" - - #================================================= - # COPY YUNOHOST SETTINGS FOR THIS APP - #================================================= - - local settings_dir="/etc/yunohost/apps" - cp -a "$settings_dir/$old_app" "$settings_dir/$new_app" - cp -a ../{scripts,conf,manifest.json} "$settings_dir/$new_app" - - # Replace the old id by the new one - ynh_replace_string --match_string="\(^id: .*\)$old_app" --replace_string="\1$new_app" --target_file="$settings_dir/$new_app/settings.yml" - # INFO: There a special behavior with yunohost app setting: - # if the id given in argument does not match with the id - # stored in the config file, the config file will be purged. - # That's why we use sed instead of app setting here. - # https://github.com/YunoHost/yunohost/blob/c6b5284be8da39cf2da4e1036a730eb5e0515096/src/yunohost/app.py#L1316-L1321 - - # Change the label if it's simply the name of the app - old_label=$(ynh_app_setting_get --app=$new_app --key=label) - if [ "${old_label,,}" == "$old_app_id" ] - then - # Build the new label from the id of the app. With the first character as upper case - new_label=$(echo $new_app_id | cut -c1 | tr [:lower:] [:upper:])$(echo $new_app_id | cut -c2-) - ynh_app_setting_set --app=$new_app --key=label --value=$new_label - fi - - permissions_name=$(yunohost user permission list $old_app --short --output-as plain) - for permission_name in $permissions_name - do - yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('$permission_name', force=True, sync_perm=False)" - done - - yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$new_app.main', url='/' , show_tile=True , sync_perm=True)" - - #================================================= - # MOVE FILES TO THE NEW DESTINATION - #================================================= - - while read file_to_move - do - # Replace all occurence of $app by $new_app in each file to move. - move_to_destination="$(eval echo "${file_to_move//\$app/$new_app}")" - local real_file_to_move="$(eval echo "${file_to_move//\$app/$old_app}")" - ynh_print_info --message="Move file $real_file_to_move to $move_to_destination" >&2 - mv "$real_file_to_move" "$move_to_destination" - done < "$temp_migration_list" - - #================================================= - # UPDATE SETTINGS KNOWN ENTRIES - #================================================= - - # Replace nginx checksum - ynh_replace_string --match_string="\(^checksum__etc_nginx.*\)_$old_app" --replace_string="\1_$new_app" --target_file="$settings_dir/$new_app/settings.yml" - - # Replace php-fpm checksums - ynh_replace_string --match_string="\(^checksum__etc_php.*[-_]\)$old_app" --replace_string="\1$new_app" --target_file="$settings_dir/$new_app/settings.yml" - - # Replace final_path - ynh_replace_string --match_string="\(^final_path: .*\)$old_app" --replace_string="\1$new_app" --target_file="$settings_dir/$new_app/settings.yml" - - # Replace fail2ban_filter - ynh_replace_string --match_string="\(^checksum__etc_fail2ban_filter.*\)_$old_app" --replace_string="\1_$new_app" --target_file="$settings_dir/$new_app/settings.yml" - - # Replace fail2ban_jail - ynh_replace_string --match_string="\(^checksum__etc_fail2ban_jail.*\)_$old_app" --replace_string="\1_$new_app" --target_file="$settings_dir/$new_app/settings.yml" - - # Replace systemd - ynh_replace_string --match_string="\(^checksum__etc_systemd_system.*\)_$old_app" --replace_string="\1_$new_app" --target_file="$settings_dir/$new_app/settings.yml" - - #================================================= - # MOVE THE MYSQL DATABASE - #================================================= - - old_db_name=$(ynh_app_setting_get --app=$old_app --key=db_name) - - # Check if a database exists before trying to move it - if [ -n "$old_db_name" ] && mysqlshow | grep -q "^| $old_db_name" - then - old_db_user=$old_db_name - db_pwd=$(ynh_app_setting_get --app=$old_app --key=mysqlpwd) - - new_db_name=$(ynh_sanitize_dbid --db_name=$new_app) - new_db_user=$new_db_name - ynh_print_info --message="Rename the database $db_name to $new_db_name" >&2 - - local sql_dump="/tmp/${db_name}-$(date '+%s').sql" - - # Dump the old database - ynh_mysql_dump_db --database="$old_db_name" > "$sql_dump" - - # Create a new database - ynh_mysql_setup_db --db_user=$new_db_user --db_name=$new_db_name --db_pwd=$db_pwd - - # Then restore the old one into the new one - ynh_mysql_connect_as --user=$new_db_user --password=$db_pwd --database=$new_db_name < "$sql_dump" - - # Remove the old database - ynh_mysql_remove_db --db_user=$old_db_user --db_name=$old_db_name - - # And the dump - ynh_secure_remove --file="$sql_dump" - - # Update the value of $db_name - db_name=$new_db_name - db_user=$new_db_user - ynh_app_setting_set --app=$new_app --key=db_name --value=$db_name - fi - - #================================================= - # CHANGE THE FAKE DEPENDENCIES PACKAGE - #================================================= - - # Check if a variable $pkg_dependencies exists - # If this variable doesn't exist, this part shall be managed in the upgrade script. - if [ -n "${pkg_dependencies:-}" ] - then - # Define the name of the package - local old_package_name="${old_app//_/-}-ynh-deps" - local new_package_name="${new_app//_/-}-ynh-deps" - - if ynh_package_is_installed --package="$old_package_name" - then - # Install a new fake package - app=$new_app - ynh_install_app_dependencies $pkg_dependencies - # Then remove the old one - app=$old_app - ynh_remove_app_dependencies - fi - fi - - #================================================= - # UPDATE THE ID OF THE APP - #================================================= - - app=$new_app - - # Set migration_process to 1 to inform that an upgrade has been made - migration_process=1 - fi -} diff --git a/scripts/ynh_send_readme_to_admin__2 b/scripts/ynh_send_readme_to_admin__2 deleted file mode 100644 index ee571cc..0000000 --- a/scripts/ynh_send_readme_to_admin__2 +++ /dev/null @@ -1,129 +0,0 @@ -#!/bin/bash - -# Send an email to inform the administrator -# -# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] -# | arg: -m --app_message= - The file with the content to send to the administrator. -# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root -# example: "root admin@domain" -# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you -# example: "root admin@domain user1 user2" -# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade' -# -# Requires YunoHost version 4.1.0 or higher. -ynh_send_readme_to_admin() { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= ) - local app_message - local recipients - local type - # Manage arguments with getopts - - ynh_handle_getopts_args "$@" - app_message="${app_message:-}" - recipients="${recipients:-root}" - type="${type:-install}" - - # Get the value of admin_mail_html - admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) - admin_mail_html="${admin_mail_html:-0}" - - # Retrieve the email of users - find_mails () { - local list_mails="$1" - local mail - local recipients=" " - # Read each mail in argument - for mail in $list_mails - do - # Keep root or a real email address as it is - if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" - then - recipients="$recipients $mail" - else - # But replace an user name without a domain after by its email - if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) - then - recipients="$recipients $mail" - fi - fi - done - echo "$recipients" - } - recipients=$(find_mails "$recipients") - - # Subject base - local mail_subject="☁️🆈🅽🅷☁️: \`$app\`" - - # Adapt the subject according to the type of mail required. - if [ "$type" = "backup" ]; then - mail_subject="$mail_subject has just been backup." - elif [ "$type" = "change_url" ]; then - mail_subject="$mail_subject has just been moved to a new URL!" - elif [ "$type" = "remove" ]; then - mail_subject="$mail_subject has just been removed!" - elif [ "$type" = "restore" ]; then - mail_subject="$mail_subject has just been restored!" - elif [ "$type" = "upgrade" ]; then - mail_subject="$mail_subject has just been upgraded!" - else # install - mail_subject="$mail_subject has just been installed!" - fi - - ynh_add_config --template="$app_message" --destination="../conf/msg__to_send" - - ynh_delete_file_checksum --file="../conf/msg__to_send" - - local mail_message="This is an automated message from your beloved YunoHost server. - -Specific information for the application $app. - -$(cat "../conf/msg__to_send")" - - # Store the message into a file for further modifications. - echo "$mail_message" > mail_to_send - - # If a html email is required. Apply html tags to the message. - if [ "$admin_mail_html" -eq 1 ] - then - # Insert 'br' tags at each ending of lines. - ynh_replace_string "$" "
" mail_to_send - - # Insert starting HTML tags - sed --in-place '1s@^@\n\n\n\n@' mail_to_send - - # Keep tabulations - ynh_replace_string " " "\ \ " mail_to_send - ynh_replace_string "\t" "\ \ " mail_to_send - - # Insert url links tags - ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send - - # Insert finishing HTML tags - echo -e "\n\n" >> mail_to_send - - # Otherwise, remove tags to keep a plain text. - else - # Remove URL tags - ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send - ynh_replace_string "__URL_TAG2__" ": " mail_to_send - fi - - # Define binary to use for mail command - if [ -e /usr/bin/bsd-mailx ] - then - local mail_bin=/usr/bin/bsd-mailx - else - local mail_bin=/usr/bin/mail.mailutils - fi - - if [ "$admin_mail_html" -eq 1 ] - then - content_type="text/html" - else - content_type="text/plain" - fi - - # Send the email to the recipients - cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients" -} diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..e69de29