From abce628819c55b716b515781b00b3e72a18753e2 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Fri, 20 Nov 2020 19:36:35 +0100 Subject: [PATCH] Use yunohost.app directory for picture storage --- conf/.env.example | 2 +- conf/nginx.conf | 4 ++++ scripts/backup | 3 ++- scripts/install | 24 ++++++++++++++---------- scripts/remove | 2 ++ scripts/restore | 8 +++++--- scripts/upgrade | 14 +++++++++++++- 7 files changed, 41 insertions(+), 16 deletions(-) diff --git a/conf/.env.example b/conf/.env.example index 7b8e2a8..db3c0da 100644 --- a/conf/.env.example +++ b/conf/.env.example @@ -33,7 +33,7 @@ TIMEZONE=UTC # folders in which the files will be stored #LYCHEE_DIST="/var/www/__APP__/public/dist/" -#LYCHEE_UPLOADS="/var/www/__APP__/public/uploads/" +LYCHEE_UPLOADS="/home/yunohost.__APP__/uploads/" # url to access those files # LYCHEE_DIST_URL="dist/" diff --git a/conf/nginx.conf b/conf/nginx.conf index 1d7ef8d..0002235 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -26,6 +26,10 @@ location ^~ __PATH__/ { } + location /lychee/uploads/ { + alias __PUBLIC_PATH__/uploads/ ; + } + # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } diff --git a/scripts/backup b/scripts/backup index e7ee942..e5ee3e8 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,6 +24,7 @@ ynh_print_info --message="Backing up Lychee..." app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) +public_path=$(ynh_app_setting_get --app=$app --key=public_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) @@ -38,7 +39,7 @@ ynh_backup --src_path="$final_path" # BACKUP MEDIA FOLDER #================================================= -#ynh_backup --src_path="/home/yunohost.$app" --is_big +ynh_backup --src_path="$public_path" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index 5e5e931..002c00d 100755 --- a/scripts/install +++ b/scripts/install @@ -33,6 +33,9 @@ ynh_script_progression --message="Validating installation parameters..." --weigh final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" +public_path=/home/yunohost.app/$app +test ! -e "${public_path}" || ynh_die --message="${public_path} already exists" + # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -64,13 +67,21 @@ 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" +#================================================= +# CREATE DIRECTORIES +#================================================= + +ynh_app_setting_set --app=$app --key=public_path --value=$public_path +mkdir -p ${public_path}/uploads +mkdir -p ${public_path}/uploads/{big,medium,small,thumb,import} + #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=2 # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_add_nginx_config "public_path" #================================================= # YUNOHOST MULTIMEDIA INTEGRATION @@ -130,21 +141,14 @@ ynh_script_progression --message="Storing the config file checksum..." # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/.env" -#================================================= -# CREATE DIRECTORIES -#================================================= - -#mkdir -p /home/yunohost.${app}/uploads -#mkdir -p /home/yunohost.${app}/uploads/{big,medium,small,thumb,import} - #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions to app files chown -R $app: $final_path -#chown -R $app: /home/yunohost.${app} -#chmod -R 750 /home/yunohost.${app} +chown -R $app: ${public_path} +chmod -R 755 ${public_path} #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 17714d2..066fa3f 100755 --- a/scripts/remove +++ b/scripts/remove @@ -18,6 +18,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +public_path=$(ynh_app_setting_get --app=$app --key=public_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name @@ -30,6 +31,7 @@ ynh_script_progression --message="Removing Lychee main directory..." --weight=3 # Remove the app directory securely ynh_secure_remove --file="$final_path" +ynh_secure_remove --file="$public_path" #================================================= # REMOVE THE MYSQL DATABASE diff --git a/scripts/restore b/scripts/restore index c0296af..a7d6c7d 100755 --- a/scripts/restore +++ b/scripts/restore @@ -25,6 +25,7 @@ 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) +public_path=$(ynh_app_setting_get --app=$app --key=public_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) @@ -65,10 +66,10 @@ ynh_system_user_create --username=$app #================================================= # RESTORE DATA #================================================= -#ynh_script_progression --message="Restoring Lychee data..." +ynh_script_progression --message="Restoring Lychee data..." # Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup. -#ynh_restore_file --origin_path="/home/yunohost.$app" --not_mandatory +ynh_restore_file --origin_path="$public_path" --not_mandatory #================================================= # RESTORE USER RIGHTS @@ -76,7 +77,8 @@ ynh_system_user_create --username=$app # Restore permissions on app files chown -R $app: $final_path -#chmod -R 750 /home/yunohost.$app/{uploads,data} +chown -R $app: $public_path +chmod -R 750 $public_path #================================================= # RESTORE THE PHP-FPM CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index 75e49fa..0fabe13 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +public_path=$(ynh_app_setting_get --app=$app --key=public_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) @@ -56,6 +57,16 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +# If public_path doesn't exist, create it +if [ -z "$public_path" ]; then + public_path=/home/yunohost.app/$app + ynh_app_setting_set --app=$app --key=public_path --value=$public_path +fi + +if [ ! -d "$public_path/uploads" ]; then + mkdir -p $public_path/uploads +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -138,7 +149,8 @@ ynh_store_file_checksum --file="$final_path/.env" # Set permissions on app files chown -R $app: $final_path -#chmod -R 750 /home/yunohost.$app/{uploads,data} +chown -R $app: $public_path +chmod -R 750 $public_path #================================================= # RELOAD NGINX