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/README.md b/README.md
index 2f5a8b8..d90eeca 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,44 @@
-# Linux-Dash package for YunoHost
+
+
+# Linux-Dash for YunoHost
+
+[](https://dash.yunohost.org/appci/app/linuxdash)  
+[](https://install-app.yunohost.org/?app=linuxdash)
+
+*[Lire ce readme en français.](./README_fr.md)*
+
+> *This package allows you to install Linux-Dash 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
-Linux-Dash package for YunoHost
A beautiful web dashboard for GNU/Linux which display CPU, RAM, memory, network and other usage.
-* [Linux-Dash repository](https://github.com/afaqurk/linux-dash)
-* [Linux-Dash demo](http://linuxdash.afaqtariq.com/)
-* [YunoHost website](https://yunohost.org/)
-### Install app
-```bash
-sudo yunohost app install https://github.com/M5oul/linuxdash_ynh
+**Shipped version:** 2.0~ynh2
+
+**Demo:** https://afaqurk.github.io/linux-dash/
+
+## Documentation and resources
+
+* Official app website: https://github.com/afaqurk/linux-dash
+* Official admin documentation: https://github.com/afaqurk/linux-dash/wiki
+* Upstream app code repository: https://github.com/afaqurk/linux-dash
+* YunoHost documentation for this app: https://yunohost.org/app_linuxdash
+* Report a bug: https://github.com/YunoHost-Apps/linuxdash_ynh/issues
+
+## Developer info
+
+Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/linuxdash_ynh/tree/testing).
+
+To try the testing branch, please proceed like that.
+```
+sudo yunohost app install https://github.com/YunoHost-Apps/linuxdash_ynh/tree/testing --debug
+or
+sudo yunohost app upgrade linuxdash -u https://github.com/YunoHost-Apps/linuxdash_ynh/tree/testing --debug
```
-### App state
-App is `working`.
+**More info regarding app packaging:** https://yunohost.org/packaging_apps
\ No newline at end of file
diff --git a/README_fr.md b/README_fr.md
new file mode 100644
index 0000000..12439bb
--- /dev/null
+++ b/README_fr.md
@@ -0,0 +1,40 @@
+# Linux-Dash pour YunoHost
+
+[](https://dash.yunohost.org/appci/app/linuxdash)  
+[](https://install-app.yunohost.org/?app=linuxdash)
+
+*[Read this readme in english.](./README.md)*
+*[Lire ce readme en français.](./README_fr.md)*
+
+> *Ce package vous permet d'installer Linux-Dash rapidement et simplement sur un serveur YunoHost.
+Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
+
+## Vue d'ensemble
+
+A beautiful web dashboard for GNU/Linux which display CPU, RAM, memory, network and other usage.
+
+
+**Version incluse :** 2.0~ynh2
+
+**Démo :** https://afaqurk.github.io/linux-dash/
+
+## Documentations et ressources
+
+* Site officiel de l'app : https://github.com/afaqurk/linux-dash
+* Documentation officielle de l'admin : https://github.com/afaqurk/linux-dash/wiki
+* Dépôt de code officiel de l'app : https://github.com/afaqurk/linux-dash
+* Documentation YunoHost pour cette app : https://yunohost.org/app_linuxdash
+* Signaler un bug : https://github.com/YunoHost-Apps/linuxdash_ynh/issues
+
+## Informations pour les développeurs
+
+Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/linuxdash_ynh/tree/testing).
+
+Pour essayer la branche testing, procédez comme suit.
+```
+sudo yunohost app install https://github.com/YunoHost-Apps/linuxdash_ynh/tree/testing --debug
+ou
+sudo yunohost app upgrade linuxdash -u https://github.com/YunoHost-Apps/linuxdash_ynh/tree/testing --debug
+```
+
+**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps
\ No newline at end of file
diff --git a/check_process b/check_process
new file mode 100644
index 0000000..32cab1f
--- /dev/null
+++ b/check_process
@@ -0,0 +1,21 @@
+;; Test complet
+ ; Manifest
+ domain="domain.tld"
+ path="/path"
+ admin="john"
+ ; Checks
+ pkg_linter=1
+ setup_sub_dir=1
+ setup_root=1
+ setup_nourl=0
+ setup_private=0
+ setup_public=0
+ upgrade=1
+ #upgrade=1 from_commit=CommitHash
+ backup_restore=1
+ multi_instance=1
+ port_already_use=0
+ change_url=1
+;;; Options
+Email=
+Notification=none
diff --git a/conf/app.src b/conf/app.src
new file mode 100644
index 0000000..94f96d2
--- /dev/null
+++ b/conf/app.src
@@ -0,0 +1,7 @@
+SOURCE_URL=https://codeload.github.com/afaqurk/linux-dash/tar.gz/186a802ea76e8bfcab7e8e7ebc533b74f80306fc
+SOURCE_SUM=506ae346f69b2002d4e3494d6aaa92104dbc8e50c8740acb2c49bc592a5939ce
+SOURCE_SUM_PRG=sha256sum
+SOURCE_FORMAT=tar.gz
+SOURCE_IN_SUBDIR=true
+SOURCE_FILENAME=
+SOURCE_EXTRACT=true
diff --git a/conf/nginx.conf b/conf/nginx.conf
index beea8dd..3fe2238 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -1,9 +1,10 @@
-location YNH_WWW_PATH/ {
- rewrite ^YNH_WWW_PATH$ YNH_WWW_PATH/ permanent;
- proxy_pass http://localhost:8081/;
- proxy_set_header Host $host;
- proxy_buffering off;
+#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
+location __PATH__/ {
- # Include SSOWAT user panel.
- include conf.d/yunohost_panel.conf.inc;
+ proxy_pass http://localhost:__PORT__/;
+ proxy_redirect off;
+ proxy_hide_header Content-Type;
+
+ # Include SSOWAT user panel.
+ #include conf.d/yunohost_panel.conf.inc;
}
diff --git a/conf/supervisor.conf b/conf/supervisor.conf
index 0c0655d..a636eb5 100644
--- a/conf/supervisor.conf
+++ b/conf/supervisor.conf
@@ -1,5 +1,6 @@
-[program:linuxdash]
-directory=/var/www/linuxdash/
-command=python python-server.py
+[program:__APP__]
+directory=__FINALPATH__/app/server/
+command=python index.py --port __PORT__
autostart=true
autorestart=true
+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 733d4f0..6c2cd06 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,45 +1,48 @@
{
"name": "Linux-Dash",
"id": "linuxdash",
+ "packaging_format": 1,
"description": {
"en": "A drop-in, low-overhead monitoring web dashboard for GNU/linux machine.",
"fr": "Tableau de bord léger pour le monitoring d’un serveur GNU/linux."
},
+ "version": "2.0~ynh2",
"url": "https://github.com/afaqurk/linux-dash",
- "license": "free",
+ "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",
"email": "moul@moul.re",
"url": "https://moul.re"
},
- "multi_instance": "false",
+ "requirements": {
+ "yunohost": ">= 4.3.0"
+ },
+ "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"
- },
+ "type": "path",
"example": "/dash",
"default": "/dash"
},
{
- "name": "user",
- "type": "user",
+ "name": "admin",
+ "type": "user",
"ask": {
"en": "Choose the YunoHost user which have access to Linux-Dash",
"fr": "Choisissez l’utilisateur YunoHost qui a accès à Linux-Dash"
diff --git a/scripts/_common.sh b/scripts/_common.sh
new file mode 100644
index 0000000..ea2aadd
--- /dev/null
+++ b/scripts/_common.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+#=================================================
+# 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
new file mode 100755
index 0000000..b084c19
--- /dev/null
+++ b/scripts/backup
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC START
+#=================================================
+# 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
+#=================================================
+
+# Exit if an error occurs during the execution of the script
+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=$app --key=final_path)
+domain=$(ynh_app_setting_get --app=$app --key=domain)
+
+#=================================================
+# DECLARE DATA AND CONF FILES TO BACKUP
+#=================================================
+ynh_print_info --message="Declaring files to be backed up..."
+
+#=================================================
+# BACKUP THE APP MAIN DIR
+#=================================================
+
+ynh_backup --src_path="$final_path"
+
+#=================================================
+# BACKUP THE NGINX CONFIGURATION
+#=================================================
+
+ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
+
+#=================================================
+# SPECIFIC BACKUP
+#=================================================
+# BACKUP SUPERVISOR
+#=================================================
+
+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 7f6b41b..da884e5 100755
--- a/scripts/install
+++ b/scripts/install
@@ -1,48 +1,134 @@
#!/bin/bash
-app=linuxdash
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
-# Retrieve arguments
-domain=$1
-path=$2
-user=$3
+source _common.sh
+source /usr/share/yunohost/helpers
-# Check domain/path availability
-sudo yunohost app checkurl $domain$path -a $app
-if [[ ! $? -eq 0 ]]; then
- exit 1
-fi
+#=================================================
+# MANAGE SCRIPT FAILURE
+#=================================================
-# Check port availability
-sudo yunohost app checkport 8081
-if [[ ! $? -eq 0 ]]; then
- exit 1
-fi
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
+#=================================================
+# RETRIEVE ARGUMENTS FROM THE MANIFEST
+#=================================================
+
+domain=$YNH_APP_ARG_DOMAIN
+path_url=$YNH_APP_ARG_PATH
+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..."
-# Copy files to the right place
final_path=/var/www/$app
-sudo mkdir -p $final_path
-sudo cp -a ../sources/* $final_path
+test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
-# Set permissions
-sudo chown -R www-data: $final_path
+# Register (book) web path
+ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
-# Set as a service with supervisor
-sudo apt-get -y -qq install supervisor
-sudo cp ../conf/supervisor.conf /etc/supervisor/conf.d/$app.conf
-sudo supervisorctl update
-sudo supervisorctl start $app
+#=================================================
+# STORE SETTINGS FROM MANIFEST
+#=================================================
+ynh_script_progression --message="Storing installation settings..."
-# Modify Nginx configuration file and copy it to Nginx conf directory
-sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
-nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
-sudo cp ../conf/nginx.conf $nginxconf
-sudo chown root: $nginxconf
-sudo chmod 600 $nginxconf
+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
-# Only give one user access to this app
-sudo yunohost app removeaccess $app
-sudo yunohost app addaccess $app -u $user
+#=================================================
+# STANDARD MODIFICATIONS
+#=================================================
+# FIND AND OPEN A PORT
+#=================================================
+ynh_script_progression --message="Finding an available port..."
-# Reload web server
-sudo service nginx reload
+# Find an available port
+port=$(ynh_find_port --port=8095)
+ynh_app_setting_set --app=$app --key=port --value=$port
+
+#=================================================
+# INSTALL DEPENDENCIES
+#=================================================
+ynh_script_progression --message="Installing dependencies..."
+
+ynh_install_app_dependencies $pkg_dependencies
+
+#=================================================
+# 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
+#=================================================
+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
+#=================================================
+# 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
+#=================================================
+# SETUP SSOWAT
+#=================================================
+ynh_script_progression --message="Configuring permissions..."
+
+# 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..."
+
+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 6d28ede..499b3c8 100755
--- a/scripts/remove
+++ b/scripts/remove
@@ -1,19 +1,72 @@
#!/bin/bash
-app=linuxdash
-domain=$(sudo yunohost app setting $app domain)
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
-# Remove sources and nginx configuration
-sudo rm -rf /var/www/$app
-sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
+source _common.sh
+source /usr/share/yunohost/helpers
-# Remove service
-sudo supervisorctl stop $app
-sudo rm -f /etc/supervisor/conf.d/$app.conf
+#=================================================
+# LOAD SETTINGS
+#=================================================
+ynh_script_progression --message="Loading installation settings..."
-# Remove supervisor package
-# Need to be manage with future manifest/moulinette Debian package management
-# sudo apt-get -y -qq remove supervisor
+app=$YNH_APP_INSTANCE_NAME
-# Reload nginx configuration
-sudo service nginx reload
+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 --file="$final_path"
+
+#=================================================
+# REMOVE NGINX CONFIGURATION
+#=================================================
+ynh_script_progression --message="Removing NGINX web server configuration..."
+
+# Remove the dedicated NGINX config
+ynh_remove_nginx_config
+
+#=================================================
+# REMOVE DEPENDENCIES
+#=================================================
+ynh_script_progression --message="Removing dependencies..."
+
+# Remove metapackage and its dependencies
+ynh_remove_app_dependencies
+
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# REMOVE DEDICATED USER
+#=================================================
+ynh_script_progression --message="Removing the dedicated system user..."
+
+# Delete a system user
+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
new file mode 100755
index 0000000..b5286da
--- /dev/null
+++ b/scripts/restore
@@ -0,0 +1,99 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC START
+#=================================================
+# 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
+#=================================================
+
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
+#=================================================
+# LOAD SETTINGS
+#=================================================
+ynh_script_progression --message="Loading installation settings..."
+
+app=$YNH_APP_INSTANCE_NAME
+
+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..."
+
+test ! -d $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 --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 --username=$app --home_dir="$final_path"
+
+#=================================================
+# RESTORE THE APP MAIN DIR
+#=================================================
+ynh_script_progression --message="Restoring the app main directory..."
+
+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 $pkg_dependencies
+
+#=================================================
+# RESTORE SUPERVISOR
+#=================================================
+ynh_script_progression --message="Restoring the supervisor configuration..."
+
+ynh_restore_file --origin_path="/etc/supervisor/conf.d/$app.conf"
+supervisorctl update
+supervisorctl restart $app
+
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# 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="Restoration completed for $app"
diff --git a/scripts/upgrade b/scripts/upgrade
index 90d4dca..f341038 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -1,30 +1,121 @@
#!/bin/bash
-# Retrieve settings
-app=linuxdash
-domain=$(sudo yunohost app setting $app domain)
-path=$(sudo yunohost app setting $app path)
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
-# Remove trailing "/" for next commands
-path=${path%/}
+source _common.sh
+source /usr/share/yunohost/helpers
-# Copy files to the right place
-final_path=/var/www/$app
-sudo mkdir -p $final_path
-sudo cp -a ../sources/* $final_path
+#=================================================
+# LOAD SETTINGS
+#=================================================
+ynh_script_progression --message="Loading installation settings..."
-# Set permissions
-sudo chown -R www-data: $final_path
+app=$YNH_APP_INSTANCE_NAME
-# Modify Nginx configuration file and copy it to Nginx conf directory
-sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
-nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
-sudo cp ../conf/nginx.conf $nginxconf
-sudo chown root: $nginxconf
-sudo chmod 600 $nginxconf
+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)
-# Restart Linux-dash service
-sudo supervisorctl restart $app
+#=================================================
+# CHECK VERSION
+#=================================================
+ynh_script_progression --message="Checking version..."
-# Reload web server & sso
-sudo service nginx reload
+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
+ ynh_restore_upgradebackup
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
+#=================================================
+# 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
+#=================================================
+
+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
+ynh_add_nginx_config
+
+#=================================================
+# UPGRADE DEPENDENCIES
+#=================================================
+ynh_script_progression --message="Upgrading dependencies..."
+
+ynh_install_app_dependencies $pkg_dependencies
+
+#=================================================
+# SPECIFIC UPGRADE
+#=================================================
+# 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
+#=================================================
+# 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="Upgrade of $app completed"
diff --git a/sources/.editorconfig b/sources/.editorconfig
deleted file mode 100755
index 4a7ea30..0000000
--- a/sources/.editorconfig
+++ /dev/null
@@ -1,12 +0,0 @@
-root = true
-
-[*]
-indent_style = space
-indent_size = 2
-end_of_line = lf
-charset = utf-8
-trim_trailing_whitespace = true
-insert_final_newline = true
-
-[*.md]
-trim_trailing_whitespace = false
diff --git a/sources/.gitignore b/sources/.gitignore
deleted file mode 100644
index 91be243..0000000
--- a/sources/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-vendor
-node_modules
diff --git a/sources/LICENSE.md b/sources/LICENSE.md
deleted file mode 100644
index ec1c59a..0000000
--- a/sources/LICENSE.md
+++ /dev/null
@@ -1,20 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2014 afaqurk
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/sources/README.md b/sources/README.md
deleted file mode 100644
index a6a8a51..0000000
--- a/sources/README.md
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
- - Demo | - Features | - - Installation | - Support - -
- -
-
-
-
-
-
-
-
-