From 00ddd5972fc5ea6d618119ca544c8fee425514ed Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 25 Mar 2022 01:09:30 +0100 Subject: [PATCH] Apply example_ynh --- .github/ISSUE_TEMPLATE.md | 55 ++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 16 ++++ check_process | 26 ++----- conf/app.src | 7 +- conf/app.src.2.0 | 6 -- conf/nginx.conf | 14 ++-- conf/supervisor.conf | 7 +- doc/.gitkeep | 0 doc/DESCRIPTION.md | 1 + doc/DISCLAIMER.md | 0 doc/screenshots/.gitkeep | 0 manifest.json | 26 +++---- scripts/_common.sh | 29 +++++--- scripts/backup | 32 ++++---- scripts/change_url | 113 ++++++++++++++++++++++++++++ scripts/install | 123 +++++++++++++++---------------- scripts/remove | 52 ++++++------- scripts/restore | 60 ++++++++------- scripts/upgrade | 114 +++++++++++++--------------- 19 files changed, 422 insertions(+), 259 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 conf/app.src.2.0 create mode 100644 doc/.gitkeep create mode 100644 doc/DESCRIPTION.md create mode 100644 doc/DISCLAIMER.md create mode 100644 doc/screenshots/.gitkeep create mode 100644 scripts/change_url diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..2729a6b --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,55 @@ +--- +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 the app 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 the_app + ``` +- *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/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ef70e18 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ +## Problem + +- *Description of why you made this PR* + +## Solution + +- *And how do you fix that problem* + +## PR Status + +- [ ] Code finished and ready to be reviewed/tested +- [ ] The fix/enhancement were manually tested (if applicable) + +## Automatic tests + +Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization) diff --git a/check_process b/check_process index c315f0d..32cab1f 100644 --- a/check_process +++ b/check_process @@ -1,8 +1,8 @@ ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - user="john" (USER) + domain="domain.tld" + path="/path" + admin="john" ; Checks pkg_linter=1 setup_sub_dir=1 @@ -11,23 +11,11 @@ setup_private=0 setup_public=0 upgrade=1 + #upgrade=1 from_commit=CommitHash backup_restore=1 - multi_instance=0 - incorrect_path=1 - port_already_use=1 (8081) - change_url=0 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto -# Level 4: Not relevant - Level 4=na - Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 + multi_instance=1 + port_already_use=0 + change_url=1 ;;; Options Email= Notification=none diff --git a/conf/app.src b/conf/app.src index 0a7b75c..94f96d2 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,6 +1,7 @@ -SOURCE_URL=https://github.com/afaqurk/linux-dash/archive/59d4787d3147e79a816a5c88ed8af482a0661e88.zip -SOURCE_SUM=9c3112c93bb20be8b719335b20bf161e11a8095ecf639baab6ea8c95ef289928 +SOURCE_URL=https://codeload.github.com/afaqurk/linux-dash/tar.gz/186a802ea76e8bfcab7e8e7ebc533b74f80306fc +SOURCE_SUM=506ae346f69b2002d4e3494d6aaa92104dbc8e50c8740acb2c49bc592a5939ce SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=zip +SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/conf/app.src.2.0 b/conf/app.src.2.0 deleted file mode 100644 index 136f8ad..0000000 --- a/conf/app.src.2.0 +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://github.com/afaqurk/linux-dash/archive/2.0.tar.gz -SOURCE_SUM=f7342807ecadd22410614336378311a356e04a18569f64935ea67b9bc27ccd56 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/nginx.conf b/conf/nginx.conf index 3ad0143..3fe2238 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,14 +1,10 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } + proxy_pass http://localhost:__PORT__/; + proxy_redirect off; + proxy_hide_header Content-Type; - proxy_pass http://localhost:__PORT__/; - proxy_set_header Host $host; - proxy_buffering off; - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + # Include SSOWAT user panel. + #include conf.d/yunohost_panel.conf.inc; } diff --git a/conf/supervisor.conf b/conf/supervisor.conf index 148e08d..a636eb5 100644 --- a/conf/supervisor.conf +++ b/conf/supervisor.conf @@ -1,7 +1,6 @@ [program:__APP__] -directory=__FINALPATH__/ -;command=python app/server/index.py (v2.0) -command=python python-server.py +directory=__FINALPATH__/app/server/ +command=python index.py --port __PORT__ autostart=true autorestart=true -user=__USER__ +user=__APP__ diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..5ede381 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1 @@ +A beautiful web dashboard for GNU/Linux which display CPU, RAM, memory, network and other usage. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/screenshots/.gitkeep b/doc/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json index a8f2fd4..66667a3 100644 --- a/manifest.json +++ b/manifest.json @@ -8,6 +8,13 @@ }, "version": "2.0", "url": "https://github.com/afaqurk/linux-dash", + "upstream": { + "license": "MIT", + "website": "https://github.com/afaqurk/linux-dash", + "demo": "https://afaqurk.github.io/linux-dash/", + "admindoc": "https://github.com/afaqurk/linux-dash/wiki", + "code": "https://github.com/afaqurk/linux-dash" + }, "license": "MIT", "maintainer": { "name": "Moul", @@ -15,35 +22,26 @@ "url": "https://moul.re" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 4.3.0" }, - "multi_instance": false, + "multi_instance": true, "services": [ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", - "type": "domain", - "ask": { - "en": "Choose a domain name for Linux-Dash", - "fr": "Choisissez un nom de domaine pour Linux-Dash" - }, - "example": "domain.org" + "type": "domain" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for Linux-Dash", - "fr": "Choisissez un chemin pour Linux-Dash" - }, "example": "/dash", "default": "/dash" }, { - "name": "user", + "name": "admin", "type": "user", "ask": { "en": "Choose the YunoHost user which have access to Linux-Dash", diff --git a/scripts/_common.sh b/scripts/_common.sh index 24bd7ba..ea2aadd 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,13 +1,20 @@ #!/bin/bash -# ============= FUTURE YUNOHOST HELPER ============= -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} +#================================================= +# COMMON VARIABLES +#================================================= + +# dependencies used by the app +pkg_dependencies="supervisor" + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index d192288..b084c19 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,12 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +# 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 #================================================= @@ -24,30 +20,40 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP #================================================= -# BACKUP SUPERVISOR CONFIG +# BACKUP SUPERVISOR #================================================= -ynh_backup "/etc/supervisor/conf.d/$app.conf" +ynh_backup --src_path="/etc/supervisor/conf.d/$app.conf" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..be378cf --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,113 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +old_domain=$YNH_APP_OLD_DOMAIN +old_path=$YNH_APP_OLD_PATH + +new_domain=$YNH_APP_NEW_DOMAIN +new_path=$YNH_APP_NEW_PATH + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# LOAD 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) + +# Add settings here as needed by your application +port=$(ynh_app_setting_get --app=$app --key=port) + +#================================================= +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP +#================================================= +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 +ynh_clean_setup () { + ynh_clean_check_starting + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# CHECK WHICH PARTS SHOULD BE CHANGED +#================================================= + +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_script_progression --message="Updating NGINX web server configuration..." + +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# Change the path in the NGINX config file +if [ $change_path -eq 1 ] +then + # Make a backup of the original NGINX config file if modified + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" + # Set global variables for NGINX helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated NGINX config + ynh_add_nginx_config +fi + +# Change the domain for NGINX +if [ $change_domain -eq 1 ] +then + # Delete file checksum for the old conf file location + ynh_delete_file_checksum --file="$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# GENERIC FINALISATION +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 8b6be88..da884e5 100755 --- a/scripts/install +++ b/scripts/install @@ -22,120 +22,113 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH -user=$YNH_APP_ARG_USER +admin=$YNH_APP_ARG_ADMIN app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_script_progression --message="Validating installation parameters..." final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) - -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app user $user +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=admin --value=$admin #================================================= # STANDARD MODIFICATIONS -#================================================= -# INSTALL DEPENDENCIES -#================================================= - -ynh_install_app_dependencies supervisor - -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= - -ynh_app_setting_set $app final_path $final_path -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" - #================================================= # FIND AND OPEN A PORT #================================================= +ynh_script_progression --message="Finding an available port..." -# Find a free port -port=$(ynh_find_port 8081) -# Open this port -yunohost firewall allow --no-upnp TCP $port 2>&1 -ynh_app_setting_set $app port $port - -# For v2.0 only -# ynh_replace_string "default=80" "default=$port" "$final_path/app/server/index.py" -ynh_replace_string "'localhost', 8081" "'localhost', $port" "$final_path/python-server.py" +# Find an available port +port=$(ynh_find_port --port=8095) +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= -# NGINX CONFIGURATION +# INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Installing dependencies..." -# Create a dedicated nginx config -if [ "$path_url" != "/" ] -then - ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" -fi -ynh_add_nginx_config +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Configuring system user..." # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app --home_dir="$final_path" + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +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 +ynh_setup_source --dest_dir="$final_path" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring NGINX web server..." + +# Create a dedicated NGINX config +ynh_add_nginx_config #================================================= # SPECIFIC SETUP -#================================================= -# SET SUPERVISOR -#================================================= - -# Set as a service with supervisor -cp ../conf/supervisor.conf /etc/supervisor/conf.d/$app.conf -ynh_replace_string "__APP__" "$app" "/etc/supervisor/conf.d/$app.conf" -ynh_replace_string "__FINALPATH__" "$final_path" "/etc/supervisor/conf.d/$app.conf" -ynh_replace_string "__USER__" "$app" "/etc/supervisor/conf.d/$app.conf" - -supervisorctl update -supervisorctl restart $app - #================================================= # REMOVE GOOGLE !!! #================================================= sed --in-place "/googlecode\|googleapis/d" "$final_path/index.html" +#================================================= +# SETUP SUPERVISOR +#================================================= +ynh_script_progression --message="Configuring supervisor..." + +ynh_add_config --template="../conf/supervisor.conf" --destination="/etc/supervisor/conf.d/$app.conf" +supervisorctl update +supervisorctl restart $app + #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions to app files -chown -R root: $final_path - #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring permissions..." -# Restrict access to admin only -yunohost app addaccess --users=$user $app +# Only the admin can access the admin panel of the app (if the app has an admin panel) +ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading NGINX web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 97e3c87..499b3c8 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,52 +12,45 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE SUPERVISOR +#================================================= +ynh_script_progression --message="Removing supervisor configuration..." + +supervisorctl stop $app +ynh_secure_remove --file="/etc/supervisor/conf.d/$app.conf" +supervisorctl update + #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Removing NGINX web server configuration..." -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - echo "Close port $port" - yunohost firewall disallow TCP $port 2>&1 -fi - -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE SUPERVISOR -#================================================= - -# Remove service -supervisorctl stop $app -ynh_secure_remove /etc/supervisor/conf.d/$app.conf - #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -67,6 +60,13 @@ ynh_remove_app_dependencies #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 0f7f62b..b5286da 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,12 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +# 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 #================================================= @@ -24,65 +20,66 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) +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) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_script_progression --message="Validating restoration parameters..." -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= - -ynh_restore_file "$final_path" +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..." # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= -# RESTORE USER RIGHTS +# RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." -# Restore permissions on app files -chown -R root: $final_path +ynh_restore_file --origin_path="$final_path" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies -ynh_install_app_dependencies supervisor +ynh_install_app_dependencies $pkg_dependencies #================================================= -# RESTORE THE SUPERVISOR CONFIGURATION +# RESTORE SUPERVISOR #================================================= +ynh_script_progression --message="Restoring the supervisor configuration..." -ynh_restore_file "/etc/supervisor/conf.d/$app.conf" - +ynh_restore_file --origin_path="/etc/supervisor/conf.d/$app.conf" supervisorctl update supervisorctl restart $app @@ -91,5 +88,12 @@ supervisorctl restart $app #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading NGINX web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 33445c0..2c7d833 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,111 +12,103 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -user=$(ynh_app_setting_get $app admin) -final_path=$(ynh_app_setting_get $app final_path) -port=$(ynh_app_setting_get $app port) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +admin=$(ynh_app_setting_get --app=$app --key=admin) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= -# ENSURE DOWNWARD COMPATIBILITY +# CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." -# If final_path doesn't exist, create it -if [ -z $final_path ]; then - final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path -fi +upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +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 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 ynh_abort_if_errors -#================================================= -# CHECK THE PATH -#================================================= - -# Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) - #================================================= # STANDARD UPGRADE STEPS +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." +#================================================= +# CREATE DEDICATED USER +#================================================= +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" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" +fi + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." -# Create a dedicated nginx config -if [ "$path_url" != "/" ] -then - ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" -fi +# Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= - -# Create a system user -ynh_system_user_create $app - #================================================= # SPECIFIC UPGRADE -#================================================= -# UPGRADE SUPERVISOR -#================================================= - -# Set as a service with supervisor -cp ../conf/supervisor.conf /etc/supervisor/conf.d/$app.conf -ynh_replace_string "__APP__" "$app" "/etc/supervisor/conf.d/$app.conf" -ynh_replace_string "__FINALPATH__" "$final_path" "/etc/supervisor/conf.d/$app.conf" -ynh_replace_string "__USER__" "$app" "/etc/supervisor/conf.d/$app.conf" - -supervisorctl update -supervisorctl restart $app - #================================================= # REMOVE GOOGLE !!! #================================================= sed --in-place "/googlecode\|googleapis/d" "$final_path/index.html" +#================================================= +# SETUP SUPERVISOR +#================================================= +ynh_script_progression --message="Configuring supervisor..." + +ynh_add_config --template="../conf/supervisor.conf" --destination="/etc/supervisor/conf.d/$app.conf" +supervisorctl update +supervisorctl restart $app + #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set right permissions for curl installation -chown -R root: $final_path - -#================================================= -# SETUP SSOWAT -#================================================= - -# Restrict access to admin only -yunohost app addaccess --users=$user $app - #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading NGINX web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed"