From cf66fcf71476b4c4630cfcb452427754723469ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 26 Oct 2023 10:14:27 +0200 Subject: [PATCH] Improve data dir management and use find to optimize permission set --- doc/ADMIN.md | 2 +- manifest.toml | 2 +- scripts/_common.sh | 10 +++++----- scripts/backup | 2 +- scripts/upgrade | 9 +++++++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/doc/ADMIN.md b/doc/ADMIN.md index 71e32cc..100ef1d 100644 --- a/doc/ADMIN.md +++ b/doc/ADMIN.md @@ -22,7 +22,7 @@ This app use now the core-only feature of the backup. To keep the integrity of t `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`. +- 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`. - Restart the seafile service with theses command: `systemctl start seafile.service seahub.service` diff --git a/manifest.toml b/manifest.toml index 2fce4b8..1b3f721 100644 --- a/manifest.toml +++ b/manifest.toml @@ -71,7 +71,7 @@ ram.runtime = "500M" subdirs = ["installed", "logs"] [resources.data_dir] - dir = "/home/yunohost.app/seafile-data" + dir = "/home/yunohost.app/__APP__" [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index 0a5b4b2..c557a8b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -75,11 +75,11 @@ set_permission() { test -e $install_dir/seafile-server-latest/seahub/media && setfacl -R -m user:www-data:rX $install_dir/seafile-server-latest/seahub/media test -e $install_dir/seahub-data && setfacl -R -m user:www-data:rX $install_dir/seahub-data - # We also check at the install time when data directory is not already initialised - if [ -e /home/yunohost.app/seafile-data ]; then - chown -R $YNH_APP_ID /home/yunohost.app/seafile-data - chmod -R o= /home/yunohost.app/seafile-data - fi + find $data_dir \( \! -perm -o= \ + -o \! -user $YNH_APP_ID \ + -o \! -group $YNH_APP_ID \) \ + -exec chown $YNH_APP_ID:$YNH_APP_ID {} \; \ + -exec chmod o= {} \; } clean_url_in_db_config() { diff --git a/scripts/backup b/scripts/backup index 372196b..b5a8e07 100644 --- a/scripts/backup +++ b/scripts/backup @@ -26,7 +26,7 @@ fi ynh_print_info --message="Backing up code..." ynh_backup --src_path $install_dir ynh_print_info --message="Backing up user data..." -ynh_backup --src_path=/home/yunohost.app/seafile-data --dest_path="data" --is_big=1 +ynh_backup --src_path=$data_dir --dest_path="data" --is_big=1 ynh_print_info --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/upgrade b/scripts/upgrade index acdf3b2..324b48f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -64,6 +64,15 @@ if [ -z ${seahub_secret_key:-} ]; then ynh_app_setting_set --app $app --key seahub_secret_key --value $seahub_secret_key fi +# Update data dir if needed +if [ $(readlink $install_dir/seafile-data) == '/home/yunohost.app/seafile-data' ]; then + rm $install_dir/seafile-data + ln -s $data_dir $install_dir/seafile-data +fi +if [ -e /home/yunohost.app/seafile-data ]; then + mv /home/yunohost.app/seafile-data $data_dir +fi + ynh_script_progression --message="Upgrading source files..." --weight=6 # Download new version from sources