From 762a9179579d0a0a36026369738fe8aa4bb2584c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josu=C3=A9=20Tille?= <josue@tille.ch>
Date: Thu, 23 Jul 2020 23:44:29 +0200
Subject: [PATCH 1/6] Fix Integration level infos

---
 README.md | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 8cad858..de9164e 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 Seafile For yunohost
 =================
 
-[![Integration level](https://dash.yunohost.org/integration/seafile.svg)](https://ci-apps.yunohost.org/ci/apps/seafile%20%28Community%29/lastBuild/consoleFull)  
+[![Integration level](https://dash.yunohost.org/integration/seafile.svg)](https://dash.yunohost.org/appci/app/seafile) ![](https://ci-apps.yunohost.org/ci/badges/seafile.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/seafile.maintain.svg)  
 [![Install seafile with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=seafile)
 
 > *This package allow you to install seafile quickly and simply on a YunoHost server.  
@@ -61,9 +61,8 @@ Since seafile 6.3 the i386 architecture is no more supported.
 
 Seafile no longer distribute binary for generic armhf architectures but rpi binary could work.
 
-* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/seafile%20(Community).svg)](https://ci-apps.yunohost.org/ci/apps/seafile/)
-* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/seafile%20(Community).svg)](https://ci-apps-arm.yunohost.org/ci/apps/seafile/)
-* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/jenkins/job/seafile%20(Community).svg)](https://ci-stretch.nohost.me/jenkins/job/seafile/)
+* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/seafile%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/seafile/)
+* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/seafile%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/seafile/)
 
 <!--Limitations
 ------------

From 754d085c8f481c6722687e14c1af99f27a8ff07f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josu=C3=A9=20Tille?= <josue@tille.ch>
Date: Fri, 2 Oct 2020 22:37:55 +0200
Subject: [PATCH 2/6] Clarify ARM support

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index de9164e..e35dafe 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ for more information.
 
 Since seafile 6.3 the i386 architecture is no more supported.
 
-Seafile no longer distribute binary for generic armhf architectures but rpi binary could work.
+Seafile don't distribute binary for generic armhf architectures but rpi binary generally work on all arm board.
 
 * x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/seafile%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/seafile/)
 * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/seafile%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/seafile/)

From 079eb9ad9b3df36f1dd0e2aa889683d14551ac97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Peterka?= <tomas.peterk@gmail.com>
Date: Mon, 26 Oct 2020 11:47:39 +0100
Subject: [PATCH 3/6] updgrade creates correct symlink to seafile-data

Bugfix: update script was creating symbolic link to seafile-data inside wrong folder
```
lrwxrwxrwx 1 seafile seafile 31 Oct 26 11:21 /opt/yunohost/seafile/seafile-data/seafile-data -> /home/yunohost.app/seafile-data
```
Only one-level of seafile-data is required.
---
 scripts/upgrade | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/upgrade b/scripts/upgrade
index dea0f9e..9340cb4 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -74,7 +74,7 @@ if [ $final_path == "/var/www/$app" ]; then
         # Data directory empty, so considere that all data are already in /home/yunohost.app/seafile
         mv /opt/yunohost/$app/seafile-data/* /home/yunohost.app/seafile-data/
         ynh_secure_remove $final_path/seafile_data
-        ln -s $seafile_data $final_path/seafile_data
+        ln -s /home/yunohost.app/seafile-data $final_path/
     fi
     ln -s $final_path/logs /var/log/seafile
     set_permission

From 46e9b23461bf77c5fa1cb5414a925fb0e21db1fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Peterka?= <tomas.peterk@gmail.com>
Date: Mon, 2 Nov 2020 15:38:09 +0100
Subject: [PATCH 4/6] Upgrade transfers data and does not lose them

---
 scripts/upgrade | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/upgrade b/scripts/upgrade
index 9340cb4..47361c3 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -71,8 +71,8 @@ if [ $final_path == "/var/www/$app" ]; then
     ynh_app_setting_set --app $app --key final_path --value $final_path
     test -e /var/log/seafile && rm /var/log/$app
     if ! [ -z "$(ls -A $final_path/seafile_data)" ]; then
-        # Data directory empty, so considere that all data are already in /home/yunohost.app/seafile
-        mv /opt/yunohost/$app/seafile-data/* /home/yunohost.app/seafile-data/
+        # Data directory NOT empty, transfer data to /home/yunohost.app/seafile
+        mv $final_path/seafile_data/* /home/yunohost.app/seafile-data/
         ynh_secure_remove $final_path/seafile_data
         ln -s /home/yunohost.app/seafile-data $final_path/
     fi

From eb481da301439913daaa6943ee9c71d9699499ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josu=C3=A9=20Tille?= <josue@tille.ch>
Date: Tue, 29 Sep 2020 22:38:08 +0200
Subject: [PATCH 5/6] Avoid current issue

---
 scripts/install | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/install b/scripts/install
index c00c158..b60d22a 100644
--- a/scripts/install
+++ b/scripts/install
@@ -103,6 +103,8 @@ chmod +x expect_scripts/install.exp
 chmod +x $final_path/seafile-server-$seafile_version/setup-seafile-mysql.sh
 expect_scripts/install.exp "$final_path/seafile-server-$seafile_version" "$server_name" "$domain" "$seafile_data" "$fileserver_port" "$db_pwd"
 
+sleep 3
+
 # Update seafile config
 ynh_replace_string --match_string http:// --replace_string https://  --target_file $final_path/conf/ccnet.conf
 ynh_replace_string --match_string :8000   --replace_string $path_url --target_file $final_path/conf/ccnet.conf

From 141654f9a65be305199e2f138b6c78d7416eff2f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josu=C3=A9=20Tille?= <josue@tille.ch>
Date: Sun, 29 Nov 2020 17:29:51 +0100
Subject: [PATCH 6/6] Add backup core only feature

---
 README.md       | 46 ++++++++++++++++++++++++++++++++--------------
 scripts/backup  |  6 +++++-
 scripts/install |  5 +++++
 scripts/remove  |  5 +++--
 4 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/README.md b/README.md
index e35dafe..959542f 100644
--- a/README.md
+++ b/README.md
@@ -72,14 +72,7 @@ Seafile don't distribute binary for generic armhf architectures but rpi binary g
 Additional informations
 -----------------------
 
-### Change URL
-
-Since now it's possible to change domain or the url of seafile.
-
-To do this run : `yunohost app change-url seafile -d new_domain.tld -p PATH new_path`
-
-Links
------
+### Links
 
  * Report a bug: https://github.com/YunoHost-Apps/seafile_ynh/issues
  * App website: https://www.seafile.com
@@ -87,19 +80,44 @@ Links
 
 ---
 
-Install
--------
+### Install
 
 From command line:
 
-`sudo yunohost app install -l seafile https://github.com/YunoHost-Apps/seafile_ynh`
+`yunohost app install seafile`
 
-Upgrade
--------
+### Upgrade
 
 From command line:
 
-`sudo yunohost app upgrade seafile -u https://github.com/YunoHost-Apps/seafile_ynh`
+`yunohost app upgrade seafile`
+
+### Backup
+
+This app use now the core-only feature of the backup. To keep the integrity of the data and to have a better guarantee of the restoration is recommended to proceed like this:
+
+- Stop seafile service with theses following command:
+
+`systemctl stop seafile.service seahub.service`
+
+- Launch the backup of seafile with this following command:
+
+`yunohost backup create --app seafile`
+
+- Do a backup of your data with your specific strategy (could be with rsync, borg backup or just cp). The data is stored in `/home/yunohost.app/seafile-data`.
+- Restart the seafile service with theses command:
+
+`systemctl start seafile.service seahub.service`
+
+### Remove
+
+Due of the backup core only feature the data directory in `/home/yunohost.app/seafile-data` **is not removed**. It need to be removed manually to purge app user data.
+
+### Change URL
+
+Since now it's possible to change domain or the url of seafile.
+
+To do this run : `yunohost app change-url seafile -d new_domain.tld -p PATH new_path`
 
 Developers infos
 ----------------
diff --git a/scripts/backup b/scripts/backup
index f081cdb..df96919 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -22,6 +22,10 @@ db_pwd=$(ynh_app_setting_get --app $app --key mysqlpwd)
 final_path=$(ynh_app_setting_get --app $app --key final_path)
 seafile_user=$app
 
+if [[ ! "$(systemctl status seafile)" =~ "Active: inactive (dead)" ]] || [[ ! "$(systemctl status seahub)" =~ "Active: inactive (dead)" ]]; then
+    ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop seafile service and seahub service with this command before to run the backup 'systemctl stop seafile.service seahub.service'"
+fi
+
 #=================================================
 # STANDARD BACKUP STEPS
 #=================================================
@@ -30,7 +34,7 @@ seafile_user=$app
 ynh_script_progression --message="Backing up code..." --weight=3
 ynh_backup --src_path $final_path
 ynh_script_progression --message="Backing up user data..." --weight=10
-ynh_backup --src_path /home/yunohost.app/seafile-data --dest_path "data"
+ynh_backup --src_path=/home/yunohost.app/seafile-data --dest_path="data" --is_big=1
 ynh_script_progression --message="Backing up configuration..."
 ynh_backup --src_path /etc/nginx/conf.d/$domain.d/${app}.conf
 ynh_backup --src_path /etc/systemd/system/seafile.service
diff --git a/scripts/install b/scripts/install
index b60d22a..1cfaa03 100644
--- a/scripts/install
+++ b/scripts/install
@@ -40,6 +40,11 @@ ynh_webpath_register --app $app --domain $domain --path_url $path_url
 
 # Check Final Path availability
 test ! -e "$final_path" || ynh_die --message "This path already contains a folder"
+if [ -e "$seafile_data" ]; then
+    old_data_dir_path="$seafile_data$(date '+%Y%m%d.%H%M%S')"
+    ynh_print_warn "A data directory already exist. Data was renamed to $old_data_dir_path"
+    mv "$seafile_data" "$old_data_dir_path"
+fi
 
 # Find available ports
 ynh_script_progression --message="Finding available ports..."
diff --git a/scripts/remove b/scripts/remove
index 296cc2c..b1df786 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -44,8 +44,6 @@ ynh_secure_remove --file=/var/log/seafile
 ynh_script_progression --message="Removing code..."
 ynh_secure_remove --file=/var/www/$app
 ynh_secure_remove --file=/opt/yunohost/$app
-ynh_script_progression --message="Removing user data..."
-ynh_secure_remove --file=/home/yunohost.app/seafile-data
 ynh_secure_remove --file=/tmp/seahub_cache
 
 # Remove databases
@@ -82,4 +80,7 @@ ynh_script_progression --message="Removing seafile service..."
 yunohost service remove seafile
 yunohost service remove seahub
 
+ynh_print_info --message="Due of the backup core only feature the data directory in '/home/yunohost.app/seafile-data' was not removed. It need to be removed manually to purge app user data."
+
 ynh_script_progression --message="Removal of $app completed" --last
+sleep 1