From a1d68a915c3b53dff45db15dd132538ab201eb7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sat, 23 Mar 2024 00:00:04 +0100 Subject: [PATCH] Uniformize data_dir creation --- scripts/_common.sh | 10 ++++++++++ scripts/install | 24 ++---------------------- scripts/upgrade | 22 +--------------------- 3 files changed, 13 insertions(+), 43 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..0e701fc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,6 +8,16 @@ # PERSONAL HELPERS #================================================= +_create_data_dirs_if_required() { + dirs=(_data galleries upload) + for dir in "${dirs[@]}"; do + if [ ! -d "$data_dir/$dir" ]; then + rsync -a "$install_dir/$dir/" "$data_dir/$dir/" + fi + ynh_secure_remove "$install_dir/$dir" + done +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index f210311..719d0af 100644 --- a/scripts/install +++ b/scripts/install @@ -21,31 +21,11 @@ ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir/plugins/Ldap_Login" --source_id=ldap_plugin ynh_setup_source --dest_dir="$install_dir/plugins" --source_id=log_failed_logins_plugin +_create_data_dirs_if_required + chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" -#================================================= -# CONFIGURE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Initializing data directory..." --weight=1 - -# Move data dirs to $data_dir unless they already exist -if [ -d "$install_dir/_data" ]; then - ynh_secure_remove "$install_dir/_data" -else - mv "$install_dir/_data" "$data_dir/_data" -fi -if [ -d "$install_dir/galleries" ]; then - ynh_secure_remove "$install_dir/galleries" -else - mv "$install_dir/galleries" "$data_dir/galleries" -fi -if [ -d "$install_dir/upload" ]; then - ynh_secure_remove "$install_dir/upload" -else - mv "$install_dir/upload" "$data_dir/upload" -fi - chmod -R o-rwx "$data_dir" chown -R "$app:www-data" "$data_dir" diff --git a/scripts/upgrade b/scripts/upgrade index cb924a5..107fed7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,17 +20,6 @@ if [ -z "${password:-}" ]; then ynh_app_setting_set --app=$app --key=password --value="$password" fi -# Get rid of legacy symlinks -if [ -L "$install_dir/_data" ]; then - ynh_secure_remove "$install_dir/_data" -fi -if [ -L "$install_dir/galleries" ]; then - ynh_secure_remove "$install_dir/galleries" -fi -if [ -L "$install_dir/upload" ]; then - ynh_secure_remove "$install_dir/upload" -fi - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -40,16 +29,7 @@ ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir/plugins/Ldap_Login" --source_id=ldap_plugin ynh_setup_source --dest_dir="$install_dir/plugins" --source_id=log_failed_logins_plugin -# We don't want to keep those in the install dir, they already are in $data_dir -if [ -d "$install_dir/_data" ] && [ ! -L "$install_dir/_data" ]; then - ynh_secure_remove "$install_dir/_data" -fi -if [ -d "$install_dir/galleries" ] && [ ! -L "$install_dir/galleries" ]; then - ynh_secure_remove "$install_dir/galleries" -fi -if [ -d "$install_dir/upload" ] && [ ! -L "$install_dir/upload" ]; then - ynh_secure_remove "$install_dir/upload" -fi +_create_data_dirs_if_required chmod -R o-rwx "$data_dir" chown -R "$app:www-data" "$data_dir"