From b7dd85d13519f1dfc6dc6df436099e9fd80cac50 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 15 Jun 2020 03:40:49 +0200 Subject: [PATCH 01/23] new nodejs helper --- conf/.env | 4 +- conf/systemd.service | 2 +- scripts/install | 24 ++----- scripts/upgrade | 102 +++++++++++++---------------- scripts/ynh_add_config | 143 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 196 insertions(+), 79 deletions(-) create mode 100644 scripts/ynh_add_config diff --git a/conf/.env b/conf/.env index 2ee41a6..8b3f976 100644 --- a/conf/.env +++ b/conf/.env @@ -4,7 +4,7 @@ NODE_ENV=production # The path to NODEJS -PATH=__NODEJS_PATH__ +__YNH_NODE_LOAD_PATH__ #--------------------------------------------- # Debug OIDC OAuth2 etc. #DEBUG=true @@ -16,7 +16,7 @@ MONGO_URL=mongodb://127.0.0.1:27017/__DB_NAME__ # Production: https://example.com/wekan # Local: http://localhost:2000 # ipaddress=$(ifdata -pa eth0) -ROOT_URL=https://__DOMAIN_URI__ +ROOT_URL=https://__DOMAIN____PATH__ #--------------------------------------------- # Working email IS NOT REQUIRED to use Wekan. # https://github.com/wekan/wekan/wiki/Adding-users diff --git a/conf/systemd.service b/conf/systemd.service index 7b13646..31b859d 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -9,7 +9,7 @@ User=__APP__ Group=__APP__ EnvironmentFile=__FINALPATH__/.env WorkingDirectory=__FINALPATH__ -ExecStart=__NODEJS_PATH__/node __FINALPATH__/main.js +ExecStart=__YNH_NODE__ __FINALPATH__/main.js Restart=on-failure #StartLimitInterval=86400 #StartLimitBurst=5 diff --git a/scripts/install b/scripts/install index bd7706c..87e4da9 100755 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ source _common.sh source ynh_detect_arch__2 +source ynh_add_config source /usr/share/yunohost/helpers #================================================= @@ -133,32 +134,15 @@ ynh_system_user_create --username=$app --home_dir="$final_path" ynh_print_info --message="Configuring a systemd service..." # Create a dedicated systemd config -ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service" -ynh_replace_string --match_string="__MONGODB_SERVICENAME__" --replace_string="$mongodb_servicename" --target_file="../conf/systemd.service" -ynh_add_systemd_config +ynh_add_systemd_config --others_var="mongodb_servicename ynh_node" #================================================= # MODIFY A CONFIG FILE #================================================= ynh_print_info --message="Modifying a config file..." -config_file="$final_path/.env" -cp "../conf/.env" $config_file - -ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$config_file" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config_file" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config_file" -ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain$path_url" --target_file="$config_file" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config_file" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= -ynh_print_info --message="Storing the config file checksum..." - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$config_file" +# Create a dedicated .env config +ynh_add_config #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 957c1c5..2f0326c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,6 +9,7 @@ source _common.sh source ynh_package_version source ynh_detect_arch__2 +source ynh_add_config source /usr/share/yunohost/helpers #================================================= @@ -38,8 +39,8 @@ ynh_print_info --message="Ensuring downward compatibility..." # 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 + db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi #================================================= @@ -47,7 +48,7 @@ fi #================================================= if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then - sleep 60 + sleep 60 fi abort_if_up_to_date # previous function is what defines 'version', more precisely the 'previous version' @@ -89,50 +90,50 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd ynh_print_info --message="Managing upgrade from previous version..." if ynh_version_gt "0.45-2" "${previous_version}" ; then - ynh_print_info --message="Upgrading to 0.45-2..." - ynh_replace_string --match_string="Environment=ROOT_URL=http://127.0.0.1:$port$path_url" --replace_string="Environment=ROOT_URL=https://$domain$path_url/" --target_file="/etc/systemd/system/$app.service" - systemctl daemon-reload + ynh_print_info --message="Upgrading to 0.45-2..." + ynh_replace_string --match_string="Environment=ROOT_URL=http://127.0.0.1:$port$path_url" --replace_string="Environment=ROOT_URL=https://$domain$path_url/" --target_file="/etc/systemd/system/$app.service" + systemctl daemon-reload fi if ynh_version_gt "0.45-3" "${previous_version}" ; then - ynh_print_info --message="Upgrading to 0.45-3..." - yunohost service add $app + ynh_print_info --message="Upgrading to 0.45-3..." + yunohost service add $app fi if ynh_version_gt "1.07~ynh2" "${previous_version}" ; then - ynh_print_info --message="Upgrading to 1.07~ynh2..." + ynh_print_info --message="Upgrading to 1.07~ynh2..." - # Replace mongodb packages - # Assume no other app needs it >.> - rm -f /etc/apt/sources.list.d/mongodb-org-3.2.list - ynh_remove_app_dependencies - ynh_install_app_dependencies "mongodb mongodb-server" - yunohost service remove mongod - yunohost service add mongodb --log "/var/log/mongodb/mongodb.log" + # Replace mongodb packages + # Assume no other app needs it >.> + rm -f /etc/apt/sources.list.d/mongodb-org-3.2.list + ynh_remove_app_dependencies + ynh_install_app_dependencies "mongodb mongodb-server" + yunohost service remove mongod + yunohost service add mongodb --log "/var/log/mongodb/mongodb.log" fi if ynh_version_gt "2.56~ynh1" "${previous_version}" ; then - # Create a dedicated .env config - config_file="$final_path/.env" - touch $config_file + # Create a dedicated .env config + config_file="$final_path/.env" + touch $config_file fi # Create the permission "admin" only if it doesn't exist. if ! ynh_permission_exists --permission="admin" then - ynh_print_info --message="Upgrading Permission configuration..." + ynh_print_info --message="Upgrading Permission configuration..." ynh_app_setting_delete --app=$app --key=unprotected_uris - is_public=$(ynh_app_setting_get --app=$app --key=is_public) + is_public=$(ynh_app_setting_get --app=$app --key=is_public) - if [ $is_public -eq 1 ]; then - ynh_permission_update --permission "main" --add "visitors" - fi + if [ $is_public -eq 1 ]; then + ynh_permission_update --permission "main" --add "visitors" + fi ynh_app_setting_delete --app=$app --key=is_public - ynh_permission_create --permission="admin" + ynh_permission_create --permission="admin" fi #================================================= @@ -142,25 +143,25 @@ fi if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_print_info --message="Upgrading source files..." - - # Create a temporary directory - tmpdir="$(mktemp -d)" + + # Create a temporary directory + tmpdir="$(mktemp -d)" - # Backup the env file in the temp dir - cp -a "$final_path/.env" "$tmpdir/.env" + # Backup the env file in the temp dir + cp -a "$final_path/.env" "$tmpdir/.env" - # Remove the app directory securely - ynh_secure_remove --file="$final_path" + # Remove the app directory securely + ynh_secure_remove --file="$final_path" - architecture=$(ynh_detect_arch) - # Download, check integrity, uncompress and patch the source from app.src + architecture=$(ynh_detect_arch) + # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" --source_id="$architecture" - #Copy the admin saved settings from tmp directory to final path - cp -a "$tmpdir/.env" "$final_path/.env" + #Copy the admin saved settings from tmp directory to final path + cp -a "$tmpdir/.env" "$final_path/.env" - # Remove the tmp directory securely - ynh_secure_remove --file="$tmpdir" + # Remove the tmp directory securely + ynh_secure_remove --file="$tmpdir" fi #================================================= @@ -181,11 +182,11 @@ ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs if [ "$(lsb_release --codename --short)" = "buster" ]; then - ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc" - mongodb_servicename=$mongodb_buster + ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc" + mongodb_servicename=$mongodb_buster else - ynh_install_app_dependencies $pkg_dependencies - mongodb_servicename=$mongodb_stretch + ynh_install_app_dependencies $pkg_dependencies + mongodb_servicename=$mongodb_stretch fi #================================================= @@ -202,16 +203,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" ynh_print_info --message="Modifying a config file..." # Create a dedicated .env config -config_file="$final_path/.env" -ynh_backup_if_checksum_is_different --file="$config_file" -cp "../conf/.env" "$config_file" -ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$config_file" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config_file" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config_file" -ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain$path_url" --target_file="$config_file" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config_file" -ynh_store_file_checksum "$config_file" +ynh_add_config #================================================= # SETUP SYSTEMD @@ -219,9 +211,7 @@ ynh_store_file_checksum "$config_file" ynh_print_info --message="Upgrading systemd configuration..." # Create a dedicated systemd config -ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service" -ynh_replace_string --match_string="__MONGODB_SERVICENAME__" --replace_string="$mongodb_servicename" --target_file="../conf/systemd.service" -ynh_add_systemd_config +ynh_add_systemd_config --others_var="mongodb_servicename ynh_node" #================================================= # GENERIC FINALIZATION @@ -242,7 +232,7 @@ ynh_print_info --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Wekan, task board" if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then - sleep 60 + sleep 60 fi #================================================= diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config new file mode 100644 index 0000000..9435819 --- /dev/null +++ b/scripts/ynh_add_config @@ -0,0 +1,143 @@ +#!/bin/bash + +# Create a dedicated config file +# +# usage: ynh_add_config [--origin="origin file"] [--destination="destination file"] [--vars="vars to replace"] +# | arg: -o, --origin= - Template config file to use (optionnal, ../conf/.env by default) +# | arg: -d, --destination= - Destination of the config file (optionnal, $final_path/.env) +# | arg: -v, --vars= - List of variables to replace separated by a space. For example: 'var_1 var_2 ...' +# +# This will use the template $origin or ../conf/.env by default +# to generate a config file $destination or $final_path/.env by default, +# by replacing the following keywords with global variables +# that should be defined before calling this helper : +# __PATH__ by $path_url +# __DOMAIN__ by $domain +# __PORT__ by $port +# __NAME__ by $app +# __NAMETOCHANGE__ by $app +# __USER__ by $app +# __APP__ by $app +# __FINALPATH__ by $final_path +# __PHPVERSION__ by $YNH_PHP_VERSION +# __YNH_NPM__ by $ynh_npm +# __YNH_NODE__ by $ynh_node +# __YNH_NODE_LOAD_PATH__ by $ynh_node_load_PATH +# __NODEJS_PATH__ by $nodejs_path +# __NODEJS_VERSION__ by $nodejs_version +# __DB_NAME__ by $db_name +# __DB_USER__ by $db_user +# __DB_PWD__ by $db_pwd +# +# And dynamic variables (from the last example) : +# __VAR_1__ by $var_1 +# __VAR_2__ by $var_2 +# +# The helper will verify the checksum and backup the destination file +# if it's different before applying the new origin file. +# And it will calculate and store a destination file checksum +# into the app settings when configuraation is done. +# +ynh_add_config () { + # Declare an array to define the options of this helper. + local legacy_args=odv + local -A args_array=( [o]=origin= [d]=destination= [v]=vars= ) + local origin + local destination + local vars + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local origin="${origin:-"../conf/.env"}" + local destination="${destination:-"$final_path/.env"}" + local vars="${vars:-}" + + ynh_backup_if_checksum_is_different --file="$destination" + cp "$origin" "$destination" + + #Replace usual YunoHost variables + if test -n "${path_url:-}" + then + # path_url_slash_less is path_url, or a blank value if path_url is only '/' + local path_url_slash_less=${path_url%/} + ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$destination" + ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$destination" + fi + if test -n "${domain:-}"; then + ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$destination" + fi + if test -n "${port:-}"; then + ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$destination" + fi + if test -n "${app:-}"; then + ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$destination" + ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$destination" + ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$destination" + ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$destination" + fi + if test -n "${final_path:-}"; then + ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$destination" + fi + if test -n "${YNH_PHP_VERSION:-}"; then + ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$destination" + fi + if test -n "${ynh_npm:-}"; then + ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$destination" + fi + if test -n "${ynh_node:-}"; then + ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$destination" + fi + if test -n "${ynh_node_load_PATH:-}"; then + ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$destination" + fi + if test -n "${nodejs_path:-}"; then + ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$destination" + fi + if test -n "${nodejs_version:-}"; then + ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$destination" + fi + if test -n "${db_name:-}"; then + ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$destination" + fi + if test -n "${db_user:-}"; then + ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$destination" + fi + if test -n "${db_pwd:-}"; then + ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$destination" + fi + + # Replace all other variables given as arguments + for var_to_replace in $vars + do + # ${var_to_replace^^} make the content of the variable on upper-cases + # ${!var_to_replace} get the content of the variable named $var_to_replace + ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$destination" + done + + ynh_store_file_checksum --file="$destination" +} + +# Remove the dedicated config +# +# usage: ynh_remove_config [--file=file] +# | arg: -f, --file= - Config file to remove (optionnal, $final_path/.env) +# +# +ynh_remove_config () { + # Declare an array to define the options of this helper. + local legacy_args=f + local -A args_array=( [f]=file= ) + local file + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local service="${file:-}" + + # The default behaviour is to use .env file. + if [ -n "$file" ]; then + file="final_path/.env" + fi + + if [ -e "$file" ] + then + ynh_secure_remove --file="$file" + fi +} From c2f5710a8e9701d19cdf7dbe5df82bcd204df73e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 15 Jun 2020 04:15:42 +0200 Subject: [PATCH 02/23] Apply last example_ynh --- README.md | 18 +++++++------- issue_template.md | 46 ++++++++++++++++++++++++++++++++++++ manifest.json | 2 +- scripts/backup | 38 ++++++++---------------------- scripts/change_url | 22 +++++++++-------- scripts/install | 37 ++++++++++++++--------------- scripts/remove | 19 +++++++-------- scripts/restore | 33 +++++++++++++------------- scripts/upgrade | 47 +++++++++++++++++++------------------ scripts/ynh_package_version | 2 +- 10 files changed, 147 insertions(+), 117 deletions(-) create mode 100644 issue_template.md diff --git a/README.md b/README.md index 1bc977c..f0c5bfb 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Wekan for Yunohost -[![Integration level](https://dash.yunohost.org/integration/wekan.svg)](https://dash.yunohost.org/appci/app/wekan) +[![Integration level](https://dash.yunohost.org/integration/wekan.svg)](https://dash.yunohost.org/appci/app/wekan) ![](https://ci-apps.yunohost.org/ci/badges/wekan.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/wekan.maintain.svg) [![Install Wekan with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=wekan) -> *This package allow you to install Wekan quickly and simply on a YunoHost server. -If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* +> *This package allows you to install Wekan 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 Wekan is an open-source kanban board (task manager and organizer) @@ -28,7 +28,7 @@ Wekan is an open-source kanban board (task manager and organizer) ## Configuration -As LDAP authentification is enabled by default, wekan admins correspond to the permission `Wekan Admin`. The user you choose during installation is member of this group. +As LDAP authentification is enabled by default, Wekan admins correspond to the permission `Wekan Admin`. The user you choose during installation is member of this group. To add an admin account, you can: - [with the webadmin] go to Users > Groups and permissions > Add the user to the permission `Wekan Admin` @@ -38,7 +38,7 @@ All others YunhoHost user can access with LDAP authentication. If you have disable ldap authentication, first registered user will be admin, and next ones normal users. If you want other admins too, you can change their permission to admin at Wekan Admin Panel. -**Private/Public mode:** In private mode, only authorized YunoHost members can access to the wekan. +**Private/Public mode:** In private mode, only authorized YunoHost members can access to the Wekan. ## Documentation @@ -46,13 +46,13 @@ If you have disable ldap authentication, first registered user will be admin, an ## YunoHost specific features -#### Multi-users support +#### Multi-user support LDAP is supported but HTTP auth is still not supported #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/wekan%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/wekan/) +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/wekan%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/wekan/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/wekan%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/wekan/) ## Links @@ -64,10 +64,10 @@ LDAP is supported but HTTP auth is still not supported --- -Developers info +Developer info ---------------- -Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/wekan_ynh/tree/testing). +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/wekan_ynh/tree/testing). To try the testing branch, please proceed like that. ``` diff --git a/issue_template.md b/issue_template.md new file mode 100644 index 0000000..3c02af4 --- /dev/null +++ b/issue_template.md @@ -0,0 +1,46 @@ +--- +name: Bug report +about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all. + +--- + +**How to post a meaningful bug report** +1. *Read this whole template first.* +2. *Determine if you are on the right place:* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!* + - *Otherwise, the issue may be due to Wekan itself. Refer to its documentation or repository for help.* + - *If you have a doubt, post here, we will figure it out together.* +3. *Delete the italic comments as you write over them below, and remove this guide.* +--- + +**Describe the bug** +*A clear and concise description of what the bug is.* + +**Versions** +- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* +- YunoHost version: x.x.x +- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes* + - If yes, please explain: +- Using, or trying to install package version/branch: +- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* + +**To Reproduce** +*Steps to reproduce the behavior.* +- *If you performed a command from the CLI, the command itself is enough. For example:* + ```sh + sudo yunohost app install wekan + ``` +- *If you used the webadmin, please perform the equivalent command from the CLI first.* +- *If the error occurs in your browser, explain what you did:* + 1. *Go to '...'* + 2. *Click on '....'* + 3. *Scroll down to '....'* + 4. *See error* + +**Expected behavior** +*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* + +**Logs** +*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.* +*If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index c102425..c7aa212 100644 --- a/manifest.json +++ b/manifest.json @@ -8,7 +8,7 @@ }, "version": "4.09~ynh1", "url": "https://wekan.io", - "license": "MIT", + "license": "MIT", "maintainer": [ { "name": "alexAubin", diff --git a/scripts/backup b/scripts/backup index 1f8315e..15f6e80 100644 --- a/scripts/backup +++ b/scripts/backup @@ -13,7 +13,6 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= -ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -33,28 +32,30 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP #================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_print_info --message="Stopping a systemd service..." - -ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd +ynh_print_info --message="Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_print_info --message="Backing up the main app directory..." ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_print_info --message="Backing up nginx web server configuration..." ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" + #================================================= # BACKUP THE MONGODB DATABASE #================================================= @@ -62,25 +63,6 @@ ynh_print_info --message="Backing up the MongoDB database..." mongodump --quiet --db="$db_name" --out="./dump" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP SYSTEMD -#================================================= -ynh_print_info --message="Backing up systemd configuration..." - -ynh_backup --src_path="/etc/systemd/system/$app.service" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_print_info --message="Starting a systemd service..." - -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Wekan, task board" -if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then - sleep 60 -fi - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 3e51575..ab60df7 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,7 +24,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) @@ -34,12 +34,10 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #db_user=$db_name #db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) -port=$(ynh_app_setting_get --app=$app --key=port) - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_print_info --message="Backing up the app before changing its url (may take a while)..." +ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -74,14 +72,14 @@ fi #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_print_info --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_print_info --message="Updating nginx web server configuration..." +ynh_script_progression --message="Updating nginx web server configuration..." nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -112,18 +110,22 @@ fi #================================================= # MODIFY URL IN .ENV #================================================= -ynh_print_info --message="Updating .env configuration..." +ynh_script_progression --message="Updating .env configuration..." +ynh_backup_if_checksum_is_different --file="$final_path/.env" ynh_replace_string --match_string="$old_domain$old_path" --replace_string="$new_domain$new_path" --target_file="$final_path/.env" +ynh_store_file_checksum --file="$final_path/.env" #================================================= # GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_print_info --message="Starting a systemd service..." +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="Started Wekan, task board" + if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then sleep 60 fi @@ -131,7 +133,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -139,4 +141,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_print_info --message="Change of URL completed for $app" +ynh_script_progression --message="Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 87e4da9..e0d60b2 100755 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,6 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= -ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -25,7 +24,6 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -ynh_print_info --message="Retrieving arguments from the manifest..." domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH @@ -37,7 +35,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_print_info --message="Validating installation parameters..." +ynh_script_progression --message="Validating installation parameters..." architecture=$(ynh_detect_arch) # Check machine architecture (in particular, we don't support ARM and 32bit machines) @@ -55,7 +53,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_print_info --message="Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url @@ -66,7 +64,7 @@ ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # FIND AND OPEN A PORT #================================================= -ynh_print_info --message="Configuring firewall..." +ynh_script_progression --message="Configuring firewall..." # Find an available port port=$(ynh_find_port --port=8095) @@ -75,7 +73,7 @@ ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_print_info --message="Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs @@ -91,7 +89,7 @@ fi #================================================= # CREATE A MONGODB DATABASE #================================================= -ynh_print_info --message="Creating a MongoDB database..." +ynh_script_progression --message="Creating a MongoDB database..." # Start mongodb systemctl enable $mongodb_servicename @@ -104,7 +102,7 @@ ynh_app_setting_set --app=$app --key=db_name --value=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_print_info --message="Setting up source files..." +ynh_script_progression --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src @@ -113,7 +111,7 @@ ynh_setup_source --dest_dir="$final_path" --source_id="$architecture" #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info --message="Configuring nginx web server..." +ynh_script_progression --message="Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config @@ -121,7 +119,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info --message="Configuring system user..." +ynh_script_progression --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app --home_dir="$final_path" @@ -131,7 +129,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # SETUP SYSTEMD #================================================= -ynh_print_info --message="Configuring a systemd service..." +ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config --others_var="mongodb_servicename ynh_node" @@ -139,7 +137,7 @@ ynh_add_systemd_config --others_var="mongodb_servicename ynh_node" #================================================= # MODIFY A CONFIG FILE #================================================= -ynh_print_info --message="Modifying a config file..." +ynh_script_progression --message="Modifying a config file..." # Create a dedicated .env config ynh_add_config @@ -149,7 +147,7 @@ ynh_add_config #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_print_info --message="Securing files and directories..." +ynh_script_progression --message="Securing files and directories..." # Set strong right permissions to app files chown -R $app: "$final_path" @@ -159,18 +157,19 @@ find "$final_path" -type d -print0 | xargs -0 chmod 750 #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_print_info --message="Integrating service in YunoHost..." +ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "Wekan daemon" +yunohost service add $app --description "Wekan daemon" --log_type "systemd" yunohost service add mongodb --description "MongoDB daemon" --log "/var/log/mongodb/mongodb.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_print_info --message="Starting a systemd service..." +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="Meteor APM: completed instrumenting the app" + if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then sleep 60 fi @@ -178,7 +177,7 @@ fi #================================================= # SETUP SSOWAT #================================================= -ynh_print_info --message="Configuring SSOwat..." +ynh_script_progression --message="Configuring SSOwat..." ynh_permission_create --permission="admin" --allowed "$admin" @@ -191,7 +190,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -199,4 +198,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_print_info --message="Installation of $app completed" +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 5211c21..2c0e2ea 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -27,19 +27,18 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -ynh_print_info --message="Removing service integration in YunoHost..." # 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_print_info --message="Removing $app service..." + ynh_script_progression --message="Removing $app service..." yunohost service remove $app fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_print_info --message="Stopping and removing the systemd service..." +ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config @@ -47,7 +46,7 @@ ynh_remove_systemd_config #================================================= # REMOVE THE MONGODB DATABASE #================================================= -ynh_print_info --message="Removing the MongoDB database..." +ynh_script_progression --message="Removing the MongoDB database..." # Remove a database if it exists, along with the associated user mongo $db_name --eval "db.dropDatabase()" @@ -55,7 +54,7 @@ mongo $db_name --eval "db.dropDatabase()" #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_print_info --message="Removing dependencies..." +ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -70,7 +69,7 @@ fi #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info --message="Removing app main directory..." +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -78,7 +77,7 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_print_info --message="Removing nginx web server configuration..." +ynh_script_progression --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -88,7 +87,7 @@ ynh_remove_nginx_config #================================================= # REMOVE DEDICATED USER #================================================= -ynh_print_info --message="Removing the dedicated system user..." +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user ynh_system_user_delete --username=$app @@ -97,4 +96,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_print_info --message="Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index e86437d..53252a9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,13 +6,13 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= -ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -23,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Loading settings..." +ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME @@ -35,7 +35,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_print_info --message="Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" @@ -47,20 +47,21 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the nginx configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_print_info --message="Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_print_info --message="Recreating the dedicated system user..." +ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir="$final_path" @@ -68,7 +69,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE USER RIGHTS #================================================= -ynh_print_info --message="Restoring user rights..." +ynh_script_progression --message="Restoring user rights..." # Restore permissions on app files chown -R $app: "$final_path" @@ -80,7 +81,7 @@ find "$final_path" -type d -print0 | xargs -0 chmod 750 #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_print_info --message="Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_nodejs --nodejs_version=$nodejsversion @@ -97,7 +98,7 @@ fi #================================================= # RESTORE THE MONGODB DATABASE #================================================= -ynh_print_info --message="Restoring the MongoDB database..." +ynh_script_progression --message="Restoring the MongoDB database..." # Start mongodb systemctl enable $mongodb_servicename @@ -107,7 +108,7 @@ mongorestore --quiet --db="$db_name" "./dump/$db_name" #================================================= # RESTORE SYSTEMD #================================================= -ynh_print_info --message="Restoring the systemd configuration..." +ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service @@ -115,18 +116,18 @@ systemctl enable $app.service #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_print_info --message="Integrating service in YunoHost..." - -yunohost service add $app --description "Wekan daemon" -yunohost service add mongodb --log "/var/log/mongodb/mongodb.log" +ynh_script_progression --message="Integrating service in YunoHost..." +yunohost service add $app --description "Wekan daemon" --log_type "systemd" +yunohost service add mongodb --description "MongoDB daemon" --log "/var/log/mongodb/mongodb.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_print_info --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Wekan, task board" + if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then sleep 60 fi @@ -136,7 +137,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -144,4 +145,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_print_info --message="Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 2f0326c..81617cc 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -28,14 +28,14 @@ port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION #================================================= -ynh_print_info --message="Checking version..." +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_print_info --message="Ensuring downward compatibility..." +ynh_script_progression --message="Ensuring downward compatibility..." # If db_name doesn't exist, create it if [ -z "$db_name" ]; then @@ -57,7 +57,7 @@ previous_version="${version}" #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_print_info --message="Backing up the app before upgrading (may take a while)..." +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -80,36 +80,36 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_print_info --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd #================================================= # MANAGE UPGRADE FROM PREVIOUS VERSION #================================================= -ynh_print_info --message="Managing upgrade from previous version..." +ynh_script_progression --message="Managing upgrade from previous version..." if ynh_version_gt "0.45-2" "${previous_version}" ; then - ynh_print_info --message="Upgrading to 0.45-2..." + ynh_script_progression --message="Upgrading to 0.45-2..." ynh_replace_string --match_string="Environment=ROOT_URL=http://127.0.0.1:$port$path_url" --replace_string="Environment=ROOT_URL=https://$domain$path_url/" --target_file="/etc/systemd/system/$app.service" systemctl daemon-reload fi if ynh_version_gt "0.45-3" "${previous_version}" ; then - ynh_print_info --message="Upgrading to 0.45-3..." - yunohost service add $app + ynh_script_progression --message="Upgrading to 0.45-3..." + yunohost service add $app --description "Wekan daemon" --log_type "systemd" fi if ynh_version_gt "1.07~ynh2" "${previous_version}" ; then - ynh_print_info --message="Upgrading to 1.07~ynh2..." + ynh_script_progression --message="Upgrading to 1.07~ynh2..." # Replace mongodb packages # Assume no other app needs it >.> rm -f /etc/apt/sources.list.d/mongodb-org-3.2.list ynh_remove_app_dependencies ynh_install_app_dependencies "mongodb mongodb-server" - yunohost service remove mongod - yunohost service add mongodb --log "/var/log/mongodb/mongodb.log" + yunohost service add $app --description "Wekan daemon" --log_type "systemd" + yunohost service add mongodb --description "MongoDB daemon" --log "/var/log/mongodb/mongodb.log" fi if ynh_version_gt "2.56~ynh1" "${previous_version}" ; then @@ -121,7 +121,7 @@ fi # Create the permission "admin" only if it doesn't exist. if ! ynh_permission_exists --permission="admin" then - ynh_print_info --message="Upgrading Permission configuration..." + ynh_script_progression --message="Upgrading Permission configuration..." ynh_app_setting_delete --app=$app --key=unprotected_uris @@ -142,7 +142,7 @@ fi if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_print_info --message="Upgrading source files..." + ynh_script_progression --message="Upgrading source files..." # Create a temporary directory tmpdir="$(mktemp -d)" @@ -167,7 +167,7 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info --message="Upgrading nginx web server configuration..." +ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config @@ -175,7 +175,7 @@ ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_print_info --message="Upgrading dependencies..." +ynh_script_progression --message="Upgrading dependencies..." ynh_remove_nodejs ynh_install_nodejs --nodejs_version=$nodejsversion @@ -192,7 +192,7 @@ fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info --message="Making sure dedicated system user exists..." +ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir="$final_path" @@ -200,7 +200,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # MODIFY A CONFIG FILE #================================================= -ynh_print_info --message="Modifying a config file..." +ynh_script_progression --message="Modifying a config file..." # Create a dedicated .env config ynh_add_config @@ -208,7 +208,7 @@ ynh_add_config #================================================= # SETUP SYSTEMD #================================================= -ynh_print_info --message="Upgrading systemd configuration..." +ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config --others_var="mongodb_servicename ynh_node" @@ -218,7 +218,7 @@ ynh_add_systemd_config --others_var="mongodb_servicename ynh_node" #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_print_info --message="Securing files and directories..." +ynh_script_progression --message="Securing files and directories..." # Set permissions on app files chown -R $app: "$final_path" @@ -228,9 +228,10 @@ find "$final_path" -type d -print0 | xargs -0 chmod 750 #================================================= # START SYSTEMD SERVICE #================================================= -ynh_print_info --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Wekan, task board" + if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then sleep 60 fi @@ -238,7 +239,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -246,4 +247,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_print_info --message="Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" diff --git a/scripts/ynh_package_version b/scripts/ynh_package_version index f6b5fd1..de13ae8 100644 --- a/scripts/ynh_package_version +++ b/scripts/ynh_package_version @@ -16,7 +16,7 @@ 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}" ]; then - ynh_print_info "Up-to-date, nothing to do" + ynh_script_progression --message="Up-to-date, nothing to do" ynh_die "" 0 fi } From 4c0ea112fa650fe4683b71cc1ce3028197781904 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 15 Jun 2020 05:00:50 +0200 Subject: [PATCH 03/23] Implement ynh_mongo_db --- scripts/backup | 3 +- scripts/install | 3 + scripts/remove | 3 +- scripts/restore | 6 +- scripts/ynh_mongo_db | 246 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 scripts/ynh_mongo_db diff --git a/scripts/backup b/scripts/backup index 15f6e80..8dd3e4a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -8,6 +8,7 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_mongo_db source /usr/share/yunohost/helpers #================================================= @@ -61,7 +62,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= ynh_print_info --message="Backing up the MongoDB database..." -mongodump --quiet --db="$db_name" --out="./dump" +ynh_mongo_dump_db --database="$db_name" > ./dump.bson #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index e0d60b2..7e947e8 100755 --- a/scripts/install +++ b/scripts/install @@ -9,6 +9,7 @@ source _common.sh source ynh_detect_arch__2 source ynh_add_config +source ynh_mongo_db source /usr/share/yunohost/helpers #================================================= @@ -97,7 +98,9 @@ systemctl start $mongodb_servicename # Registering db name 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_mongo_setup_db --db_user=$db_user --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE diff --git a/scripts/remove b/scripts/remove index 2c0e2ea..6781b33 100755 --- a/scripts/remove +++ b/scripts/remove @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_mongo_db source /usr/share/yunohost/helpers #================================================= @@ -49,7 +50,7 @@ ynh_remove_systemd_config ynh_script_progression --message="Removing the MongoDB database..." # Remove a database if it exists, along with the associated user -mongo $db_name --eval "db.dropDatabase()" +ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE DEPENDENCIES diff --git a/scripts/restore b/scripts/restore index 53252a9..ee64abd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,6 +8,7 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_mongo_db source /usr/share/yunohost/helpers #================================================= @@ -31,6 +32,7 @@ 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 #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -103,7 +105,9 @@ ynh_script_progression --message="Restoring the MongoDB database..." # Start mongodb systemctl enable $mongodb_servicename systemctl start $mongodb_servicename -mongorestore --quiet --db="$db_name" "./dump/$db_name" +db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mongo_restore_db --database="$db_name" < ./dump.bson #================================================= # RESTORE SYSTEMD diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db new file mode 100644 index 0000000..a3d0b80 --- /dev/null +++ b/scripts/ynh_mongo_db @@ -0,0 +1,246 @@ +#!/bin/bash + +# Evaluate a mongo command +# +# example: ynh_mongo_eval_as --command='db.getMongo().getDBNames().indexOf("wekan")' +# example: ynh_mongo_eval_as --command="db.getMongo().getDBNames().indexOf(\"wekan\")" +# +# usage: ynh_mongo_eval_as [--user=user] [--password=password] [--database=database] [--host=host] [--port=port] --command="command" +# | arg: -u, --user= - the user name to connect as +# | arg: -p, --password= - the user password +# | arg: -d, --database= - the database to connect to +# | arg: -h, --host= - the host to connect to +# | arg: -P, --port= - the port to connect to +# | arg: -c, --command= - the command to evaluate +# +# +ynh_mongo_eval_as() { + # Declare an array to define the options of this helper. + local legacy_args=updhPc + local -A args_array=( [u]=user= [p]=password= [d]=database= [h]=host= [P]=port= [c]=command= ) + local user + local password + local database + local host + local port + local command + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + user="${user:-}" + password="${password:-}" + database="${database:-}" + host="${host:-}" + port="${port:-}" + + # If user is provided + if [ -n "$user" ] + then + user="--username=$user" + + # If password is provided + if [ -n "$password" ] + then + password="--password=$password" + fi + + # If database is provided + if [ -n "$database" ] + then + database="--authenticationDatabase=$database" + fi + else + password="" + database="" + fi + + # If host is provided + if [ -n "$host" ] + then + host="--host=$host" + fi + + # If host is provided + if [ -n "$port" ] + then + port="--port=$port" + fi + + mongo --quiet $user $password $database $host $port --eval="$command" +} + +# Create a database and grant optionnaly privilegies to a user +# +# [internal] +# +# usage: ynh_mongo_create_db db_name [db_user] +# | arg: db_name - the database name to create +# | arg: db_user - the user to grant privilegies +# +# +ynh_mongo_create_db() { + local db_name=$1 + local db_user=$2 + + # Set the user as admin of the db + ynh_mongo_eval_as --database="$db_name" --command='db.grantRolesToUser("'${db_user}'",[{ role: "clusterMonitor", db: "admin" }]);' +} + +# Drop a database +# +# [internal] +# +# If you intend to drop the database *and* the associated user, +# consider using ynh_mongo_remove_db instead. +# +# usage: ynh_mongo_drop_db db +# | arg: db - the database name to drop +# +# +ynh_mongo_drop_db() { + ynh_mongo_eval_as --database="${1}" --command='db.runCommand({dropDatabase: 1})' +} + +# Dump a database +# +# example: ynh_mongo_dump_db --database=wekan > ./dump.bson +# +# usage: ynh_mongo_dump_db --database=database +# | arg: -d, --database= - the database name to dump +# | ret: the mongodump output +# +# +ynh_mongo_dump_db() { + # Declare an array to define the options of this helper. + local legacy_args=d + local -A args_array=( [d]=database= ) + local database + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + mongodump --quiet --db="$database" --archive +} + +# Create a user +# +# [internal] +# +# usage: ynh_mongo_create_user user pwd [host] +# | arg: user - the user name to create +# | arg: pwd - the password to identify user by +# +# +ynh_mongo_create_user() { + ynh_mongo_eval_as --command='db.createUser( { user: "'${1}'", pwd: "'${2}'", roles: [ "readWrite" ] } );' +} + +# Check if a mongo database exists +# +# usage: ynh_mongo_database_exists --database=database +# | arg: -d, --database= - the database for which to check existence +# | exit: Return 1 if the database doesn't exist, 0 otherwise +# +# +ynh_mongo_database_exists() { + # Declare an array to define the options of this helper. + local legacy_args=d + local -A args_array=([d]=database=) + local database + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + if [ $(ynh_mongo_eval_as --command='db.getMongo().getDBNames().indexOf("'${database}'")') -lt 0 ] + then + return 0 + else + return 1 + fi +} + +# Restore a database +# +# example: ynh_mongo_restore_db --database=wekan < ./dump.bson +# +# usage: ynh_mongo_restore_db --database=database +# | arg: -d, --database= - the database name to restore +# +# +ynh_mongo_restore_db() { + # Declare an array to define the options of this helper. + local legacy_args=d + local -A args_array=( [d]=database= ) + local database + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + mongorestore --quiet --db="$database" --archive +} + +# Drop a user +# +# [internal] +# +# usage: ynh_mongo_drop_user user +# | arg: user - the user name to drop +# +# +ynh_mongo_drop_user() { + ynh_mongo_eval_as --command='db.dropUser("'${1}'", {w: "majority", wtimeout: 5000})' +} + +# Create a database, an user and its password. Then store the password in the app's config +# +# usage: ynh_mongo_setup_db --db_user=user --db_name=name [--db_pwd=pwd] +# | arg: -u, --db_user= - Owner of the database +# | arg: -n, --db_name= - Name of the database +# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated +# +# After executing this helper, the password of the created database will be available in $db_pwd +# It will also be stored as "mongopwd" into the app settings. +# +# +ynh_mongo_setup_db() { + # Declare an array to define the options of this helper. + local legacy_args=unp + local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= ) + local db_user + local db_name + local db_pwd="" + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local new_db_pwd=$(ynh_string_random) # Generate a random password + # If $db_pwd is not provided, use new_db_pwd instead for db_pwd + db_pwd="${db_pwd:-$new_db_pwd}" + + ynh_mongo_create_user "$db_user" "$db_pwd" # Create the user + + ynh_mongo_create_db "$db_name" "$db_user" # Create the database + ynh_app_setting_set --app=$app --key=mongopwd --value=$db_pwd # Store the password in the app's config +} + +# Remove a database if it exists, and the associated user +# +# usage: ynh_mongo_remove_db --db_user=user --db_name=name +# | arg: -u, --db_user= - Owner of the database +# | arg: -n, --db_name= - Name of the database +# +# +ynh_mongo_remove_db() { + # Declare an array to define the options of this helper. + local legacy_args=un + local -A args_array=( [u]=db_user= [n]=db_name= ) + local db_user + local db_name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + if ynh_mongo_database_exists --database=$db_name + then # Check if the database exists + ynh_mongo_drop_db $db_name # Remove the database + else + ynh_print_warn --message="Database $db_name not found" + fi + + # Remove mongo user if it exists + ynh_mongo_drop_user $db_user +} From 7861692ff3aa6e81874dea93074446ec0ec26a91 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 15 Jun 2020 23:44:39 +0200 Subject: [PATCH 04/23] Missing port --- scripts/change_url | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/change_url b/scripts/change_url index ab60df7..f0ef135 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -33,6 +33,7 @@ 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=db_pwd) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP From c2e83b949ad31a7b06291d5459cee866d5be0a7c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 16 Jun 2020 06:13:34 +0200 Subject: [PATCH 05/23] Update ynh_add_config --- scripts/ynh_add_config | 164 ++++++++++++++++++++++++++--------------- 1 file changed, 105 insertions(+), 59 deletions(-) diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config index 9435819..2fa451c 100644 --- a/scripts/ynh_add_config +++ b/scripts/ynh_add_config @@ -1,6 +1,6 @@ #!/bin/bash -# Create a dedicated config file +# Create a dedicated config file # # usage: ynh_add_config [--origin="origin file"] [--destination="destination file"] [--vars="vars to replace"] # | arg: -o, --origin= - Template config file to use (optionnal, ../conf/.env by default) @@ -54,64 +54,7 @@ ynh_add_config () { ynh_backup_if_checksum_is_different --file="$destination" cp "$origin" "$destination" - #Replace usual YunoHost variables - if test -n "${path_url:-}" - then - # path_url_slash_less is path_url, or a blank value if path_url is only '/' - local path_url_slash_less=${path_url%/} - ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$destination" - ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$destination" - fi - if test -n "${domain:-}"; then - ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$destination" - fi - if test -n "${port:-}"; then - ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$destination" - fi - if test -n "${app:-}"; then - ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$destination" - ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$destination" - ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$destination" - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$destination" - fi - if test -n "${final_path:-}"; then - ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$destination" - fi - if test -n "${YNH_PHP_VERSION:-}"; then - ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$destination" - fi - if test -n "${ynh_npm:-}"; then - ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$destination" - fi - if test -n "${ynh_node:-}"; then - ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$destination" - fi - if test -n "${ynh_node_load_PATH:-}"; then - ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$destination" - fi - if test -n "${nodejs_path:-}"; then - ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$destination" - fi - if test -n "${nodejs_version:-}"; then - ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$destination" - fi - if test -n "${db_name:-}"; then - ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$destination" - fi - if test -n "${db_user:-}"; then - ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$destination" - fi - if test -n "${db_pwd:-}"; then - ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$destination" - fi - - # Replace all other variables given as arguments - for var_to_replace in $vars - do - # ${var_to_replace^^} make the content of the variable on upper-cases - # ${!var_to_replace} get the content of the variable named $var_to_replace - ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$destination" - done + ynh_replace_vars --file="$destination" --vars="$vars" ynh_store_file_checksum --file="$destination" } @@ -141,3 +84,106 @@ ynh_remove_config () { ynh_secure_remove --file="$file" fi } + +# Replace variables in a file +# +# usage: ynh_replace_vars --file="file" [--vars="vars to replace"] +# | arg: -o, --file= - Template config file to use +# | arg: -v, --vars= - List of variables to replace separated by a space. For example: 'var_1 var_2 ...' +# +# This will replace in the the following keywords with global variables +# that should be defined before calling this helper : +# __PATH__ by $path_url +# __DOMAIN__ by $domain +# __PORT__ by $port +# __NAME__ by $app +# __NAMETOCHANGE__ by $app +# __USER__ by $app +# __APP__ by $app +# __FINALPATH__ by $final_path +# __PHPVERSION__ by $YNH_PHP_VERSION +# __YNH_NPM__ by $ynh_npm +# __YNH_NODE__ by $ynh_node +# __YNH_NODE_LOAD_PATH__ by $ynh_node_load_PATH +# __NODEJS_PATH__ by $nodejs_path +# __NODEJS_VERSION__ by $nodejs_version +# __DB_NAME__ by $db_name +# __DB_USER__ by $db_user +# __DB_PWD__ by $db_pwd +# +# And dynamic variables (from the last example) : +# __VAR_1__ by $var_1 +# __VAR_2__ by $var_2 +# +# +ynh_replace_vars () { + # Declare an array to define the options of this helper. + local legacy_args=fv + local -A args_array=( [f]=file= [v]=vars= ) + local file + local vars + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local file="${file:-}" + local vars="${vars:-}" + + + #Replace usual YunoHost variables + if test -n "${path_url:-}" + then + # path_url_slash_less is path_url, or a blank value if path_url is only '/' + local path_url_slash_less=${path_url%/} + ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$file" + ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$file" + fi + if test -n "${domain:-}"; then + ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$file" + fi + if test -n "${port:-}"; then + ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$file" + fi + if test -n "${app:-}"; then + ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$file" + ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$file" + ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$file" + ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$file" + fi + if test -n "${final_path:-}"; then + ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$file" + fi + if test -n "${YNH_PHP_VERSION:-}"; then + ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$file" + fi + if test -n "${ynh_npm:-}"; then + ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$file" + fi + if test -n "${ynh_node:-}"; then + ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$file" + fi + if test -n "${ynh_node_load_PATH:-}"; then + ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file" + fi + if test -n "${nodejs_path:-}"; then + ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$file" + fi + if test -n "${nodejs_version:-}"; then + ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$file" + fi + if test -n "${db_name:-}"; then + ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$file" + fi + if test -n "${db_user:-}"; then + ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$file" + fi + if test -n "${db_pwd:-}"; then + ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$file" + fi + + # Replace all other variables given as arguments + for var_to_replace in $vars + do + # ${var_to_replace^^} make the content of the variable on upper-cases + # ${!var_to_replace} get the content of the variable named $var_to_replace + ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$file" + done +} \ No newline at end of file From 9de9501a84d7d74e0354029c4793ceada24c69be Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 16 Jun 2020 08:01:34 +0200 Subject: [PATCH 06/23] Update ynh_mongo_db --- scripts/ynh_mongo_db | 118 ++++++++++++++++++++++++++----------------- 1 file changed, 71 insertions(+), 47 deletions(-) diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index a3d0b80..0dd049f 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -5,21 +5,23 @@ # example: ynh_mongo_eval_as --command='db.getMongo().getDBNames().indexOf("wekan")' # example: ynh_mongo_eval_as --command="db.getMongo().getDBNames().indexOf(\"wekan\")" # -# usage: ynh_mongo_eval_as [--user=user] [--password=password] [--database=database] [--host=host] [--port=port] --command="command" -# | arg: -u, --user= - the user name to connect as -# | arg: -p, --password= - the user password -# | arg: -d, --database= - the database to connect to -# | arg: -h, --host= - the host to connect to -# | arg: -P, --port= - the port to connect to -# | arg: -c, --command= - the command to evaluate +# usage: ynh_mongo_eval_as [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" +# | arg: -u, --user= - the user name to connect as +# | arg: -p, --password= - the user password +# | arg: -d, --authenticationdatabase= - the authenticationdatabase to connect to +# | arg: -d, --database= - the database to connect to +# | arg: -h, --host= - the host to connect to +# | arg: -P, --port= - the port to connect to +# | arg: -c, --command= - the command to evaluate # # ynh_mongo_eval_as() { # Declare an array to define the options of this helper. - local legacy_args=updhPc - local -A args_array=( [u]=user= [p]=password= [d]=database= [h]=host= [P]=port= [c]=command= ) + local legacy_args=upadhPc + local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= ) local user local password + local authenticationdatabase local database local host local port @@ -28,7 +30,8 @@ ynh_mongo_eval_as() { ynh_handle_getopts_args "$@" user="${user:-}" password="${password:-}" - database="${database:-}" + authenticationdatabase="${authenticationdatabase:-"admin"}" + database="${database:-"admin"}" host="${host:-}" port="${port:-}" @@ -36,23 +39,16 @@ ynh_mongo_eval_as() { if [ -n "$user" ] then user="--username=$user" - - # If password is provided - if [ -n "$password" ] - then - password="--password=$password" - fi - - # If database is provided - if [ -n "$database" ] - then - database="--authenticationDatabase=$database" - fi + password="--password=$password" + authenticationdatabase="--authenticationDatabase=$authenticationdatabase" else password="" - database="" + authenticationdatabase="" fi + # Configure dabase connection + database="use $database" + # If host is provided if [ -n "$host" ] then @@ -65,24 +61,25 @@ ynh_mongo_eval_as() { port="--port=$port" fi - mongo --quiet $user $password $database $host $port --eval="$command" + mongo --quiet $user $password $authenticationdatabase $host $port < Date: Tue, 4 Aug 2020 22:55:02 +0200 Subject: [PATCH 07/23] Update ynh_mongo_db --- scripts/ynh_mongo_db | 62 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index 0dd049f..9322c96 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -2,20 +2,20 @@ # Evaluate a mongo command # -# example: ynh_mongo_eval_as --command='db.getMongo().getDBNames().indexOf("wekan")' -# example: ynh_mongo_eval_as --command="db.getMongo().getDBNames().indexOf(\"wekan\")" +# example: ynh_mongo_exec_as --command='db.getMongo().getDBNames().indexOf("wekan")' +# example: ynh_mongo_exec_as --command="db.getMongo().getDBNames().indexOf(\"wekan\")" # -# usage: ynh_mongo_eval_as [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" -# | arg: -u, --user= - the user name to connect as -# | arg: -p, --password= - the user password -# | arg: -d, --authenticationdatabase= - the authenticationdatabase to connect to -# | arg: -d, --database= - the database to connect to -# | arg: -h, --host= - the host to connect to -# | arg: -P, --port= - the port to connect to -# | arg: -c, --command= - the command to evaluate +# usage: ynh_mongo_exec_as [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" +# | arg: -u, --user= - The user name to connect as +# | arg: -p, --password= - The user password +# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to +# | arg: -d, --database= - The database to connect to +# | arg: -h, --host= - The host to connect to +# | arg: -P, --port= - The port to connect to +# | arg: -c, --command= - The command to evaluate # # -ynh_mongo_eval_as() { +ynh_mongo_exec_as() { # Declare an array to define the options of this helper. local legacy_args=upadhPc local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= ) @@ -73,7 +73,7 @@ EOF # [internal] # # usage: ynh_mongo_create_db db_name -# | arg: db_name - the database name to create +# | arg: db_name - The database name to create # # ynh_mongo_create_db() { @@ -89,8 +89,8 @@ ynh_mongo_create_db() { # If you intend to drop the database *and* the associated user, # consider using ynh_mongo_remove_db instead. # -# usage: ynh_mongo_drop_db -database=db -# | arg: -d, --database= - the database name to drop +# usage: ynh_mongo_drop_db -database=db_name +# | arg: -d, --database= - The database name to drop # # ynh_mongo_drop_db() { @@ -100,15 +100,15 @@ ynh_mongo_drop_db() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - ynh_mongo_eval_as --database="${database}" --command='db.runCommand({dropDatabase: 1})' + ynh_mongo_exec_as --database="${database}" --command='db.runCommand({dropDatabase: 1})' } # Dump a database # # example: ynh_mongo_dump_db --database=wekan > ./dump.bson # -# usage: ynh_mongo_dump_db --database=database -# | arg: -d, --database= - the database name to dump +# usage: ynh_mongo_dump_db --database=db_name +# | arg: -d, --database= - The database name to dump # | ret: the mongodump output # # @@ -128,8 +128,8 @@ ynh_mongo_dump_db() { # [internal] # # usage: ynh_mongo_create_user --db_user=db_user --db_pwd=db_pwd --db_name=db_name -# | arg: -u, --db_user= - the user name to create -# | arg: -p, --db_pwd= - the password to identify user by +# | arg: -u, --db_user= - The user name to create +# | arg: -p, --db_pwd= - The password to identify user by # | arg: -n, --db_name= - Name of the database to grant privilegies # # @@ -144,16 +144,16 @@ ynh_mongo_create_user() { ynh_handle_getopts_args "$@" # Create the user and set the user as admin of the db - ynh_mongo_eval_as --database="$db_name" --command='db.createUser( { user: "'${db_user}'", pwd: "'${db_pwd}'", roles: [ { role: "readWrite", db: "'${db_name}'" } ] } );' + ynh_mongo_exec_as --database="$db_name" --command='db.createUser( { user: "'${db_user}'", pwd: "'${db_pwd}'", roles: [ { role: "readWrite", db: "'${db_name}'" } ] } );' # Add clustermonitoring rights - ynh_mongo_eval_as --database="$db_name" --command='db.grantRolesToUser("'${db_user}'",[{ role: "clusterMonitor", db: "admin" }]);' + ynh_mongo_exec_as --database="$db_name" --command='db.grantRolesToUser("'${db_user}'",[{ role: "clusterMonitor", db: "admin" }]);' } # Check if a mongo database exists # -# usage: ynh_mongo_database_exists --database=database -# | arg: -d, --database= - the database for which to check existence +# usage: ynh_mongo_database_exists --database=db_name +# | arg: -d, --database= - The database for which to check existence # | exit: Return 1 if the database doesn't exist, 0 otherwise # # @@ -165,7 +165,7 @@ ynh_mongo_database_exists() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - if [ $(ynh_mongo_eval_as --command='db.getMongo().getDBNames().indexOf("'${database}'")') -lt 0 ] + if [ $(ynh_mongo_exec_as --command='db.getMongo().getDBNames().indexOf("'${database}'")') -lt 0 ] then return 0 else @@ -177,8 +177,8 @@ ynh_mongo_database_exists() { # # example: ynh_mongo_restore_db --database=wekan < ./dump.bson # -# usage: ynh_mongo_restore_db --database=database -# | arg: -d, --database= - the database name to restore +# usage: ynh_mongo_restore_db --database=db_name +# | arg: -d, --database= - The database name to restore # # ynh_mongo_restore_db() { @@ -196,8 +196,8 @@ ynh_mongo_restore_db() { # # [internal] # -# usage: ynh_mongo_drop_user --db_user=user -# | arg: -u, --db_user= -the user to drop +# usage: ynh_mongo_drop_user --db_user=db_user +# | arg: -u, --db_user= - The user to drop # # ynh_mongo_drop_user() { @@ -208,12 +208,12 @@ ynh_mongo_drop_user() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - ynh_mongo_eval_as --command='db.dropUser("'${db_user}'", {w: "majority", wtimeout: 5000})' + ynh_mongo_exec_as --command='db.dropUser("'${db_user}'", {w: "majority", wtimeout: 5000})' } # Create a database, an user and its password. Then store the password in the app's config # -# usage: ynh_mongo_setup_db --db_user=user --db_name=name [--db_pwd=pwd] +# usage: ynh_mongo_setup_db --db_user=db_user --db_name=db_name [--db_pwd=db_pwd] # | arg: -u, --db_user= - Owner of the database # | arg: -n, --db_name= - Name of the database # | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated @@ -244,7 +244,7 @@ ynh_mongo_setup_db() { # Remove a database if it exists, and the associated user # -# usage: ynh_mongo_remove_db --db_user=user --db_name=name +# usage: ynh_mongo_remove_db --db_user=db_user --db_name=db_name # | arg: -u, --db_user= - Owner of the database # | arg: -n, --db_name= - Name of the database # From 3b7535a79d5ff5e5d8728e88d45e3f5de1bd1da0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 6 Aug 2020 04:37:00 +0200 Subject: [PATCH 08/23] Update ynh_mongo_db --- scripts/install | 9 +- scripts/remove | 6 +- scripts/restore | 9 +- scripts/upgrade | 9 +- scripts/ynh_mongo_db | 190 +++++++++++++++++++++++++++++-------------- 5 files changed, 135 insertions(+), 88 deletions(-) diff --git a/scripts/install b/scripts/install index 7e947e8..d237541 100755 --- a/scripts/install +++ b/scripts/install @@ -79,13 +79,7 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs -if [ "$(lsb_release --codename --short)" = "buster" ]; then - ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc" - mongodb_servicename=$mongodb_buster -else - ynh_install_app_dependencies $pkg_dependencies - mongodb_servicename=$mongodb_stretch -fi +ynh_mongo_install #================================================= # CREATE A MONGODB DATABASE @@ -163,7 +157,6 @@ find "$final_path" -type d -print0 | xargs -0 chmod 750 ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --description "Wekan daemon" --log_type "systemd" -yunohost service add mongodb --description "MongoDB daemon" --log "/var/log/mongodb/mongodb.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index 6781b33..b1a910c 100755 --- a/scripts/remove +++ b/scripts/remove @@ -61,11 +61,7 @@ ynh_script_progression --message="Removing dependencies..." ynh_remove_app_dependencies ynh_remove_nodejs -# Only remove the mongodb service if it is not installed. -if ! ynh_package_is_installed --package="mongodb" -then - yunohost service remove mongodb -fi +ynh_mongo_remove #================================================= # REMOVE APP MAIN DIR diff --git a/scripts/restore b/scripts/restore index ee64abd..bd1eaff 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,13 +89,7 @@ ynh_script_progression --message="Reinstalling dependencies..." ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs -if [ "$(lsb_release --codename --short)" = "buster" ]; then - ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc" - mongodb_servicename=$mongodb_buster -else - ynh_install_app_dependencies $pkg_dependencies - mongodb_servicename=$mongodb_stretch -fi +ynh_mongo_install #================================================= # RESTORE THE MONGODB DATABASE @@ -123,7 +117,6 @@ systemctl enable $app.service ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --description "Wekan daemon" --log_type "systemd" -yunohost service add mongodb --description "MongoDB daemon" --log "/var/log/mongodb/mongodb.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 81617cc..b69cc76 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -109,7 +109,6 @@ if ynh_version_gt "1.07~ynh2" "${previous_version}" ; then ynh_remove_app_dependencies ynh_install_app_dependencies "mongodb mongodb-server" yunohost service add $app --description "Wekan daemon" --log_type "systemd" - yunohost service add mongodb --description "MongoDB daemon" --log "/var/log/mongodb/mongodb.log" fi if ynh_version_gt "2.56~ynh1" "${previous_version}" ; then @@ -181,13 +180,7 @@ ynh_remove_nodejs ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs -if [ "$(lsb_release --codename --short)" = "buster" ]; then - ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc" - mongodb_servicename=$mongodb_buster -else - ynh_install_app_dependencies $pkg_dependencies - mongodb_servicename=$mongodb_stretch -fi +ynh_mongo_install #================================================= # CREATE DEDICATED USER diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index 9322c96..b00a756 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -1,11 +1,20 @@ #!/bin/bash -# Evaluate a mongo command +MONGO_SERVICENAME_STRETCH="mongodb" +MONGO_SERVICENAME_BUSTER="mongod" +MONGO_DEPENDENCIES_STRETCH="mongodb mongodb-server mongo-tools" +MONGO_DEPENDENCIES_BUSTER="mongodb-org mongodb-org-server mongodb-org-tools" +MONGO_CONFIG_STRETCH="/etc/mongodb.conf" +MONGO_CONFIG_BUSTER="/etc/mongod.conf" +MONGO_REPO_BUSTER="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" +MONGO_KEY_BUSTER="https://www.mongodb.org/static/pgp/server-4.2.asc" + +# Execute a mongo command # -# example: ynh_mongo_exec_as --command='db.getMongo().getDBNames().indexOf("wekan")' -# example: ynh_mongo_exec_as --command="db.getMongo().getDBNames().indexOf(\"wekan\")" +# example: ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("wekan")' +# example: ynh_mongo_exec --command="db.getMongo().getDBNames().indexOf(\"wekan\")" # -# usage: ynh_mongo_exec_as [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" +# usage: ynh_mongo_exec [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" [--eval] # | arg: -u, --user= - The user name to connect as # | arg: -p, --password= - The user password # | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to @@ -13,12 +22,13 @@ # | arg: -h, --host= - The host to connect to # | arg: -P, --port= - The port to connect to # | arg: -c, --command= - The command to evaluate +# | arg: -e, --eval - Evaluate instead of execute the command. # # -ynh_mongo_exec_as() { +ynh_mongo_exec() { # Declare an array to define the options of this helper. - local legacy_args=upadhPc - local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= ) + local legacy_args=upadhPce + local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= [e]=eval ) local user local password local authenticationdatabase @@ -26,60 +36,79 @@ ynh_mongo_exec_as() { local host local port local command + local eval # Manage arguments with getopts ynh_handle_getopts_args "$@" user="${user:-}" password="${password:-}" - authenticationdatabase="${authenticationdatabase:-"admin"}" - database="${database:-"admin"}" + authenticationdatabase="${authenticationdatabase:-}" + database="${database:-}" host="${host:-}" port="${port:-}" + eval=${eval:-0} # If user is provided if [ -n "$user" ] then user="--username=$user" - password="--password=$password" - authenticationdatabase="--authenticationDatabase=$authenticationdatabase" + + # If password is provided + if [ -n "$password" ] + then + password="--password=$password" + fi + + # If authenticationdatabase is provided + if [ -n "$authenticationdatabase" ] + then + authenticationdatabase="--authenticationDatabase=$authenticationdatabase" + else + authenticationdatabase="--authenticationDatabase=admin" + fi else password="" authenticationdatabase="" fi - # Configure dabase connection - database="use $database" - # If host is provided if [ -n "$host" ] then host="--host=$host" fi - # If host is provided + # If port is provided if [ -n "$port" ] then port="--port=$port" fi - mongo --quiet $user $password $authenticationdatabase $host $port < ./dump.bson # -# usage: ynh_mongo_dump_db --database=db_name +# usage: ynh_mongo_dump_db --database=database # | arg: -d, --database= - The database name to dump # | ret: the mongodump output # @@ -127,10 +157,10 @@ ynh_mongo_dump_db() { # # [internal] # -# usage: ynh_mongo_create_user --db_user=db_user --db_pwd=db_pwd --db_name=db_name +# usage: ynh_mongo_create_user --db_user=user --db_pwd=pwd --db_name=name # | arg: -u, --db_user= - The user name to create # | arg: -p, --db_pwd= - The password to identify user by -# | arg: -n, --db_name= - Name of the database to grant privilegies +# | arg: -n, --db_name= - Name of the database to grant privilegies # # ynh_mongo_create_user() { @@ -144,15 +174,15 @@ ynh_mongo_create_user() { ynh_handle_getopts_args "$@" # Create the user and set the user as admin of the db - ynh_mongo_exec_as --database="$db_name" --command='db.createUser( { user: "'${db_user}'", pwd: "'${db_pwd}'", roles: [ { role: "readWrite", db: "'${db_name}'" } ] } );' + ynh_mongo_exec --database="$db_name" --command='db.createUser( { user: "'${db_user}'", pwd: "'${db_pwd}'", roles: [ { role: "readWrite", db: "'${db_name}'" } ] } );' # Add clustermonitoring rights - ynh_mongo_exec_as --database="$db_name" --command='db.grantRolesToUser("'${db_user}'",[{ role: "clusterMonitor", db: "admin" }]);' + ynh_mongo_exec --database="$db_name" --command='db.grantRolesToUser("'${db_user}'",[{ role: "clusterMonitor", db: "admin" }]);' } # Check if a mongo database exists # -# usage: ynh_mongo_database_exists --database=db_name +# usage: ynh_mongo_database_exists --database=database # | arg: -d, --database= - The database for which to check existence # | exit: Return 1 if the database doesn't exist, 0 otherwise # @@ -165,11 +195,11 @@ ynh_mongo_database_exists() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - if [ $(ynh_mongo_exec_as --command='db.getMongo().getDBNames().indexOf("'${database}'")') -lt 0 ] + if [ $(ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("'${database}'")' --eval) -lt 0 ] then - return 0 - else return 1 + else + return 0 fi } @@ -177,7 +207,7 @@ ynh_mongo_database_exists() { # # example: ynh_mongo_restore_db --database=wekan < ./dump.bson # -# usage: ynh_mongo_restore_db --database=db_name +# usage: ynh_mongo_restore_db --database=database # | arg: -d, --database= - The database name to restore # # @@ -196,27 +226,29 @@ ynh_mongo_restore_db() { # # [internal] # -# usage: ynh_mongo_drop_user --db_user=db_user -# | arg: -u, --db_user= - The user to drop +# usage: ynh_mongo_drop_user --db_user=user --db_name=name +# | arg: -u, --db_user= - The user to drop +# | arg: -n, --db_name= - Name of the database # # ynh_mongo_drop_user() { # Declare an array to define the options of this helper. - local legacy_args=u - local -A args_array=( [u]=db_user= ) + local legacy_args=un + local -A args_array=( [u]=db_user= [n]=db_name= ) local db_user + local db_name # Manage arguments with getopts ynh_handle_getopts_args "$@" - ynh_mongo_exec_as --command='db.dropUser("'${db_user}'", {w: "majority", wtimeout: 5000})' + ynh_mongo_exec --database="$db_name" --command='db.dropUser("'$db_user'", {w: "majority", wtimeout: 5000})' } # Create a database, an user and its password. Then store the password in the app's config # -# usage: ynh_mongo_setup_db --db_user=db_user --db_name=db_name [--db_pwd=db_pwd] -# | arg: -u, --db_user= - Owner of the database -# | arg: -n, --db_name= - Name of the database -# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated +# usage: ynh_mongo_setup_db --db_user=user --db_name=name [--db_pwd=pwd] +# | arg: -u, --db_user= - Owner of the database +# | arg: -n, --db_name= - Name of the database +# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated # # After executing this helper, the password of the created database will be available in $db_pwd # It will also be stored as "mongopwd" into the app settings. @@ -228,7 +260,7 @@ ynh_mongo_setup_db() { local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= ) local db_user local db_name - local db_pwd + db_pwd="" # Manage arguments with getopts ynh_handle_getopts_args "$@" @@ -239,14 +271,15 @@ ynh_mongo_setup_db() { # Create the user and grant access to the database ynh_mongo_create_user --db_user="$db_user" --db_pwd="$db_pwd" --db_name="$db_name" + # Store the password in the app's config ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd } # Remove a database if it exists, and the associated user # -# usage: ynh_mongo_remove_db --db_user=db_user --db_name=db_name -# | arg: -u, --db_user= - Owner of the database -# | arg: -n, --db_name= - Name of the database +# usage: ynh_mongo_remove_db --db_user=user --db_name=name +# | arg: -u, --db_user= - Owner of the database +# | arg: -n, --db_name= - Name of the database # # ynh_mongo_remove_db() { @@ -258,13 +291,52 @@ ynh_mongo_remove_db() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - if ynh_mongo_database_exists --database=$db_name - then # Check if the database exists - ynh_mongo_drop_db --database="$db_name" # Remove the database + if ynh_mongo_database_exists --database=$db_name; then # Check if the database exists + ynh_mongo_drop_db --database=$db_name # Remove the database else ynh_print_warn --message="Database $db_name not found" fi # Remove mongo user if it exists - ynh_mongo_drop_user --db_user=$db_user + ynh_mongo_drop_user --db_user=$db_user --db_name=$db_name +} + +# Install MongoDB and integrate MongoDB service in YunoHost +# +# usage: ynh_mongo_install +# +# +ynh_mongo_install() { + # Define Mongo Service Name + if [ "$(lsb_release --codename --short)" = "buster" ]; then + ynh_install_extra_app_dependencies --repo="$MONGO_REPO_BUSTER" --package="$MONGO_DEPENDENCIES_BUSTER" --key="$MONGO_KEY_BUSTER" + MONGODB_SERVICENAME=$MONGO_SERVICENAME_BUSTER + else + ynh_install_app_dependencies $MONGO_DEPENDENCIES_STRETCH + MONGODB_SERVICENAME=$MONGO_SERVICENAME_STRETCH + fi + mongodb_servicename=$MONGODB_SERVICENAME + + # Make sure MongoDB is started and enabled + systemctl is-enabled $MONGODB_SERVICENAME -q || systemctl enable $MONGODB_SERVICENAME --quiet + systemctl is-active $MONGODB_SERVICENAME -q || ynh_systemd_action --service_name=$MONGODB_SERVICENAME --action=restart + + # Integrate MongoDB service in YunoHost + yunohost service add $MONGODB_SERVICENAME --description "MongoDB daemon" --log "/var/log/mongodb/$MONGODB_SERVICENAME.log" +} + +# Remove MongoDB +# Only remove the MongoDB service integration in YunoHost for now +# if MongoDB package as been removed +# +# usage: ynh_mongo_remove +# +# +ynh_mongo_remove() { + # Only remove the mongodb service if it is not installed. + if ! ynh_package_is_installed --package="mongodb*" + then + yunohost service remove $MONGODB_SERVICENAME + # ynh_secure_remove --file=$MONGO_ROOT_PWD_FILE + fi } From 5c93cb6583e2d4ac08eeb22a6e95d13a0c244cfb Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 6 Aug 2020 04:44:39 +0200 Subject: [PATCH 09/23] fix ynh_mongo_db --- scripts/_common.sh | 6 ++---- scripts/install | 5 +---- scripts/restore | 4 +--- scripts/upgrade | 1 + 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index b71abe9..d531f63 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,10 +5,8 @@ #================================================= # dependencies used by the app -pkg_dependencies="mongodb mongodb-server mongo-tools" -pkg_dependencies_buster="mongodb-org mongodb-org-server mongodb-org-tools" -mongodb_stretch="mongodb" -mongodb_buster="mongod" +pkg_dependencies="" + nodejsversion=12.16.3 #================================================= diff --git a/scripts/install b/scripts/install index d237541..a405fbe 100755 --- a/scripts/install +++ b/scripts/install @@ -76,6 +76,7 @@ ynh_app_setting_set --app=$app --key=port --value=$port #================================================= ynh_script_progression --message="Installing dependencies..." +ynh_install_app_dependencies $pkg_dependencies ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs @@ -86,10 +87,6 @@ ynh_mongo_install #================================================= ynh_script_progression --message="Creating a MongoDB database..." -# Start mongodb -systemctl enable $mongodb_servicename -systemctl start $mongodb_servicename - # Registering db name db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name diff --git a/scripts/restore b/scripts/restore index bd1eaff..58b69dd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -86,6 +86,7 @@ find "$final_path" -type d -print0 | xargs -0 chmod 750 ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs @@ -96,9 +97,6 @@ ynh_mongo_install #================================================= ynh_script_progression --message="Restoring the MongoDB database..." -# Start mongodb -systemctl enable $mongodb_servicename -systemctl start $mongodb_servicename db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mongo_restore_db --database="$db_name" < ./dump.bson diff --git a/scripts/upgrade b/scripts/upgrade index b69cc76..0e7a51c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -176,6 +176,7 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." +ynh_install_app_dependencies $pkg_dependencies ynh_remove_nodejs ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs From 9f43c740b61f3ba6853f9877b3f9097f739b696b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 6 Aug 2020 04:51:45 +0200 Subject: [PATCH 10/23] Upgrade ynh_mongo_db --- scripts/install | 3 +-- scripts/remove | 3 +-- scripts/restore | 3 +-- scripts/upgrade | 3 +-- scripts/ynh_mongo_db | 8 ++++---- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/install b/scripts/install index a405fbe..52d8084 100755 --- a/scripts/install +++ b/scripts/install @@ -79,8 +79,7 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs - -ynh_mongo_install +ynh_install_mongo #================================================= # CREATE A MONGODB DATABASE diff --git a/scripts/remove b/scripts/remove index b1a910c..463ca8f 100755 --- a/scripts/remove +++ b/scripts/remove @@ -60,8 +60,7 @@ ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies ynh_remove_nodejs - -ynh_mongo_remove +ynh_remove_mongo #================================================= # REMOVE APP MAIN DIR diff --git a/scripts/restore b/scripts/restore index 58b69dd..6907a74 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,8 +89,7 @@ ynh_script_progression --message="Reinstalling dependencies..." ynh_install_app_dependencies $pkg_dependencies ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs - -ynh_mongo_install +ynh_install_mongo #================================================= # RESTORE THE MONGODB DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 0e7a51c..1acf661 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -180,8 +180,7 @@ ynh_install_app_dependencies $pkg_dependencies ynh_remove_nodejs ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs - -ynh_mongo_install +ynh_install_mongo #================================================= # CREATE DEDICATED USER diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index b00a756..297ad83 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -303,10 +303,10 @@ ynh_mongo_remove_db() { # Install MongoDB and integrate MongoDB service in YunoHost # -# usage: ynh_mongo_install +# usage: ynh_install_mongo # # -ynh_mongo_install() { +ynh_install_mongo() { # Define Mongo Service Name if [ "$(lsb_release --codename --short)" = "buster" ]; then ynh_install_extra_app_dependencies --repo="$MONGO_REPO_BUSTER" --package="$MONGO_DEPENDENCIES_BUSTER" --key="$MONGO_KEY_BUSTER" @@ -329,10 +329,10 @@ ynh_mongo_install() { # Only remove the MongoDB service integration in YunoHost for now # if MongoDB package as been removed # -# usage: ynh_mongo_remove +# usage: ynh_remove_mongo # # -ynh_mongo_remove() { +ynh_remove_mongo() { # Only remove the mongodb service if it is not installed. if ! ynh_package_is_installed --package="mongodb*" then From dd8ecd9172b157246594c78686a988bbdb79806f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 6 Aug 2020 19:42:52 +0200 Subject: [PATCH 11/23] fix ./upgrade: line 183: ynh_install_mongo: command not found --- scripts/upgrade | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/upgrade b/scripts/upgrade index 1acf661..1b20b74 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,6 +10,7 @@ source _common.sh source ynh_package_version source ynh_detect_arch__2 source ynh_add_config +source ynh_mongo_db source /usr/share/yunohost/helpers #================================================= From 4ab6057958d2df467c486041bcbd0230759c140c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 7 Aug 2020 01:27:22 +0200 Subject: [PATCH 12/23] Upgrade mongodb to 4.4 --- scripts/ynh_mongo_db | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index 297ad83..ff2c419 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -6,8 +6,8 @@ MONGO_DEPENDENCIES_STRETCH="mongodb mongodb-server mongo-tools" MONGO_DEPENDENCIES_BUSTER="mongodb-org mongodb-org-server mongodb-org-tools" MONGO_CONFIG_STRETCH="/etc/mongodb.conf" MONGO_CONFIG_BUSTER="/etc/mongod.conf" -MONGO_REPO_BUSTER="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" -MONGO_KEY_BUSTER="https://www.mongodb.org/static/pgp/server-4.2.asc" +MONGO_REPO_BUSTER="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" +MONGO_KEY_BUSTER="https://www.mongodb.org/static/pgp/server-4.4.asc" # Execute a mongo command # From 9d5fb5cc8c362dd1b2a2940d97606ca54ef39662 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 7 Aug 2020 19:44:24 +0200 Subject: [PATCH 13/23] fix mongo service start --- scripts/ynh_mongo_db | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index ff2c419..4a43534 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -323,6 +323,9 @@ ynh_install_mongo() { # Integrate MongoDB service in YunoHost yunohost service add $MONGODB_SERVICENAME --description "MongoDB daemon" --log "/var/log/mongodb/$MONGODB_SERVICENAME.log" + + # Waiting Mongo DB to be fully started + sleep 10 } # Remove MongoDB From 2b896476a0389c1661cc6b4091d91583ef278019 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 7 Aug 2020 19:48:33 +0200 Subject: [PATCH 14/23] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Éric Gaspar <46165813+ericgaspar@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f0c5bfb..756a924 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Wekan for Yunohost +# Wekan for YunoHost [![Integration level](https://dash.yunohost.org/integration/wekan.svg)](https://dash.yunohost.org/appci/app/wekan) ![](https://ci-apps.yunohost.org/ci/badges/wekan.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/wekan.maintain.svg) [![Install Wekan with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=wekan) From 03b38c0b824b792e5e2df68c0d784d08f2f1ae7b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 8 Aug 2020 00:51:13 +0200 Subject: [PATCH 15/23] Switching sleep 10 --- scripts/ynh_mongo_db | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index 4a43534..82bb1ea 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -319,13 +319,10 @@ ynh_install_mongo() { # Make sure MongoDB is started and enabled systemctl is-enabled $MONGODB_SERVICENAME -q || systemctl enable $MONGODB_SERVICENAME --quiet - systemctl is-active $MONGODB_SERVICENAME -q || ynh_systemd_action --service_name=$MONGODB_SERVICENAME --action=restart + systemctl is-active $MONGODB_SERVICENAME -q || ynh_systemd_action --service_name=$MONGODB_SERVICENAME --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$MONGODB_SERVICENAME.log" # Integrate MongoDB service in YunoHost yunohost service add $MONGODB_SERVICENAME --description "MongoDB daemon" --log "/var/log/mongodb/$MONGODB_SERVICENAME.log" - - # Waiting Mongo DB to be fully started - sleep 10 } # Remove MongoDB From 7869bbfe7f83b83822cd8f0c465c23c83480dd9f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 8 Aug 2020 01:21:08 +0200 Subject: [PATCH 16/23] Adding ynh_print_info --- scripts/ynh_mongo_db | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index 82bb1ea..942bfb6 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -307,6 +307,8 @@ ynh_mongo_remove_db() { # # ynh_install_mongo() { + ynh_print_info --message="Installing MongoDB..." + # Define Mongo Service Name if [ "$(lsb_release --codename --short)" = "buster" ]; then ynh_install_extra_app_dependencies --repo="$MONGO_REPO_BUSTER" --package="$MONGO_DEPENDENCIES_BUSTER" --key="$MONGO_KEY_BUSTER" @@ -333,6 +335,8 @@ ynh_install_mongo() { # # ynh_remove_mongo() { + ynh_print_info --message="Removing MongoDB..." + # Only remove the mongodb service if it is not installed. if ! ynh_package_is_installed --package="mongodb*" then From cddb5f6d9dd675b3639de56babbe618fdd1d84ae Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 8 Aug 2020 20:27:34 +0200 Subject: [PATCH 17/23] Update ynh_add_config --- scripts/ynh_add_config | 204 +++++++++++++++-------------------------- 1 file changed, 76 insertions(+), 128 deletions(-) diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config index 2fa451c..e92e46f 100644 --- a/scripts/ynh_add_config +++ b/scripts/ynh_add_config @@ -1,134 +1,99 @@ #!/bin/bash -# Create a dedicated config file +# Create a dedicated config file from a template # -# usage: ynh_add_config [--origin="origin file"] [--destination="destination file"] [--vars="vars to replace"] -# | arg: -o, --origin= - Template config file to use (optionnal, ../conf/.env by default) -# | arg: -d, --destination= - Destination of the config file (optionnal, $final_path/.env) -# | arg: -v, --vars= - List of variables to replace separated by a space. For example: 'var_1 var_2 ...' +# examples: +# ynh_add_config --template=".env" --destination="$final_path/.env" +# ynh_add_config --template="../conf/.env" --destination="$final_path/.env" +# ynh_add_config --template="/etc/nginx/sites-available/default" --destination="etc/nginx/sites-available/mydomain.conf" # -# This will use the template $origin or ../conf/.env by default -# to generate a config file $destination or $final_path/.env by default, -# by replacing the following keywords with global variables +# usage: ynh_add_config --template="template" --destination="destination" +# | arg: -t, --template= - Template config file to use +# | arg: -d, --destination= - Destination of the config file +# +# The template can be by default the name of a file in the conf directory +# of a YunoHost Package, a relative path or an absolute path +# The helper will use the template $template to generate a config file +# $destination by replacing the following keywords with global variables # that should be defined before calling this helper : -# __PATH__ by $path_url -# __DOMAIN__ by $domain -# __PORT__ by $port -# __NAME__ by $app +# __PATH__ by $path_url +# __NAME__ by $app # __NAMETOCHANGE__ by $app -# __USER__ by $app -# __APP__ by $app -# __FINALPATH__ by $final_path -# __PHPVERSION__ by $YNH_PHP_VERSION -# __YNH_NPM__ by $ynh_npm -# __YNH_NODE__ by $ynh_node -# __YNH_NODE_LOAD_PATH__ by $ynh_node_load_PATH -# __NODEJS_PATH__ by $nodejs_path -# __NODEJS_VERSION__ by $nodejs_version -# __DB_NAME__ by $db_name -# __DB_USER__ by $db_user -# __DB_PWD__ by $db_pwd +# __USER__ by $app +# __FINALPATH__ by $final_path +# __PHPVERSION__ by $YNH_PHP_VERSION # -# And dynamic variables (from the last example) : +# And any dynamic variables that should be defined before calling this helper like: +# __DOMAIN__ by $domain +# __APP__ by $app # __VAR_1__ by $var_1 # __VAR_2__ by $var_2 # # The helper will verify the checksum and backup the destination file -# if it's different before applying the new origin file. -# And it will calculate and store a destination file checksum -# into the app settings when configuraation is done. +# if it's different before applying the new template. +# And it will calculate and store the destination file checksum +# into the app settings when configuration is done. +# # ynh_add_config () { # Declare an array to define the options of this helper. - local legacy_args=odv - local -A args_array=( [o]=origin= [d]=destination= [v]=vars= ) - local origin + local legacy_args=tdv + local -A args_array=( [t]=template= [d]=destination= ) + local template local destination - local vars # Manage arguments with getopts ynh_handle_getopts_args "$@" - local origin="${origin:-"../conf/.env"}" - local destination="${destination:-"$final_path/.env"}" - local vars="${vars:-}" + local template_path + + if [ -f "../conf/$template" ]; then + template_path="../conf/$template" + elif [ -f "../settings/conf/$template" ]; then + template_path="../settings/conf/$template" + elif [ -f "$template" ]; then + template_path=$template + else + ynh_die --message="The provided template $template doesn't exist" + fi ynh_backup_if_checksum_is_different --file="$destination" - cp "$origin" "$destination" - ynh_replace_vars --file="$destination" --vars="$vars" + cp "$template_path" "$destination" + + ynh_replace_vars --file="$destination" ynh_store_file_checksum --file="$destination" } -# Remove the dedicated config -# -# usage: ynh_remove_config [--file=file] -# | arg: -f, --file= - Config file to remove (optionnal, $final_path/.env) -# -# -ynh_remove_config () { - # Declare an array to define the options of this helper. - local legacy_args=f - local -A args_array=( [f]=file= ) - local file - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - local service="${file:-}" - - # The default behaviour is to use .env file. - if [ -n "$file" ]; then - file="final_path/.env" - fi - - if [ -e "$file" ] - then - ynh_secure_remove --file="$file" - fi -} - # Replace variables in a file # -# usage: ynh_replace_vars --file="file" [--vars="vars to replace"] -# | arg: -o, --file= - Template config file to use -# | arg: -v, --vars= - List of variables to replace separated by a space. For example: 'var_1 var_2 ...' +# usage: ynh_replace_vars --file="file" +# | arg: -f, --file= - File where to replace variables # -# This will replace in the the following keywords with global variables +# The helper will replace the following keywords with global variables # that should be defined before calling this helper : -# __PATH__ by $path_url -# __DOMAIN__ by $domain -# __PORT__ by $port -# __NAME__ by $app +# __PATH__ by $path_url +# __NAME__ by $app # __NAMETOCHANGE__ by $app -# __USER__ by $app -# __APP__ by $app -# __FINALPATH__ by $final_path -# __PHPVERSION__ by $YNH_PHP_VERSION -# __YNH_NPM__ by $ynh_npm -# __YNH_NODE__ by $ynh_node -# __YNH_NODE_LOAD_PATH__ by $ynh_node_load_PATH -# __NODEJS_PATH__ by $nodejs_path -# __NODEJS_VERSION__ by $nodejs_version -# __DB_NAME__ by $db_name -# __DB_USER__ by $db_user -# __DB_PWD__ by $db_pwd +# __USER__ by $app +# __FINALPATH__ by $final_path +# __PHPVERSION__ by $YNH_PHP_VERSION # -# And dynamic variables (from the last example) : +# And any dynamic variables that should be defined before calling this helper like: +# __DOMAIN__ by $domain +# __APP__ by $app # __VAR_1__ by $var_1 # __VAR_2__ by $var_2 # # ynh_replace_vars () { # Declare an array to define the options of this helper. - local legacy_args=fv - local -A args_array=( [f]=file= [v]=vars= ) + local legacy_args=f + local -A args_array=( [f]=file= ) local file - local vars # Manage arguments with getopts ynh_handle_getopts_args "$@" - local file="${file:-}" - local vars="${vars:-}" - - #Replace usual YunoHost variables + # Replace specific YunoHost variables if test -n "${path_url:-}" then # path_url_slash_less is path_url, or a blank value if path_url is only '/' @@ -136,17 +101,10 @@ ynh_replace_vars () { ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$file" ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$file" fi - if test -n "${domain:-}"; then - ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$file" - fi - if test -n "${port:-}"; then - ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$file" - fi if test -n "${app:-}"; then ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$file" ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$file" ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$file" - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$file" fi if test -n "${final_path:-}"; then ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$file" @@ -154,36 +112,26 @@ ynh_replace_vars () { if test -n "${YNH_PHP_VERSION:-}"; then ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$file" fi - if test -n "${ynh_npm:-}"; then - ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$file" - fi - if test -n "${ynh_node:-}"; then - ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$file" - fi - if test -n "${ynh_node_load_PATH:-}"; then - ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file" - fi - if test -n "${nodejs_path:-}"; then - ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$file" - fi - if test -n "${nodejs_version:-}"; then - ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$file" - fi - if test -n "${db_name:-}"; then - ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$file" - fi - if test -n "${db_user:-}"; then - ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$file" - fi - if test -n "${db_pwd:-}"; then - ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$file" - fi - # Replace all other variables given as arguments - for var_to_replace in $vars + # Replace othes variables + + # List other unique (__ __) variables in $file + local uniques_vars=( $(grep -o '__[A-Z0-9_]*__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" )) + + # Do the replacement + local delimit=@ + for one_var in "${uniques_vars[@]}" do - # ${var_to_replace^^} make the content of the variable on upper-cases - # ${!var_to_replace} get the content of the variable named $var_to_replace - ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$file" + # Validate that one_var is indeed defined + test -n "${!one_var:-}" || ynh_die --message="\$$one_var wasn't initialized when trying to replace __${one_var^^}__ in $file" + + # Escape delimiter in match/replace string + match_string="__${one_var^^}__" + match_string=${match_string//${delimit}/"\\${delimit}"} + replace_string="${!one_var}" + replace_string=${replace_string//${delimit}/"\\${delimit}"} + + # Actually replace (sed is used instead of ynh_replace_string to avoid triggering an epic amount of debug logs) + sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$file" done -} \ No newline at end of file +} From 2b97b7f45de46e770865df1c666ee829cae45273 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 8 Aug 2020 20:49:19 +0200 Subject: [PATCH 18/23] Implement new ynh_add_config --- scripts/install | 2 +- scripts/upgrade | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 52d8084..e11e79e 100755 --- a/scripts/install +++ b/scripts/install @@ -133,7 +133,7 @@ ynh_add_systemd_config --others_var="mongodb_servicename ynh_node" ynh_script_progression --message="Modifying a config file..." # Create a dedicated .env config -ynh_add_config +ynh_add_config --template=".env" --destination="$final_path/.env" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 1b20b74..4a1070e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -197,7 +197,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" ynh_script_progression --message="Modifying a config file..." # Create a dedicated .env config -ynh_add_config +ynh_add_config --template=".env" --destination="$final_path/.env" #================================================= # SETUP SYSTEMD From d848d115de91a411ead631dc150bd567fecfebb8 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 8 Aug 2020 21:02:38 +0200 Subject: [PATCH 19/23] Update ynh_add_config --- scripts/ynh_add_config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config index e92e46f..f404cd1 100644 --- a/scripts/ynh_add_config +++ b/scripts/ynh_add_config @@ -112,6 +112,9 @@ ynh_replace_vars () { if test -n "${YNH_PHP_VERSION:-}"; then ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$file" fi + if test -n "${ynh_node_load_PATH:-}"; then + ynh_replace_string --match_string="__YNH_NODE_LODE_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file" + fi # Replace othes variables From a73550cb73af9c84d0796c867fc927933e0f200d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 8 Aug 2020 21:19:10 +0200 Subject: [PATCH 20/23] Update ynh_add_config --- scripts/ynh_add_config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config index f404cd1..cfbcb3f 100644 --- a/scripts/ynh_add_config +++ b/scripts/ynh_add_config @@ -116,7 +116,7 @@ ynh_replace_vars () { ynh_replace_string --match_string="__YNH_NODE_LODE_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file" fi - # Replace othes variables + # Replace others variables # List other unique (__ __) variables in $file local uniques_vars=( $(grep -o '__[A-Z0-9_]*__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" )) From 174b32f21e4c53ab623456e573917b10d144cdc8 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 8 Aug 2020 21:46:47 +0200 Subject: [PATCH 21/23] Update ynh_add_config --- scripts/ynh_add_config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config index cfbcb3f..31513ba 100644 --- a/scripts/ynh_add_config +++ b/scripts/ynh_add_config @@ -113,10 +113,10 @@ ynh_replace_vars () { ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$file" fi if test -n "${ynh_node_load_PATH:-}"; then - ynh_replace_string --match_string="__YNH_NODE_LODE_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file" + ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file" fi - # Replace others variables + # Replace othes variables # List other unique (__ __) variables in $file local uniques_vars=( $(grep -o '__[A-Z0-9_]*__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" )) From 5d10d0699eafe1d61e06d36ef5e89489dd652639 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 8 Aug 2020 21:48:23 +0200 Subject: [PATCH 22/23] Update ynh_add_config --- scripts/ynh_add_config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config index 31513ba..58fad65 100644 --- a/scripts/ynh_add_config +++ b/scripts/ynh_add_config @@ -116,7 +116,7 @@ ynh_replace_vars () { ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file" fi - # Replace othes variables + # Replace others variables # List other unique (__ __) variables in $file local uniques_vars=( $(grep -o '__[A-Z0-9_]*__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" )) From cf8beb9d9e3a294130d1d54c48de888795d11a00 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 20 Oct 2020 23:55:44 +0200 Subject: [PATCH 23/23] Update check_process --- check_process | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/check_process b/check_process index c1b5d1f..db440f7 100644 --- a/check_process +++ b/check_process @@ -17,7 +17,9 @@ # 3.95~ynh1 upgrade=1 from_commit=46f4b540cb99090a3fe1d35828094dbbfb34b692 # 3.95~ynh1 - upgrade=1 from_commit=3cd252289f4fd138879872658762f4c6ae415cc4 + upgrade=1 from_commit=3cd252289f4fd138879872658762f4c6ae415cc4 + # 4.09~ynh1 + upgrade=1 from_commit=c2b4715e8591031f3054cedb1220e7619607bb36 backup_restore=1 multi_instance=1 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. @@ -36,4 +38,6 @@ Notification=down ; commit=46f4b540cb99090a3fe1d35828094dbbfb34b692 name=3.95~ynh1 ; commit=3cd252289f4fd138879872658762f4c6ae415cc4 - name=3.95~ynh1 \ No newline at end of file + name=3.95~ynh1 + ; commit=c2b4715e8591031f3054cedb1220e7619607bb36 + name=4.09~ynh1