From 4747cdc7a4efbdc622272c8a3843c9d5bd0e7792 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 28 Feb 2021 11:37:19 +0100 Subject: [PATCH] Apply last example_ynh --- README.md | 2 +- check_process | 4 ++ conf/app.src | 1 + issue_template.md | 29 ++++++--- manifest.json | 6 +- scripts/change_url | 6 +- scripts/install | 14 ++--- scripts/remove | 2 +- scripts/upgrade | 31 +++------ scripts/ynh_add_config | 140 ----------------------------------------- 10 files changed, 47 insertions(+), 188 deletions(-) delete mode 100644 scripts/ynh_add_config diff --git a/README.md b/README.md index f2b90e4..bb148c0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Distbin for YunoHost [![Integration level](https://dash.yunohost.org/integration/distbin.svg)](https://dash.yunohost.org/appci/app/distbin) ![](https://ci-apps.yunohost.org/ci/badges/distbin.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/distbin.maintain.svg) -[![Install distbin with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=distbin) +[![Install Distbin with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=distbin) > *This package allows you to install Distbin 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.* diff --git a/check_process b/check_process index 86c6e14..f2ab4ae 100644 --- a/check_process +++ b/check_process @@ -22,6 +22,8 @@ upgrade=1 from_commit=0dda384e84bbe2513cb67cfd1eef15d667e50354 # 1.3.0~ynh5 upgrade=1 from_commit=f7bc083d037eb771afeddc2237a24505a5ef1c68 + # 1.3.0~ynh6 + upgrade=1 from_commit=cdec64125b179f6b19470ceb8379225ed03c10a8 backup_restore=1 multi_instance=1 port_already_use=0 @@ -36,3 +38,5 @@ Notification=all name=1.3.0~ynh4 ; commit=f7bc083d037eb771afeddc2237a24505a5ef1c68 name=1.3.0~ynh5 + ; commit=cdec64125b179f6b19470ceb8379225ed03c10a8 + name=1.3.0~ynh6 diff --git a/conf/app.src b/conf/app.src index 9595f68..84e6716 100644 --- a/conf/app.src +++ b/conf/app.src @@ -4,3 +4,4 @@ SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/issue_template.md b/issue_template.md index e62f591..ba70717 100644 --- a/issue_template.md +++ b/issue_template.md @@ -1,6 +1,6 @@ --- 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. +about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. --- @@ -8,15 +8,17 @@ about: Create a report to help us debug, it would be nice to fill the template a 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 Distbin itself. Refer to its documentation or repository for help.* - - *If you have a doubt, post here, we will figure it out together.* + - *Otherwise, the issue may be due to distbin itself. Refer to its documentation or repository for help.* + - *When in doubt, post here and we will figure it out together.* 3. *Delete the italic comments as you write over them below, and remove this guide.* --- -**Describe the bug** +### Describe the bug + *A clear and concise description of what the bug is.* -**Versions** +### Context + - 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 | ...* @@ -25,8 +27,8 @@ about: Create a report to help us debug, it would be nice to fill the template a - 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.* +### Steps to reproduce + - *If you performed a command from the CLI, the command itself is enough. For example:* ```sh sudo yunohost app install distbin @@ -38,9 +40,16 @@ about: Create a report to help us debug, it would be nice to fill the template a 3. *Scroll down to '...'* 4. *See error* -**Expected behavior** +### 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.* +### Logs + +*When an operation fails, YunoHost provides a simple way to share the logs.* +- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.* +- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.* + +*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)* + *If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index 0be64ba..0c5b69a 100644 --- a/manifest.json +++ b/manifest.json @@ -6,14 +6,14 @@ "en": "Distributed pastebin with ActivityPub.", "fr": "Pastebin distribué utilisant le protocole ActivityPub." }, - "version": "1.3.0~ynh6", + "version": "1.3.0~ynh7", "url": "https://distbin.com/", "license": "Apache-2.0", "maintainer": { "name": "yalh76" }, "requirements": { - "yunohost": ">= 3.8.1" + "yunohost": ">= 4.1.3" }, "multi_instance": true, "services": [ @@ -28,7 +28,7 @@ "en": "Choose a domain name for Distbin", "fr": "Choisissez un nom de domaine pour Distbin" }, - "example": "distbin.example.com" + "example": "example.com" }, { "name": "path", diff --git a/scripts/change_url b/scripts/change_url index 1dfc46b..cb80a0e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_add_config source /usr/share/yunohost/helpers #================================================= @@ -116,9 +115,9 @@ ynh_backup_if_checksum_is_different --file="$config" if [ "$new_path" == "/" ] then - new_domain_uri="$new_domain" + new_domain_uri="$new_domain" else - new_domain_uri="$new_domain$new_path" + new_domain_uri="$new_domain$new_path" fi ynh_replace_string --match_string="EXTERNAL_URL=.*" --replace_string="EXTERNAL_URL=https://$new_domain_uri/" --target_file="$config" @@ -128,7 +127,6 @@ ynh_replace_string --match_string="EXTERNAL_URL=.*" --replace_string="EXTERNAL_U #================================================= ynh_print_info --message="Storing the config file checksum..." - # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$config" diff --git a/scripts/install b/scripts/install index c71c23d..4007e59 100644 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_add_config source /usr/share/yunohost/helpers #================================================= @@ -48,7 +47,6 @@ 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 -ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # STANDARD MODIFICATIONS @@ -121,14 +119,14 @@ ynh_script_progression --message="Installing Distbin..." chown -R "$app":"$app" "$final_path" pushd $final_path - ynh_use_nodejs - sudo -u $app $ynh_node_load_PATH $ynh_npm install --ignore-scripts - sudo -u $app $ynh_node_load_PATH $ynh_npm run build + ynh_use_nodejs + sudo -u $app $ynh_node_load_PATH $ynh_npm install --ignore-scripts + sudo -u $app $ynh_node_load_PATH $ynh_npm run build cp package* dist/ popd pushd $final_path/dist - sudo -u $app $ynh_node_load_PATH $ynh_npm install --ignore-scripts --production + sudo -u $app $ynh_node_load_PATH $ynh_npm install --ignore-scripts --production popd #================================================= @@ -179,13 +177,13 @@ 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 Distbin Service" if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then - sleep 60 + sleep 60 fi #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." +ynh_script_progression --message="Configuring permissions..." # Make app public if necessary if [ $is_public -eq 1 ] diff --git a/scripts/remove b/scripts/remove index fd81101..ca83f0c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -47,8 +47,8 @@ ynh_remove_systemd_config ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies -ynh_remove_app_dependencies ynh_remove_nodejs +ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR diff --git a/scripts/upgrade b/scripts/upgrade index 310e92c..cd015c3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_add_config source /usr/share/yunohost/helpers #================================================= @@ -19,7 +18,6 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) @@ -35,19 +33,11 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=0 - is_public=0 -fi +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all -# If final_path doesn't exist, create it -if [ -z "$final_path" ]; then - final_path=/var/www/$app - ynh_app_setting_set --app=$app --key=final_path --value=$final_path + ynh_app_setting_delete --app=$app --key=is_public fi #================================================= @@ -99,9 +89,8 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_remove_nodejs -ynh_install_nodejs --nodejs_version=$nodejs_version ynh_install_app_dependencies $pkg_dependencies +ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # CREATE DEDICATED USER @@ -129,7 +118,7 @@ ynh_script_progression --message="Creating storage folder..." DIRECTORY="$final_path/db" #Move old db if [ -d "$DIRECTORY" ]; then - mv "$final_path/db" "$final_path/distbin-db" + mv "$final_path/db" "$final_path/distbin-db" fi #================================================= @@ -140,14 +129,14 @@ ynh_script_progression --message="Making upgrade..." chown -R "$app":"$app" "$final_path" pushd $final_path - ynh_use_nodejs - sudo -u $app $ynh_node_load_PATH $ynh_npm install --ignore-scripts - sudo -u $app $ynh_node_load_PATH $ynh_npm run build + ynh_use_nodejs + sudo -u $app $ynh_node_load_PATH $ynh_npm install --ignore-scripts + sudo -u $app $ynh_node_load_PATH $ynh_npm run build cp package* dist/ popd pushd $final_path/dist - sudo -u $app $ynh_node_load_PATH $ynh_npm install --ignore-scripts --production + sudo -u $app $ynh_node_load_PATH $ynh_npm install --ignore-scripts --production popd #================================================= diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config deleted file mode 100644 index 58fad65..0000000 --- a/scripts/ynh_add_config +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/bash - -# Create a dedicated config file from a template -# -# 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" -# -# 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 -# __NAME__ by $app -# __NAMETOCHANGE__ by $app -# __USER__ by $app -# __FINALPATH__ by $final_path -# __PHPVERSION__ by $YNH_PHP_VERSION -# -# 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 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=tdv - local -A args_array=( [t]=template= [d]=destination= ) - local template - local destination - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - 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 "$template_path" "$destination" - - ynh_replace_vars --file="$destination" - - ynh_store_file_checksum --file="$destination" -} - -# Replace variables in a file -# -# usage: ynh_replace_vars --file="file" -# | arg: -f, --file= - File where to replace variables -# -# The helper will replace the following keywords with global variables -# that should be defined before calling this helper : -# __PATH__ by $path_url -# __NAME__ by $app -# __NAMETOCHANGE__ by $app -# __USER__ by $app -# __FINALPATH__ by $final_path -# __PHPVERSION__ by $YNH_PHP_VERSION -# -# 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=f - local -A args_array=( [f]=file= ) - local file - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - # 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 '/' - 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 "${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" - 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_node_load_PATH:-}"; then - ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file" - fi - - # 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" )) - - # Do the replacement - local delimit=@ - for one_var in "${uniques_vars[@]}" - do - # 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 -}