From 0f9c82f70dea15af040f1dcb289d7750df805fe6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 5 Feb 2022 11:16:18 +0100 Subject: [PATCH] Apply last example_ynh (#14) * Apply last example_ynh * More Readme * Update DISCLAIMER.md * Auto-update README Co-authored-by: oiseauroch <5622590+oiseauroch@users.noreply.github.com> Co-authored-by: Tobias Ollive Co-authored-by: Yunohost-Bot <> --- .gitignore | 104 ----------------------------- README.md | 5 ++ README_fr.md | 5 ++ check_process | 6 +- doc/DESCRIPTION.md | 0 doc/{manifest.md => DISCLAIMER.md} | 5 +- issue_template | 55 --------------- manifest.json | 13 ++-- scripts/_common.sh | 16 +++++ scripts/backup | 14 ++-- scripts/install | 59 ++++++++-------- scripts/remove | 20 +++--- scripts/restore | 29 +++----- scripts/upgrade | 37 +++++----- 14 files changed, 110 insertions(+), 258 deletions(-) delete mode 100644 .gitignore create mode 100644 doc/DESCRIPTION.md rename doc/{manifest.md => DISCLAIMER.md} (65%) delete mode 100644 issue_template diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 6704566..0000000 --- a/.gitignore +++ /dev/null @@ -1,104 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and *not* Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port diff --git a/README.md b/README.md index 54a9cc8..df7cbf2 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ The news reader that doesn't know you ![](./doc/screenshots/petrolette.png) +## Disclaimers / important information + +- require a dedicated domain + +- the application doesn't store anything locally. Restore/uprade operation is basically reinstalling the app. ## Documentation and resources * Upstream app code repository: https://framagit.org/yphil/petrolette diff --git a/README_fr.md b/README_fr.md index 1e312ee..a0dca68 100644 --- a/README_fr.md +++ b/README_fr.md @@ -21,6 +21,11 @@ La page d'actu qui ne sait rien de toi ![](./doc/screenshots/petrolette.png) +## Avertissements / informations importantes + +- require a dedicated domain + +- the application doesn't store anything locally. Restore/uprade operation is basically reinstalling the app. ## Documentations et ressources * Dépôt de code officiel de l'app : https://framagit.org/yphil/petrolette diff --git a/check_process b/check_process index d025f61..eb9891c 100644 --- a/check_process +++ b/check_process @@ -1,7 +1,7 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - ;; Test complet + ; Manifest + domain="domain.tld" + is_public=1 ; Checks pkg_linter=1 setup_sub_dir=0 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/manifest.md b/doc/DISCLAIMER.md similarity index 65% rename from doc/manifest.md rename to doc/DISCLAIMER.md index aa39943..6ae57c2 100644 --- a/doc/manifest.md +++ b/doc/DISCLAIMER.md @@ -1,6 +1,3 @@ - - - require a dedicated domain -- the application doesn't store anything locally. Restore/uprade operation is basically reinstalling the app. - +- the application doesn't store anything locally. Restore/uprade operation is basically reinstalling the app. \ No newline at end of file diff --git a/issue_template b/issue_template deleted file mode 100644 index 8aebf51..0000000 --- a/issue_template +++ /dev/null @@ -1,55 +0,0 @@ ---- -name: Bug report -about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. - ---- - -**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 Whitebophir 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 - -*A clear and concise description of what the bug is.* - -### 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 | ...* -- 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`* - -### Steps to reproduce - -- *If you performed a command from the CLI, the command itself is enough. For example:* - ```sh - sudo yunohost app install whitebophir - ``` -- *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 - -*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 7459764..919741b 100644 --- a/manifest.json +++ b/manifest.json @@ -6,31 +6,30 @@ "en": "The news reader that doesn't know you", "fr": "La page d'actu qui ne sait rien de toi" }, + "version": "1.4.3~ynh1", "url": "https://framagit.org/yphil/petrolette", "upstream": { "license": "AGPL-3.0-only", "demo": "https://petrolette.space", "code": "https://framagit.org/yphil/petrolette" }, - "version": "1.4.3~ynh1", "license": "AGPL-3.0-only", - "maintainer": [{ + "maintainer": { "name": "oiseauroch.", "email": "tobias.ollive@oiseauroch.fr" - }], + }, "requirements": { - "yunohost": ">= 4.2.0" + "yunohost": ">= 4.3.0" }, "multi_instance": true, "services": [ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", - "type": "domain", - "example": "domain.org" + "type": "domain" }, { "name": "is_public", diff --git a/scripts/_common.sh b/scripts/_common.sh index 2bd973b..3ffd8ad 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,3 +1,19 @@ #!/bin/bash +#================================================= +# COMMON VARIABLES +#================================================= + NODEJS_VERSION=15 + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index 3fd95ee..0aa3035 100644 --- a/scripts/backup +++ b/scripts/backup @@ -17,7 +17,6 @@ source /usr/share/yunohost/helpers ynh_clean_setup () { ynh_clean_check_starting } - # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -37,6 +36,12 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= ynh_print_info --message="Declaring files to be backed up..." +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup --src_path="$final_path" --is_big + #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= @@ -49,13 +54,6 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# BACKUP THE DATA DIRECTORY -#================================================= -ynh_print_info --message="Backing up data directory..." - -ynh_backup --src_path="$final_path" --is_big - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index ab0e5cb..1ed00b7 100644 --- a/scripts/install +++ b/scripts/install @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= + domain=$YNH_APP_ARG_DOMAIN path_url="/" is_public=$YNH_APP_ARG_IS_PUBLIC @@ -42,7 +43,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url 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_url --value=$path_url +ynh_app_setting_set --app=$app --key=path --value=$path_url #================================================= # STANDARD MODIFICATIONS @@ -53,8 +54,9 @@ ynh_script_progression --message="Finding an available port..." # Find an available port port=$(ynh_find_port --port=8001) -https_port=$(ynh_find_port --port=8002) ynh_app_setting_set --app=$app --key=port --value=$port + +https_port=$(ynh_find_port --port=8002) ynh_app_setting_set --app=$app --key=https_port --value=$https_port #================================================= @@ -64,6 +66,14 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -76,19 +86,13 @@ ynh_setup_source --dest_dir="$final_path" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." +ynh_script_progression --message="Configuring NGINX web server..." -# Create a dedicated nginx config -ynh_add_nginx_config +# Create a dedicated NGINX config +ynh_add_nginx_config #================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path - +# SPECIFIC SETUP #================================================= # INSTALL PETROLETTE #================================================= @@ -98,7 +102,7 @@ pushd $final_path # set port in configuration file sed -i "/HTTP_PORT/s/[0-9]*[0-9]/$port/" package.json sed -i "/HTTPS_PORT/s/[0-9]*[0-9]/$https_port/" package.json -# use custom home value to avoid bower storing values in root and have right errors + # use custom home value to avoid bower storing values in root and have right errors [[ -v HOME ]] && TMP_HOME=$HOME HOME=$(pwd) ynh_use_nodejs @@ -106,22 +110,9 @@ pushd $final_path [[ -v TMP_HOME ]] && HOME=$TMP_HOME || unset HOME popd -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - - chown -R $app:$app $final_path chmod -R o-rwx $final_path - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="The news reader that doesn't know you" --log="/home/yunohost.app/${app}/storage/logs/petrolette.log" - #================================================= # SETUP SYSTEMD #================================================= @@ -130,6 +121,15 @@ ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config +#================================================= +# GENERIC FINALIZATION +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --description="The news reader that doesn't know you" --log="/home/yunohost.app/${app}/storage/logs/petrolette.log" + #================================================= # START SYSTEMD SERVICE #================================================= @@ -146,14 +146,15 @@ ynh_script_progression --message="Configuring permissions..." # Make app public if necessary if [ $is_public -eq 1 ] then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_permission_update --permission="main" --add="visitors" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/remove b/scripts/remove index 14c2d0c..1c56593 100644 --- a/scripts/remove +++ b/scripts/remove @@ -16,8 +16,8 @@ ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE @@ -28,7 +28,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." + ynh_script_progression --message="Removing $app service integration..." yunohost service remove $app fi @@ -40,12 +40,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= - -ynh_remove_nodejs - #================================================= # REMOVE APP MAIN DIR #================================================= @@ -57,11 +51,17 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." +ynh_script_progression --message="Removing NGINX web server configuration..." -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +ynh_remove_nodejs + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index fd0d36a..801fc33 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# 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 @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script @@ -39,9 +38,6 @@ https_port=$(ynh_app_setting_get --app=$app --key=https_port) #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" - test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " @@ -50,9 +46,18 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # SPECIFIC RESTORATION #================================================= @@ -69,7 +74,6 @@ ynh_script_progression --message="Reinstalling the app ..." --weight=5 ynh_setup_source --dest_dir="$final_path" -pushd $final_path pushd $final_path # set port in configuration file sed -i "/HTTP_PORT/s/[0-9]*[0-9]/$port/" package.json @@ -81,19 +85,6 @@ pushd $final_path [[ -v TMP_HOME ]] && HOME=$TMP_HOME || unset HOME popd - -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# RESTORE USER RIGHTS -#================================================= - # Restore permissions on app files chown -R $app:$app $final_path chmod -R o-rwx $final_path diff --git a/scripts/upgrade b/scripts/upgrade index 8a7ecea..ad18d88 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -25,6 +25,7 @@ https_port=$(ynh_app_setting_get --app=$app --key=https_port) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -36,7 +37,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -51,6 +52,14 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=8 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -68,16 +77,18 @@ fi #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= -# UPGRADE DEPENDENCIES (NODEJS) +# UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=2 ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +#================================================= +# SPECIFIC UPGRADE #================================================= # UPDATE APP #================================================= @@ -95,32 +106,20 @@ pushd $final_path [[ -v TMP_HOME ]] && HOME=$TMP_HOME || unset HOME popd -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=8 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +# Set permissions on app files +chown -R $app:$app $final_path +chmod -R o-rwx $final_path #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 -ynh_replace_vars "../conf/systemd.service" +# Create a dedicated systemd config ynh_add_systemd_config #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions on app files -chown -R $app:$app $final_path -chmod -R o-rwx $final_path - #================================================= # INTEGRATE SERVICE IN YUNOHOST #=================================================